Mercurial > hg > orthanc
annotate OrthancServer/OrthancRestApi.cpp @ 210:96b7918a6a18
start of the refactoring of the Orthanc REST API
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Nov 2012 18:03:44 +0100 |
parents | de640de989b8 |
children | b7aea293b965 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
0 | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
62 | 33 #include "OrthancRestApi.h" |
0 | 34 |
62 | 35 #include "OrthancInitialization.h" |
0 | 36 #include "FromDcmtkBridge.h" |
37 #include "../Core/Uuid.h" | |
208 | 38 #include "../Core/HttpServer/FilesystemHttpSender.h" |
0 | 39 |
40 #include <dcmtk/dcmdata/dcistrmb.h> | |
41 #include <dcmtk/dcmdata/dcfilefo.h> | |
42 #include <boost/lexical_cast.hpp> | |
43 | |
62 | 44 namespace Orthanc |
0 | 45 { |
46 static void SendJson(HttpOutput& output, | |
47 const Json::Value& value) | |
48 { | |
49 Json::StyledWriter writer; | |
50 std::string s = writer.write(value); | |
51 output.AnswerBufferWithContentType(s, "application/json"); | |
52 } | |
53 | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
54 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
55 static void SimplifyTagsRecursion(Json::Value& target, |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
56 const Json::Value& source) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
57 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
58 assert(source.isObject()); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
59 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
60 target = Json::objectValue; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
61 Json::Value::Members members = source.getMemberNames(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
62 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
63 for (size_t i = 0; i < members.size(); i++) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
64 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
65 const Json::Value& v = source[members[i]]; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
66 const std::string& name = v["Name"].asString(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
67 const std::string& type = v["Type"].asString(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
68 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
69 if (type == "String") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
70 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
71 target[name] = v["Value"].asString(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
72 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
73 else if (type == "TooLong" || |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
74 type == "Null") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
75 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
76 target[name] = Json::nullValue; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
77 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
78 else if (type == "Sequence") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
79 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
80 const Json::Value& array = v["Value"]; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
81 assert(array.isArray()); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
82 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
83 Json::Value children = Json::arrayValue; |
126 | 84 for (Json::Value::ArrayIndex i = 0; i < array.size(); i++) |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
85 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
86 Json::Value c; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
87 SimplifyTagsRecursion(c, array[i]); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
88 children.append(c); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
89 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
90 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
91 target[name] = children; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
92 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
93 else |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
94 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
95 assert(0); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
96 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
97 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
98 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
99 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
100 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
101 static void SimplifyTags(Json::Value& target, |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
102 const FileStorage& storage, |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
103 const std::string& fileUuid) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
104 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
105 std::string s; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
106 storage.ReadFile(s, fileUuid); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
107 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
108 Json::Value source; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
109 Json::Reader reader; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
110 if (!reader.parse(s, source)) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
111 { |
62 | 112 throw OrthancException("Corrupted JSON file"); |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
113 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
114 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
115 SimplifyTagsRecursion(target, source); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
116 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
117 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
118 |
62 | 119 bool OrthancRestApi::Store(Json::Value& result, |
50 | 120 const std::string& postData) |
0 | 121 { |
122 // Prepare an input stream for the memory buffer | |
123 DcmInputBufferStream is; | |
124 if (postData.size() > 0) | |
125 { | |
126 is.setBuffer(&postData[0], postData.size()); | |
127 } | |
128 is.setEos(); | |
129 | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
130 //printf("[%d]\n", postData.size()); |
0 | 131 |
132 DcmFileFormat dicomFile; | |
133 if (dicomFile.read(is).good()) | |
134 { | |
135 DicomMap dicomSummary; | |
136 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset()); | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
137 |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
138 DicomInstanceHasher hasher(dicomSummary); |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
139 |
0 | 140 Json::Value dicomJson; |
141 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset()); | |
142 | |
143 StoreStatus status = StoreStatus_Failure; | |
144 if (postData.size() > 0) | |
145 { | |
146 status = index_.Store | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
147 (storage_, reinterpret_cast<const char*>(&postData[0]), |
0 | 148 postData.size(), dicomSummary, dicomJson, ""); |
149 } | |
150 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
151 result["ID"] = hasher.HashInstance(); |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
152 result["Path"] = "/instances/" + hasher.HashInstance(); |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
153 |
0 | 154 switch (status) |
155 { | |
156 case StoreStatus_Success: | |
157 result["Status"] = "Success"; | |
158 return true; | |
159 | |
160 case StoreStatus_AlreadyStored: | |
161 result["Status"] = "AlreadyStored"; | |
162 return true; | |
163 | |
164 default: | |
165 return false; | |
166 } | |
167 } | |
168 | |
169 return false; | |
170 } | |
171 | |
62 | 172 void OrthancRestApi::ConnectToModality(DicomUserConnection& c, |
50 | 173 const std::string& name) |
0 | 174 { |
175 std::string aet, address; | |
176 int port; | |
177 GetDicomModality(name, aet, address, port); | |
62 | 178 c.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
0 | 179 c.SetDistantApplicationEntityTitle(aet); |
180 c.SetDistantHost(address); | |
181 c.SetDistantPort(port); | |
182 c.Open(); | |
183 } | |
184 | |
62 | 185 bool OrthancRestApi::MergeQueryAndTemplate(DicomMap& result, |
50 | 186 const std::string& postData) |
0 | 187 { |
188 Json::Value query; | |
189 Json::Reader reader; | |
190 | |
191 if (!reader.parse(postData, query) || | |
8 | 192 query.type() != Json::objectValue) |
0 | 193 { |
194 return false; | |
195 } | |
196 | |
197 Json::Value::Members members = query.getMemberNames(); | |
198 for (size_t i = 0; i < members.size(); i++) | |
199 { | |
200 DicomTag t = FromDcmtkBridge::FindTag(members[i]); | |
201 result.SetValue(t, query[members[i]].asString()); | |
202 } | |
203 | |
204 return true; | |
205 } | |
206 | |
62 | 207 bool OrthancRestApi::DicomFindPatient(Json::Value& result, |
50 | 208 DicomUserConnection& c, |
209 const std::string& postData) | |
0 | 210 { |
211 DicomMap m; | |
212 DicomMap::SetupFindPatientTemplate(m); | |
213 if (!MergeQueryAndTemplate(m, postData)) | |
214 { | |
215 return false; | |
216 } | |
217 | |
218 DicomFindAnswers answers; | |
219 c.FindPatient(answers, m); | |
220 answers.ToJson(result); | |
221 return true; | |
222 } | |
223 | |
62 | 224 bool OrthancRestApi::DicomFindStudy(Json::Value& result, |
50 | 225 DicomUserConnection& c, |
226 const std::string& postData) | |
0 | 227 { |
228 DicomMap m; | |
229 DicomMap::SetupFindStudyTemplate(m); | |
230 if (!MergeQueryAndTemplate(m, postData)) | |
231 { | |
232 return false; | |
233 } | |
234 | |
80 | 235 if (m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && |
236 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) | |
0 | 237 { |
238 return false; | |
239 } | |
240 | |
241 DicomFindAnswers answers; | |
242 c.FindStudy(answers, m); | |
243 answers.ToJson(result); | |
244 return true; | |
245 } | |
246 | |
62 | 247 bool OrthancRestApi::DicomFindSeries(Json::Value& result, |
50 | 248 DicomUserConnection& c, |
249 const std::string& postData) | |
0 | 250 { |
251 DicomMap m; | |
252 DicomMap::SetupFindSeriesTemplate(m); | |
253 if (!MergeQueryAndTemplate(m, postData)) | |
254 { | |
255 return false; | |
256 } | |
257 | |
80 | 258 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && |
259 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) || | |
260 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2) | |
0 | 261 { |
262 return false; | |
263 } | |
264 | |
265 DicomFindAnswers answers; | |
266 c.FindSeries(answers, m); | |
267 answers.ToJson(result); | |
268 return true; | |
269 } | |
270 | |
62 | 271 bool OrthancRestApi::DicomFind(Json::Value& result, |
50 | 272 DicomUserConnection& c, |
273 const std::string& postData) | |
0 | 274 { |
275 DicomMap m; | |
276 DicomMap::SetupFindPatientTemplate(m); | |
277 if (!MergeQueryAndTemplate(m, postData)) | |
278 { | |
279 return false; | |
280 } | |
281 | |
282 DicomFindAnswers patients; | |
283 c.FindPatient(patients, m); | |
284 | |
285 // Loop over the found patients | |
286 result = Json::arrayValue; | |
287 for (size_t i = 0; i < patients.GetSize(); i++) | |
288 { | |
289 Json::Value patient(Json::objectValue); | |
290 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i)); | |
291 | |
292 DicomMap::SetupFindStudyTemplate(m); | |
293 if (!MergeQueryAndTemplate(m, postData)) | |
294 { | |
295 return false; | |
296 } | |
80 | 297 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID); |
0 | 298 |
299 DicomFindAnswers studies; | |
300 c.FindStudy(studies, m); | |
301 | |
302 patient["Studies"] = Json::arrayValue; | |
303 | |
304 // Loop over the found studies | |
305 for (size_t j = 0; j < studies.GetSize(); j++) | |
306 { | |
307 Json::Value study(Json::objectValue); | |
308 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j)); | |
309 | |
310 DicomMap::SetupFindSeriesTemplate(m); | |
311 if (!MergeQueryAndTemplate(m, postData)) | |
312 { | |
313 return false; | |
314 } | |
80 | 315 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID); |
316 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID); | |
0 | 317 |
318 DicomFindAnswers series; | |
319 c.FindSeries(series, m); | |
320 | |
321 // Loop over the found series | |
322 study["Series"] = Json::arrayValue; | |
323 for (size_t k = 0; k < series.GetSize(); k++) | |
324 { | |
325 Json::Value series2(Json::objectValue); | |
326 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k)); | |
327 study["Series"].append(series2); | |
328 } | |
329 | |
330 patient["Studies"].append(study); | |
331 } | |
332 | |
333 result.append(patient); | |
334 } | |
335 | |
336 return true; | |
337 } | |
338 | |
339 | |
340 | |
62 | 341 bool OrthancRestApi::DicomStore(Json::Value& result, |
50 | 342 DicomUserConnection& c, |
343 const std::string& postData) | |
0 | 344 { |
345 Json::Value found(Json::objectValue); | |
346 | |
347 if (!Toolbox::IsUuid(postData)) | |
348 { | |
349 // This is not a UUID, assume this is a DICOM instance | |
350 c.Store(postData); | |
351 } | |
352 else if (index_.GetSeries(found, postData)) | |
353 { | |
354 // The UUID corresponds to a series | |
126 | 355 for (Json::Value::ArrayIndex i = 0; i < found["Instances"].size(); i++) |
0 | 356 { |
357 std::string uuid = found["Instances"][i].asString(); | |
358 Json::Value instance(Json::objectValue); | |
359 if (index_.GetInstance(instance, uuid)) | |
360 { | |
361 std::string content; | |
362 storage_.ReadFile(content, instance["FileUuid"].asString()); | |
363 c.Store(content); | |
364 } | |
365 else | |
366 { | |
367 return false; | |
368 } | |
369 } | |
370 } | |
371 else if (index_.GetInstance(found, postData)) | |
372 { | |
373 // The UUID corresponds to an instance | |
374 std::string content; | |
375 storage_.ReadFile(content, found["FileUuid"].asString()); | |
376 c.Store(content); | |
377 } | |
378 else | |
379 { | |
380 return false; | |
381 } | |
382 | |
383 return true; | |
384 } | |
385 | |
386 | |
62 | 387 OrthancRestApi::OrthancRestApi(ServerIndex& index, |
50 | 388 const std::string& path) : |
0 | 389 index_(index), |
390 storage_(path) | |
391 { | |
392 GetListOfDicomModalities(modalities_); | |
393 } | |
394 | |
395 | |
62 | 396 void OrthancRestApi::Handle( |
0 | 397 HttpOutput& output, |
398 const std::string& method, | |
399 const UriComponents& uri, | |
400 const Arguments& headers, | |
207 | 401 const Arguments& getArguments, |
0 | 402 const std::string& postData) |
403 { | |
404 if (uri.size() == 0) | |
405 { | |
406 if (method == "GET") | |
407 { | |
85
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
408 output.Redirect("app/explorer.html"); |
0 | 409 } |
410 else | |
411 { | |
412 output.SendMethodNotAllowedError("GET"); | |
413 } | |
414 | |
415 return; | |
416 } | |
417 | |
418 bool existingResource = false; | |
419 Json::Value result(Json::objectValue); | |
420 | |
421 | |
422 // List all the instances --------------------------------------------------- | |
423 | |
424 if (uri.size() == 1 && uri[0] == "instances") | |
425 { | |
426 if (method == "GET") | |
427 { | |
428 result = Json::Value(Json::arrayValue); | |
190 | 429 index_.GetAllUuids(result, ResourceType_Instance); |
0 | 430 existingResource = true; |
431 } | |
432 else if (method == "POST") | |
433 { | |
434 // Add a new instance to the storage | |
435 if (Store(result, postData)) | |
436 { | |
437 SendJson(output, result); | |
438 return; | |
439 } | |
440 else | |
441 { | |
62 | 442 output.SendHeader(Orthanc_HttpStatus_415_UnsupportedMediaType); |
0 | 443 return; |
444 } | |
445 } | |
446 else | |
447 { | |
448 output.SendMethodNotAllowedError("GET,POST"); | |
449 return; | |
450 } | |
451 } | |
452 | |
453 | |
454 // List all the patients, studies or series --------------------------------- | |
455 | |
456 if (uri.size() == 1 && | |
457 (uri[0] == "series" || | |
458 uri[0] == "studies" || | |
459 uri[0] == "patients")) | |
460 { | |
461 if (method == "GET") | |
462 { | |
463 result = Json::Value(Json::arrayValue); | |
464 | |
465 if (uri[0] == "instances") | |
190 | 466 index_.GetAllUuids(result, ResourceType_Instance); |
0 | 467 else if (uri[0] == "series") |
190 | 468 index_.GetAllUuids(result, ResourceType_Series); |
0 | 469 else if (uri[0] == "studies") |
190 | 470 index_.GetAllUuids(result, ResourceType_Study); |
0 | 471 else if (uri[0] == "patients") |
190 | 472 index_.GetAllUuids(result, ResourceType_Patient); |
0 | 473 |
474 existingResource = true; | |
475 } | |
476 else | |
477 { | |
478 output.SendMethodNotAllowedError("GET"); | |
479 return; | |
480 } | |
481 } | |
482 | |
483 | |
484 // Information about a single object ---------------------------------------- | |
485 | |
486 else if (uri.size() == 2 && | |
487 (uri[0] == "instances" || | |
488 uri[0] == "series" || | |
489 uri[0] == "studies" || | |
490 uri[0] == "patients")) | |
491 { | |
492 if (method == "GET") | |
493 { | |
494 if (uri[0] == "patients") | |
495 { | |
496 existingResource = index_.GetPatient(result, uri[1]); | |
199 | 497 assert(!existingResource || result["Type"] == "Patient"); |
0 | 498 } |
499 else if (uri[0] == "studies") | |
500 { | |
501 existingResource = index_.GetStudy(result, uri[1]); | |
199 | 502 assert(!existingResource || result["Type"] == "Study"); |
0 | 503 } |
504 else if (uri[0] == "series") | |
505 { | |
506 existingResource = index_.GetSeries(result, uri[1]); | |
199 | 507 assert(!existingResource || result["Type"] == "Series"); |
0 | 508 } |
509 else if (uri[0] == "instances") | |
510 { | |
511 existingResource = index_.GetInstance(result, uri[1]); | |
199 | 512 assert(!existingResource || result["Type"] == "Instance"); |
0 | 513 } |
514 } | |
515 else if (method == "DELETE") | |
516 { | |
517 if (uri[0] == "patients") | |
518 { | |
519 existingResource = index_.DeletePatient(result, uri[1]); | |
520 } | |
521 else if (uri[0] == "studies") | |
522 { | |
523 existingResource = index_.DeleteStudy(result, uri[1]); | |
524 } | |
525 else if (uri[0] == "series") | |
526 { | |
527 existingResource = index_.DeleteSeries(result, uri[1]); | |
528 } | |
529 else if (uri[0] == "instances") | |
530 { | |
531 existingResource = index_.DeleteInstance(result, uri[1]); | |
532 } | |
533 | |
534 if (existingResource) | |
535 { | |
536 result["Status"] = "Success"; | |
537 } | |
538 } | |
539 else | |
540 { | |
541 output.SendMethodNotAllowedError("GET,DELETE"); | |
542 return; | |
543 } | |
544 } | |
545 | |
546 | |
547 // Get the DICOM or the JSON file of one instance --------------------------- | |
548 | |
549 else if (uri.size() == 3 && | |
550 uri[0] == "instances" && | |
551 (uri[2] == "file" || | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
552 uri[2] == "tags" || |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
553 uri[2] == "simplified-tags")) |
0 | 554 { |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
555 CompressionType compressionType; |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
556 std::string fileUuid, contentType, filename; |
0 | 557 if (uri[2] == "file") |
558 { | |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
559 existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Dicom); |
0 | 560 contentType = "application/dicom"; |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
561 filename = fileUuid + ".dcm"; |
0 | 562 } |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
563 else if (uri[2] == "tags" || |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
564 uri[2] == "simplified-tags") |
0 | 565 { |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
566 existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Json); |
0 | 567 contentType = "application/json"; |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
568 filename = fileUuid + ".json"; |
0 | 569 } |
570 | |
571 if (existingResource) | |
572 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
573 if (uri[2] == "simplified-tags") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
574 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
575 Json::Value v; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
576 SimplifyTags(v, storage_, fileUuid); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
577 SendJson(output, v); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
578 return; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
579 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
580 else |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
581 { |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
582 output.AnswerFile(storage_, fileUuid, contentType, filename.c_str()); |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
583 return; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
584 } |
0 | 585 } |
586 } | |
587 | |
588 | |
589 else if (uri.size() == 3 && | |
590 uri[0] == "instances" && | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
591 uri[2] == "frames") |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
592 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
593 Json::Value instance(Json::objectValue); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
594 existingResource = index_.GetInstance(instance, uri[1]); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
595 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
596 if (existingResource) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
597 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
598 result = Json::arrayValue; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
599 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
600 unsigned int numberOfFrames = 1; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
601 try |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
602 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
603 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"]; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
604 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString()); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
605 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
606 catch (boost::bad_lexical_cast) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
607 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
608 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
609 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
610 for (unsigned int i = 0; i < numberOfFrames; i++) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
611 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
612 result.append(i); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
613 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
614 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
615 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
616 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
617 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
618 else if (uri[0] == "instances" && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
619 ((uri.size() == 3 && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
620 (uri[2] == "preview" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
621 uri[2] == "image-uint8" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
622 uri[2] == "image-uint16")) || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
623 (uri.size() == 5 && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
624 uri[2] == "frames" && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
625 (uri[4] == "preview" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
626 uri[4] == "image-uint8" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
627 uri[4] == "image-uint16")))) |
0 | 628 { |
629 std::string uuid; | |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
630 CompressionType compressionType; |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
631 existingResource = index_.GetFile(uuid, compressionType, uri[1], AttachedFileType_Dicom); |
0 | 632 |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
633 std::string action = uri[2]; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
634 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
635 unsigned int frame = 0; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
636 if (existingResource && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
637 uri.size() == 5) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
638 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
639 // Access to multi-frame image |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
640 action = uri[4]; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
641 try |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
642 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
643 frame = boost::lexical_cast<unsigned int>(uri[3]); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
644 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
645 catch (boost::bad_lexical_cast) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
646 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
647 existingResource = false; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
648 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
649 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
650 |
0 | 651 if (existingResource) |
652 { | |
653 std::string dicomContent, png; | |
654 storage_.ReadFile(dicomContent, uuid); | |
655 try | |
656 { | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
657 if (action == "preview") |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
658 { |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
659 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_Preview); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
660 } |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
661 else if (action == "image-uint8") |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
662 { |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
663 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt8); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
664 } |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
665 else if (action == "image-uint16") |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
666 { |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
667 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt16); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
668 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
669 else |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
670 { |
62 | 671 throw OrthancException(ErrorCode_InternalError); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
672 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
673 |
0 | 674 output.AnswerBufferWithContentType(png, "image/png"); |
675 return; | |
676 } | |
62 | 677 catch (OrthancException&) |
0 | 678 { |
85
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
679 std::string root = ""; |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
680 for (size_t i = 1; i < uri.size(); i++) |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
681 { |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
682 root += "../"; |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
683 } |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
684 |
129 | 685 output.Redirect(root + "app/images/unsupported.png"); |
0 | 686 return; |
687 } | |
688 } | |
689 } | |
690 | |
691 | |
692 // DICOM bridge ------------------------------------------------------------- | |
693 | |
694 if ((uri.size() == 2 || | |
695 uri.size() == 3) && | |
696 uri[0] == "modalities") | |
697 { | |
698 if (modalities_.find(uri[1]) == modalities_.end()) | |
699 { | |
700 // Unknown modality | |
701 } | |
702 else if (uri.size() == 2) | |
703 { | |
704 if (method != "GET") | |
705 { | |
706 output.SendMethodNotAllowedError("POST"); | |
707 return; | |
708 } | |
709 else | |
710 { | |
711 existingResource = true; | |
712 result = Json::arrayValue; | |
713 result.append("find-patient"); | |
714 result.append("find-study"); | |
715 result.append("find-series"); | |
716 result.append("find"); | |
717 result.append("store"); | |
718 } | |
719 } | |
720 else if (uri.size() == 3) | |
721 { | |
722 if (uri[2] != "find-patient" && | |
723 uri[2] != "find-study" && | |
724 uri[2] != "find-series" && | |
725 uri[2] != "find" && | |
726 uri[2] != "store") | |
727 { | |
728 // Unknown request | |
729 } | |
730 else if (method != "POST") | |
731 { | |
732 output.SendMethodNotAllowedError("POST"); | |
733 return; | |
734 } | |
735 else | |
736 { | |
737 DicomUserConnection connection; | |
738 ConnectToModality(connection, uri[1]); | |
739 existingResource = true; | |
740 | |
741 if ((uri[2] == "find-patient" && !DicomFindPatient(result, connection, postData)) || | |
742 (uri[2] == "find-study" && !DicomFindStudy(result, connection, postData)) || | |
743 (uri[2] == "find-series" && !DicomFindSeries(result, connection, postData)) || | |
744 (uri[2] == "find" && !DicomFind(result, connection, postData)) || | |
745 (uri[2] == "store" && !DicomStore(result, connection, postData))) | |
746 { | |
62 | 747 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); |
0 | 748 return; |
749 } | |
750 } | |
751 } | |
752 } | |
753 | |
754 | |
755 if (existingResource) | |
756 { | |
757 SendJson(output, result); | |
758 } | |
759 else | |
760 { | |
62 | 761 output.SendHeader(Orthanc_HttpStatus_404_NotFound); |
0 | 762 } |
763 } | |
764 } |