diff OrthancServer/Sources/Database/FindResponse.cpp @ 5774:f96abfe08946 find-refactoring

implementation of specialized SQL commands in SQLiteDatabaseWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Sep 2024 08:25:41 +0200
parents 093a8693ba16
children
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/FindResponse.cpp	Wed Sep 11 21:21:42 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.cpp	Thu Sep 12 08:25:41 2024 +0200
@@ -505,6 +505,54 @@
   }
 
 
+  void FindResponse::Resource::SetOneInstancePublicId(const std::string& instancePublicId)
+  {
+    SetOneInstanceMetadataAndAttachments(instancePublicId, std::map<MetadataType, std::string>(),
+                                         std::map<FileContentType, FileInfo>());
+  }
+
+
+  void FindResponse::Resource::AddOneInstanceMetadata(MetadataType metadata,
+                                                      const std::string& value)
+  {
+    if (hasOneInstanceMetadataAndAttachments_)
+    {
+      if (oneInstanceMetadata_.find(metadata) == oneInstanceMetadata_.end())
+      {
+        oneInstanceMetadata_[metadata] = value;
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls, "Metadata already exists");
+      }
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
+  void FindResponse::Resource::AddOneInstanceAttachment(const FileInfo& attachment)
+  {
+    if (hasOneInstanceMetadataAndAttachments_)
+    {
+      if (oneInstanceAttachments_.find(attachment.GetContentType()) == oneInstanceAttachments_.end())
+      {
+        oneInstanceAttachments_[attachment.GetContentType()] = attachment;
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_BadSequenceOfCalls, "Attachment already exists");
+      }
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
   const std::string& FindResponse::Resource::GetOneInstancePublicId() const
   {
     if (hasOneInstanceMetadataAndAttachments_)
@@ -591,7 +639,7 @@
   static void DebugAttachments(Json::Value& target,
                                const std::map<FileContentType, FileInfo>& attachments)
   {
-    Json::Value v = Json::objectValue;
+    target = Json::objectValue;
     for (std::map<FileContentType, FileInfo>::const_iterator it = attachments.begin();
          it != attachments.end(); ++it)
     {
@@ -601,7 +649,7 @@
       }
       else
       {
-        DebugAddAttachment(v, it->second);
+        DebugAddAttachment(target, it->second);
       }
     }
   }
@@ -701,7 +749,8 @@
       DebugAttachments(target["Attachments"], attachments_);
     }
 
-    if (request.IsRetrieveOneInstanceMetadataAndAttachments())
+    if (request.GetLevel() != ResourceType_Instance &&
+        request.IsRetrieveOneInstanceMetadataAndAttachments())
     {
       DebugMetadata(target["OneInstance"]["Metadata"], GetOneInstanceMetadata());
       DebugAttachments(target["OneInstance"]["Attachments"], GetOneInstanceAttachments());