diff OrthancServer/Sources/ResourceFinder.cpp @ 5621:732ec9feeea8 find-refactoring

introduction of FindRequest::ChildrenRetrieveSpecification
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 11 May 2024 15:43:07 +0200
parents 4bfd885fb45f
children 3f13db27b399
line wrap: on
line diff
--- a/OrthancServer/Sources/ResourceFinder.cpp	Sat May 11 15:11:22 2024 +0200
+++ b/OrthancServer/Sources/ResourceFinder.cpp	Sat May 11 15:43:07 2024 +0200
@@ -371,23 +371,30 @@
       request_.SetRetrieveMetadata(true);
       request_.SetRetrieveLabels(true);
 
-      if (level == ResourceType_Series)
-      {
-        request_.AddRetrieveChildrenMetadata(MetadataType_Instance_IndexInSeries); // required for the SeriesStatus
-      }
-
-      if (level == ResourceType_Instance)
+      switch (level)
       {
-        request_.SetRetrieveAttachments(true); // for FileSize & FileUuid
-      }
-      else
-      {
-        request_.SetRetrieveChildrenIdentifiers(true);
-      }
+        case ResourceType_Patient:
+          request_.GetChildrenRetrieveSpecification(ResourceType_Study).SetRetrieveIdentifiers(true);
+          break;
+
+        case ResourceType_Study:
+          request_.GetChildrenRetrieveSpecification(ResourceType_Series).SetRetrieveIdentifiers(true);
+          request_.SetRetrieveParentIdentifier(true);
+          break;
 
-      if (level != ResourceType_Patient)
-      {
-        request_.SetRetrieveParentIdentifier(true);
+        case ResourceType_Series:
+          request_.AddRetrieveChildrenMetadata(MetadataType_Instance_IndexInSeries); // required for the SeriesStatus
+          request_.GetChildrenRetrieveSpecification(ResourceType_Instance).SetRetrieveIdentifiers(true);
+          request_.SetRetrieveParentIdentifier(true);
+          break;
+
+        case ResourceType_Instance:
+          request_.SetRetrieveAttachments(true); // for FileSize & FileUuid
+          request_.SetRetrieveParentIdentifier(true);
+          break;
+
+        default:
+          throw OrthancException(ErrorCode_ParameterOutOfRange);
       }
     }
   }
@@ -491,7 +498,7 @@
 
 
   void ResourceFinder::Execute(Json::Value& target,
-                               ServerContext& context)
+                               ServerContext& context) const
   {
     FindResponse response;
     context.GetIndex().ExecuteFind(response, request_);
@@ -502,6 +509,12 @@
     {
       const FindResponse::Resource& resource = response.GetResourceByIndex(i);
 
+      {
+        Json::Value v;
+        resource.DebugExport(v, request_);
+        std::cout << v.toStyledString();
+      }
+
       if (expand_)
       {
         Json::Value item;
@@ -607,7 +620,7 @@
 
 
   bool ResourceFinder::ExecuteOneResource(Json::Value& target,
-                                          ServerContext& context)
+                                          ServerContext& context) const
   {
     Json::Value answer;
     Execute(answer, context);