diff OrthancServer/Sources/Database/Compatibility/GenericFind.cpp @ 5592:1e2631b8b9af find-refactoring

GenericFind::Execute() is working for a basic request
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 03 May 2024 21:26:06 +0200
parents 8b32213af23e
children 862b54b4cfe2
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Fri May 03 18:30:29 2024 +0200
+++ b/OrthancServer/Sources/Database/Compatibility/GenericFind.cpp	Fri May 03 21:26:06 2024 +0200
@@ -22,6 +22,7 @@
 
 #include "GenericFind.h"
 
+#include "../../../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
 #include "../../../../OrthancFramework/Sources/OrthancException.h"
 
 
@@ -38,10 +39,6 @@
           !request.GetOrthancIdentifiers().HasInstanceId() &&
           request.GetDicomTagConstraintsCount() == 0 &&
           request.GetMetadataConstraintsCount() == 0 &&
-          !request.IsRetrieveTagsAtLevel(ResourceType_Patient) &&
-          !request.IsRetrieveTagsAtLevel(ResourceType_Study) &&
-          !request.IsRetrieveTagsAtLevel(ResourceType_Series) &&
-          !request.IsRetrieveTagsAtLevel(ResourceType_Instance) &&
           request.GetOrdering().empty() &&
           request.GetLabels().empty())
       {
@@ -58,7 +55,53 @@
 
         for (std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
         {
-          response.Add(new FindResponse::Resource(request.GetLevel(), *it));
+          int64_t internalId;
+          ResourceType t;
+          if (!transaction_.LookupResource(internalId, t, *it) ||
+              t != request.GetLevel())
+          {
+            throw OrthancException(ErrorCode_InternalError);
+          }
+
+          std::unique_ptr<FindResponse::Resource> resource(new FindResponse::Resource(request.GetLevel(), *it));
+
+          if (request.IsRetrieveMainDicomTags())
+          {
+            DicomMap m;
+            transaction_.GetMainDicomTags(m, internalId);
+
+            DicomArray a(m);
+            for (size_t i = 0; i < a.GetSize(); i++)
+            {
+              const DicomElement& element = a.GetElement(i);
+              if (element.GetValue().IsString())
+              {
+                resource->AddStringDicomTag(element.GetTag().GetGroup(), element.GetTag().GetElement(),
+                                            element.GetValue().GetContent());
+              }
+              else
+              {
+                throw OrthancException(ErrorCode_BadParameterType);
+              }
+            }
+          }
+
+          if (request.IsRetrieveParentIdentifier())
+          {
+            int64_t parentId;
+            if (transaction_.LookupParent(parentId, internalId))
+            {
+              resource->SetParentIdentifier(transaction_.GetPublicId(parentId));
+            }
+            else
+            {
+              throw OrthancException(ErrorCode_InternalError);
+            }
+          }
+
+          // TODO-FIND: Continue
+
+          response.Add(resource.release());
         }
       }
       else
@@ -75,10 +118,10 @@
       {
         const FindResponse::Resource& resource = response.GetResource(i);
 
-        if (request.IsRetrieveTagsAtLevel(request.GetLevel()))
+        if (request.IsRetrieveMainDicomTags())
         {
           DicomMap tmp;
-          resource.GetDicomTagsAtLevel(tmp, request.GetLevel());
+          resource.GetMainDicomTags(tmp);
           if (tmp.GetSize() == 0)
           {
             throw OrthancException(ErrorCode_InternalError);