Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
4935:acd3f72e2a21 | 4936:8422e4f99a18 |
---|---|
711 | 711 |
712 | 712 |
713 bool StatelessDatabaseOperations::ExpandResource(ExpandedResource& target, | 713 bool StatelessDatabaseOperations::ExpandResource(ExpandedResource& target, |
714 const std::string& publicId, | 714 const std::string& publicId, |
715 ResourceType level, | 715 ResourceType level, |
716 DicomToJsonFormat format) | 716 DicomToJsonFormat format, |
717 const std::set<DicomTag>& requestedTags) | |
717 { | 718 { |
718 class Operations : public ReadOnlyOperationsT5< | 719 class Operations : public ReadOnlyOperationsT6< |
719 bool&, ExpandedResource&, const std::string&, ResourceType, DicomToJsonFormat> | 720 bool&, ExpandedResource&, const std::string&, ResourceType, DicomToJsonFormat, const std::set<DicomTag>&> |
720 { | 721 { |
721 private: | 722 private: |
722 | 723 |
723 static bool LookupStringMetadata(std::string& result, | 724 static bool LookupStringMetadata(std::string& result, |
724 const std::map<MetadataType, std::string>& metadata, | 725 const std::map<MetadataType, std::string>& metadata, |
763 public: | 764 public: |
764 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 765 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
765 const Tuple& tuple) ORTHANC_OVERRIDE | 766 const Tuple& tuple) ORTHANC_OVERRIDE |
766 { | 767 { |
767 // Lookup for the requested resource | 768 // Lookup for the requested resource |
768 int64_t internalId; // unused | 769 int64_t internalId; |
769 ResourceType type; | 770 ResourceType type; |
770 std::string parent; | 771 std::string parent; |
771 if (!transaction.LookupResourceAndParent(internalId, type, parent, tuple.get<2>()) || | 772 if (!transaction.LookupResourceAndParent(internalId, type, parent, tuple.get<2>()) || |
772 type != tuple.get<3>()) | 773 type != tuple.get<3>()) |
773 { | 774 { |
864 target.id_ = tuple.get<2>(); | 865 target.id_ = tuple.get<2>(); |
865 | 866 |
866 // read all tags from DB | 867 // read all tags from DB |
867 transaction.GetMainDicomTags(target.tags_, internalId); | 868 transaction.GetMainDicomTags(target.tags_, internalId); |
868 | 869 |
869 // MORE_TAGS: TODO: eventualy get parent dicom tags if requested .... | 870 // check if we have access to all requestedTags or if we must get tags from parents |
871 const std::set<DicomTag>& requestedTags = tuple.get<5>(); | |
872 | |
873 if (requestedTags.size() > 0) | |
874 { | |
875 std::set<DicomTag> savedMainDicomTags; | |
876 | |
877 FromDcmtkBridge::ParseListOfTags(savedMainDicomTags, target.mainDicomTagsSignature_); | |
878 | |
879 // read parent main dicom tags as long as we don't have gathered all requested tags | |
880 ResourceType currentLevel = target.type_; | |
881 int64_t currentInternalId = internalId; | |
882 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags); | |
883 | |
884 while ((target.missingRequestedTags_.size() > 0) | |
885 && currentLevel != ResourceType_Patient) | |
886 { | |
887 currentLevel = GetParentResourceType(currentLevel); | |
888 | |
889 int64_t currentParentId; | |
890 if (!transaction.LookupParent(currentParentId, currentInternalId)) | |
891 { | |
892 break; | |
893 } | |
894 | |
895 std::map<MetadataType, std::string> parentMetadata; | |
896 transaction.GetAllMetadata(parentMetadata, currentParentId); | |
897 | |
898 std::string parentMainDicomTagsSignature = DicomMap::GetDefaultMainDicomTagsSignature(currentLevel); | |
899 LookupStringMetadata(parentMainDicomTagsSignature, parentMetadata, MetadataType_MainDicomTagsSignature); | |
900 | |
901 std::set<DicomTag> parentSavedMainDicomTags; | |
902 FromDcmtkBridge::ParseListOfTags(parentSavedMainDicomTags, parentMainDicomTagsSignature); | |
903 | |
904 size_t previousMissingCount = target.missingRequestedTags_.size(); | |
905 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags); | |
906 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags); | |
907 | |
908 // read the parent tags from DB only if it reduces the number of missing tags | |
909 if (target.missingRequestedTags_.size() < previousMissingCount) | |
910 { | |
911 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags); | |
912 | |
913 DicomMap parentTags; | |
914 transaction.GetMainDicomTags(parentTags, currentParentId); | |
915 | |
916 target.tags_.Merge(parentTags); | |
917 } | |
918 | |
919 currentInternalId = currentParentId; | |
920 } | |
921 } | |
870 | 922 |
871 std::string tmp; | 923 std::string tmp; |
872 | 924 |
873 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_AnonymizedFrom)) | 925 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_AnonymizedFrom)) |
874 { | 926 { |
901 } | 953 } |
902 }; | 954 }; |
903 | 955 |
904 bool found; | 956 bool found; |
905 Operations operations; | 957 Operations operations; |
906 operations.Apply(*this, found, target, publicId, level, format); | 958 operations.Apply(*this, found, target, publicId, level, format, requestedTags); |
907 return found; | 959 return found; |
908 } | 960 } |
909 | 961 |
910 | 962 |
911 void StatelessDatabaseOperations::GetAllMetadata(std::map<MetadataType, std::string>& target, | 963 void StatelessDatabaseOperations::GetAllMetadata(std::map<MetadataType, std::string>& target, |