Mercurial > hg > orthanc
comparison OrthancServer/Search/LookupResource.cpp @ 3012:af1530b45290
Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Dec 2018 17:54:06 +0100 |
parents | 8265a6b56100 |
children | 4e43e67f8ecf |
comparison
equal
deleted
inserted
replaced
3010:9f859a18cbc2 | 3012:af1530b45290 |
---|---|
40 #include "../../Core/DicomParsing/FromDcmtkBridge.h" | 40 #include "../../Core/DicomParsing/FromDcmtkBridge.h" |
41 | 41 |
42 | 42 |
43 namespace Orthanc | 43 namespace Orthanc |
44 { | 44 { |
45 static bool DoesDicomMapMatch(const DicomMap& dicom, | |
46 const DicomTag& tag, | |
47 const IFindConstraint& constraint) | |
48 { | |
49 const DicomValue* value = dicom.TestAndGetValue(tag); | |
50 | |
51 return (value != NULL && | |
52 !value->IsNull() && | |
53 !value->IsBinary() && | |
54 constraint.Match(value->GetContent())); | |
55 } | |
56 | |
57 | |
45 LookupResource::Level::Level(ResourceType level) : level_(level) | 58 LookupResource::Level::Level(ResourceType level) : level_(level) |
46 { | 59 { |
47 const DicomTag* tags = NULL; | 60 const DicomTag* tags = NULL; |
48 size_t size; | 61 size_t size; |
49 | 62 |
116 // This is not a main DICOM tag | 129 // This is not a main DICOM tag |
117 return false; | 130 return false; |
118 } | 131 } |
119 } | 132 } |
120 | 133 |
134 | |
135 bool LookupResource::Level::IsMatch(const DicomMap& dicom) const | |
136 { | |
137 for (Constraints::const_iterator it = identifiersConstraints_.begin(); | |
138 it != identifiersConstraints_.end(); ++it) | |
139 { | |
140 assert(it->second != NULL); | |
141 | |
142 if (!DoesDicomMapMatch(dicom, it->first, *it->second)) | |
143 { | |
144 return false; | |
145 } | |
146 } | |
147 | |
148 for (Constraints::const_iterator it = mainTagsConstraints_.begin(); | |
149 it != mainTagsConstraints_.end(); ++it) | |
150 { | |
151 assert(it->second != NULL); | |
152 | |
153 if (!DoesDicomMapMatch(dicom, it->first, *it->second)) | |
154 { | |
155 return false; | |
156 } | |
157 } | |
158 | |
159 return true; | |
160 } | |
161 | |
121 | 162 |
122 LookupResource::LookupResource(ResourceType level) : level_(level) | 163 LookupResource::LookupResource(ResourceType level) : level_(level) |
123 { | 164 { |
124 switch (level) | 165 switch (level) |
125 { | 166 { |
281 } | 322 } |
282 } | 323 } |
283 | 324 |
284 | 325 |
285 | 326 |
286 bool LookupResource::IsMatch(const Json::Value& dicomAsJson) const | 327 bool LookupResource::IsMatch(const DicomMap& dicom) const |
287 { | 328 { |
329 for (Levels::const_iterator it = levels_.begin(); it != levels_.end(); ++it) | |
330 { | |
331 if (!it->second->IsMatch(dicom)) | |
332 { | |
333 return false; | |
334 } | |
335 } | |
336 | |
288 for (Constraints::const_iterator it = unoptimizedConstraints_.begin(); | 337 for (Constraints::const_iterator it = unoptimizedConstraints_.begin(); |
289 it != unoptimizedConstraints_.end(); ++it) | 338 it != unoptimizedConstraints_.end(); ++it) |
290 { | 339 { |
291 std::string tag = it->first.Format(); | 340 assert(it->second != NULL); |
292 if (dicomAsJson.isMember(tag) && | 341 |
293 dicomAsJson[tag]["Type"] == "String") | 342 if (!DoesDicomMapMatch(dicom, it->first, *it->second)) |
294 { | |
295 std::string value = dicomAsJson[tag]["Value"].asString(); | |
296 if (!it->second->Match(value)) | |
297 { | |
298 return false; | |
299 } | |
300 } | |
301 else | |
302 { | 343 { |
303 return false; | 344 return false; |
304 } | 345 } |
305 } | 346 } |
306 | 347 |