Mercurial > hg > orthanc
annotate OrthancServer/DicomProtocol/DicomFindAnswers.cpp @ 2082:d2a0c41869ab
fix for sandboxed environments
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 08 Sep 2016 16:27:22 +0200 |
parents | 8e67325eaa3f |
children | 9329ba17a069 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "../PrecompiledHeadersServer.h" |
0 | 34 #include "DicomFindAnswers.h" |
35 | |
36 #include "../FromDcmtkBridge.h" | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
37 #include "../ToDcmtkBridge.h" |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
38 #include "../../Core/OrthancException.h" |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
39 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
40 #include <memory> |
1789 | 41 #include <dcmtk/dcmdata/dcfilefo.h> |
1847 | 42 #include <boost/noncopyable.hpp> |
1789 | 43 |
0 | 44 |
62 | 45 namespace Orthanc |
0 | 46 { |
1847 | 47 class DicomFindAnswers::Answer : public boost::noncopyable |
1789 | 48 { |
49 private: | |
50 ParsedDicomFile* dicom_; | |
51 DicomMap* map_; | |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
52 |
2059 | 53 void CleanupDicom(bool isWorklist) |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
54 { |
2059 | 55 if (isWorklist && |
56 dicom_ != NULL) | |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
57 { |
2059 | 58 // These lines are necessary when serving worklists, otherwise |
59 // Orthanc does not behave as "wlmscpfs" | |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
60 dicom_->Remove(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID); |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
61 dicom_->Remove(DICOM_TAG_SOP_INSTANCE_UID); |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
62 } |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
63 } |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
64 |
1789 | 65 public: |
2059 | 66 Answer(bool isWorklist, |
67 ParsedDicomFile& dicom) : | |
1789 | 68 dicom_(dicom.Clone()), |
69 map_(NULL) | |
70 { | |
2059 | 71 CleanupDicom(isWorklist); |
1789 | 72 } |
73 | |
2059 | 74 Answer(bool isWorklist, |
75 const void* dicom, | |
1789 | 76 size_t size) : |
77 dicom_(new ParsedDicomFile(dicom, size)), | |
78 map_(NULL) | |
79 { | |
2059 | 80 CleanupDicom(isWorklist); |
1789 | 81 } |
82 | |
83 Answer(const DicomMap& map) : | |
84 dicom_(NULL), | |
85 map_(map.Clone()) | |
86 { | |
87 } | |
88 | |
89 ~Answer() | |
90 { | |
91 if (dicom_ != NULL) | |
92 { | |
93 delete dicom_; | |
94 } | |
95 | |
96 if (map_ != NULL) | |
97 { | |
98 delete map_; | |
99 } | |
100 } | |
101 | |
102 ParsedDicomFile& GetDicomFile() | |
103 { | |
104 if (dicom_ == NULL) | |
105 { | |
106 assert(map_ != NULL); | |
107 dicom_ = new ParsedDicomFile(*map_); | |
108 } | |
109 | |
110 return *dicom_; | |
111 } | |
112 | |
113 DcmDataset* ExtractDcmDataset() const | |
114 { | |
115 if (dicom_ != NULL) | |
116 { | |
117 return new DcmDataset(*dicom_->GetDcmtkObject().getDataset()); | |
118 } | |
119 else | |
120 { | |
121 assert(map_ != NULL); | |
122 return ToDcmtkBridge::Convert(*map_); | |
123 } | |
124 } | |
125 }; | |
126 | |
127 | |
2059 | 128 void DicomFindAnswers::SetWorklist(bool isWorklist) |
129 { | |
130 if (answers_.empty()) | |
131 { | |
132 isWorklist_ = isWorklist; | |
133 } | |
134 else | |
135 { | |
136 // This set of answers is not empty anymore, cannot change its type | |
137 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
138 } | |
139 } | |
140 | |
141 | |
0 | 142 void DicomFindAnswers::Clear() |
143 { | |
1789 | 144 for (size_t i = 0; i < answers_.size(); i++) |
0 | 145 { |
1789 | 146 assert(answers_[i] != NULL); |
147 delete answers_[i]; | |
0 | 148 } |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
149 |
1789 | 150 answers_.clear(); |
0 | 151 } |
152 | |
1789 | 153 |
0 | 154 void DicomFindAnswers::Reserve(size_t size) |
155 { | |
1789 | 156 if (size > answers_.size()) |
0 | 157 { |
1789 | 158 answers_.reserve(size); |
0 | 159 } |
160 } | |
161 | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
162 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
163 void DicomFindAnswers::Add(const DicomMap& map) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
164 { |
1789 | 165 answers_.push_back(new Answer(map)); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
166 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
167 |
1789 | 168 |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
169 void DicomFindAnswers::Add(ParsedDicomFile& dicom) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
170 { |
2059 | 171 answers_.push_back(new Answer(isWorklist_, dicom)); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
172 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
173 |
1789 | 174 |
1995
f0acfa753973
New callback to handle non-worklists C-Find requests: OrthancPluginRegisterCFindCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
175 void DicomFindAnswers::Add(const void* dicom, |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
176 size_t size) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
177 { |
2059 | 178 answers_.push_back(new Answer(isWorklist_, dicom, size)); |
1789 | 179 } |
180 | |
181 | |
182 DicomFindAnswers::Answer& DicomFindAnswers::GetAnswerInternal(size_t index) const | |
183 { | |
184 if (index < answers_.size()) | |
185 { | |
186 return *answers_.at(index); | |
187 } | |
188 else | |
189 { | |
190 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
191 } | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
192 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
193 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
194 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
195 ParsedDicomFile& DicomFindAnswers::GetAnswer(size_t index) const |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
196 { |
1789 | 197 return GetAnswerInternal(index).GetDicomFile(); |
198 } | |
199 | |
200 | |
201 DcmDataset* DicomFindAnswers::ExtractDcmDataset(size_t index) const | |
202 { | |
203 return GetAnswerInternal(index).ExtractDcmDataset(); | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
204 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
205 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
206 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
207 void DicomFindAnswers::ToJson(Json::Value& target, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
208 size_t index, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
209 bool simplify) const |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
210 { |
1860
c7d70f659190
DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
211 DicomToJsonFormat format = (simplify ? DicomToJsonFormat_Human : DicomToJsonFormat_Full); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
212 GetAnswer(index).ToJson(target, format, DicomToJsonFlags_None, 0); |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
213 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
214 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
215 |
1368 | 216 void DicomFindAnswers::ToJson(Json::Value& target, |
217 bool simplify) const | |
0 | 218 { |
219 target = Json::arrayValue; | |
220 | |
221 for (size_t i = 0; i < GetSize(); i++) | |
222 { | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
223 Json::Value answer; |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
224 ToJson(answer, i, simplify); |
0 | 225 target.append(answer); |
226 } | |
227 } | |
228 } |