diff OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5568:b0b5546f1b9f find-refactoring

find refactor: re-use existing code. /studies?expand is almost fully implemented with new code
author Alain Mazy <am@orthanc.team>
date Thu, 25 Apr 2024 09:22:07 +0200
parents def06a42e5ef
children 738f80622e91
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Apr 23 16:49:44 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Thu Apr 25 09:22:07 2024 +0200
@@ -234,16 +234,14 @@
 
       FindRequest request(resourceType);
 
-#if 0
-      // TODO - This version should be executed if no disk access is needed
       if (expand)
       {
-        request.SetResponseContent(FindRequest::ResponseContent_MainDicomTags |
+        request.SetResponseContent(static_cast<FindRequest::ResponseContent>(FindRequest::ResponseContent_MainDicomTags |
                                    FindRequest::ResponseContent_Metadata |
                                    FindRequest::ResponseContent_Labels |
                                    FindRequest::ResponseContent_Attachments |
                                    FindRequest::ResponseContent_Parent |
-                                   FindRequest::ResponseContent_Children)
+                                   FindRequest::ResponseContent_Children));
 
         request.SetRetrieveTagsAtLevel(resourceType, true);
 
@@ -256,9 +254,6 @@
       {
         request.SetResponseContent(FindRequest::ResponseContent_IdentifiersOnly);
       }
-#else
-      request.SetResponseContent(FindRequest::ResponseContent_IdentifiersOnly);
-#endif
 
       if (call.HasArgument("limit") ||
           call.HasArgument("since"))
@@ -285,35 +280,27 @@
       FindResponse response;
       index.ExecuteFind(response, request);
 
-      std::set<DicomTag> requestedTags;
-      OrthancRestApi::GetRequestedTags(requestedTags, call);
-
-      const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
-
+      // TODO-FIND: put this in an AnswerFindResponse method !
       Json::Value answer = Json::arrayValue;
 
-      for (size_t i = 0; i < response.GetSize(); i++)
+      if (request.IsResponseIdentifiersOnly())
       {
-        std::string resourceId = response.GetItem(i).GetIdentifiers().GetLevel(resourceType);
-
-        if (expand)
+        for (size_t i = 0; i < response.GetSize(); i++)
         {
-          Json::Value expanded;
-
-          context.ExpandResource(expanded, resourceId, resourceType, format, requestedTags, true /* allowStorageAccess */);
-
-          if (expanded.type() == Json::objectValue)
-          {
-            answer.append(expanded);
-          }
-          else
-          {
-            throw OrthancException(ErrorCode_InternalError);
-          }
+          std::string resourceId = response.GetItem(i).GetResourceId();
+          answer.append(resourceId);
         }
-        else
+      }
+      else
+      {
+        std::set<DicomTag> requestedTags;
+        OrthancRestApi::GetRequestedTags(requestedTags, call);
+
+        const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
+
+        for (size_t i = 0; i < response.GetSize(); i++)
         {
-          answer.append(resourceId);
+          context.AppendFindResponse(answer, response.GetItem(i), format, requestedTags, true /* allowStorageAccess */);
         }
       }