comparison OrthancServer/OrthancFindRequestHandler.cpp @ 941:83489fddd8c5

Options to limit the number of results for an incoming C-FIND query
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Jun 2014 11:08:11 +0200
parents 84513f2ee1f3
children c2c28dd17e87 67a6031f09ae
comparison
equal deleted inserted replaced
940:4864b3e304be 941:83489fddd8c5
440 } 440 }
441 }; 441 };
442 } 442 }
443 443
444 444
445 void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers, 445 bool OrthancFindRequestHandler::HasReachedLimit(const DicomFindAnswers& answers,
446 ResourceType level) const
447 {
448 switch (level)
449 {
450 case ResourceType_Patient:
451 case ResourceType_Study:
452 case ResourceType_Series:
453 return (maxResults_ != 0 && answers.GetSize() >= maxResults_);
454
455 case ResourceType_Instance:
456 return (maxInstances_ != 0 && answers.GetSize() >= maxInstances_);
457
458 default:
459 throw OrthancException(ErrorCode_InternalError);
460 }
461 }
462
463
464 bool OrthancFindRequestHandler::Handle(DicomFindAnswers& answers,
446 const DicomMap& input, 465 const DicomMap& input,
447 const std::string& callingAETitle) 466 const std::string& callingAETitle)
448 { 467 {
449 /** 468 /**
450 * Retrieve the manufacturer of this modality. 469 * Retrieve the manufacturer of this modality.
578 Json::Value info; 597 Json::Value info;
579 context_.ReadJson(info, instance); 598 context_.ReadJson(info, instance);
580 599
581 if (Matches(info, query)) 600 if (Matches(info, query))
582 { 601 {
602 if (HasReachedLimit(answers, level))
603 {
604 // Too many results, stop before recording this new match
605 return false;
606 }
607
583 AddAnswer(answers, info, query); 608 AddAnswer(answers, info, query);
584 } 609 }
585 } 610 }
586 } 611 }
587 catch (OrthancException&) 612 catch (OrthancException&)
588 { 613 {
589 // This resource has probably been deleted during the find request 614 // This resource has probably been deleted during the find request
590 } 615 }
591 } 616 }
617
618 return true; // All the matching resources have been returned
592 } 619 }
593 } 620 }
594 621
595 622
596 623