changeset 5405:62bb63346185

All 'expand' GET arguments now accepts expand=true and expand=false values + /studies/../instances now supports expand=false
author Alain Mazy <am@osimis.io>
date Tue, 17 Oct 2023 15:06:11 +0200
parents 7bae5f7ebe6a
children aaf7c49a9ddc 3206537cbb56 08177310e269
files NEWS OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp
diffstat 4 files changed, 17 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Oct 17 10:31:21 2023 +0200
+++ b/NEWS	Tue Oct 17 15:06:11 2023 +0200
@@ -14,6 +14,10 @@
 
 * API version upgraded to 22
 * Added a route to delete completed jobs from history: DELETE /jobs/{id}
+* All 'expand' GET arguments now accepts expand=true and expand=false values.
+  The /studies/../instances and sibling routes are the only whose expand is true if not specified.
+  These routes now accepts expand=false to simply list the child resources ids.
+
 
 Maintenance
 -----------
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Tue Oct 17 10:31:21 2023 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Tue Oct 17 15:06:11 2023 +0200
@@ -843,7 +843,7 @@
       return;
     }
 
-    const bool expand = call.HasArgument("expand");
+    const bool expand = call.HasArgument("expand") && call.GetBooleanArgument("expand", true);
     const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Full);
     
     QueryAccessor query(call);
@@ -1649,7 +1649,7 @@
     OrthancRestApi::SetOfStrings peers;
     lock.GetConfiguration().GetListOfOrthancPeers(peers);
 
-    if (call.HasArgument("expand"))
+    if (call.HasArgument("expand") && call.GetBooleanArgument("expand", true))
     {
       Json::Value result = Json::objectValue;
       for (OrthancRestApi::SetOfStrings::const_iterator
@@ -1933,7 +1933,7 @@
     OrthancRestApi::SetOfStrings modalities;
     lock.GetConfiguration().GetListOfDicomModalities(modalities);
 
-    if (call.HasArgument("expand"))
+    if (call.HasArgument("expand") && call.GetBooleanArgument("expand", true))
     {
       Json::Value result = Json::objectValue;
       for (OrthancRestApi::SetOfStrings::const_iterator
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Oct 17 10:31:21 2023 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Oct 17 15:06:11 2023 +0200
@@ -254,7 +254,7 @@
       index.GetAllUuids(result, resourceType);
     }
 
-    AnswerListOfResources(call.GetOutput(), context, result, resourceType, call.HasArgument("expand"),
+    AnswerListOfResources(call.GetOutput(), context, result, resourceType, call.HasArgument("expand") && call.GetBooleanArgument("expand", true),
                           OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human),
                           requestedTags,
                           true /* allowStorageAccess */);
@@ -1701,7 +1701,7 @@
 
     bool isNumeric = call.HasArgument("numeric");
 
-    if (call.HasArgument("expand"))
+    if (call.HasArgument("expand") && call.GetBooleanArgument("expand", true))
     {
       result = Json::objectValue;
       
@@ -3324,12 +3324,15 @@
         .SetDescription("Get detailed information about the child " + children + " of the DICOM " +
                         resource + " whose Orthanc identifier is provided in the URL")
         .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
+        .SetHttpGetArgument("expand", RestApiCallDocumentation::Type_String,
+                            "If false or missing, only retrieve the list of child " + children, false)
         .AddAnswerType(MimeType_Json, "JSON array containing information about the child DICOM " + children)
         .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + children, 5);
       return;
     }
 
     ServerIndex& index = OrthancRestApi::GetIndex(call);
+    ServerContext& context = OrthancRestApi::GetContext(call);
 
     std::set<DicomTag> requestedTags;
     OrthancRestApi::GetRequestedTags(requestedTags, call);
@@ -3355,21 +3358,10 @@
       a.splice(a.begin(), b);
     }
 
-    Json::Value result = Json::arrayValue;
-
-    const DicomToJsonFormat format = OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human);
-
-    for (std::list<std::string>::const_iterator
-           it = a.begin(); it != a.end(); ++it)
-    {
-      Json::Value resource;
-      if (OrthancRestApi::GetContext(call).ExpandResource(resource, *it, end, format, requestedTags, true /* allowStorageAccess */))
-      {
-        result.append(resource);
-      }
-    }
-
-    call.GetOutput().AnswerJson(result);
+    AnswerListOfResources(call.GetOutput(), context, a, type, !call.HasArgument("expand") || call.GetBooleanArgument("expand", false),  // this "expand" is the only one to have a false default value to keep backward compatibility
+                          OrthancRestApi::GetDicomFormat(call, DicomToJsonFormat_Human),
+                          requestedTags,
+                          true /* allowStorageAccess */);
   }
 
 
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Tue Oct 17 10:31:21 2023 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Tue Oct 17 15:06:11 2023 +0200
@@ -657,7 +657,7 @@
       return;
     }
 
-    bool expand = call.HasArgument("expand");
+    bool expand = call.HasArgument("expand") && call.GetBooleanArgument("expand", true);
 
     Json::Value v = Json::arrayValue;