changeset 5672:e300f22a46f0 find-refactoring

implemented computed tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 06 Jul 2024 14:24:45 +0200
parents b4c97c51f9db
children ebcbb448bea8
files OrthancServer/Sources/Database/Compatibility/GenericFind.cpp OrthancServer/Sources/Database/FindResponse.cpp OrthancServer/Sources/Database/FindResponse.h OrthancServer/Sources/ResourceFinder.cpp
diffstat 4 files changed, 141 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Sat Jul 06 13:57:14 2024 +0200
+++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Sat Jul 06 14:24:45 2024 +0200
@@ -497,8 +497,7 @@
 
               for (std::list<std::string>::const_iterator it3 = values.begin(); it3 != values.end(); ++it3)
               {
-                // TODO-FIND - Inject this value in the response
-                printf("[%s]\n", it3->c_str());
+                resource->AddChildrenMetadataValue(childrenLevel, *it, *it3);
               }
             }
           }
@@ -530,8 +529,7 @@
                   std::string value;
                   if (m.LookupStringValue(value, *it2, false /* no binary allowed */))
                   {
-                    // TODO-FIND - Inject this value in the response
-                    printf("<%s>\n", value.c_str());
+                    resource->AddChildrenMainDicomTagValue(childrenLevel, *it2, value);
                   }
                 }
               }
--- a/OrthancServer/Sources/Database/FindResponse.cpp	Sat Jul 06 13:57:14 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.cpp	Sat Jul 06 14:24:45 2024 +0200
@@ -155,6 +155,74 @@
   }
 
 
+  void FindResponse::ChildrenInformation::AddMetadataValue(MetadataType metadata,
+                                                           const std::string& value)
+  {
+    MetadataValues::iterator found = metadataValues_.find(metadata);
+
+    if (found == metadataValues_.end())
+    {
+      std::set<std::string> s;
+      s.insert(value);
+      metadataValues_[metadata] = s;
+    }
+    else
+    {
+      found->second.insert(value);
+    }
+  }
+
+
+  void FindResponse::ChildrenInformation::GetMetadataValues(std::set<std::string>& values,
+                                                            MetadataType metadata) const
+  {
+    MetadataValues::const_iterator found = metadataValues_.find(metadata);
+
+    if (found == metadataValues_.end())
+    {
+      values.clear();
+    }
+    else
+    {
+      values = found->second;
+    }
+  }
+
+
+  void FindResponse::ChildrenInformation::AddMainDicomTagValue(const DicomTag& tag,
+                                                               const std::string& value)
+  {
+    MainDicomTagValues::iterator found = mainDicomTagValues_.find(tag);
+
+    if (found == mainDicomTagValues_.end())
+    {
+      std::set<std::string> s;
+      s.insert(value);
+      mainDicomTagValues_[tag] = s;
+    }
+    else
+    {
+      found->second.insert(value);
+    }
+  }
+
+
+  void FindResponse::ChildrenInformation::GetMainDicomTagValues(std::set<std::string>& values,
+                                                                const DicomTag& tag) const
+  {
+    MainDicomTagValues::const_iterator found = mainDicomTagValues_.find(tag);
+
+    if (found == mainDicomTagValues_.end())
+    {
+      values.clear();
+    }
+    else
+    {
+      values = found->second;
+    }
+  }
+
+
   FindResponse::ChildrenInformation& FindResponse::Resource::GetChildrenInformation(ResourceType level)
   {
     switch (level)
--- a/OrthancServer/Sources/Database/FindResponse.h	Sat Jul 06 13:57:14 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.h	Sat Jul 06 14:24:45 2024 +0200
@@ -69,7 +69,12 @@
     class ChildrenInformation : public boost::noncopyable
     {
     private:
+      typedef std::map<MetadataType, std::set<std::string> >  MetadataValues;
+      typedef std::map<DicomTag, std::set<std::string> >      MainDicomTagValues;
+
       std::set<std::string>  identifiers_;
+      MetadataValues         metadataValues_;
+      MainDicomTagValues     mainDicomTagValues_;
 
     public:
       void AddIdentifier(const std::string& identifier);
@@ -78,6 +83,18 @@
       {
         return identifiers_;
       }
+
+      void AddMetadataValue(MetadataType metadata,
+                            const std::string& value);
+
+      void GetMetadataValues(std::set<std::string>& values,
+                             MetadataType metadata) const;
+
+      void AddMainDicomTagValue(const DicomTag& tag,
+                                const std::string& value);
+
+      void GetMainDicomTagValues(std::set<std::string>& values,
+                                 const DicomTag& tag) const;
     };
 
 
@@ -104,7 +121,7 @@
       ChildrenInformation                   childrenInstancesInformation_;
       std::set<std::string>                 labels_;
       std::map<FileContentType, FileInfo>   attachments_;
-      ChildrenMetadata                      childrenMetadata_;
+      ChildrenMetadata                      childrenMetadata_;  // TODO-FIND: REMOVE
 
       MainDicomTagsAtLevel& GetMainDicomTagsAtLevel(ResourceType level);
 
@@ -200,6 +217,34 @@
         return GetChildrenInformation(level).GetIdentifiers();
       }
 
+      void AddChildrenMetadataValue(ResourceType level,
+                                    MetadataType metadata,
+                                    const std::string& value)
+      {
+        GetChildrenInformation(level).AddMetadataValue(metadata, value);
+      }
+
+      void GetChildrenMetadataValues(std::set<std::string>& values,
+                                     ResourceType level,
+                                     MetadataType metadata) const
+      {
+        GetChildrenInformation(level).GetMetadataValues(values, metadata);
+      }
+
+      void AddChildrenMainDicomTagValue(ResourceType level,
+                                        const DicomTag& tag,
+                                        const std::string& value)
+      {
+        GetChildrenInformation(level).AddMainDicomTagValue(tag, value);
+      }
+
+      void GetChildrenMainDicomTagValues(std::set<std::string>& values,
+                                         ResourceType level,
+                                         const DicomTag& tag) const
+      {
+        GetChildrenInformation(level).GetMainDicomTagValues(values, tag);
+      }
+
       void AddLabel(const std::string& label);
 
       std::set<std::string>& GetLabels()
@@ -222,9 +267,11 @@
         return attachments_;
       }
 
+      // TODO-FIND: REMOVE
       void AddChildrenMetadata(MetadataType metadata,
                                const std::list<std::string>& values);
 
+      // TODO-FIND: REMOVE
       bool LookupChildrenMetadata(std::list<std::string>& values,
                                   MetadataType metadata) const;
 
--- a/OrthancServer/Sources/ResourceFinder.cpp	Sat Jul 06 13:57:14 2024 +0200
+++ b/OrthancServer/Sources/ResourceFinder.cpp	Sat Jul 06 14:24:45 2024 +0200
@@ -75,6 +75,29 @@
       case ResourceType_Study:
         InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_STUDY_RELATED_SERIES, resource, ResourceType_Series);
         InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_STUDY_RELATED_INSTANCES, resource, ResourceType_Instance);
+
+        if (IsRequestedComputedTag(DICOM_TAG_MODALITIES_IN_STUDY))
+        {
+          std::set<std::string> modalities;
+          resource.GetChildrenMainDicomTagValues(modalities, ResourceType_Series, DICOM_TAG_MODALITY);
+
+          std::string s;
+          Toolbox::JoinStrings(s, modalities, "\\");
+
+          requestedTags.SetValue(DICOM_TAG_MODALITIES_IN_STUDY, s, false);
+        }
+
+        if (IsRequestedComputedTag(DICOM_TAG_SOP_CLASSES_IN_STUDY))
+        {
+          std::set<std::string> classes;
+          resource.GetChildrenMetadataValues(classes, ResourceType_Instance, MetadataType_Instance_SopClassUid);
+
+          std::string s;
+          Toolbox::JoinStrings(s, classes, "\\");
+
+          requestedTags.SetValue(DICOM_TAG_SOP_CLASSES_IN_STUDY, s, false);
+        }
+
         break;
 
       case ResourceType_Series: