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