Mercurial > hg > orthanc
comparison OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp @ 4339:fc5caed6f940
"/tools/dicom-echo": Execute C-Echo SCU to a modality that is not registered in "/modalities"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 03 Dec 2020 11:47:03 +0100 |
parents | 1263e727d048 |
children | 6fa8bb987be2 |
comparison
equal
deleted
inserted
replaced
4338:1263e727d048 | 4339:fc5caed6f940 |
---|---|
71 | 71 |
72 | 72 |
73 static void InjectAssociationTimeout(DicomAssociationParameters& params, | 73 static void InjectAssociationTimeout(DicomAssociationParameters& params, |
74 const Json::Value& body) | 74 const Json::Value& body) |
75 { | 75 { |
76 if (body.type() != Json::objectValue) | 76 if (body.type() == Json::objectValue && |
77 { | 77 body.isMember(KEY_TIMEOUT)) |
78 throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object"); | |
79 } | |
80 else if (body.isMember(KEY_TIMEOUT)) | |
81 { | 78 { |
82 // New in Orthanc 1.7.0 | 79 // New in Orthanc 1.7.0 |
83 params.SetTimeout(SerializationToolbox::ReadUnsignedInteger(body, KEY_TIMEOUT)); | 80 params.SetTimeout(SerializationToolbox::ReadUnsignedInteger(body, KEY_TIMEOUT)); |
84 } | 81 } |
85 } | 82 } |
100 | 97 |
101 | 98 |
102 static DicomAssociationParameters GetAssociationParameters(RestApiPostCall& call) | 99 static DicomAssociationParameters GetAssociationParameters(RestApiPostCall& call) |
103 { | 100 { |
104 Json::Value body; | 101 Json::Value body; |
105 call.ParseJsonRequest(body); | 102 |
103 if (!call.ParseJsonRequest(body)) | |
104 { | |
105 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse the JSON body"); | |
106 } | |
107 | |
106 return GetAssociationParameters(call, body); | 108 return GetAssociationParameters(call, body); |
107 } | 109 } |
108 | 110 |
109 | 111 |
110 /*************************************************************************** | 112 /*************************************************************************** |
111 * DICOM C-Echo SCU | 113 * DICOM C-Echo SCU |
112 ***************************************************************************/ | 114 ***************************************************************************/ |
113 | 115 |
116 static void ExecuteEcho(RestApiOutput& output, | |
117 const DicomAssociationParameters& parameters) | |
118 { | |
119 DicomControlUserConnection connection(parameters); | |
120 | |
121 if (connection.Echo()) | |
122 { | |
123 // Echo has succeeded | |
124 output.AnswerBuffer("{}", MimeType_Json); | |
125 return; | |
126 } | |
127 else | |
128 { | |
129 // Echo has failed | |
130 output.SignalError(HttpStatus_500_InternalServerError); | |
131 } | |
132 } | |
133 | |
134 | |
114 static void DicomEcho(RestApiPostCall& call) | 135 static void DicomEcho(RestApiPostCall& call) |
115 { | 136 { |
116 DicomControlUserConnection connection(GetAssociationParameters(call)); | 137 ExecuteEcho(call.GetOutput(), GetAssociationParameters(call)); |
117 | 138 } |
118 if (connection.Echo()) | 139 |
119 { | 140 |
120 // Echo has succeeded | 141 static void DicomEchoTool(RestApiPostCall& call) |
121 call.GetOutput().AnswerBuffer("{}", MimeType_Json); | 142 { |
122 return; | 143 Json::Value body; |
144 if (call.ParseJsonRequest(body)) | |
145 { | |
146 RemoteModalityParameters modality; | |
147 modality.Unserialize(body); | |
148 | |
149 const std::string& localAet = | |
150 OrthancRestApi::GetContext(call).GetDefaultLocalApplicationEntityTitle(); | |
151 | |
152 DicomAssociationParameters params(localAet, modality); | |
153 InjectAssociationTimeout(params, body); | |
154 | |
155 ExecuteEcho(call.GetOutput(), params); | |
123 } | 156 } |
124 else | 157 else |
125 { | 158 { |
126 // Echo has failed | 159 throw OrthancException(ErrorCode_BadFileFormat, "Cannot parse the JSON body"); |
127 call.GetOutput().SignalError(HttpStatus_500_InternalServerError); | 160 } |
128 } | 161 } |
129 } | |
130 | |
131 | 162 |
132 | 163 |
133 /*************************************************************************** | 164 /*************************************************************************** |
134 * DICOM C-Find SCU => DEPRECATED! | 165 * DICOM C-Find SCU => DEPRECATED! |
135 ***************************************************************************/ | 166 ***************************************************************************/ |
1292 } | 1323 } |
1293 | 1324 |
1294 context.SignalUpdatedModalities(); | 1325 context.SignalUpdatedModalities(); |
1295 | 1326 |
1296 call.GetOutput().AnswerBuffer("", MimeType_PlainText); | 1327 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
1328 } | |
1329 else | |
1330 { | |
1331 throw OrthancException(ErrorCode_BadFileFormat); | |
1297 } | 1332 } |
1298 } | 1333 } |
1299 | 1334 |
1300 | 1335 |
1301 static void DeleteModality(RestApiDeleteCall& call) | 1336 static void DeleteModality(RestApiDeleteCall& call) |
1684 | 1719 |
1685 // Storage commitment | 1720 // Storage commitment |
1686 Register("/modalities/{id}/storage-commitment", StorageCommitmentScu); | 1721 Register("/modalities/{id}/storage-commitment", StorageCommitmentScu); |
1687 Register("/storage-commitment/{id}", GetStorageCommitmentReport); | 1722 Register("/storage-commitment/{id}", GetStorageCommitmentReport); |
1688 Register("/storage-commitment/{id}/remove", RemoveAfterStorageCommitment); | 1723 Register("/storage-commitment/{id}/remove", RemoveAfterStorageCommitment); |
1724 | |
1725 Register("/tools/dicom-echo", DicomEchoTool); // New in 1.8.1 | |
1689 } | 1726 } |
1690 } | 1727 } |