Mercurial > hg > orthanc
annotate OrthancServer/OrthancRestApi.cpp @ 171:da7e915202c7 Orthanc-0.2.3-Paulus
quick and dirty access to raw tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Nov 2012 13:45:36 +0100 |
parents | 93e1b0e3b83a |
children | 68dae290d5fa |
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" | |
171
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
38 #include "../Core/DicomFormat/DicomArray.h" |
0 | 39 |
40 #include <dcmtk/dcmdata/dcistrmb.h> | |
41 #include <dcmtk/dcmdata/dcfilefo.h> | |
42 #include <boost/lexical_cast.hpp> | |
171
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
43 #include <glog/logging.h> |
0 | 44 |
62 | 45 namespace Orthanc |
0 | 46 { |
47 static void SendJson(HttpOutput& output, | |
48 const Json::Value& value) | |
49 { | |
50 Json::StyledWriter writer; | |
51 std::string s = writer.write(value); | |
52 output.AnswerBufferWithContentType(s, "application/json"); | |
53 } | |
54 | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
55 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
56 static void SimplifyTagsRecursion(Json::Value& target, |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
57 const Json::Value& source) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
58 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
59 assert(source.isObject()); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
60 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
61 target = Json::objectValue; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
62 Json::Value::Members members = source.getMemberNames(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
63 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
64 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
|
65 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
66 const Json::Value& v = source[members[i]]; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
67 const std::string& name = v["Name"].asString(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
68 const std::string& type = v["Type"].asString(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
69 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
70 if (type == "String") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
71 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
72 target[name] = v["Value"].asString(); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
73 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
74 else if (type == "TooLong" || |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
75 type == "Null") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
76 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
77 target[name] = Json::nullValue; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
78 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
79 else if (type == "Sequence") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
80 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
81 const Json::Value& array = v["Value"]; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
82 assert(array.isArray()); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
83 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
84 Json::Value children = Json::arrayValue; |
126 | 85 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
|
86 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
87 Json::Value c; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
88 SimplifyTagsRecursion(c, array[i]); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
89 children.append(c); |
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 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
92 target[name] = children; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
93 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
94 else |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
95 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
96 assert(0); |
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 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
102 static void SimplifyTags(Json::Value& target, |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
103 const FileStorage& storage, |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
104 const std::string& fileUuid) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
105 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
106 std::string s; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
107 storage.ReadFile(s, fileUuid); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
108 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
109 Json::Value source; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
110 Json::Reader reader; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
111 if (!reader.parse(s, source)) |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
112 { |
62 | 113 throw OrthancException("Corrupted JSON file"); |
35
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 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
116 SimplifyTagsRecursion(target, source); |
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 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
119 |
171
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
120 static bool GetTagContent(HttpOutput& output, |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
121 const FileStorage& storage, |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
122 const std::string& fileUuid, |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
123 const UriComponents& uri) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
124 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
125 // TODO: Implement a true caching mechanism! |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
126 static boost::mutex mutex_; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
127 static std::string lastFileUuid_; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
128 static DcmFileFormat dicomFile_; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
129 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
130 boost::mutex::scoped_lock lock(mutex_); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
131 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
132 if (fileUuid != lastFileUuid_) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
133 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
134 LOG(INFO) << "Parsing file " << fileUuid; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
135 std::string content; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
136 storage.ReadFile(content, fileUuid); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
137 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
138 DcmInputBufferStream is; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
139 if (content.size() > 0) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
140 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
141 is.setBuffer(&content[0], content.size()); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
142 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
143 is.setEos(); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
144 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
145 if (!dicomFile_.read(is).good()) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
146 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
147 return false; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
148 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
149 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
150 lastFileUuid_ = fileUuid; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
151 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
152 else |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
153 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
154 LOG(INFO) << "Already parsed file " << fileUuid; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
155 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
156 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
157 if (uri.size() == 3) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
158 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
159 DicomMap dicomSummary; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
160 FromDcmtkBridge::Convert(dicomSummary, *dicomFile_.getDataset()); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
161 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
162 DicomArray a(dicomSummary); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
163 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
164 Json::Value target = Json::arrayValue; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
165 for (size_t i = 0; i < a.GetSize(); i++) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
166 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
167 char b[16]; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
168 sprintf(b, "%04x-%04x", a.GetElement(i).GetTagGroup(), |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
169 a.GetElement(i).GetTagElement()); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
170 target.append(b); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
171 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
172 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
173 SendJson(output, target); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
174 return true; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
175 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
176 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
177 if (uri.size() == 4) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
178 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
179 if (uri[3].size() != 9 || |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
180 uri[3][4] != '-') |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
181 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
182 return false; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
183 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
184 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
185 unsigned int group, element; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
186 if (sscanf(uri[3].c_str(), "%04x-%04x", &group, &element) != 2) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
187 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
188 return false; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
189 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
190 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
191 DcmTagKey tag(group, element); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
192 DcmElement* item = NULL; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
193 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
194 if (dicomFile_.getDataset()->findAndGetElement(tag, item).good() && |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
195 item != NULL) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
196 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
197 std::string buffer; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
198 buffer.resize(65536); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
199 Uint32 length = item->getLength(); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
200 Uint32 offset = 0; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
201 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
202 while (offset < length) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
203 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
204 Uint32 nbytes; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
205 if (length - offset < buffer.size()) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
206 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
207 nbytes = length - offset; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
208 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
209 else |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
210 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
211 nbytes = buffer.size(); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
212 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
213 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
214 output.SendOkHeader("application/octet-stream"); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
215 if (item->getPartialValue(&buffer[0], offset, nbytes).good()) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
216 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
217 output.Send(&buffer[0], nbytes); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
218 offset += nbytes; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
219 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
220 else |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
221 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
222 return true; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
223 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
224 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
225 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
226 return true; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
227 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
228 else |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
229 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
230 return false; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
231 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
232 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
233 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
234 return false; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
235 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
236 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
237 |
62 | 238 bool OrthancRestApi::Store(Json::Value& result, |
50 | 239 const std::string& postData) |
0 | 240 { |
241 // Prepare an input stream for the memory buffer | |
242 DcmInputBufferStream is; | |
243 if (postData.size() > 0) | |
244 { | |
245 is.setBuffer(&postData[0], postData.size()); | |
246 } | |
247 is.setEos(); | |
248 | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
249 //printf("[%d]\n", postData.size()); |
0 | 250 |
251 DcmFileFormat dicomFile; | |
252 if (dicomFile.read(is).good()) | |
253 { | |
254 DicomMap dicomSummary; | |
255 FromDcmtkBridge::Convert(dicomSummary, *dicomFile.getDataset()); | |
256 | |
257 Json::Value dicomJson; | |
258 FromDcmtkBridge::ToJson(dicomJson, *dicomFile.getDataset()); | |
259 | |
260 std::string instanceUuid; | |
261 StoreStatus status = StoreStatus_Failure; | |
262 if (postData.size() > 0) | |
263 { | |
264 status = index_.Store | |
265 (instanceUuid, storage_, reinterpret_cast<const char*>(&postData[0]), | |
266 postData.size(), dicomSummary, dicomJson, ""); | |
267 } | |
268 | |
269 switch (status) | |
270 { | |
271 case StoreStatus_Success: | |
272 result["ID"] = instanceUuid; | |
273 result["Path"] = "/instances/" + instanceUuid; | |
274 result["Status"] = "Success"; | |
275 return true; | |
276 | |
277 case StoreStatus_AlreadyStored: | |
278 result["ID"] = instanceUuid; | |
279 result["Path"] = "/instances/" + instanceUuid; | |
280 result["Status"] = "AlreadyStored"; | |
281 return true; | |
282 | |
283 default: | |
284 return false; | |
285 } | |
286 } | |
287 | |
288 return false; | |
289 } | |
290 | |
62 | 291 void OrthancRestApi::ConnectToModality(DicomUserConnection& c, |
50 | 292 const std::string& name) |
0 | 293 { |
294 std::string aet, address; | |
295 int port; | |
296 GetDicomModality(name, aet, address, port); | |
62 | 297 c.SetLocalApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
0 | 298 c.SetDistantApplicationEntityTitle(aet); |
299 c.SetDistantHost(address); | |
300 c.SetDistantPort(port); | |
301 c.Open(); | |
302 } | |
303 | |
62 | 304 bool OrthancRestApi::MergeQueryAndTemplate(DicomMap& result, |
50 | 305 const std::string& postData) |
0 | 306 { |
307 Json::Value query; | |
308 Json::Reader reader; | |
309 | |
310 if (!reader.parse(postData, query) || | |
8 | 311 query.type() != Json::objectValue) |
0 | 312 { |
313 return false; | |
314 } | |
315 | |
316 Json::Value::Members members = query.getMemberNames(); | |
317 for (size_t i = 0; i < members.size(); i++) | |
318 { | |
319 DicomTag t = FromDcmtkBridge::FindTag(members[i]); | |
320 result.SetValue(t, query[members[i]].asString()); | |
321 } | |
322 | |
323 return true; | |
324 } | |
325 | |
62 | 326 bool OrthancRestApi::DicomFindPatient(Json::Value& result, |
50 | 327 DicomUserConnection& c, |
328 const std::string& postData) | |
0 | 329 { |
330 DicomMap m; | |
331 DicomMap::SetupFindPatientTemplate(m); | |
332 if (!MergeQueryAndTemplate(m, postData)) | |
333 { | |
334 return false; | |
335 } | |
336 | |
337 DicomFindAnswers answers; | |
338 c.FindPatient(answers, m); | |
339 answers.ToJson(result); | |
340 return true; | |
341 } | |
342 | |
62 | 343 bool OrthancRestApi::DicomFindStudy(Json::Value& result, |
50 | 344 DicomUserConnection& c, |
345 const std::string& postData) | |
0 | 346 { |
347 DicomMap m; | |
348 DicomMap::SetupFindStudyTemplate(m); | |
349 if (!MergeQueryAndTemplate(m, postData)) | |
350 { | |
351 return false; | |
352 } | |
353 | |
80 | 354 if (m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && |
355 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) | |
0 | 356 { |
357 return false; | |
358 } | |
359 | |
360 DicomFindAnswers answers; | |
361 c.FindStudy(answers, m); | |
362 answers.ToJson(result); | |
363 return true; | |
364 } | |
365 | |
62 | 366 bool OrthancRestApi::DicomFindSeries(Json::Value& result, |
50 | 367 DicomUserConnection& c, |
368 const std::string& postData) | |
0 | 369 { |
370 DicomMap m; | |
371 DicomMap::SetupFindSeriesTemplate(m); | |
372 if (!MergeQueryAndTemplate(m, postData)) | |
373 { | |
374 return false; | |
375 } | |
376 | |
80 | 377 if ((m.GetValue(DICOM_TAG_ACCESSION_NUMBER).AsString().size() <= 2 && |
378 m.GetValue(DICOM_TAG_PATIENT_ID).AsString().size() <= 2) || | |
379 m.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString().size() <= 2) | |
0 | 380 { |
381 return false; | |
382 } | |
383 | |
384 DicomFindAnswers answers; | |
385 c.FindSeries(answers, m); | |
386 answers.ToJson(result); | |
387 return true; | |
388 } | |
389 | |
62 | 390 bool OrthancRestApi::DicomFind(Json::Value& result, |
50 | 391 DicomUserConnection& c, |
392 const std::string& postData) | |
0 | 393 { |
394 DicomMap m; | |
395 DicomMap::SetupFindPatientTemplate(m); | |
396 if (!MergeQueryAndTemplate(m, postData)) | |
397 { | |
398 return false; | |
399 } | |
400 | |
401 DicomFindAnswers patients; | |
402 c.FindPatient(patients, m); | |
403 | |
404 // Loop over the found patients | |
405 result = Json::arrayValue; | |
406 for (size_t i = 0; i < patients.GetSize(); i++) | |
407 { | |
408 Json::Value patient(Json::objectValue); | |
409 FromDcmtkBridge::ToJson(patient, patients.GetAnswer(i)); | |
410 | |
411 DicomMap::SetupFindStudyTemplate(m); | |
412 if (!MergeQueryAndTemplate(m, postData)) | |
413 { | |
414 return false; | |
415 } | |
80 | 416 m.CopyTagIfExists(patients.GetAnswer(i), DICOM_TAG_PATIENT_ID); |
0 | 417 |
418 DicomFindAnswers studies; | |
419 c.FindStudy(studies, m); | |
420 | |
421 patient["Studies"] = Json::arrayValue; | |
422 | |
423 // Loop over the found studies | |
424 for (size_t j = 0; j < studies.GetSize(); j++) | |
425 { | |
426 Json::Value study(Json::objectValue); | |
427 FromDcmtkBridge::ToJson(study, studies.GetAnswer(j)); | |
428 | |
429 DicomMap::SetupFindSeriesTemplate(m); | |
430 if (!MergeQueryAndTemplate(m, postData)) | |
431 { | |
432 return false; | |
433 } | |
80 | 434 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_PATIENT_ID); |
435 m.CopyTagIfExists(studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID); | |
0 | 436 |
437 DicomFindAnswers series; | |
438 c.FindSeries(series, m); | |
439 | |
440 // Loop over the found series | |
441 study["Series"] = Json::arrayValue; | |
442 for (size_t k = 0; k < series.GetSize(); k++) | |
443 { | |
444 Json::Value series2(Json::objectValue); | |
445 FromDcmtkBridge::ToJson(series2, series.GetAnswer(k)); | |
446 study["Series"].append(series2); | |
447 } | |
448 | |
449 patient["Studies"].append(study); | |
450 } | |
451 | |
452 result.append(patient); | |
453 } | |
454 | |
455 return true; | |
456 } | |
457 | |
458 | |
459 | |
62 | 460 bool OrthancRestApi::DicomStore(Json::Value& result, |
50 | 461 DicomUserConnection& c, |
462 const std::string& postData) | |
0 | 463 { |
464 Json::Value found(Json::objectValue); | |
465 | |
466 if (!Toolbox::IsUuid(postData)) | |
467 { | |
468 // This is not a UUID, assume this is a DICOM instance | |
469 c.Store(postData); | |
470 } | |
471 else if (index_.GetSeries(found, postData)) | |
472 { | |
473 // The UUID corresponds to a series | |
126 | 474 for (Json::Value::ArrayIndex i = 0; i < found["Instances"].size(); i++) |
0 | 475 { |
476 std::string uuid = found["Instances"][i].asString(); | |
477 Json::Value instance(Json::objectValue); | |
478 if (index_.GetInstance(instance, uuid)) | |
479 { | |
480 std::string content; | |
481 storage_.ReadFile(content, instance["FileUuid"].asString()); | |
482 c.Store(content); | |
483 } | |
484 else | |
485 { | |
486 return false; | |
487 } | |
488 } | |
489 } | |
490 else if (index_.GetInstance(found, postData)) | |
491 { | |
492 // The UUID corresponds to an instance | |
493 std::string content; | |
494 storage_.ReadFile(content, found["FileUuid"].asString()); | |
495 c.Store(content); | |
496 } | |
497 else | |
498 { | |
499 return false; | |
500 } | |
501 | |
502 return true; | |
503 } | |
504 | |
505 | |
62 | 506 OrthancRestApi::OrthancRestApi(ServerIndex& index, |
50 | 507 const std::string& path) : |
0 | 508 index_(index), |
509 storage_(path) | |
510 { | |
511 GetListOfDicomModalities(modalities_); | |
512 } | |
513 | |
514 | |
62 | 515 void OrthancRestApi::Handle( |
0 | 516 HttpOutput& output, |
517 const std::string& method, | |
518 const UriComponents& uri, | |
519 const Arguments& headers, | |
520 const Arguments& arguments, | |
521 const std::string& postData) | |
522 { | |
523 if (uri.size() == 0) | |
524 { | |
525 if (method == "GET") | |
526 { | |
85
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
527 output.Redirect("app/explorer.html"); |
0 | 528 } |
529 else | |
530 { | |
531 output.SendMethodNotAllowedError("GET"); | |
532 } | |
533 | |
534 return; | |
535 } | |
536 | |
537 bool existingResource = false; | |
538 Json::Value result(Json::objectValue); | |
539 | |
540 | |
151 | 541 // Version information ------------------------------------------------------ |
542 | |
543 if (uri.size() == 1 && uri[0] == "system") | |
544 { | |
545 if (method == "GET") | |
546 { | |
547 result = Json::Value(Json::objectValue); | |
548 result["Version"] = ORTHANC_VERSION; | |
549 result["Name"] = GetGlobalStringParameter("Name", ""); | |
550 existingResource = true; | |
551 } | |
552 else | |
553 { | |
554 output.SendMethodNotAllowedError("GET,POST"); | |
555 return; | |
556 } | |
557 } | |
558 | |
559 | |
0 | 560 // List all the instances --------------------------------------------------- |
561 | |
562 if (uri.size() == 1 && uri[0] == "instances") | |
563 { | |
564 if (method == "GET") | |
565 { | |
566 result = Json::Value(Json::arrayValue); | |
567 index_.GetAllUuids(result, "Instances"); | |
568 existingResource = true; | |
569 } | |
570 else if (method == "POST") | |
571 { | |
572 // Add a new instance to the storage | |
573 if (Store(result, postData)) | |
574 { | |
575 SendJson(output, result); | |
576 return; | |
577 } | |
578 else | |
579 { | |
62 | 580 output.SendHeader(Orthanc_HttpStatus_415_UnsupportedMediaType); |
0 | 581 return; |
582 } | |
583 } | |
584 else | |
585 { | |
586 output.SendMethodNotAllowedError("GET,POST"); | |
587 return; | |
588 } | |
589 } | |
590 | |
591 | |
592 // List all the patients, studies or series --------------------------------- | |
593 | |
594 if (uri.size() == 1 && | |
595 (uri[0] == "series" || | |
596 uri[0] == "studies" || | |
597 uri[0] == "patients")) | |
598 { | |
599 if (method == "GET") | |
600 { | |
601 result = Json::Value(Json::arrayValue); | |
602 | |
603 if (uri[0] == "instances") | |
604 index_.GetAllUuids(result, "Instances"); | |
605 else if (uri[0] == "series") | |
606 index_.GetAllUuids(result, "Series"); | |
607 else if (uri[0] == "studies") | |
608 index_.GetAllUuids(result, "Studies"); | |
609 else if (uri[0] == "patients") | |
610 index_.GetAllUuids(result, "Patients"); | |
611 | |
612 existingResource = true; | |
613 } | |
614 else | |
615 { | |
616 output.SendMethodNotAllowedError("GET"); | |
617 return; | |
618 } | |
619 } | |
620 | |
621 | |
622 // Information about a single object ---------------------------------------- | |
623 | |
624 else if (uri.size() == 2 && | |
625 (uri[0] == "instances" || | |
626 uri[0] == "series" || | |
627 uri[0] == "studies" || | |
628 uri[0] == "patients")) | |
629 { | |
630 if (method == "GET") | |
631 { | |
632 if (uri[0] == "patients") | |
633 { | |
634 existingResource = index_.GetPatient(result, uri[1]); | |
635 } | |
636 else if (uri[0] == "studies") | |
637 { | |
638 existingResource = index_.GetStudy(result, uri[1]); | |
639 } | |
640 else if (uri[0] == "series") | |
641 { | |
642 existingResource = index_.GetSeries(result, uri[1]); | |
643 } | |
644 else if (uri[0] == "instances") | |
645 { | |
646 existingResource = index_.GetInstance(result, uri[1]); | |
647 } | |
648 } | |
649 else if (method == "DELETE") | |
650 { | |
651 if (uri[0] == "patients") | |
652 { | |
653 existingResource = index_.DeletePatient(result, uri[1]); | |
654 } | |
655 else if (uri[0] == "studies") | |
656 { | |
657 existingResource = index_.DeleteStudy(result, uri[1]); | |
658 } | |
659 else if (uri[0] == "series") | |
660 { | |
661 existingResource = index_.DeleteSeries(result, uri[1]); | |
662 } | |
663 else if (uri[0] == "instances") | |
664 { | |
665 existingResource = index_.DeleteInstance(result, uri[1]); | |
666 } | |
667 | |
668 if (existingResource) | |
669 { | |
670 result["Status"] = "Success"; | |
671 } | |
672 } | |
673 else | |
674 { | |
675 output.SendMethodNotAllowedError("GET,DELETE"); | |
676 return; | |
677 } | |
678 } | |
679 | |
680 | |
681 // Get the DICOM or the JSON file of one instance --------------------------- | |
682 | |
683 else if (uri.size() == 3 && | |
684 uri[0] == "instances" && | |
685 (uri[2] == "file" || | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
686 uri[2] == "tags" || |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
687 uri[2] == "simplified-tags")) |
0 | 688 { |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
689 std::string fileUuid, contentType, filename; |
0 | 690 if (uri[2] == "file") |
691 { | |
692 existingResource = index_.GetDicomFile(fileUuid, uri[1]); | |
693 contentType = "application/dicom"; | |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
694 filename = fileUuid + ".dcm"; |
0 | 695 } |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
696 else if (uri[2] == "tags" || |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
697 uri[2] == "simplified-tags") |
0 | 698 { |
699 existingResource = index_.GetJsonFile(fileUuid, uri[1]); | |
700 contentType = "application/json"; | |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
701 filename = fileUuid + ".json"; |
0 | 702 } |
703 | |
704 if (existingResource) | |
705 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
706 if (uri[2] == "simplified-tags") |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
707 { |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
708 Json::Value v; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
709 SimplifyTags(v, storage_, fileUuid); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
710 SendJson(output, v); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
711 return; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
712 } |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
713 else |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
714 { |
155
93e1b0e3b83a
filenames when downloading json/dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
715 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
|
716 return; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
34
diff
changeset
|
717 } |
0 | 718 } |
719 } | |
720 | |
721 | |
722 else if (uri.size() == 3 && | |
723 uri[0] == "instances" && | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
724 uri[2] == "frames") |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
725 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
726 Json::Value instance(Json::objectValue); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
727 existingResource = index_.GetInstance(instance, uri[1]); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
728 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
729 if (existingResource) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
730 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
731 result = Json::arrayValue; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
732 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
733 unsigned int numberOfFrames = 1; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
734 try |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
735 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
736 Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"]; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
737 numberOfFrames = boost::lexical_cast<unsigned int>(tmp.asString()); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
738 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
739 catch (boost::bad_lexical_cast) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
740 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
741 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
742 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
743 for (unsigned int i = 0; i < numberOfFrames; i++) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
744 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
745 result.append(i); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
746 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
747 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
748 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
749 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
750 |
171
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
751 else if (uri.size() >= 3 && |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
752 uri[0] == "instances" && |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
753 uri[2] == "content") |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
754 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
755 Json::Value instance(Json::objectValue); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
756 std::string fileUuid; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
757 existingResource = index_.GetDicomFile(fileUuid, uri[1]); |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
758 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
759 if (existingResource) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
760 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
761 if (GetTagContent(output, storage_, fileUuid, uri)) |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
762 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
763 return; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
764 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
765 else |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
766 { |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
767 existingResource = false; |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
768 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
769 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
770 } |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
771 |
da7e915202c7
quick and dirty access to raw tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
772 |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
773 else if (uri[0] == "instances" && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
774 ((uri.size() == 3 && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
775 (uri[2] == "preview" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
776 uri[2] == "image-uint8" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
777 uri[2] == "image-uint16")) || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
778 (uri.size() == 5 && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
779 uri[2] == "frames" && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
780 (uri[4] == "preview" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
781 uri[4] == "image-uint8" || |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
782 uri[4] == "image-uint16")))) |
0 | 783 { |
784 std::string uuid; | |
785 existingResource = index_.GetDicomFile(uuid, uri[1]); | |
786 | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
787 std::string action = uri[2]; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
788 |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
789 unsigned int frame = 0; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
790 if (existingResource && |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
791 uri.size() == 5) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
792 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
793 // Access to multi-frame image |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
794 action = uri[4]; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
795 try |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
796 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
797 frame = boost::lexical_cast<unsigned int>(uri[3]); |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
798 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
799 catch (boost::bad_lexical_cast) |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
800 { |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
801 existingResource = false; |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
802 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
803 } |
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
804 |
0 | 805 if (existingResource) |
806 { | |
807 std::string dicomContent, png; | |
808 storage_.ReadFile(dicomContent, uuid); | |
809 try | |
810 { | |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
811 if (action == "preview") |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
812 { |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
813 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_Preview); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
814 } |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
815 else if (action == "image-uint8") |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
816 { |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
817 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt8); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
818 } |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
819 else if (action == "image-uint16") |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
820 { |
53
293038baf8f1
access to multi-frame images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
50
diff
changeset
|
821 FromDcmtkBridge::ExtractPngImage(png, dicomContent, frame, ImageExtractionMode_UInt16); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
822 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
823 else |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
824 { |
62 | 825 throw OrthancException(ErrorCode_InternalError); |
42
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
826 } |
ea48f38afe5f
access to raw images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
41
diff
changeset
|
827 |
0 | 828 output.AnswerBufferWithContentType(png, "image/png"); |
829 return; | |
830 } | |
62 | 831 catch (OrthancException&) |
0 | 832 { |
85
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
833 std::string root = ""; |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
834 for (size_t i = 1; i < uri.size(); i++) |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
835 { |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
836 root += "../"; |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
837 } |
ebce15865cce
relative redirection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
80
diff
changeset
|
838 |
129 | 839 output.Redirect(root + "app/images/unsupported.png"); |
0 | 840 return; |
841 } | |
842 } | |
843 } | |
844 | |
845 | |
846 | |
847 // Changes API -------------------------------------------------------------- | |
848 | |
849 if (uri.size() == 1 && uri[0] == "changes") | |
850 { | |
851 if (method == "GET") | |
852 { | |
853 const static unsigned int MAX_RESULTS = 100; | |
854 | |
855 std::string filter = GetArgument(arguments, "filter", ""); | |
856 int64_t since; | |
857 unsigned int limit; | |
858 try | |
859 { | |
860 since = boost::lexical_cast<int64_t>(GetArgument(arguments, "since", "0")); | |
861 limit = boost::lexical_cast<unsigned int>(GetArgument(arguments, "limit", "0")); | |
862 } | |
863 catch (boost::bad_lexical_cast) | |
864 { | |
62 | 865 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); |
0 | 866 return; |
867 } | |
868 | |
869 if (limit == 0 || limit > MAX_RESULTS) | |
870 { | |
871 limit = MAX_RESULTS; | |
872 } | |
873 | |
874 if (!index_.GetChanges(result, since, filter, limit)) | |
875 { | |
62 | 876 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); |
0 | 877 return; |
878 } | |
879 | |
880 existingResource = true; | |
881 } | |
882 else | |
883 { | |
884 output.SendMethodNotAllowedError("GET"); | |
885 return; | |
886 } | |
887 } | |
888 | |
889 | |
890 // DICOM bridge ------------------------------------------------------------- | |
891 | |
892 if (uri.size() == 1 && | |
893 uri[0] == "modalities") | |
894 { | |
895 if (method == "GET") | |
896 { | |
897 result = Json::Value(Json::arrayValue); | |
898 existingResource = true; | |
899 | |
900 for (Modalities::const_iterator it = modalities_.begin(); | |
901 it != modalities_.end(); it++) | |
902 { | |
903 result.append(*it); | |
904 } | |
905 } | |
906 else | |
907 { | |
908 output.SendMethodNotAllowedError("GET"); | |
909 return; | |
910 } | |
911 } | |
912 | |
913 if ((uri.size() == 2 || | |
914 uri.size() == 3) && | |
915 uri[0] == "modalities") | |
916 { | |
917 if (modalities_.find(uri[1]) == modalities_.end()) | |
918 { | |
919 // Unknown modality | |
920 } | |
921 else if (uri.size() == 2) | |
922 { | |
923 if (method != "GET") | |
924 { | |
925 output.SendMethodNotAllowedError("POST"); | |
926 return; | |
927 } | |
928 else | |
929 { | |
930 existingResource = true; | |
931 result = Json::arrayValue; | |
932 result.append("find-patient"); | |
933 result.append("find-study"); | |
934 result.append("find-series"); | |
935 result.append("find"); | |
936 result.append("store"); | |
937 } | |
938 } | |
939 else if (uri.size() == 3) | |
940 { | |
941 if (uri[2] != "find-patient" && | |
942 uri[2] != "find-study" && | |
943 uri[2] != "find-series" && | |
944 uri[2] != "find" && | |
945 uri[2] != "store") | |
946 { | |
947 // Unknown request | |
948 } | |
949 else if (method != "POST") | |
950 { | |
951 output.SendMethodNotAllowedError("POST"); | |
952 return; | |
953 } | |
954 else | |
955 { | |
956 DicomUserConnection connection; | |
957 ConnectToModality(connection, uri[1]); | |
958 existingResource = true; | |
959 | |
960 if ((uri[2] == "find-patient" && !DicomFindPatient(result, connection, postData)) || | |
961 (uri[2] == "find-study" && !DicomFindStudy(result, connection, postData)) || | |
962 (uri[2] == "find-series" && !DicomFindSeries(result, connection, postData)) || | |
963 (uri[2] == "find" && !DicomFind(result, connection, postData)) || | |
964 (uri[2] == "store" && !DicomStore(result, connection, postData))) | |
965 { | |
62 | 966 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); |
0 | 967 return; |
968 } | |
969 } | |
970 } | |
971 } | |
972 | |
973 | |
974 if (existingResource) | |
975 { | |
976 SendJson(output, result); | |
977 } | |
978 else | |
979 { | |
62 | 980 output.SendHeader(Orthanc_HttpStatus_404_NotFound); |
0 | 981 } |
982 } | |
983 } |