Mercurial > hg > orthanc
annotate OrthancServer/OrthancFindRequestHandler.cpp @ 1331:77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Mar 2015 10:47:32 +0100 |
parents | 6e7e5ed91c2d |
children | f2033e228864 |
rev | line source |
---|---|
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * License, or (at your option) any later version. |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * program give permission to link the code of its release with the |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * in the program, then also delete it here. |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * General Public License for more details. |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 **/ |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
32 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "PrecompiledHeadersServer.h" |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "OrthancFindRequestHandler.h" |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include <glog/logging.h> |
608 | 37 #include <boost/regex.hpp> |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include "../Core/DicomFormat/DicomArray.h" |
608 | 40 #include "ServerToolbox.h" |
618 | 41 #include "OrthancInitialization.h" |
795 | 42 #include "FromDcmtkBridge.h" |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 namespace Orthanc |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
615 | 46 static bool IsWildcard(const std::string& constraint) |
47 { | |
48 return (constraint.find('-') != std::string::npos || | |
49 constraint.find('*') != std::string::npos || | |
50 constraint.find('\\') != std::string::npos || | |
51 constraint.find('?') != std::string::npos); | |
52 } | |
53 | |
608 | 54 static bool ApplyRangeConstraint(const std::string& value, |
55 const std::string& constraint) | |
56 { | |
610 | 57 size_t separator = constraint.find('-'); |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
58 std::string lower, upper, v; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
59 Toolbox::ToLowerCase(lower, constraint.substr(0, separator)); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
60 Toolbox::ToLowerCase(upper, constraint.substr(separator + 1)); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
61 Toolbox::ToLowerCase(v, value); |
610 | 62 |
63 if (lower.size() == 0 && upper.size() == 0) | |
64 { | |
65 return false; | |
66 } | |
67 | |
68 if (lower.size() == 0) | |
69 { | |
70 return v <= upper; | |
71 } | |
72 | |
73 if (upper.size() == 0) | |
74 { | |
75 return v >= lower; | |
76 } | |
77 | |
78 return (v >= lower && v <= upper); | |
608 | 79 } |
80 | |
81 | |
82 static bool ApplyListConstraint(const std::string& value, | |
83 const std::string& constraint) | |
84 { | |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
85 std::string v1; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
86 Toolbox::ToLowerCase(v1, value); |
608 | 87 |
88 std::vector<std::string> items; | |
89 Toolbox::TokenizeString(items, constraint, '\\'); | |
90 | |
91 for (size_t i = 0; i < items.size(); i++) | |
92 { | |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
93 std::string lower; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
94 Toolbox::ToLowerCase(lower, items[i]); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
95 if (lower == v1) |
608 | 96 { |
97 return true; | |
98 } | |
99 } | |
100 | |
101 return false; | |
102 } | |
103 | |
104 | |
105 static bool Matches(const std::string& value, | |
106 const std::string& constraint) | |
107 { | |
108 // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained | |
109 // http://dicomiseasy.blogspot.be/2012/01/dicom-queryretrieve-part-i.html | |
110 | |
111 if (constraint.find('-') != std::string::npos) | |
112 { | |
113 return ApplyRangeConstraint(value, constraint); | |
114 } | |
115 | |
116 if (constraint.find('\\') != std::string::npos) | |
117 { | |
118 return ApplyListConstraint(value, constraint); | |
119 } | |
120 | |
121 if (constraint.find('*') != std::string::npos || | |
122 constraint.find('?') != std::string::npos) | |
123 { | |
124 // TODO - Cache the constructed regular expression | |
125 boost::regex pattern(Toolbox::WildcardToRegularExpression(constraint), | |
126 boost::regex::icase /* case insensitive search */); | |
127 return boost::regex_match(value, pattern); | |
128 } | |
129 else | |
130 { | |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
131 std::string v, c; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
132 Toolbox::ToLowerCase(v, value); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
133 Toolbox::ToLowerCase(c, constraint); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
134 return v == c; |
608 | 135 } |
136 } | |
137 | |
138 | |
139 static bool LookupOneInstance(std::string& result, | |
140 ServerIndex& index, | |
141 const std::string& id, | |
142 ResourceType type) | |
143 { | |
144 if (type == ResourceType_Instance) | |
145 { | |
146 result = id; | |
147 return true; | |
148 } | |
149 | |
150 std::string childId; | |
151 | |
152 { | |
153 std::list<std::string> children; | |
154 index.GetChildInstances(children, id); | |
155 | |
656 | 156 if (children.empty()) |
608 | 157 { |
158 return false; | |
159 } | |
160 | |
161 childId = children.front(); | |
162 } | |
163 | |
164 return LookupOneInstance(result, index, childId, GetChildResourceType(type)); | |
165 } | |
166 | |
167 | |
168 static bool Matches(const Json::Value& resource, | |
169 const DicomArray& query) | |
170 { | |
171 for (size_t i = 0; i < query.GetSize(); i++) | |
172 { | |
173 if (query.GetElement(i).GetValue().IsNull() || | |
174 query.GetElement(i).GetTag() == DICOM_TAG_QUERY_RETRIEVE_LEVEL || | |
611
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
175 query.GetElement(i).GetTag() == DICOM_TAG_SPECIFIC_CHARACTER_SET || |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
176 query.GetElement(i).GetTag() == DICOM_TAG_MODALITIES_IN_STUDY) |
608 | 177 { |
178 continue; | |
179 } | |
180 | |
181 std::string tag = query.GetElement(i).GetTag().Format(); | |
182 std::string value; | |
183 if (resource.isMember(tag)) | |
184 { | |
185 value = resource.get(tag, Json::arrayValue).get("Value", "").asString(); | |
186 } | |
187 | |
188 if (!Matches(value, query.GetElement(i).GetValue().AsString())) | |
189 { | |
190 return false; | |
191 } | |
192 } | |
193 | |
194 return true; | |
195 } | |
196 | |
197 | |
198 static void AddAnswer(DicomFindAnswers& answers, | |
199 const Json::Value& resource, | |
1331
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
200 const DicomArray& query, |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
201 bool isFirst) |
608 | 202 { |
203 DicomMap result; | |
204 | |
205 for (size_t i = 0; i < query.GetSize(); i++) | |
206 { | |
207 if (query.GetElement(i).GetTag() != DICOM_TAG_QUERY_RETRIEVE_LEVEL && | |
208 query.GetElement(i).GetTag() != DICOM_TAG_SPECIFIC_CHARACTER_SET) | |
209 { | |
210 std::string tag = query.GetElement(i).GetTag().Format(); | |
211 std::string value; | |
212 if (resource.isMember(tag)) | |
213 { | |
214 value = resource.get(tag, Json::arrayValue).get("Value", "").asString(); | |
215 result.SetValue(query.GetElement(i).GetTag(), value); | |
216 } | |
722 | 217 else |
218 { | |
219 result.SetValue(query.GetElement(i).GetTag(), ""); | |
220 } | |
608 | 221 } |
222 } | |
223 | |
1331
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
224 if (result.GetSize() == 0) |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
225 { |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
226 if (isFirst) |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
227 { |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
228 LOG(WARNING) << "The C-FIND request does not return any DICOM tag"; |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
229 } |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
230 } |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
231 else |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
232 { |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
233 answers.Add(result); |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
234 } |
608 | 235 } |
236 | |
237 | |
615 | 238 static bool ApplyModalitiesInStudyFilter(std::list<std::string>& filteredStudies, |
239 const std::list<std::string>& studies, | |
612 | 240 const DicomMap& input, |
241 ServerIndex& index) | |
242 { | |
615 | 243 filteredStudies.clear(); |
612 | 244 |
245 const DicomValue& v = input.GetValue(DICOM_TAG_MODALITIES_IN_STUDY); | |
246 if (v.IsNull()) | |
247 { | |
248 return false; | |
249 } | |
250 | |
251 // Move the allowed modalities into a "std::set" | |
252 std::vector<std::string> tmp; | |
253 Toolbox::TokenizeString(tmp, v.AsString(), '\\'); | |
254 | |
255 std::set<std::string> modalities; | |
256 for (size_t i = 0; i < tmp.size(); i++) | |
257 { | |
258 modalities.insert(tmp[i]); | |
259 } | |
260 | |
261 // Loop over the studies | |
615 | 262 for (std::list<std::string>::const_iterator |
656 | 263 it = studies.begin(); it != studies.end(); ++it) |
612 | 264 { |
265 try | |
266 { | |
267 // We are considering a single study. Check whether one of | |
268 // its child series matches one of the modalities. | |
269 Json::Value study; | |
615 | 270 if (index.LookupResource(study, *it, ResourceType_Study)) |
612 | 271 { |
272 // Loop over the series of the considered study. | |
273 for (Json::Value::ArrayIndex j = 0; j < study["Series"].size(); j++) // (*) | |
274 { | |
275 Json::Value series; | |
276 if (index.LookupResource(series, study["Series"][j].asString(), ResourceType_Series)) | |
277 { | |
278 // Get the modality of this series | |
279 if (series["MainDicomTags"].isMember("Modality")) | |
280 { | |
281 std::string modality = series["MainDicomTags"]["Modality"].asString(); | |
282 if (modalities.find(modality) != modalities.end()) | |
283 { | |
284 // This series of the considered study matches one | |
285 // of the required modalities. Take the study into | |
286 // consideration for future filtering. | |
615 | 287 filteredStudies.push_back(*it); |
612 | 288 |
289 // We have finished considering this study. Break the study loop at (*). | |
290 break; | |
291 } | |
292 } | |
293 } | |
294 } | |
295 } | |
296 } | |
297 catch (OrthancException&) | |
298 { | |
299 // This resource has probably been deleted during the find request | |
300 } | |
301 } | |
302 | |
303 return true; | |
304 } | |
305 | |
306 | |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
307 namespace |
615 | 308 { |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
309 class CandidateResources |
615 | 310 { |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
311 private: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
312 ServerIndex& index_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
313 ModalityManufacturer manufacturer_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
314 ResourceType level_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
315 bool isFilterApplied_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
316 std::set<std::string> filtered_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
317 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
318 static void ListToSet(std::set<std::string>& target, |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
319 const std::list<std::string>& source) |
615 | 320 { |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
321 for (std::list<std::string>::const_iterator |
716 | 322 it = source.begin(); it != source.end(); ++it) |
615 | 323 { |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
324 target.insert(*it); |
615 | 325 } |
326 } | |
327 | |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
328 void ApplyExactFilter(const DicomTag& tag, const std::string& value) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
329 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
330 LOG(INFO) << "Applying exact filter on tag " |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
331 << FromDcmtkBridge::GetName(tag) << " (value: " << value << ")"; |
615 | 332 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
333 std::list<std::string> resources; |
1162 | 334 index_.LookupIdentifier(resources, tag, value, level_); |
615 | 335 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
336 if (isFilterApplied_) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
337 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
338 std::set<std::string> s; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
339 ListToSet(s, resources); |
615 | 340 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
341 std::set<std::string> tmp = filtered_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
342 filtered_.clear(); |
615 | 343 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
344 for (std::set<std::string>::const_iterator |
716 | 345 it = tmp.begin(); it != tmp.end(); ++it) |
665 | 346 { |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
347 if (s.find(*it) != s.end()) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
348 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
349 filtered_.insert(*it); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
350 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
351 } |
665 | 352 } |
353 else | |
354 { | |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
355 assert(filtered_.empty()); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
356 isFilterApplied_ = true; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
357 ListToSet(filtered_, resources); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
358 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
359 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
360 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
361 public: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
362 CandidateResources(ServerIndex& index, |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
363 ModalityManufacturer manufacturer) : |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
364 index_(index), |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
365 manufacturer_(manufacturer), |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
366 level_(ResourceType_Patient), |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
367 isFilterApplied_(false) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
368 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
369 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
370 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
371 ResourceType GetLevel() const |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
372 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
373 return level_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
374 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
375 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
376 void GoDown() |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
377 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
378 assert(level_ != ResourceType_Instance); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
379 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
380 if (isFilterApplied_) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
381 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
382 std::set<std::string> tmp = filtered_; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
383 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
384 filtered_.clear(); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
385 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
386 for (std::set<std::string>::const_iterator |
716 | 387 it = tmp.begin(); it != tmp.end(); ++it) |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
388 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
389 std::list<std::string> children; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
390 index_.GetChildren(children, *it); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
391 ListToSet(filtered_, children); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
392 } |
665 | 393 } |
394 | |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
395 switch (level_) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
396 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
397 case ResourceType_Patient: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
398 level_ = ResourceType_Study; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
399 break; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
400 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
401 case ResourceType_Study: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
402 level_ = ResourceType_Series; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
403 break; |
615 | 404 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
405 case ResourceType_Series: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
406 level_ = ResourceType_Instance; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
407 break; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
408 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
409 default: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
410 throw OrthancException(ErrorCode_InternalError); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
411 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
412 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
413 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
414 void Flatten(std::list<std::string>& resources) const |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
415 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
416 resources.clear(); |
615 | 417 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
418 if (isFilterApplied_) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
419 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
420 for (std::set<std::string>::const_iterator |
716 | 421 it = filtered_.begin(); it != filtered_.end(); ++it) |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
422 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
423 resources.push_back(*it); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
424 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
425 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
426 else |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
427 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
428 Json::Value tmp; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
429 index_.GetAllUuids(tmp, level_); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
430 for (Json::Value::ArrayIndex i = 0; i < tmp.size(); i++) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
431 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
432 resources.push_back(tmp[i].asString()); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
433 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
434 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
435 } |
615 | 436 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
437 void ApplyFilter(const DicomTag& tag, const DicomMap& query) |
615 | 438 { |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
439 if (query.HasTag(tag)) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
440 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
441 const DicomValue& value = query.GetValue(tag); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
442 if (!value.IsNull()) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
443 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
444 std::string value = query.GetValue(tag).AsString(); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
445 if (!IsWildcard(value)) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
446 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
447 ApplyExactFilter(tag, value); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
448 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
449 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
450 } |
615 | 451 } |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
452 }; |
615 | 453 } |
454 | |
455 | |
941
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
456 bool OrthancFindRequestHandler::HasReachedLimit(const DicomFindAnswers& answers, |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
457 ResourceType level) const |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
458 { |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
459 switch (level) |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
460 { |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
461 case ResourceType_Patient: |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
462 case ResourceType_Study: |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
463 case ResourceType_Series: |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
464 return (maxResults_ != 0 && answers.GetSize() >= maxResults_); |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
465 |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
466 case ResourceType_Instance: |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
467 return (maxInstances_ != 0 && answers.GetSize() >= maxInstances_); |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
468 |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
469 default: |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
470 throw OrthancException(ErrorCode_InternalError); |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
471 } |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
472 } |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
473 |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
474 |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
475 bool OrthancFindRequestHandler::Handle(DicomFindAnswers& answers, |
665 | 476 const DicomMap& input, |
477 const std::string& callingAETitle) | |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
478 { |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
479 /** |
665 | 480 * Retrieve the manufacturer of this modality. |
481 **/ | |
482 | |
483 ModalityManufacturer manufacturer; | |
484 | |
485 { | |
806 | 486 RemoteModalityParameters modality; |
665 | 487 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
488 if (!Configuration::LookupDicomModalityUsingAETitle(modality, callingAETitle)) |
665 | 489 { |
490 throw OrthancException("Unknown modality"); | |
491 } | |
806 | 492 |
493 manufacturer = modality.GetManufacturer(); | |
665 | 494 } |
495 | |
496 | |
497 /** | |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
498 * Retrieve the query level. |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
499 **/ |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
500 |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL); |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
502 if (levelTmp == NULL) |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
503 { |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
504 throw OrthancException(ErrorCode_BadRequest); |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
505 } |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
506 |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
507 ResourceType level = StringToResourceType(levelTmp->AsString().c_str()); |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
508 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
509 if (level != ResourceType_Patient && |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
510 level != ResourceType_Study && |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
511 level != ResourceType_Series && |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
512 level != ResourceType_Instance) |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
513 { |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
514 throw OrthancException(ErrorCode_NotImplemented); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
515 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
516 |
665 | 517 |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
518 DicomArray query(input); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
519 LOG(INFO) << "DICOM C-Find request at level: " << EnumerationToString(level); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
520 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
521 for (size_t i = 0; i < query.GetSize(); i++) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
522 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
523 if (!query.GetElement(i).GetValue().IsNull()) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
524 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
525 LOG(INFO) << " " << query.GetElement(i).GetTag() |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
526 << " " << FromDcmtkBridge::GetName(query.GetElement(i).GetTag()) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
527 << " = " << query.GetElement(i).GetValue().AsString(); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
528 } |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
529 } |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
530 |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
531 |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
532 /** |
615 | 533 * Retrieve the candidate resources for this query level. Whenever |
534 * possible, we avoid returning ALL the resources for this query | |
535 * level, as it would imply reading the JSON file on the harddisk | |
536 * for each of them. | |
608 | 537 **/ |
538 | |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
539 CandidateResources candidates(context_.GetIndex(), manufacturer); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
540 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
541 for (;;) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
542 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
543 switch (candidates.GetLevel()) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
544 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
545 case ResourceType_Patient: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
546 candidates.ApplyFilter(DICOM_TAG_PATIENT_ID, input); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
547 break; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
548 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
549 case ResourceType_Study: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
550 candidates.ApplyFilter(DICOM_TAG_STUDY_INSTANCE_UID, input); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
551 candidates.ApplyFilter(DICOM_TAG_ACCESSION_NUMBER, input); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
552 break; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
553 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
554 case ResourceType_Series: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
555 candidates.ApplyFilter(DICOM_TAG_SERIES_INSTANCE_UID, input); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
556 break; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
557 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
558 case ResourceType_Instance: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
559 candidates.ApplyFilter(DICOM_TAG_SOP_INSTANCE_UID, input); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
560 break; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
561 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
562 default: |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
563 throw OrthancException(ErrorCode_InternalError); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
564 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
565 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
566 if (candidates.GetLevel() == level) |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
567 { |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
568 break; |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
569 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
570 |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
571 candidates.GoDown(); |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
572 } |
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
573 |
615 | 574 std::list<std::string> resources; |
714
6a1dbba0cca7
new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
575 candidates.Flatten(resources); |
608 | 576 |
611
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
577 |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
578 /** |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
579 * Apply filtering on modalities for studies, if asked (this is an |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
580 * extension to standard DICOM) |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
581 * http://www.medicalconnections.co.uk/kb/Filtering_on_and_Retrieving_the_Modality_in_a_C_FIND |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
582 **/ |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
583 |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
584 if (level == ResourceType_Study && |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
585 input.HasTag(DICOM_TAG_MODALITIES_IN_STUDY)) |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
586 { |
615 | 587 std::list<std::string> filtered; |
612 | 588 if (ApplyModalitiesInStudyFilter(filtered, resources, input, context_.GetIndex())) |
611
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
589 { |
612 | 590 resources = filtered; |
611
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
591 } |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
592 } |
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
593 |
608 | 594 /** |
595 * Loop over all the resources for this query level. | |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
596 **/ |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
597 |
1331
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
598 LOG(INFO) << "Number of candidate resources after exact filtering on the identifiers only: " << resources.size(); |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
599 |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
600 bool isFirst = true; |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
601 |
615 | 602 for (std::list<std::string>::const_iterator |
656 | 603 resource = resources.begin(); resource != resources.end(); ++resource) |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
604 { |
608 | 605 try |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
606 { |
608 | 607 std::string instance; |
615 | 608 if (LookupOneInstance(instance, context_.GetIndex(), *resource, level)) |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
609 { |
615 | 610 Json::Value info; |
611 context_.ReadJson(info, instance); | |
1331
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
612 |
615 | 613 if (Matches(info, query)) |
608 | 614 { |
941
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
615 if (HasReachedLimit(answers, level)) |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
616 { |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
617 // Too many results, stop before recording this new match |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
618 return false; |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
619 } |
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
620 |
1331
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
621 AddAnswer(answers, info, query, isFirst); |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
622 isFirst = false; |
608 | 623 } |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
624 } |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
625 } |
608 | 626 catch (OrthancException&) |
627 { | |
611
9924aec1d694
filtering on modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
610
diff
changeset
|
628 // This resource has probably been deleted during the find request |
608 | 629 } |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
630 } |
941
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
631 |
1331
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
632 LOG(INFO) << "Number of candidate resources after filtering on all tags: " << answers.GetSize(); |
77e129ba64e4
Prevent freeze on C-FIND if no DICOM tag is to be returned
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
633 |
941
83489fddd8c5
Options to limit the number of results for an incoming C-FIND query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
634 return true; // All the matching resources have been returned |
565
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
635 } |
c931ac02db82
refactoring of find class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
636 } |
682
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
637 |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
638 |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
639 |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
640 /** |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
641 * TODO : Case-insensitive match for PN value representation (Patient |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
642 * Name). Case-senstive match for all the other value representations. |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
643 * |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
644 * Reference: DICOM PS 3.4 |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
645 * - C.2.2.2.1 ("Single Value Matching") |
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
646 * - C.2.2.2.4 ("Wild Card Matching") |
1070 | 647 * http://medical.nema.org/Dicom/2011/11_04pu.pdf |
648 * | |
649 * "Except for Attributes with a PN Value Representation, only | |
650 * entities with values which match exactly the value specified in the | |
651 * request shall match. This matching is case-sensitive, i.e., | |
652 * sensitive to the exact encoding of the key attribute value in | |
653 * character sets where a letter may have multiple encodings (e.g., | |
654 * based on its case, its position in a word, or whether it is | |
655 * accented) | |
656 * | |
657 * For Attributes with a PN Value Representation (e.g., Patient Name | |
658 * (0010,0010)), an application may perform literal matching that is | |
659 * either case-sensitive, or that is insensitive to some or all | |
660 * aspects of case, position, accent, or other character encoding | |
661 * variants." | |
662 * | |
663 * (0008,0018) UI SOPInstanceUID => Case-sensitive | |
664 * (0008,0050) SH AccessionNumber => Case-sensitive | |
665 * (0010,0020) LO PatientID => Case-sensitive | |
666 * (0020,000D) UI StudyInstanceUID => Case-sensitive | |
667 * (0020,000E) UI SeriesInstanceUID => Case-sensitive | |
682
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
665
diff
changeset
|
668 **/ |