Mercurial > hg > orthanc
changeset 3003:5ae3ff2398e9
refactoring OrthancFindRequestHandler using LookupResource::IVisitor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Dec 2018 19:02:51 +0100 |
parents | 9ceb7dafae2e |
children | 80d1a3452807 |
files | OrthancServer/OrthancFindRequestHandler.cpp OrthancServer/OrthancFindRequestHandler.h OrthancServer/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Search/LookupResource.h OrthancServer/ServerContext.cpp |
diffstat | 5 files changed, 69 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/OrthancFindRequestHandler.cpp Tue Dec 11 18:36:52 2018 +0100 +++ b/OrthancServer/OrthancFindRequestHandler.cpp Tue Dec 11 19:02:51 2018 +0100 @@ -521,6 +521,47 @@ } + class OrthancFindRequestHandler::LookupVisitor : public LookupResource::IVisitor + { + private: + DicomFindAnswers& answers_; + ServerContext& context_; + ResourceType level_; + const DicomMap& filteredInput_; + const std::list<DicomTag>& sequencesToReturn_; + DicomArray query_; + + public: + LookupVisitor(DicomFindAnswers& answers, + ServerContext& context, + ResourceType level, + const DicomMap& filteredInput, + const std::list<DicomTag>& sequencesToReturn) : + answers_(answers), + context_(context), + level_(level), + filteredInput_(filteredInput), + sequencesToReturn_(sequencesToReturn), + query_(filteredInput) + { + answers_.SetComplete(false); + } + + virtual void MarkAsComplete() + { + answers_.SetComplete(true); + } + + virtual void Visit(const std::string& publicId, + const std::string& instanceId, + const Json::Value& dicom) + { + std::auto_ptr<DicomMap> counters(ComputeCounters(context_, instanceId, level_, filteredInput_)); + AddAnswer(answers_, dicom, query_, sequencesToReturn_, counters.get()); + } + }; + + void OrthancFindRequestHandler::Handle(DicomFindAnswers& answers, const DicomMap& input, const std::list<DicomTag>& sequencesToReturn, @@ -649,6 +690,15 @@ size_t limit = (level == ResourceType_Instance) ? maxInstances_ : maxResults_; + +#if 1 + LookupVisitor visitor(answers, context_, level, *filteredInput, sequencesToReturn); + context_.Apply(visitor, lookup, 0 /* "since" is not relevant to C-FIND */, limit); + +#else + // Backup - Implementation of Orthanc <= 1.5.0 + // TODO - Remove this code + // TODO - Use ServerContext::Apply() at this point, in order to // share the code with the "/tools/find" REST URI std::vector<std::string> resources, instances; @@ -685,6 +735,7 @@ LOG(INFO) << "Number of matching resources: " << answers.GetSize(); answers.SetComplete(complete); +#endif }
--- a/OrthancServer/OrthancFindRequestHandler.h Tue Dec 11 18:36:52 2018 +0100 +++ b/OrthancServer/OrthancFindRequestHandler.h Tue Dec 11 19:02:51 2018 +0100 @@ -41,6 +41,8 @@ class OrthancFindRequestHandler : public IFindRequestHandler { private: + class LookupVisitor; + ServerContext& context_; unsigned int maxResults_; unsigned int maxInstances_;
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Dec 11 18:36:52 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Dec 11 19:02:51 2018 +0100 @@ -1289,7 +1289,8 @@ } virtual void Visit(const std::string& publicId, - const Json::Value& dicom) + const std::string& instanceId /* unused */, + const Json::Value& dicom /* unused */) { resources_.push_back(publicId); }
--- a/OrthancServer/Search/LookupResource.h Tue Dec 11 18:36:52 2018 +0100 +++ b/OrthancServer/Search/LookupResource.h Tue Dec 11 19:02:51 2018 +0100 @@ -92,6 +92,7 @@ virtual void MarkAsComplete() = 0; virtual void Visit(const std::string& publicId, + const std::string& instanceId, const Json::Value& dicom) = 0; };
--- a/OrthancServer/ServerContext.cpp Tue Dec 11 18:36:52 2018 +0100 +++ b/OrthancServer/ServerContext.cpp Tue Dec 11 19:02:51 2018 +0100 @@ -781,10 +781,13 @@ std::vector<std::string> resources, instances; GetIndex().FindCandidates(resources, instances, lookup); + LOG(INFO) << "Number of candidate resources after fast DB filtering: " << resources.size(); + assert(resources.size() == instances.size()); size_t countResults = 0; size_t skipped = 0; + bool complete = true; for (size_t i = 0; i < instances.size(); i++) { @@ -802,17 +805,24 @@ else if (limit != 0 && countResults >= limit) { - return; // too many results, don't mark as complete + // Too many results, don't mark as complete + complete = false; + break; } else { - visitor.Visit(resources[i], dicom); + visitor.Visit(resources[i], instances[i], dicom); countResults ++; } } } - visitor.MarkAsComplete(); + if (complete) + { + visitor.MarkAsComplete(); + } + + LOG(INFO) << "Number of matching resources: " << countResults; }