Mercurial > hg > orthanc-stone
annotate Framework/Oracle/ParseDicomSuccessMessage.cpp @ 1326:55166e57a77c broker
doc
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 24 Mar 2020 21:32:35 +0100 |
parents | c38c89684d83 |
children | 30deba7bc8e2 |
rev | line source |
---|---|
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1271
0ca50d275b9a
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1151
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "ParseDicomSuccessMessage.h" |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include <Core/DicomParsing/ParsedDicomFile.h> |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include <Core/HttpServer/MultipartStreamReader.h> |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include <Core/OrthancException.h> |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 namespace OrthancStone |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 class MultipartHandler : public Orthanc::MultipartStreamReader::IHandler |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 private: |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1271
diff
changeset
|
33 std::unique_ptr<Orthanc::ParsedDicomFile> dicom_; |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 size_t size_; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 public: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 MultipartHandler() : |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 size_(0) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 virtual void HandlePart(const std::map<std::string, std::string>& headers, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 const void* part, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 size_t size) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 if (dicom_.get()) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 "Multiple DICOM instances were contained in a WADO-RS request"); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 else |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 dicom_.reset(new Orthanc::ParsedDicomFile(part, size)); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 size_ = size; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 Orthanc::ParsedDicomFile* ReleaseDicom() |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 if (dicom_.get()) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 return dicom_.release(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 else |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 "WADO-RS request didn't contain any DICOM instance"); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 size_t GetSize() const |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 return size_; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 }; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 Orthanc::ParsedDicomFile* ParseDicomSuccessMessage::ParseWadoAnswer( |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 size_t& fileSize /* OUT */, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 const std::string& answer, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 const std::map<std::string, std::string>& headers) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 std::string contentType, subType, boundary, header; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 if (Orthanc::MultipartStreamReader::GetMainContentType(header, headers) && |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 Orthanc::MultipartStreamReader::ParseMultipartContentType(contentType, subType, boundary, header) && |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 contentType == "multipart/related" && |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 subType == "application/dicom") |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 MultipartHandler handler; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 Orthanc::MultipartStreamReader reader(boundary); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 reader.SetHandler(handler); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 reader.AddChunk(answer); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 reader.CloseStream(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 fileSize = handler.GetSize(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 return handler.ReleaseDicom(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 else |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 "Multipart/related answer of application/dicom was expected from DICOMweb server"); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |