Mercurial > hg > orthanc
comparison OrthancServer/OrthancFindRequestHandler.cpp @ 612:fdd5f7f9c4d7 find-move-scp
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Oct 2013 14:17:51 +0200 |
parents | 9924aec1d694 |
children | ec0b7a51d7bd |
comparison
equal
deleted
inserted
replaced
611:9924aec1d694 | 612:fdd5f7f9c4d7 |
---|---|
207 | 207 |
208 answers.Add(result); | 208 answers.Add(result); |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 static bool ApplyModalitiesInStudyFilter(Json::Value& filteredStudies, | |
213 const Json::Value& studies, | |
214 const DicomMap& input, | |
215 ServerIndex& index) | |
216 { | |
217 filteredStudies = Json::arrayValue; | |
218 | |
219 const DicomValue& v = input.GetValue(DICOM_TAG_MODALITIES_IN_STUDY); | |
220 if (v.IsNull()) | |
221 { | |
222 return false; | |
223 } | |
224 | |
225 // Move the allowed modalities into a "std::set" | |
226 std::vector<std::string> tmp; | |
227 Toolbox::TokenizeString(tmp, v.AsString(), '\\'); | |
228 | |
229 std::set<std::string> modalities; | |
230 for (size_t i = 0; i < tmp.size(); i++) | |
231 { | |
232 modalities.insert(tmp[i]); | |
233 } | |
234 | |
235 // Loop over the studies | |
236 for (Json::Value::ArrayIndex i = 0; i < studies.size(); i++) | |
237 { | |
238 try | |
239 { | |
240 // We are considering a single study. Check whether one of | |
241 // its child series matches one of the modalities. | |
242 Json::Value study; | |
243 if (index.LookupResource(study, studies[i].asString(), ResourceType_Study)) | |
244 { | |
245 // Loop over the series of the considered study. | |
246 for (Json::Value::ArrayIndex j = 0; j < study["Series"].size(); j++) // (*) | |
247 { | |
248 Json::Value series; | |
249 if (index.LookupResource(series, study["Series"][j].asString(), ResourceType_Series)) | |
250 { | |
251 // Get the modality of this series | |
252 if (series["MainDicomTags"].isMember("Modality")) | |
253 { | |
254 std::string modality = series["MainDicomTags"]["Modality"].asString(); | |
255 if (modalities.find(modality) != modalities.end()) | |
256 { | |
257 // This series of the considered study matches one | |
258 // of the required modalities. Take the study into | |
259 // consideration for future filtering. | |
260 filteredStudies.append(studies[i]); | |
261 | |
262 // We have finished considering this study. Break the study loop at (*). | |
263 break; | |
264 } | |
265 } | |
266 } | |
267 } | |
268 } | |
269 } | |
270 catch (OrthancException&) | |
271 { | |
272 // This resource has probably been deleted during the find request | |
273 } | |
274 } | |
275 | |
276 return true; | |
277 } | |
278 | |
279 | |
212 void OrthancFindRequestHandler::Handle(const DicomMap& input, | 280 void OrthancFindRequestHandler::Handle(const DicomMap& input, |
213 DicomFindAnswers& answers) | 281 DicomFindAnswers& answers) |
214 { | 282 { |
215 LOG(WARNING) << "Find-SCU request received"; | 283 LOG(WARNING) << "Find-SCU request received"; |
216 | 284 |
254 **/ | 322 **/ |
255 | 323 |
256 if (level == ResourceType_Study && | 324 if (level == ResourceType_Study && |
257 input.HasTag(DICOM_TAG_MODALITIES_IN_STUDY)) | 325 input.HasTag(DICOM_TAG_MODALITIES_IN_STUDY)) |
258 { | 326 { |
259 const DicomValue& v = input.GetValue(DICOM_TAG_MODALITIES_IN_STUDY); | 327 Json::Value filtered; |
260 if (!v.IsNull()) | 328 if (ApplyModalitiesInStudyFilter(filtered, resources, input, context_.GetIndex())) |
261 { | 329 { |
262 // Move the allowed modalities into a "std::set" | 330 resources = filtered; |
263 std::vector<std::string> tmp; | |
264 Toolbox::TokenizeString(tmp, v.AsString(), '\\'); | |
265 | |
266 std::set<std::string> modalities; | |
267 for (size_t i = 0; i < tmp.size(); i++) | |
268 { | |
269 modalities.insert(tmp[i]); | |
270 } | |
271 | |
272 // Loop over the studies | |
273 Json::Value studies = resources; | |
274 resources = Json::arrayValue; | |
275 | |
276 for (Json::Value::ArrayIndex i = 0; i < studies.size(); i++) | |
277 { | |
278 // We are considering a single study. Check whether one of | |
279 // its child series matches one of the modalities. | |
280 Json::Value study; | |
281 if (context_.GetIndex().LookupResource(study, studies[i].asString(), ResourceType_Study)) | |
282 { | |
283 // Loop over the series of the considered study. | |
284 for (Json::Value::ArrayIndex j = 0; j < study["Series"].size(); j++) // (*) | |
285 { | |
286 Json::Value series; | |
287 if (context_.GetIndex().LookupResource(series, study["Series"][j].asString(), ResourceType_Series)) | |
288 { | |
289 // Get the modality of this series | |
290 if (series["MainDicomTags"].isMember("Modality")) | |
291 { | |
292 std::string modality = series["MainDicomTags"]["Modality"].asString(); | |
293 if (modalities.find(modality) != modalities.end()) | |
294 { | |
295 // This series of the considered study matches one | |
296 // of the required modalities. Take the study into | |
297 // consideration for future filtering. | |
298 resources.append(studies[i]); | |
299 | |
300 // We have finished considering this study. Break the study loop at (*). | |
301 break; | |
302 } | |
303 } | |
304 } | |
305 } | |
306 } | |
307 } | |
308 } | 331 } |
309 } | 332 } |
310 | 333 |
311 | 334 |
312 /** | 335 /** |