changeset 2899:5dd649de253d

POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Oct 2018 12:03:51 +0200
parents e5e3253a1164
children 668d5ad73c74
files NEWS OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/OrthancRestApi/OrthancRestApi.cpp OrthancServer/OrthancRestApi/OrthancRestApi.h
diffstat 4 files changed, 49 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Oct 18 11:44:17 2018 +0200
+++ b/NEWS	Thu Oct 18 12:03:51 2018 +0200
@@ -18,6 +18,7 @@
 
 * New URI: "/studies/.../merge" to merge a study
 * New URI: "/studies/.../split" to split a study
+* POST-ing a DICOM file to "/instances" also answers the patient/study/series ID
 
 Maintenance
 -----------
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Thu Oct 18 11:44:17 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Thu Oct 18 12:03:51 2018 +0200
@@ -208,7 +208,8 @@
 
   static void StoreCreatedInstance(std::string& id /* out */,
                                    RestApiPostCall& call,
-                                   ParsedDicomFile& dicom)
+                                   ParsedDicomFile& dicom,
+                                   bool sendAnswer)
   {
     DicomInstanceToStore toStore;
     toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
@@ -221,6 +222,11 @@
     {
       throw OrthancException(ErrorCode_CannotStoreInstance);
     }
+
+    if (sendAnswer)
+    {
+      OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status);
+    }
   }
 
 
@@ -356,7 +362,7 @@
         dicom->ReplacePlainString(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1));
         dicom->ReplacePlainString(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1));
 
-        StoreCreatedInstance(someInstance, call, *dicom);
+        StoreCreatedInstance(someInstance, call, *dicom, false);
       }
     }
     catch (OrthancException&)
@@ -583,10 +589,7 @@
     }
 
     std::string id;
-    StoreCreatedInstance(id, call, dicom);
-    OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success);
-
-    return;
+    StoreCreatedInstance(id, call, dicom, true);
   }
 
 
@@ -610,8 +613,7 @@
       CreateDicomV1(dicom, call, request);
 
       std::string id;
-      StoreCreatedInstance(id, call, dicom);
-      OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success);
+      StoreCreatedInstance(id, call, dicom, true);
     }
   }
 
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Thu Oct 18 11:44:17 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Thu Oct 18 12:03:51 2018 +0200
@@ -40,20 +40,46 @@
 
 namespace Orthanc
 {
-  void OrthancRestApi::AnswerStoredResource(RestApiPostCall& call,
-                                            const std::string& publicId,
-                                            ResourceType resourceType,
-                                            StoreStatus status) const
+  static void SetupResourceAnswer(Json::Value& result,
+                                  const std::string& publicId,
+                                  ResourceType resourceType,
+                                  StoreStatus status)
   {
-    Json::Value result = Json::objectValue;
+    result = Json::objectValue;
 
     if (status != StoreStatus_Failure)
     {
       result["ID"] = publicId;
       result["Path"] = GetBasePath(resourceType, publicId);
     }
+    
+    result["Status"] = EnumerationToString(status);
+  }
 
-    result["Status"] = EnumerationToString(status);
+
+  void OrthancRestApi::AnswerStoredInstance(RestApiPostCall& call,
+                                            DicomInstanceToStore& instance,
+                                            StoreStatus status) const
+  {
+    Json::Value result;
+    SetupResourceAnswer(result, instance.GetHasher().HashInstance(), 
+                        ResourceType_Instance, status);
+
+    result["ParentPatient"] = instance.GetHasher().HashPatient();
+    result["ParentStudy"] = instance.GetHasher().HashStudy();
+    result["ParentSeries"] = instance.GetHasher().HashSeries();
+
+    call.GetOutput().AnswerJson(result);
+  }
+
+
+  void OrthancRestApi::AnswerStoredResource(RestApiPostCall& call,
+                                            const std::string& publicId,
+                                            ResourceType resourceType,
+                                            StoreStatus status) const
+  {
+    Json::Value result;
+    SetupResourceAnswer(result, publicId, resourceType, status);
     call.GetOutput().AnswerJson(result);
   }
 
@@ -100,7 +126,7 @@
     std::string publicId;
     StoreStatus status = context.Store(publicId, toStore);
 
-    OrthancRestApi::GetApi(call).AnswerStoredResource(call, publicId, ResourceType_Instance, status);
+    OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status);
   }
 
 
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.h	Thu Oct 18 11:44:17 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.h	Thu Oct 18 12:03:51 2018 +0200
@@ -44,6 +44,7 @@
 {
   class ServerContext;
   class ServerIndex;
+  class DicomInstanceToStore;
 
   class OrthancRestApi : public RestApi
   {
@@ -93,6 +94,10 @@
 
     static ServerIndex& GetIndex(RestApiCall& call);
 
+    void AnswerStoredInstance(RestApiPostCall& call,
+                              DicomInstanceToStore& instance,
+                              StoreStatus status) const;
+
     void AnswerStoredResource(RestApiPostCall& call,
                               const std::string& publicId,
                               ResourceType resourceType,