Mercurial > hg > orthanc
diff OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 4936:8422e4f99a18 more-tags
Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 11 Mar 2022 17:38:16 +0100 |
parents | acd3f72e2a21 |
children | f630796a59b1 |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Thu Mar 10 19:00:43 2022 +0100 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Fri Mar 11 17:38:16 2022 +0100 @@ -713,10 +713,11 @@ bool StatelessDatabaseOperations::ExpandResource(ExpandedResource& target, const std::string& publicId, ResourceType level, - DicomToJsonFormat format) + DicomToJsonFormat format, + const std::set<DicomTag>& requestedTags) { - class Operations : public ReadOnlyOperationsT5< - bool&, ExpandedResource&, const std::string&, ResourceType, DicomToJsonFormat> + class Operations : public ReadOnlyOperationsT6< + bool&, ExpandedResource&, const std::string&, ResourceType, DicomToJsonFormat, const std::set<DicomTag>&> { private: @@ -765,7 +766,7 @@ const Tuple& tuple) ORTHANC_OVERRIDE { // Lookup for the requested resource - int64_t internalId; // unused + int64_t internalId; ResourceType type; std::string parent; if (!transaction.LookupResourceAndParent(internalId, type, parent, tuple.get<2>()) || @@ -866,7 +867,58 @@ // read all tags from DB transaction.GetMainDicomTags(target.tags_, internalId); - // MORE_TAGS: TODO: eventualy get parent dicom tags if requested .... + // check if we have access to all requestedTags or if we must get tags from parents + const std::set<DicomTag>& requestedTags = tuple.get<5>(); + + if (requestedTags.size() > 0) + { + std::set<DicomTag> savedMainDicomTags; + + FromDcmtkBridge::ParseListOfTags(savedMainDicomTags, target.mainDicomTagsSignature_); + + // read parent main dicom tags as long as we don't have gathered all requested tags + ResourceType currentLevel = target.type_; + int64_t currentInternalId = internalId; + Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags); + + while ((target.missingRequestedTags_.size() > 0) + && currentLevel != ResourceType_Patient) + { + currentLevel = GetParentResourceType(currentLevel); + + int64_t currentParentId; + if (!transaction.LookupParent(currentParentId, currentInternalId)) + { + break; + } + + std::map<MetadataType, std::string> parentMetadata; + transaction.GetAllMetadata(parentMetadata, currentParentId); + + std::string parentMainDicomTagsSignature = DicomMap::GetDefaultMainDicomTagsSignature(currentLevel); + LookupStringMetadata(parentMainDicomTagsSignature, parentMetadata, MetadataType_MainDicomTagsSignature); + + std::set<DicomTag> parentSavedMainDicomTags; + FromDcmtkBridge::ParseListOfTags(parentSavedMainDicomTags, parentMainDicomTagsSignature); + + size_t previousMissingCount = target.missingRequestedTags_.size(); + Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags); + Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags); + + // read the parent tags from DB only if it reduces the number of missing tags + if (target.missingRequestedTags_.size() < previousMissingCount) + { + Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags); + + DicomMap parentTags; + transaction.GetMainDicomTags(parentTags, currentParentId); + + target.tags_.Merge(parentTags); + } + + currentInternalId = currentParentId; + } + } std::string tmp; @@ -903,7 +955,7 @@ bool found; Operations operations; - operations.Apply(*this, found, target, publicId, level, format); + operations.Apply(*this, found, target, publicId, level, format, requestedTags); return found; }