changeset 5671:b4c97c51f9db find-refactoring

added FindResponse::Resource::ChildrenInformation
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 06 Jul 2024 13:57:14 +0200
parents 56859a7ffa99
children e300f22a46f0
files OrthancServer/Sources/Database/FindResponse.cpp OrthancServer/Sources/Database/FindResponse.h
diffstat 2 files changed, 47 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/FindResponse.cpp	Sat Jul 06 01:04:25 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.cpp	Sat Jul 06 13:57:14 2024 +0200
@@ -142,14 +142,27 @@
   }
 
 
-  std::set<std::string>& FindResponse::Resource::GetChildrenIdentifiers(ResourceType level)
+  void FindResponse::ChildrenInformation::AddIdentifier(const std::string& identifier)
+  {
+    if (identifiers_.find(identifier) == identifiers_.end())
+    {
+      identifiers_.insert(identifier);
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
+  FindResponse::ChildrenInformation& FindResponse::Resource::GetChildrenInformation(ResourceType level)
   {
     switch (level)
     {
       case ResourceType_Study:
         if (level_ == ResourceType_Patient)
         {
-          return childrenStudiesIdentifiers_;
+          return childrenStudiesInformation_;
         }
         else
         {
@@ -160,7 +173,7 @@
         if (level_ == ResourceType_Patient ||
             level_ == ResourceType_Study)
         {
-          return childrenSeriesIdentifiers_;
+          return childrenSeriesInformation_;
         }
         else
         {
@@ -172,7 +185,7 @@
             level_ == ResourceType_Study ||
             level_ == ResourceType_Series)
         {
-          return childrenInstancesIdentifiers_;
+          return childrenInstancesInformation_;
         }
         else
         {
@@ -185,22 +198,6 @@
   }
 
 
-  void FindResponse::Resource::AddChildIdentifier(ResourceType level,
-                                                  const std::string& identifier)
-  {
-    std::set<std::string>& target = GetChildrenIdentifiers(level);
-
-    if (target.find(identifier) == target.end())
-    {
-      target.insert(identifier);
-    }
-    else
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-  }
-
-
   FindResponse::MainDicomTagsAtLevel& FindResponse::Resource::GetMainDicomTagsAtLevel(ResourceType level)
   {
     if (!IsResourceLevelAboveOrEqual(level, level_))
@@ -423,7 +420,7 @@
 
   const std::string& FindResponse::Resource::GetOneInstanceIdentifier() const
   {
-    const std::set<std::string>& instances = GetChildrenIdentifiers(ResourceType_Instance);
+    const std::set<std::string>& instances = GetChildrenInformation(ResourceType_Instance).GetIdentifiers();
 
     if (instances.size() == 0)
     {
@@ -531,7 +528,7 @@
       {
         if (request.GetChildrenRetrieveSpecification(levels[i]).IsRetrieveIdentifiers())
         {
-          const std::set<std::string>& ids = GetChildrenIdentifiers(levels[i]);
+          const std::set<std::string>& ids = GetChildrenInformation(levels[i]).GetIdentifiers();
 
           Json::Value v = Json::arrayValue;
           for (std::set<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
--- a/OrthancServer/Sources/Database/FindResponse.h	Sat Jul 06 01:04:25 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.h	Sat Jul 06 13:57:14 2024 +0200
@@ -66,6 +66,20 @@
       void Export(DicomMap& target) const;
     };
 
+    class ChildrenInformation : public boost::noncopyable
+    {
+    private:
+      std::set<std::string>  identifiers_;
+
+    public:
+      void AddIdentifier(const std::string& identifier);
+
+      const std::set<std::string>& GetIdentifiers() const
+      {
+        return identifiers_;
+      }
+    };
+
 
   public:
     class Resource : public boost::noncopyable
@@ -85,9 +99,9 @@
       std::map<MetadataType, std::string>   metadataStudy_;
       std::map<MetadataType, std::string>   metadataSeries_;
       std::map<MetadataType, std::string>   metadataInstance_;
-      std::set<std::string>                 childrenStudiesIdentifiers_;
-      std::set<std::string>                 childrenSeriesIdentifiers_;
-      std::set<std::string>                 childrenInstancesIdentifiers_;
+      ChildrenInformation                   childrenStudiesInformation_;
+      ChildrenInformation                   childrenSeriesInformation_;
+      ChildrenInformation                   childrenInstancesInformation_;
       std::set<std::string>                 labels_;
       std::map<FileContentType, FileInfo>   attachments_;
       ChildrenMetadata                      childrenMetadata_;
@@ -99,7 +113,12 @@
         return const_cast<Resource&>(*this).GetMainDicomTagsAtLevel(level);
       }
 
-      std::set<std::string>& GetChildrenIdentifiers(ResourceType level);
+      ChildrenInformation& GetChildrenInformation(ResourceType level);
+
+      const ChildrenInformation& GetChildrenInformation(ResourceType level) const
+      {
+        return const_cast<Resource&>(*this).GetChildrenInformation(level);
+      }
 
     public:
       Resource(ResourceType level,
@@ -171,11 +190,14 @@
                           MetadataType metadata) const;
 
       void AddChildIdentifier(ResourceType level,
-                              const std::string& childId);
+                              const std::string& childId)
+      {
+        GetChildrenInformation(level).AddIdentifier(childId);;
+      }
 
       const std::set<std::string>& GetChildrenIdentifiers(ResourceType level) const
       {
-        return const_cast<Resource&>(*this).GetChildrenIdentifiers(level);
+        return GetChildrenInformation(level).GetIdentifiers();
       }
 
       void AddLabel(const std::string& label);