changeset 4524:f8660649ae96

added "/peers/{id}/store-straight": Synchronously send the DICOM instance in POST body to the peer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 23 Feb 2021 15:05:55 +0100
parents fba1a8fff2b8
children 8262ffb393ff
files NEWS OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp
diffstat 3 files changed, 60 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Feb 23 13:46:58 2021 +0100
+++ b/NEWS	Tue Feb 23 15:05:55 2021 +0100
@@ -15,9 +15,11 @@
 REST API
 --------
 
+* API version upgraded to 11
 * BREAKING CHANGES:
   - External applications should *not* call "/instances/.../attachments/dicom-as-json" anymore
   - "/instances/.../tags" route does not report the tags after "Pixel Data" (7fe0,0010) anymore
+* "/peers/{id}/store-straight": Synchronously send the DICOM instance in POST body to the peer
 * New arguments in the REST API:
   - "Timeout" in "/modalities/.../query"
   - "Timeout" in "/modalities/.../storage-commitment"
--- a/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Tue Feb 23 13:46:58 2021 +0100
+++ b/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Tue Feb 23 15:05:55 2021 +0100
@@ -37,7 +37,7 @@
 # Version of the Orthanc API, can be retrieved from "/system" URI in
 # order to check whether new URI endpoints are available even if using
 # the mainline version of Orthanc
-set(ORTHANC_API_VERSION "10")
+set(ORTHANC_API_VERSION "11")
 
 
 #####################################################################
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Tue Feb 23 13:46:58 2021 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Tue Feb 23 15:05:55 2021 +0100
@@ -1820,6 +1820,62 @@
     }
   }
 
+  static void PeerStoreStraight(RestApiPostCall& call)
+  {
+    if (call.IsDocumentation())
+    {
+      call.GetDocumentation()
+        .SetTag("Networking")
+        .SetSummary("Straight store to peer")
+        .SetDescription("Synchronously send the DICOM instance in the POST body to the Orthanc peer "
+                        "whose identifier is provided in URL, without having to first store it locally within Orthanc. "
+                        "This is an alternative to command-line tools such as `curl`.")
+        .SetUriArgument("id", "Identifier of the modality of interest")
+        .AddRequestType(MimeType_Dicom, "DICOM instance to be sent")
+        .SetAnswerField("ID", RestApiCallDocumentation::Type_String,
+                        "Orthanc identifier of the DICOM instance in the remote Orthanc peer")
+        .SetAnswerField("ParentPatient", RestApiCallDocumentation::Type_String,
+                        "Orthanc identifier of the parent patient in the remote Orthanc peer")
+        .SetAnswerField("ParentStudy", RestApiCallDocumentation::Type_String,
+                        "Orthanc identifier of the parent study in the remote Orthanc peer")
+        .SetAnswerField("ParentSeries", RestApiCallDocumentation::Type_String,
+                        "Orthanc identifier of the parent series in the remote Orthanc peer")
+        .SetAnswerField("Path", RestApiCallDocumentation::Type_String,
+                        "Path to the DICOM instance in the remote Orthanc server")
+        .SetAnswerField("Status", RestApiCallDocumentation::Type_String,
+                        "Status of the store operation");
+      return;
+    }
+
+    const std::string peer = call.GetUriComponent("id", "");
+
+    WebServiceParameters info;  
+
+    {
+      OrthancConfiguration::ReaderLock lock;
+      if (!lock.GetConfiguration().LookupOrthancPeer(info, peer))
+      {
+        throw OrthancException(ErrorCode_UnknownResource, "No peer with symbolic name: " + peer);
+      }
+    }
+
+    HttpClient client(info, "instances");
+    client.SetMethod(HttpMethod_Post);
+    client.AddHeader("Expect", "");
+    client.GetBody().assign(reinterpret_cast<const char*>(call.GetBodyData()), call.GetBodySize());
+
+    Json::Value answer;
+    if (client.Apply(answer))
+    {
+      call.GetOutput().AnswerJson(answer);
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_NetworkProtocol, "Cannot send DICOM to remote peer: " + peer);
+    }
+  }
+
+
   // DICOM bridge -------------------------------------------------------------
 
   static bool IsExistingModality(const OrthancRestApi::SetOfStrings& modalities,
@@ -2465,6 +2521,7 @@
     Register("/peers/{id}/store", PeerStore);
     Register("/peers/{id}/system", PeerSystem);
     Register("/peers/{id}/configuration", GetPeerConfiguration);  // New in 1.8.1
+    Register("/peers/{id}/store-straight", PeerStoreStraight);    // New in 1.9.1
 
     Register("/modalities/{id}/find-worklist", DicomFindWorklist);