comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 3203:810772486249

URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Feb 2019 15:45:16 +0100
parents 4bbadcd03966
children 4066998150ef
comparison
equal deleted inserted replaced
3202:ef4d86d05503 3203:810772486249
33 33
34 #include "../PrecompiledHeadersServer.h" 34 #include "../PrecompiledHeadersServer.h"
35 #include "OrthancRestApi.h" 35 #include "OrthancRestApi.h"
36 36
37 #include "../../Core/Compression/GzipCompressor.h" 37 #include "../../Core/Compression/GzipCompressor.h"
38 #include "../../Core/DicomParsing/DicomWebJsonVisitor.h"
38 #include "../../Core/DicomParsing/FromDcmtkBridge.h" 39 #include "../../Core/DicomParsing/FromDcmtkBridge.h"
39 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h" 40 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h"
40 #include "../../Core/HttpServer/HttpContentNegociation.h" 41 #include "../../Core/HttpServer/HttpContentNegociation.h"
41 #include "../../Core/Logging.h" 42 #include "../../Core/Logging.h"
42 #include "../DefaultDicomImageDecoder.h" 43 #include "../DefaultDicomImageDecoder.h"
242 static void GetInstanceFile(RestApiGetCall& call) 243 static void GetInstanceFile(RestApiGetCall& call)
243 { 244 {
244 ServerContext& context = OrthancRestApi::GetContext(call); 245 ServerContext& context = OrthancRestApi::GetContext(call);
245 246
246 std::string publicId = call.GetUriComponent("id", ""); 247 std::string publicId = call.GetUriComponent("id", "");
248
249 IHttpHandler::Arguments::const_iterator accept = call.GetHttpHeaders().find("accept");
250 if (accept != call.GetHttpHeaders().end())
251 {
252 // New in Orthanc 1.5.4
253 try
254 {
255 MimeType mime = StringToMimeType(accept->second.c_str());
256
257 if (mime == MimeType_DicomWebJson ||
258 mime == MimeType_DicomWebXml)
259 {
260 DicomWebJsonVisitor visitor;
261
262 {
263 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId);
264 locker.GetDicom().Apply(visitor);
265 }
266
267 if (mime == MimeType_DicomWebJson)
268 {
269 std::string s = visitor.GetResult().toStyledString();
270 call.GetOutput().AnswerBuffer(s, MimeType_DicomWebJson);
271 }
272 else
273 {
274 std::string xml;
275 visitor.FormatXml(xml);
276 call.GetOutput().AnswerBuffer(xml, MimeType_DicomWebXml);
277 }
278
279 return;
280 }
281 }
282 catch (OrthancException&)
283 {
284 }
285 }
286
247 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom); 287 context.AnswerAttachment(call.GetOutput(), publicId, FileContentType_Dicom);
248 } 288 }
249 289
250 290
251 static void ExportInstanceFile(RestApiPostCall& call) 291 static void ExportInstanceFile(RestApiPostCall& call)