comparison OrthancServer/OrthancFindRequestHandler.cpp @ 681:3bdb5db8e839 query-retrieve

generalization of query/retrieve
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 24 Jan 2014 17:40:45 +0100
parents 41b3e5ccb291
children 67e6400fca03
comparison
equal deleted inserted replaced
679:28e4b3ec8aff 681:3bdb5db8e839
309 309
310 return false; 310 return false;
311 } 311 }
312 312
313 313
314 static bool LookupCandidateResourcesInternal(/* inout */ std::set<std::string>& resources,
315 /* in */ bool alreadyFiltered,
316 /* in */ ServerIndex& index,
317 /* in */ ResourceType level,
318 /* in */ const DicomMap& query,
319 /* in */ DicomTag tag)
320 {
321 assert(alreadyFiltered || resources.size() == 0);
322
323 if (!query.HasTag(tag))
324 {
325 return alreadyFiltered;
326 }
327
328 const DicomValue& value = query.GetValue(tag);
329 if (value.IsNull())
330 {
331 return alreadyFiltered;
332 }
333
334 std::string str = query.GetValue(tag).AsString();
335 if (IsWildcard(str))
336 {
337 return alreadyFiltered;
338 }
339
340 std::list<std::string> matches;
341 index.LookupTagValue(matches, tag, str/*, level*/);
342
343 if (alreadyFiltered)
344 {
345 std::set<std::string> previous = resources;
346
347 for (std::list<std::string>::const_iterator
348 it = matches.begin(); it != matches.end(); it++)
349 {
350 if (previous.find(*it) != previous.end())
351 {
352 resources.insert(*it);
353 }
354 }
355 }
356 else
357 {
358 for (std::list<std::string>::const_iterator
359 it = matches.begin(); it != matches.end(); it++)
360 {
361 resources.insert(*it);
362 }
363 }
364
365 return true;
366 }
367
368
369 static bool LookupCandidateResourcesAtOneLevel(/* out */ std::set<std::string>& resources,
370 /* in */ ServerIndex& index,
371 /* in */ ResourceType level,
372 /* in */ const DicomMap& fullQuery,
373 /* in */ ModalityManufacturer manufacturer)
374 {
375 DicomMap tmp;
376 fullQuery.ExtractMainDicomTagsForLevel(tmp, level);
377 DicomArray query(tmp);
378
379 if (query.GetSize() == 0)
380 {
381 return false;
382 }
383
384 for (size_t i = 0; i < query.GetSize(); i++)
385 {
386 const DicomTag tag = query.GetElement(i).GetTag();
387 const DicomValue& value = query.GetElement(i).GetValue();
388 if (!value.IsNull())
389 {
390 // TODO TODO TODO
391 }
392 }
393
394 printf(">>>>>>>>>>\n");
395 query.Print(stdout);
396 printf("<<<<<<<<<<\n\n");
397 return true;
398 }
399
400
314 static void LookupCandidateResources(/* out */ std::list<std::string>& resources, 401 static void LookupCandidateResources(/* out */ std::list<std::string>& resources,
315 /* in */ ServerIndex& index, 402 /* in */ ServerIndex& index,
316 /* in */ ResourceType level, 403 /* in */ ResourceType level,
317 /* in */ const DicomMap& query, 404 /* in */ const DicomMap& query,
318 /* in */ ModalityManufacturer manufacturer) 405 /* in */ ModalityManufacturer manufacturer)
319 { 406 {
407 #if 1
408 {
409 std::set<std::string> s;
410 LookupCandidateResourcesAtOneLevel(s, index, ResourceType_Patient, query, manufacturer);
411 LookupCandidateResourcesAtOneLevel(s, index, ResourceType_Study, query, manufacturer);
412 LookupCandidateResourcesAtOneLevel(s, index, ResourceType_Series, query, manufacturer);
413 LookupCandidateResourcesAtOneLevel(s, index, ResourceType_Instance, query, manufacturer);
414 }
415
416 std::set<std::string> filtered;
417 bool isFiltered = false;
418
419 // Filter by indexed tags, from most specific to least specific
420 //isFiltered = LookupCandidateResourcesInternal(filtered, isFiltered, index, level, query, DICOM_TAG_SOP_INSTANCE_UID);
421 isFiltered = LookupCandidateResourcesInternal(filtered, isFiltered, index, level, query, DICOM_TAG_SERIES_INSTANCE_UID);
422 //isFiltered = LookupCandidateResourcesInternal(filtered, isFiltered, index, level, query, DICOM_TAG_STUDY_INSTANCE_UID);
423 //isFiltered = LookupCandidateResourcesInternal(filtered, isFiltered, index, level, query, DICOM_TAG_PATIENT_ID);
424
425 resources.clear();
426
427 if (isFiltered)
428 {
429 for (std::set<std::string>::const_iterator
430 it = filtered.begin(); it != filtered.end(); it++)
431 {
432 resources.push_back(*it);
433 }
434 }
435 else
436 {
437 // No indexed tag matches the query. Return all the resources at this query level.
438 Json::Value allResources;
439 index.GetAllUuids(allResources, level);
440 assert(allResources.type() == Json::arrayValue);
441
442 for (Json::Value::ArrayIndex i = 0; i < allResources.size(); i++)
443 {
444 resources.push_back(allResources[i].asString());
445 }
446 }
447
448 #else
449
320 // TODO : Speed up using full querying against the MainDicomTags. 450 // TODO : Speed up using full querying against the MainDicomTags.
321 451
322 resources.clear(); 452 resources.clear();
323 453
324 bool done = false; 454 bool done = false;
369 for (Json::Value::ArrayIndex i = 0; i < allResources.size(); i++) 499 for (Json::Value::ArrayIndex i = 0; i < allResources.size(); i++)
370 { 500 {
371 resources.push_back(allResources[i].asString()); 501 resources.push_back(allResources[i].asString());
372 } 502 }
373 } 503 }
504 #endif
374 } 505 }
375 506
376 507
377 void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers, 508 void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers,
378 const DicomMap& input, 509 const DicomMap& input,
414 break; 545 break;
415 546
416 default: 547 default:
417 if (level != ResourceType_Patient && 548 if (level != ResourceType_Patient &&
418 level != ResourceType_Study && 549 level != ResourceType_Study &&
419 level != ResourceType_Series) 550 level != ResourceType_Series &&
551 level != ResourceType_Instance)
420 { 552 {
421 throw OrthancException(ErrorCode_NotImplemented); 553 throw OrthancException(ErrorCode_NotImplemented);
422 } 554 }
423 } 555 }
424 556
454 /** 586 /**
455 * Loop over all the resources for this query level. 587 * Loop over all the resources for this query level.
456 **/ 588 **/
457 589
458 DicomArray query(input); 590 DicomArray query(input);
591 query.Print(stdout);
592
459 for (std::list<std::string>::const_iterator 593 for (std::list<std::string>::const_iterator
460 resource = resources.begin(); resource != resources.end(); ++resource) 594 resource = resources.begin(); resource != resources.end(); ++resource)
461 { 595 {
462 try 596 try
463 { 597 {