comparison OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 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 251614c2edac
children ae20fccdd867
comparison
equal deleted inserted replaced
2898:e5e3253a1164 2899:5dd649de253d
38 #include "../../Core/SerializationToolbox.h" 38 #include "../../Core/SerializationToolbox.h"
39 #include "../ServerContext.h" 39 #include "../ServerContext.h"
40 40
41 namespace Orthanc 41 namespace Orthanc
42 { 42 {
43 static void SetupResourceAnswer(Json::Value& result,
44 const std::string& publicId,
45 ResourceType resourceType,
46 StoreStatus status)
47 {
48 result = Json::objectValue;
49
50 if (status != StoreStatus_Failure)
51 {
52 result["ID"] = publicId;
53 result["Path"] = GetBasePath(resourceType, publicId);
54 }
55
56 result["Status"] = EnumerationToString(status);
57 }
58
59
60 void OrthancRestApi::AnswerStoredInstance(RestApiPostCall& call,
61 DicomInstanceToStore& instance,
62 StoreStatus status) const
63 {
64 Json::Value result;
65 SetupResourceAnswer(result, instance.GetHasher().HashInstance(),
66 ResourceType_Instance, status);
67
68 result["ParentPatient"] = instance.GetHasher().HashPatient();
69 result["ParentStudy"] = instance.GetHasher().HashStudy();
70 result["ParentSeries"] = instance.GetHasher().HashSeries();
71
72 call.GetOutput().AnswerJson(result);
73 }
74
75
43 void OrthancRestApi::AnswerStoredResource(RestApiPostCall& call, 76 void OrthancRestApi::AnswerStoredResource(RestApiPostCall& call,
44 const std::string& publicId, 77 const std::string& publicId,
45 ResourceType resourceType, 78 ResourceType resourceType,
46 StoreStatus status) const 79 StoreStatus status) const
47 { 80 {
48 Json::Value result = Json::objectValue; 81 Json::Value result;
49 82 SetupResourceAnswer(result, publicId, resourceType, status);
50 if (status != StoreStatus_Failure)
51 {
52 result["ID"] = publicId;
53 result["Path"] = GetBasePath(resourceType, publicId);
54 }
55
56 result["Status"] = EnumerationToString(status);
57 call.GetOutput().AnswerJson(result); 83 call.GetOutput().AnswerJson(result);
58 } 84 }
59 85
60 86
61 void OrthancRestApi::ResetOrthanc(RestApiPostCall& call) 87 void OrthancRestApi::ResetOrthanc(RestApiPostCall& call)
98 toStore.SetBuffer(postData); 124 toStore.SetBuffer(postData);
99 125
100 std::string publicId; 126 std::string publicId;
101 StoreStatus status = context.Store(publicId, toStore); 127 StoreStatus status = context.Store(publicId, toStore);
102 128
103 OrthancRestApi::GetApi(call).AnswerStoredResource(call, publicId, ResourceType_Instance, status); 129 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status);
104 } 130 }
105 131
106 132
107 133
108 // Registration of the various REST handlers -------------------------------- 134 // Registration of the various REST handlers --------------------------------