annotate OrthancStone/Sources/Oracle/ParseDicomSuccessMessage.cpp @ 1928:c73e696967b0 StoneWebViewer-2.3

StoneWebViewer-2.3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Mar 2022 09:08:51 +0100
parents 7053b8a0aaec
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1151
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
1151
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
20 * <http://www.gnu.org/licenses/>.
1151
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
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 "ParseDicomSuccessMessage.h"
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
26 #include <DicomParsing/ParsedDicomFile.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
27 #include <HttpServer/MultipartStreamReader.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
28 #include <OrthancException.h>
1151
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancStone
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 class MultipartHandler : public Orthanc::MultipartStreamReader::IHandler
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 private:
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
35 std::unique_ptr<Orthanc::ParsedDicomFile> dicom_;
1151
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 size_t size_;
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 public:
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 MultipartHandler() :
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 size_(0)
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 virtual void HandlePart(const std::map<std::string, std::string>& headers,
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 const void* part,
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
46 size_t size) ORTHANC_OVERRIDE
1151
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 if (dicom_.get())
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 "Multiple DICOM instances were contained in a WADO-RS request");
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 else
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 dicom_.reset(new Orthanc::ParsedDicomFile(part, size));
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 size_ = size;
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 Orthanc::ParsedDicomFile* ReleaseDicom()
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 if (dicom_.get())
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 return dicom_.release();
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 else
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 "WADO-RS request didn't contain any DICOM instance");
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 size_t GetSize() const
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 return size_;
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
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 Orthanc::ParsedDicomFile* ParseDicomSuccessMessage::ParseWadoAnswer(
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 size_t& fileSize /* OUT */,
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 const std::string& answer,
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 const std::map<std::string, std::string>& headers)
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 std::string contentType, subType, boundary, header;
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 if (Orthanc::MultipartStreamReader::GetMainContentType(header, headers) &&
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 Orthanc::MultipartStreamReader::ParseMultipartContentType(contentType, subType, boundary, header) &&
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 contentType == "multipart/related" &&
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 subType == "application/dicom")
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 MultipartHandler handler;
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 Orthanc::MultipartStreamReader reader(boundary);
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 reader.SetHandler(handler);
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 reader.AddChunk(answer);
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 reader.CloseStream();
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 fileSize = handler.GetSize();
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return handler.ReleaseDicom();
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 else
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 "Multipart/related answer of application/dicom was expected from DICOMweb server");
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
48befc2bf66d ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }