comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5222:3a61fd50f804 db-protobuf

starting refactoring ExpandedResource
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Apr 2023 21:14:45 +0200
parents d0f7c742d397
children 49e906a8fea2
comparison
equal deleted inserted replaced
5221:d0f7c742d397 5222:3a61fd50f804
713 713
714 bool StatelessDatabaseOperations::ExpandResource(ExpandedResource& target, 714 bool StatelessDatabaseOperations::ExpandResource(ExpandedResource& target,
715 const std::string& publicId, 715 const std::string& publicId,
716 ResourceType level, 716 ResourceType level,
717 const std::set<DicomTag>& requestedTags, 717 const std::set<DicomTag>& requestedTags,
718 ExpandResourceDbFlags expandFlags) 718 ExpandResourceFlags expandFlags)
719 { 719 {
720 class Operations : public ReadOnlyOperationsT6< 720 class Operations : public ReadOnlyOperationsT6<
721 bool&, ExpandedResource&, const std::string&, ResourceType, const std::set<DicomTag>&, ExpandResourceDbFlags> 721 bool&, ExpandedResource&, const std::string&, ResourceType, const std::set<DicomTag>&, ExpandResourceFlags>
722 { 722 {
723 private: 723 private:
724 724
725 static bool LookupStringMetadata(std::string& result, 725 static bool LookupStringMetadata(std::string& result,
726 const std::map<MetadataType, std::string>& metadata, 726 const std::map<MetadataType, std::string>& metadata,
776 tuple.get<0>() = false; 776 tuple.get<0>() = false;
777 } 777 }
778 else 778 else
779 { 779 {
780 ExpandedResource& target = tuple.get<1>(); 780 ExpandedResource& target = tuple.get<1>();
781 ExpandResourceDbFlags expandFlags = tuple.get<5>(); 781 ExpandResourceFlags expandFlags = tuple.get<5>();
782 782
783 // Set information about the parent resource (if it exists) 783 // Set information about the parent resource (if it exists)
784 if (type == ResourceType_Patient) 784 if (type == ResourceType_Patient)
785 { 785 {
786 if (!parent.empty()) 786 if (!parent.empty())
796 } 796 }
797 797
798 target.parentId_ = parent; 798 target.parentId_ = parent;
799 } 799 }
800 800
801 target.type_ = type; 801 target.SetResource(type, tuple.get<2>());
802 target.id_ = tuple.get<2>(); 802
803 803 if (expandFlags & ExpandResourceFlags_IncludeChildren)
804 if (expandFlags & ExpandResourceDbFlags_IncludeChildren)
805 { 804 {
806 // List the children resources 805 // List the children resources
807 transaction.GetChildrenPublicId(target.childrenIds_, internalId); 806 transaction.GetChildrenPublicId(target.childrenIds_, internalId);
808 } 807 }
809 808
810 if (expandFlags & ExpandResourceDbFlags_IncludeMetadata) 809 if (expandFlags & ExpandResourceFlags_IncludeMetadata)
811 { 810 {
812 // Extract the metadata 811 // Extract the metadata
813 transaction.GetAllMetadata(target.metadata_, internalId); 812 transaction.GetAllMetadata(target.metadata_, internalId);
814 813
815 switch (type) 814 switch (type)
867 // check the main dicom tags list has not changed since the resource was stored 866 // check the main dicom tags list has not changed since the resource was stored
868 target.mainDicomTagsSignature_ = DicomMap::GetDefaultMainDicomTagsSignature(type); 867 target.mainDicomTagsSignature_ = DicomMap::GetDefaultMainDicomTagsSignature(type);
869 LookupStringMetadata(target.mainDicomTagsSignature_, target.metadata_, MetadataType_MainDicomTagsSignature); 868 LookupStringMetadata(target.mainDicomTagsSignature_, target.metadata_, MetadataType_MainDicomTagsSignature);
870 } 869 }
871 870
872 if (expandFlags & ExpandResourceDbFlags_IncludeMainDicomTags) 871 if (expandFlags & ExpandResourceFlags_IncludeMainDicomTags)
873 { 872 {
874 // read all tags from DB 873 // read all tags from DB
875 transaction.GetMainDicomTags(target.tags_, internalId); 874 transaction.GetMainDicomTags(target.GetMainDicomTags(), internalId);
876 875
877 // read all main sequences from DB 876 // read all main sequences from DB
878 std::string serializedSequences; 877 std::string serializedSequences;
879 if (LookupStringMetadata(serializedSequences, target.metadata_, MetadataType_MainDicomSequences)) 878 if (LookupStringMetadata(serializedSequences, target.metadata_, MetadataType_MainDicomSequences))
880 { 879 {
881 Json::Value jsonMetadata; 880 Json::Value jsonMetadata;
882 Toolbox::ReadJson(jsonMetadata, serializedSequences); 881 Toolbox::ReadJson(jsonMetadata, serializedSequences);
883 882
884 assert(jsonMetadata["Version"].asInt() == 1); 883 assert(jsonMetadata["Version"].asInt() == 1);
885 target.tags_.FromDicomAsJson(jsonMetadata["Sequences"], true /* append */, true /* parseSequences */); 884 target.GetMainDicomTags().FromDicomAsJson(jsonMetadata["Sequences"], true /* append */, true /* parseSequences */);
886 } 885 }
887 886
888 // check if we have access to all requestedTags or if we must get tags from parents 887 // check if we have access to all requestedTags or if we must get tags from parents
889 const std::set<DicomTag>& requestedTags = tuple.get<4>(); 888 const std::set<DicomTag>& requestedTags = tuple.get<4>();
890 889
893 std::set<DicomTag> savedMainDicomTags; 892 std::set<DicomTag> savedMainDicomTags;
894 893
895 FromDcmtkBridge::ParseListOfTags(savedMainDicomTags, target.mainDicomTagsSignature_); 894 FromDcmtkBridge::ParseListOfTags(savedMainDicomTags, target.mainDicomTagsSignature_);
896 895
897 // read parent main dicom tags as long as we have not gathered all requested tags 896 // read parent main dicom tags as long as we have not gathered all requested tags
898 ResourceType currentLevel = target.type_; 897 ResourceType currentLevel = target.GetLevel();
899 int64_t currentInternalId = internalId; 898 int64_t currentInternalId = internalId;
900 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags); 899 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags);
901 900
902 while ((target.missingRequestedTags_.size() > 0) 901 while ((target.missingRequestedTags_.size() > 0)
903 && currentLevel != ResourceType_Patient) 902 && currentLevel != ResourceType_Patient)
929 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags); 928 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags);
930 929
931 DicomMap parentTags; 930 DicomMap parentTags;
932 transaction.GetMainDicomTags(parentTags, currentParentId); 931 transaction.GetMainDicomTags(parentTags, currentParentId);
933 932
934 target.tags_.Merge(parentTags); 933 target.GetMainDicomTags().Merge(parentTags);
935 } 934 }
936 935
937 currentInternalId = currentParentId; 936 currentInternalId = currentParentId;
938 } 937 }
939 } 938 }
940 } 939 }
941 940
942 if (expandFlags & ExpandResourceDbFlags_IncludeLabels) 941 if (expandFlags & ExpandResourceFlags_IncludeLabels)
943 { 942 {
944 transaction.ListLabels(target.labels_, internalId); 943 transaction.ListLabels(target.labels_, internalId);
945 } 944 }
946 945
947 std::string tmp; 946 std::string tmp;