Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
1330:7227b096a6dc | 1331:77e129ba64e4 |
---|---|
195 } | 195 } |
196 | 196 |
197 | 197 |
198 static void AddAnswer(DicomFindAnswers& answers, | 198 static void AddAnswer(DicomFindAnswers& answers, |
199 const Json::Value& resource, | 199 const Json::Value& resource, |
200 const DicomArray& query) | 200 const DicomArray& query, |
201 bool isFirst) | |
201 { | 202 { |
202 DicomMap result; | 203 DicomMap result; |
203 | 204 |
204 for (size_t i = 0; i < query.GetSize(); i++) | 205 for (size_t i = 0; i < query.GetSize(); i++) |
205 { | 206 { |
218 result.SetValue(query.GetElement(i).GetTag(), ""); | 219 result.SetValue(query.GetElement(i).GetTag(), ""); |
219 } | 220 } |
220 } | 221 } |
221 } | 222 } |
222 | 223 |
223 answers.Add(result); | 224 if (result.GetSize() == 0) |
225 { | |
226 if (isFirst) | |
227 { | |
228 LOG(WARNING) << "The C-FIND request does not return any DICOM tag"; | |
229 } | |
230 } | |
231 else | |
232 { | |
233 answers.Add(result); | |
234 } | |
224 } | 235 } |
225 | 236 |
226 | 237 |
227 static bool ApplyModalitiesInStudyFilter(std::list<std::string>& filteredStudies, | 238 static bool ApplyModalitiesInStudyFilter(std::list<std::string>& filteredStudies, |
228 const std::list<std::string>& studies, | 239 const std::list<std::string>& studies, |
561 } | 572 } |
562 | 573 |
563 std::list<std::string> resources; | 574 std::list<std::string> resources; |
564 candidates.Flatten(resources); | 575 candidates.Flatten(resources); |
565 | 576 |
566 LOG(INFO) << "Number of candidate resources after exact filtering: " << resources.size(); | |
567 | 577 |
568 /** | 578 /** |
569 * Apply filtering on modalities for studies, if asked (this is an | 579 * Apply filtering on modalities for studies, if asked (this is an |
570 * extension to standard DICOM) | 580 * extension to standard DICOM) |
571 * http://www.medicalconnections.co.uk/kb/Filtering_on_and_Retrieving_the_Modality_in_a_C_FIND | 581 * http://www.medicalconnections.co.uk/kb/Filtering_on_and_Retrieving_the_Modality_in_a_C_FIND |
579 { | 589 { |
580 resources = filtered; | 590 resources = filtered; |
581 } | 591 } |
582 } | 592 } |
583 | 593 |
584 | |
585 /** | 594 /** |
586 * Loop over all the resources for this query level. | 595 * Loop over all the resources for this query level. |
587 **/ | 596 **/ |
588 | 597 |
598 LOG(INFO) << "Number of candidate resources after exact filtering on the identifiers only: " << resources.size(); | |
599 | |
600 bool isFirst = true; | |
601 | |
589 for (std::list<std::string>::const_iterator | 602 for (std::list<std::string>::const_iterator |
590 resource = resources.begin(); resource != resources.end(); ++resource) | 603 resource = resources.begin(); resource != resources.end(); ++resource) |
591 { | 604 { |
592 try | 605 try |
593 { | 606 { |
594 std::string instance; | 607 std::string instance; |
595 if (LookupOneInstance(instance, context_.GetIndex(), *resource, level)) | 608 if (LookupOneInstance(instance, context_.GetIndex(), *resource, level)) |
596 { | 609 { |
597 Json::Value info; | 610 Json::Value info; |
598 context_.ReadJson(info, instance); | 611 context_.ReadJson(info, instance); |
599 | 612 |
600 if (Matches(info, query)) | 613 if (Matches(info, query)) |
601 { | 614 { |
602 if (HasReachedLimit(answers, level)) | 615 if (HasReachedLimit(answers, level)) |
603 { | 616 { |
604 // Too many results, stop before recording this new match | 617 // Too many results, stop before recording this new match |
605 return false; | 618 return false; |
606 } | 619 } |
607 | 620 |
608 AddAnswer(answers, info, query); | 621 AddAnswer(answers, info, query, isFirst); |
622 isFirst = false; | |
609 } | 623 } |
610 } | 624 } |
611 } | 625 } |
612 catch (OrthancException&) | 626 catch (OrthancException&) |
613 { | 627 { |
614 // This resource has probably been deleted during the find request | 628 // This resource has probably been deleted during the find request |
615 } | 629 } |
616 } | 630 } |
631 | |
632 LOG(INFO) << "Number of candidate resources after filtering on all tags: " << answers.GetSize(); | |
617 | 633 |
618 return true; // All the matching resources have been returned | 634 return true; // All the matching resources have been returned |
619 } | 635 } |
620 } | 636 } |
621 | 637 |