Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi.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 |
---|---|
50 Json::StyledWriter writer; | 50 Json::StyledWriter writer; |
51 std::string s = writer.write(value); | 51 std::string s = writer.write(value); |
52 output.AnswerBufferWithContentType(s, "application/json"); | 52 output.AnswerBufferWithContentType(s, "application/json"); |
53 } | 53 } |
54 | 54 |
55 bool OrthancRestApi::Store(Json::Value& result, | |
56 const std::string& postData) | |
57 { | |
58 // Prepare an input stream for the memory buffer | |
59 DcmInputBufferStream is; | |
60 if (postData.size() > 0) | |
61 { | |
62 is.setBuffer(&postData[0], postData.size()); | |
63 } | |
64 is.setEos(); | |
65 | |
66 //printf("[%d]\n", postData.size()); | |
67 | |
68 DcmFileFormat dicomFile; | |
69 if (dicomFile.read(is).good()) | |
70 { | |
71 DicomMap dicomSummary; | |
72 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset()); | |
73 | |
74 DicomInstanceHasher hasher(dicomSummary); | |
75 | |
76 Json::Value dicomJson; | |
77 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset()); | |
78 | |
79 StoreStatus status = StoreStatus_Failure; | |
80 if (postData.size() > 0) | |
81 { | |
82 status = index_.Store | |
83 (storage_, reinterpret_cast<const char*>(&postData[0]), | |
84 postData.size(), dicomSummary, dicomJson, ""); | |
85 } | |
86 | |
87 result["ID"] = hasher.HashInstance(); | |
88 result["Path"] = "/instances/" + hasher.HashInstance(); | |
89 | |
90 switch (status) | |
91 { | |
92 case StoreStatus_Success: | |
93 result["Status"] = "Success"; | |
94 return true; | |
95 | |
96 case StoreStatus_AlreadyStored: | |
97 result["Status"] = "AlreadyStored"; | |
98 return true; | |
99 | |
100 default: | |
101 return false; | |
102 } | |
103 } | |
104 | |
105 return false; | |
106 } | |
107 | |
108 void OrthancRestApi::ConnectToModality(DicomUserConnection& c, | 55 void OrthancRestApi::ConnectToModality(DicomUserConnection& c, |
109 const std::string& name) | 56 const std::string& name) |
110 { | 57 { |
111 std::string aet, address; | 58 std::string aet, address; |
112 int port; | 59 int port; |
338 const std::string& postData) | 285 const std::string& postData) |
339 { | 286 { |
340 bool existingResource = false; | 287 bool existingResource = false; |
341 Json::Value result(Json::objectValue); | 288 Json::Value result(Json::objectValue); |
342 | 289 |
343 | |
344 // List all the instances --------------------------------------------------- | |
345 | |
346 if (uri.size() == 1 && uri[0] == "instances") | |
347 { | |
348 if (method == "GET") | |
349 { | |
350 result = Json::Value(Json::arrayValue); | |
351 index_.GetAllUuids(result, ResourceType_Instance); | |
352 existingResource = true; | |
353 } | |
354 else if (method == "POST") | |
355 { | |
356 // Add a new instance to the storage | |
357 if (Store(result, postData)) | |
358 { | |
359 SendJson(output, result); | |
360 return; | |
361 } | |
362 else | |
363 { | |
364 output.SendHeader(Orthanc_HttpStatus_415_UnsupportedMediaType); | |
365 return; | |
366 } | |
367 } | |
368 else | |
369 { | |
370 output.SendMethodNotAllowedError("GET,POST"); | |
371 return; | |
372 } | |
373 } | |
374 | 290 |
375 // DICOM bridge ------------------------------------------------------------- | 291 // DICOM bridge ------------------------------------------------------------- |
376 | 292 |
377 if ((uri.size() == 2 || | 293 if ((uri.size() == 2 || |
378 uri.size() == 3) && | 294 uri.size() == 3) && |