comparison OrthancServer/OrthancFindRequestHandler.cpp @ 3003:5ae3ff2398e9

refactoring OrthancFindRequestHandler using LookupResource::IVisitor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Dec 2018 19:02:51 +0100
parents 7695a9c81099
children 8265a6b56100
comparison
equal deleted inserted replaced
3002:9ceb7dafae2e 3003:5ae3ff2398e9
519 maxInstances_(0) 519 maxInstances_(0)
520 { 520 {
521 } 521 }
522 522
523 523
524 class OrthancFindRequestHandler::LookupVisitor : public LookupResource::IVisitor
525 {
526 private:
527 DicomFindAnswers& answers_;
528 ServerContext& context_;
529 ResourceType level_;
530 const DicomMap& filteredInput_;
531 const std::list<DicomTag>& sequencesToReturn_;
532 DicomArray query_;
533
534 public:
535 LookupVisitor(DicomFindAnswers& answers,
536 ServerContext& context,
537 ResourceType level,
538 const DicomMap& filteredInput,
539 const std::list<DicomTag>& sequencesToReturn) :
540 answers_(answers),
541 context_(context),
542 level_(level),
543 filteredInput_(filteredInput),
544 sequencesToReturn_(sequencesToReturn),
545 query_(filteredInput)
546 {
547 answers_.SetComplete(false);
548 }
549
550 virtual void MarkAsComplete()
551 {
552 answers_.SetComplete(true);
553 }
554
555 virtual void Visit(const std::string& publicId,
556 const std::string& instanceId,
557 const Json::Value& dicom)
558 {
559 std::auto_ptr<DicomMap> counters(ComputeCounters(context_, instanceId, level_, filteredInput_));
560 AddAnswer(answers_, dicom, query_, sequencesToReturn_, counters.get());
561 }
562 };
563
564
524 void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers, 565 void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers,
525 const DicomMap& input, 566 const DicomMap& input,
526 const std::list<DicomTag>& sequencesToReturn, 567 const std::list<DicomTag>& sequencesToReturn,
527 const std::string& remoteIp, 568 const std::string& remoteIp,
528 const std::string& remoteAet, 569 const std::string& remoteAet,
647 * Run the query. 688 * Run the query.
648 **/ 689 **/
649 690
650 size_t limit = (level == ResourceType_Instance) ? maxInstances_ : maxResults_; 691 size_t limit = (level == ResourceType_Instance) ? maxInstances_ : maxResults_;
651 692
693
694 #if 1
695 LookupVisitor visitor(answers, context_, level, *filteredInput, sequencesToReturn);
696 context_.Apply(visitor, lookup, 0 /* "since" is not relevant to C-FIND */, limit);
697
698 #else
699 // Backup - Implementation of Orthanc <= 1.5.0
700 // TODO - Remove this code
701
652 // TODO - Use ServerContext::Apply() at this point, in order to 702 // TODO - Use ServerContext::Apply() at this point, in order to
653 // share the code with the "/tools/find" REST URI 703 // share the code with the "/tools/find" REST URI
654 std::vector<std::string> resources, instances; 704 std::vector<std::string> resources, instances;
655 context_.GetIndex().FindCandidates(resources, instances, lookup); 705 context_.GetIndex().FindCandidates(resources, instances, lookup);
656 706
683 } 733 }
684 734
685 LOG(INFO) << "Number of matching resources: " << answers.GetSize(); 735 LOG(INFO) << "Number of matching resources: " << answers.GetSize();
686 736
687 answers.SetComplete(complete); 737 answers.SetComplete(complete);
738 #endif
688 } 739 }
689 740
690 741
691 void OrthancFindRequestHandler::FormatOrigin(Json::Value& origin, 742 void OrthancFindRequestHandler::FormatOrigin(Json::Value& origin,
692 const std::string& remoteIp, 743 const std::string& remoteIp,