changeset 4883:504624b0a062

Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve the full information about an attachment (size, type, MD5 and UUID)
author Alain Mazy <am@osimis.io>
date Wed, 09 Feb 2022 13:10:11 +0100
parents 6971ea27a2a9
children d7d5d63985c8
files NEWS OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 2 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Jan 31 17:22:05 2022 +0100
+++ b/NEWS	Wed Feb 09 13:10:11 2022 +0100
@@ -34,7 +34,10 @@
 * "/instances/{...}/frames/{...}/numpy": Download the frame as a Python numpy array
 * "/instances/{...}/numpy": Download the instance as a Python numpy array
 * "/series/{...}/numpy": Download the series as a Python numpy array
-* Added a ?full option to "/patients|studies|series|instances/{...}/attachments route
+* Added a ?full option to "/patients|studies|series|instances/{...}/attachments" route
+  to show the mapping alias<->numerical id.
+* Added "/patients|studies|series|instances/{...}/attachments/{...}/info" route to retrieve
+  the full information about an attachment (size, type, MD5 and UUID)
 
 Lua
 ---
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon Jan 31 17:22:05 2022 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Wed Feb 09 13:10:11 2022 +0100
@@ -2048,6 +2048,7 @@
 
       operations.append("compressed-size");
       operations.append("data");
+      operations.append("info");
       operations.append("is-compressed");
 
       if (info.GetUncompressedMD5() != "")
@@ -2064,6 +2065,8 @@
         operations.append("verify-md5");
       }
 
+      operations.append("uuid");
+
       call.GetOutput().AnswerJson(operations);
     }
   }
@@ -2151,6 +2154,36 @@
     }
   }
 
+  static void GetAttachmentInfo(RestApiGetCall& call)
+  {
+    if (call.IsDocumentation())
+    {
+      ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str());
+      std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */);
+      AddAttachmentDocumentation(call, r);
+      call.GetDocumentation()
+        .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */))
+        .SetSummary("Get info about the attachment")
+        .SetDescription("Get all the information about the attachment associated with the given " + r)
+        .AddAnswerType(MimeType_Json, "JSON object containing the information about the attachment")
+        .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/dicom/info", true);
+      return;
+    }
+
+    FileInfo info;
+    if (GetAttachmentInfo(info, call))
+    {
+      Json::Value result = Json::objectValue;    
+      result["Uuid"] = info.GetUuid();
+      result["ContentType"] = info.GetContentType();
+      result["UncompressedSize"] = Json::Value::UInt64(info.GetUncompressedSize());
+      result["CompressedSize"] = Json::Value::UInt64(info.GetCompressedSize());
+      result["UncompressedMD5"] = info.GetUncompressedMD5();
+      result["CompressedMD5"] = info.GetCompressedMD5();
+
+      call.GetOutput().AnswerJson(result);
+    }
+  }
 
   static void GetAttachmentCompressedSize(RestApiGetCall& call)
   {
@@ -3696,6 +3729,7 @@
       Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/md5", GetAttachmentMD5);
       Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/size", GetAttachmentSize);
       Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/uncompress", ChangeAttachmentCompression<CompressionType_None>);
+      Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/info", GetAttachmentInfo);
       Register("/" + resourceTypes[i] + "/{id}/attachments/{name}/verify-md5", VerifyAttachment);
     }