Mercurial > hg > orthanc
diff OrthancServer/OrthancFindRequestHandler.cpp @ 3012:af1530b45290
Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Dec 2018 17:54:06 +0100 |
parents | 8265a6b56100 |
children | abe49ca61cd5 |
line wrap: on
line diff
--- a/OrthancServer/OrthancFindRequestHandler.cpp Thu Dec 13 17:16:32 2018 +0100 +++ b/OrthancServer/OrthancFindRequestHandler.cpp Thu Dec 13 17:54:06 2018 +0100 @@ -365,7 +365,8 @@ static void AddAnswer(DicomFindAnswers& answers, - const Json::Value& resource, + const DicomMap& mainDicomTags, + const Json::Value* dicomAsJson, // only used for sequences const DicomArray& query, const std::list<DicomTag>& sequencesToReturn, const DicomMap* counters) @@ -383,13 +384,13 @@ { // Do not include the encoding, this is handled by class ParsedDicomFile } - else + else if (dicomAsJson != NULL) { std::string tag = query.GetElement(i).GetTag().Format(); std::string value; - if (resource.isMember(tag)) + if (dicomAsJson->isMember(tag)) { - value = resource.get(tag, Json::arrayValue).get("Value", "").asString(); + value = dicomAsJson->get(tag, Json::arrayValue).get("Value", "").asString(); result.SetValue(query.GetElement(i).GetTag(), value, false); } else @@ -397,6 +398,12 @@ result.SetValue(query.GetElement(i).GetTag(), "", false); } } + else + { + // Best-effort + // TODO + throw OrthancException(ErrorCode_NotImplemented); + } } if (counters != NULL) @@ -413,7 +420,8 @@ { LOG(WARNING) << "The C-FIND request does not return any DICOM tag"; } - else if (sequencesToReturn.empty()) + else if (sequencesToReturn.empty() || + dicomAsJson == NULL) { answers.Add(result); } @@ -424,7 +432,8 @@ for (std::list<DicomTag>::const_iterator tag = sequencesToReturn.begin(); tag != sequencesToReturn.end(); ++tag) { - const Json::Value& source = resource[tag->Format()]; + assert(dicomAsJson != NULL); + const Json::Value& source = (*dicomAsJson) [tag->Format()]; if (source.type() == Json::objectValue && source.isMember("Type") && @@ -546,6 +555,30 @@ { answers_.SetComplete(false); } + + virtual bool IsDicomAsJsonNeeded() const + { +#if 1 + return true; + +#else + // TODO + + // Ask the "DICOM-as-JSON" attachment only if sequences are to + // be returned OR if "query_" contains non-main DICOM tags! + + // TODO - configuration option + bool findFromDatabase; + + { + // New configuration option in 1.5.1 + OrthancConfiguration::ReaderLock lock; + findFromDatabase = lock.GetConfiguration().GetUnsignedIntegerParameter("FindFromDatabase", false); + } + + return !sequencesToReturn_.empty(); +#endif + } virtual void MarkAsComplete() { @@ -554,10 +587,11 @@ virtual void Visit(const std::string& publicId, const std::string& instanceId, - const Json::Value& dicom) + const DicomMap& mainDicomTags, + const Json::Value* dicomAsJson) { std::auto_ptr<DicomMap> counters(ComputeCounters(context_, instanceId, level_, filteredInput_)); - AddAnswer(answers_, dicom, query_, sequencesToReturn_, counters.get()); + AddAnswer(answers_, mainDicomTags, dicomAsJson, query_, sequencesToReturn_, counters.get()); } }; @@ -690,6 +724,7 @@ size_t limit = (level == ResourceType_Instance) ? maxInstances_ : maxResults_; + LookupVisitor visitor(answers, context_, level, *filteredInput, sequencesToReturn); context_.Apply(visitor, lookup, 0 /* "since" is not relevant to C-FIND */, limit); }