diff OrthancServer/Sources/Database/Compatibility/GenericFind.cpp @ 5772:093a8693ba16 find-refactoring

replaced SetRetrieveOneInstanceIdentifier() by SetRetrieveOneInstanceMetadataAndAttachments()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Sep 2024 20:49:34 +0200
parents 4db9f897df58
children 3b7dce0e43c6
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Wed Sep 11 16:31:11 2024 +0200
+++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Wed Sep 11 20:49:34 2024 +0200
@@ -566,8 +566,8 @@
         }
       }
 
-      if (request.IsRetrieveOneInstanceIdentifier() &&
-          !request.GetChildrenSpecification(ResourceType_Instance).IsRetrieveIdentifiers())
+      if (request.GetLevel() != ResourceType_Instance &&
+          request.IsRetrieveOneInstanceMetadataAndAttachments())
       {
         int64_t currentId = internalId;
         ResourceType currentLevel = level;
@@ -587,7 +587,28 @@
           }
         }
 
-        resource->AddChildIdentifier(ResourceType_Instance, transaction_.GetPublicId(currentId));
+        std::map<MetadataType, std::string> metadata;
+        transaction_.GetAllMetadata(metadata, currentId);
+
+        std::set<FileContentType> attachmentsType;
+        transaction_.ListAvailableAttachments(attachmentsType, currentId);
+
+        std::map<FileContentType, FileInfo> attachments;
+        for (std::set<FileContentType>::const_iterator it = attachmentsType.begin(); it != attachmentsType.end(); ++it)
+        {
+          FileInfo info;
+          int64_t revision;  // Unused in this case
+          if (transaction_.LookupAttachment(info, revision, currentId, *it))
+          {
+            attachments[*it] = info;
+          }
+          else
+          {
+            throw OrthancException(ErrorCode_DatabasePlugin);
+          }
+        }
+
+        resource->SetOneInstanceMetadataAndAttachments(transaction_.GetPublicId(currentId), metadata, attachments);
       }
 
       response.Add(resource.release());