Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi2.cpp @ 216:e5d5d4a9a326
refactored upload of dicom through http
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 11:57:35 +0100 |
parents | c07170f3f4f7 |
children | 1ac3aacd10a5 |
comparison
equal
deleted
inserted
replaced
215:c07170f3f4f7 | 216:e5d5d4a9a326 |
---|---|
39 #include "ServerToolbox.h" | 39 #include "ServerToolbox.h" |
40 | 40 |
41 #include <dcmtk/dcmdata/dcistrmb.h> | 41 #include <dcmtk/dcmdata/dcistrmb.h> |
42 #include <dcmtk/dcmdata/dcfilefo.h> | 42 #include <dcmtk/dcmdata/dcfilefo.h> |
43 #include <boost/lexical_cast.hpp> | 43 #include <boost/lexical_cast.hpp> |
44 #include <glog/logging.h> | |
44 | 45 |
45 | 46 |
46 #define RETRIEVE_CONTEXT(call) \ | 47 #define RETRIEVE_CONTEXT(call) \ |
47 OrthancRestApi2& context = dynamic_cast<OrthancRestApi2&>(call.GetContext()) | 48 OrthancRestApi2& context = dynamic_cast<OrthancRestApi2&>(call.GetContext()) |
48 | 49 |
267 } | 268 } |
268 } | 269 } |
269 } | 270 } |
270 | 271 |
271 | 272 |
273 // Upload of DICOM files through HTTP --------------------------------------- | |
274 | |
275 static void UploadDicomFile(RestApi::PostCall& call) | |
276 { | |
277 RETRIEVE_CONTEXT(call); | |
278 | |
279 const std::string& postData = call.GetPostBody(); | |
280 | |
281 LOG(INFO) << "Receiving a DICOM file of " << postData.size() << " bytes through HTTP"; | |
282 | |
283 // Prepare an input stream for the memory buffer | |
284 DcmInputBufferStream is; | |
285 if (postData.size() > 0) | |
286 { | |
287 is.setBuffer(&postData[0], postData.size()); | |
288 } | |
289 is.setEos(); | |
290 | |
291 DcmFileFormat dicomFile; | |
292 if (!dicomFile.read(is).good()) | |
293 { | |
294 call.GetOutput().SignalError(Orthanc_HttpStatus_415_UnsupportedMediaType); | |
295 return; | |
296 } | |
297 | |
298 DicomMap dicomSummary; | |
299 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset()); | |
300 | |
301 DicomInstanceHasher hasher(dicomSummary); | |
302 | |
303 Json::Value dicomJson; | |
304 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset()); | |
305 | |
306 StoreStatus status = StoreStatus_Failure; | |
307 if (postData.size() > 0) | |
308 { | |
309 status = context.GetIndex().Store | |
310 (context.GetFileStorage(), reinterpret_cast<const char*>(&postData[0]), | |
311 postData.size(), dicomSummary, dicomJson, ""); | |
312 } | |
313 | |
314 Json::Value result = Json::objectValue; | |
315 | |
316 if (status != StoreStatus_Failure) | |
317 { | |
318 result["ID"] = hasher.HashInstance(); | |
319 result["Path"] = GetBasePath(ResourceType_Instance, hasher.HashInstance()); | |
320 } | |
321 | |
322 result["Status"] = ToString(status); | |
323 call.GetOutput().AnswerJson(result); | |
324 } | |
272 | 325 |
273 | 326 |
274 // DICOM bridge ------------------------------------------------------------- | 327 // DICOM bridge ------------------------------------------------------------- |
275 | 328 |
276 static void ListModalities(RestApi::GetCall& call) | 329 static void ListModalities(RestApi::GetCall& call) |
303 Register("/", ServeRoot); | 356 Register("/", ServeRoot); |
304 Register("/system", GetSystemInformation); | 357 Register("/system", GetSystemInformation); |
305 Register("/changes", GetChanges); | 358 Register("/changes", GetChanges); |
306 Register("/modalities", ListModalities); | 359 Register("/modalities", ListModalities); |
307 | 360 |
361 Register("/instances", UploadDicomFile); | |
308 Register("/instances", ListResources<ResourceType_Instance>); | 362 Register("/instances", ListResources<ResourceType_Instance>); |
309 Register("/patients", ListResources<ResourceType_Patient>); | 363 Register("/patients", ListResources<ResourceType_Patient>); |
310 Register("/series", ListResources<ResourceType_Series>); | 364 Register("/series", ListResources<ResourceType_Series>); |
311 Register("/studies", ListResources<ResourceType_Study>); | 365 Register("/studies", ListResources<ResourceType_Study>); |
312 | 366 |