comparison OrthancServer/ResourceFinder.cpp @ 1353:d7da97e21161

ResourceFinder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 12 May 2015 18:27:14 +0200
parents 382439943749
children 3dd494f201a1
comparison
equal deleted inserted replaced
1352:382439943749 1353:d7da97e21161
58 namespace 58 namespace
59 { 59 {
60 class CandidateResources 60 class CandidateResources
61 { 61 {
62 private: 62 private:
63 typedef std::map<DicomTag, std::string> Query;
64
63 ServerIndex& index_; 65 ServerIndex& index_;
64 ResourceType level_; 66 ResourceType level_;
65 bool isFilterApplied_; 67 bool isFilterApplied_;
66 std::set<std::string> filtered_; 68 std::set<std::string> filtered_;
67 69
71 { 73 {
72 for (std::list<std::string>::const_iterator 74 for (std::list<std::string>::const_iterator
73 it = source.begin(); it != source.end(); ++it) 75 it = source.begin(); it != source.end(); ++it)
74 { 76 {
75 target.insert(*it); 77 target.insert(*it);
78 }
79 }
80
81
82 void RestrictIdentifier(const DicomTag& tag,
83 const std::string& value)
84 {
85 assert((level_ == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) ||
86 (level_ == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) ||
87 (level_ == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) ||
88 (level_ == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) ||
89 (level_ == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID));
90
91 LOG(INFO) << "Lookup for identifier tag "
92 << FromDcmtkBridge::GetName(tag) << " (value: " << value << ")";
93
94 std::list<std::string> resources;
95 index_.LookupIdentifier(resources, tag, value, level_);
96
97 if (isFilterApplied_)
98 {
99 std::set<std::string> s;
100 ListToSet(s, resources);
101
102 std::set<std::string> tmp = filtered_;
103 filtered_.clear();
104
105 for (std::set<std::string>::const_iterator
106 it = tmp.begin(); it != tmp.end(); ++it)
107 {
108 if (s.find(*it) != s.end())
109 {
110 filtered_.insert(*it);
111 }
112 }
113 }
114 else
115 {
116 assert(filtered_.empty());
117 isFilterApplied_ = true;
118 ListToSet(filtered_, resources);
119 }
120 }
121
122
123 void RestrictIdentifier(const Query& query,
124 const DicomTag& tag)
125 {
126 Query::const_iterator it = query.find(tag);
127 if (it != query.end())
128 {
129 RestrictIdentifier(it->first, it->second);
76 } 130 }
77 } 131 }
78 132
79 133
80 public: 134 public:
151 } 205 }
152 } 206 }
153 } 207 }
154 208
155 209
156 void RestrictIdentifier(const DicomTag& tag, 210 void RestrictIdentifier(const Query& query)
157 const std::string& value) 211 {
158 { 212 switch (level_)
159 assert((level_ == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) || 213 {
160 (level_ == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) || 214 case ResourceType_Patient:
161 (level_ == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) || 215 {
162 (level_ == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) || 216 RestrictIdentifier(query, DICOM_TAG_PATIENT_ID);
163 (level_ == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID)); 217 break;
164 218 }
165 LOG(INFO) << "Lookup for identifier tag " 219
166 << FromDcmtkBridge::GetName(tag) << " (value: " << value << ")"; 220 case ResourceType_Study:
167 221 {
168 std::list<std::string> resources; 222 RestrictIdentifier(query, DICOM_TAG_STUDY_INSTANCE_UID);
169 index_.LookupIdentifier(resources, tag, value, level_); 223 RestrictIdentifier(query, DICOM_TAG_ACCESSION_NUMBER);
170 224 break;
171 if (isFilterApplied_) 225 }
172 { 226
173 std::set<std::string> s; 227 case ResourceType_Series:
174 ListToSet(s, resources); 228 {
175 229 RestrictIdentifier(query, DICOM_TAG_SERIES_INSTANCE_UID);
176 std::set<std::string> tmp = filtered_; 230 break;
177 filtered_.clear(); 231 }
178 232
179 for (std::set<std::string>::const_iterator 233 case ResourceType_Instance:
180 it = tmp.begin(); it != tmp.end(); ++it) 234 {
181 { 235 RestrictIdentifier(query, DICOM_TAG_SOP_INSTANCE_UID);
182 if (s.find(*it) != s.end()) 236 break;
183 { 237 }
184 filtered_.insert(*it); 238
185 } 239 default:
186 } 240 throw OrthancException(ErrorCode_InternalError);
187 } 241 }
188 else 242 }
189 { 243
190 assert(filtered_.empty()); 244
191 isFilterApplied_ = true; 245 void RestrictMainDicomTags(const Query& query,
192 ListToSet(filtered_, resources);
193 }
194 }
195
196
197 void RestrictMainDicomTags(const ResourceFinder::Query& query,
198 bool caseSensitive) 246 bool caseSensitive)
199 { 247 {
248 if (query.size() == 0)
249 {
250 return;
251 }
252
200 std::list<std::string> resources; 253 std::list<std::string> resources;
201 Flatten(resources); 254 Flatten(resources);
202 255
203 isFilterApplied_ = true; 256 isFilterApplied_ = true;
204 filtered_.clear(); 257 filtered_.clear();
207 it = resources.begin(); it != resources.end(); it++) 260 it = resources.begin(); it != resources.end(); it++)
208 { 261 {
209 DicomMap mainTags; 262 DicomMap mainTags;
210 if (index_.GetMainDicomTags(mainTags, *it, level_)) 263 if (index_.GetMainDicomTags(mainTags, *it, level_))
211 { 264 {
212 for (ResourceFinder::Query::const_iterator 265 for (Query::const_iterator tag = query.begin();
213 tag = query.begin(); tag != query.end(); ++tag) 266 tag != query.end(); ++tag)
214 { 267 {
215 assert(DicomMap::IsMainDicomTag(tag->first, level_)); 268 assert(DicomMap::IsMainDicomTag(tag->first, level_));
216 LOG(INFO) << "Lookup for main DICOM tag " 269 if (tag->first != DICOM_TAG_PATIENT_ID &&
217 << FromDcmtkBridge::GetName(tag->first) << " (value: " << tag->second << ")"; 270 tag->first != DICOM_TAG_STUDY_INSTANCE_UID &&
218 271 tag->first != DICOM_TAG_ACCESSION_NUMBER &&
219 const DicomValue* value = mainTags.TestAndGetValue(tag->first); 272 tag->first != DICOM_TAG_SERIES_INSTANCE_UID &&
220 if (value != NULL && 273 tag->first != DICOM_TAG_SOP_INSTANCE_UID)
221 Compare(value->AsString(), tag->second, caseSensitive))
222 { 274 {
223 filtered_.insert(*it); 275 LOG(INFO) << "Lookup for main DICOM tag "
276 << FromDcmtkBridge::GetName(tag->first) << " (value: " << tag->second << ")";
277
278 const DicomValue* value = mainTags.TestAndGetValue(tag->first);
279 if (value != NULL &&
280 Compare(value->AsString(), tag->second, caseSensitive))
281 {
282 filtered_.insert(*it);
283 }
224 } 284 }
225 } 285 }
226 } 286 }
227 } 287 }
228 } 288 }
243 { 303 {
244 AddTag(FromDcmtkBridge::ParseTag(tag.c_str()), value); 304 AddTag(FromDcmtkBridge::ParseTag(tag.c_str()), value);
245 } 305 }
246 306
247 307
308 void ResourceFinder::GetTagsForLevel(Query& result,
309 const Query& source,
310 ResourceType level)
311 {
312 typedef std::set<DicomTag> Tags;
313
314 Tags tags;
315 DicomMap::GetMainDicomTags(tags, level);
316
317 for (Tags::const_iterator tag = tags.begin(); tag != tags.end(); tag++)
318 {
319 Query::const_iterator value = source.find(*tag);
320 if (value != source.end())
321 {
322 result.insert(*value);
323 }
324 }
325 }
326
327
248 void ResourceFinder::Apply(std::list<std::string>& result) 328 void ResourceFinder::Apply(std::list<std::string>& result)
249 { 329 {
250 result.clear(); 330 result.clear();
331
251 } 332 }
252 } 333 }