Mercurial > hg > orthanc
diff OrthancServer/Search/LookupResource.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 | 4e43e67f8ecf |
line wrap: on
line diff
--- a/OrthancServer/Search/LookupResource.cpp Thu Dec 13 17:16:32 2018 +0100 +++ b/OrthancServer/Search/LookupResource.cpp Thu Dec 13 17:54:06 2018 +0100 @@ -42,6 +42,19 @@ namespace Orthanc { + static bool DoesDicomMapMatch(const DicomMap& dicom, + const DicomTag& tag, + const IFindConstraint& constraint) + { + const DicomValue* value = dicom.TestAndGetValue(tag); + + return (value != NULL && + !value->IsNull() && + !value->IsBinary() && + constraint.Match(value->GetContent())); + } + + LookupResource::Level::Level(ResourceType level) : level_(level) { const DicomTag* tags = NULL; @@ -119,6 +132,34 @@ } + bool LookupResource::Level::IsMatch(const DicomMap& dicom) const + { + for (Constraints::const_iterator it = identifiersConstraints_.begin(); + it != identifiersConstraints_.end(); ++it) + { + assert(it->second != NULL); + + if (!DoesDicomMapMatch(dicom, it->first, *it->second)) + { + return false; + } + } + + for (Constraints::const_iterator it = mainTagsConstraints_.begin(); + it != mainTagsConstraints_.end(); ++it) + { + assert(it->second != NULL); + + if (!DoesDicomMapMatch(dicom, it->first, *it->second)) + { + return false; + } + } + + return true; + } + + LookupResource::LookupResource(ResourceType level) : level_(level) { switch (level) @@ -283,22 +324,22 @@ - bool LookupResource::IsMatch(const Json::Value& dicomAsJson) const + bool LookupResource::IsMatch(const DicomMap& dicom) const { + for (Levels::const_iterator it = levels_.begin(); it != levels_.end(); ++it) + { + if (!it->second->IsMatch(dicom)) + { + return false; + } + } + for (Constraints::const_iterator it = unoptimizedConstraints_.begin(); it != unoptimizedConstraints_.end(); ++it) { - std::string tag = it->first.Format(); - if (dicomAsJson.isMember(tag) && - dicomAsJson[tag]["Type"] == "String") - { - std::string value = dicomAsJson[tag]["Value"].asString(); - if (!it->second->Match(value)) - { - return false; - } - } - else + assert(it->second != NULL); + + if (!DoesDicomMapMatch(dicom, it->first, *it->second)) { return false; }