Mercurial > hg > orthanc-stone
annotate Framework/Oracle/GenericOracleRunner.cpp @ 1128:8e3763d1736a broker
removing CustomOracleCommand
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 05 Nov 2019 22:39:25 +0100 |
parents | a8bf81756839 |
children | 87fbeb823375 |
rev | line source |
---|---|
1077 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "GenericOracleRunner.h" | |
23 | |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
24 #if !defined(ORTHANC_ENABLE_DCMTK) |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
25 # error The macro ORTHANC_ENABLE_DCMTK must be defined |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
26 #endif |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
27 |
1077 | 28 #include "GetOrthancImageCommand.h" |
29 #include "GetOrthancWebViewerJpegCommand.h" | |
30 #include "HttpCommand.h" | |
31 #include "OracleCommandExceptionMessage.h" | |
32 #include "OrthancRestApiCommand.h" | |
1104 | 33 #include "ReadFileCommand.h" |
1077 | 34 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
35 #if ORTHANC_ENABLE_DCMTK == 1 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
36 # include "ParseDicomFileCommand.h" |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
37 # include <dcmtk/dcmdata/dcdeftag.h> |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
38 #endif |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
39 |
1077 | 40 #include <Core/Compression/GzipCompressor.h> |
41 #include <Core/HttpClient.h> | |
42 #include <Core/OrthancException.h> | |
43 #include <Core/Toolbox.h> | |
1104 | 44 #include <Core/SystemToolbox.h> |
45 | |
46 #include <boost/filesystem.hpp> | |
1077 | 47 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
48 |
1077 | 49 namespace OrthancStone |
50 { | |
51 static void CopyHttpHeaders(Orthanc::HttpClient& client, | |
52 const Orthanc::HttpClient::HttpHeaders& headers) | |
53 { | |
54 for (Orthanc::HttpClient::HttpHeaders::const_iterator | |
55 it = headers.begin(); it != headers.end(); it++ ) | |
56 { | |
57 client.AddHeader(it->first, it->second); | |
58 } | |
59 } | |
60 | |
61 | |
62 static void DecodeAnswer(std::string& answer, | |
63 const Orthanc::HttpClient::HttpHeaders& headers) | |
64 { | |
65 Orthanc::HttpCompression contentEncoding = Orthanc::HttpCompression_None; | |
66 | |
67 for (Orthanc::HttpClient::HttpHeaders::const_iterator it = headers.begin(); | |
68 it != headers.end(); ++it) | |
69 { | |
70 std::string s; | |
71 Orthanc::Toolbox::ToLowerCase(s, it->first); | |
72 | |
73 if (s == "content-encoding") | |
74 { | |
75 if (it->second == "gzip") | |
76 { | |
77 contentEncoding = Orthanc::HttpCompression_Gzip; | |
78 } | |
79 else | |
80 { | |
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, | |
82 "Unsupported HTTP Content-Encoding: " + it->second); | |
83 } | |
84 | |
85 break; | |
86 } | |
87 } | |
88 | |
89 if (contentEncoding == Orthanc::HttpCompression_Gzip) | |
90 { | |
91 std::string compressed; | |
92 answer.swap(compressed); | |
93 | |
94 Orthanc::GzipCompressor compressor; | |
95 compressor.Uncompress(answer, compressed.c_str(), compressed.size()); | |
96 | |
97 LOG(INFO) << "Uncompressing gzip Encoding: from " << compressed.size() | |
98 << " to " << answer.size() << " bytes"; | |
99 } | |
100 } | |
101 | |
102 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
103 static IMessage* Execute(const HttpCommand& command) |
1077 | 104 { |
105 Orthanc::HttpClient client; | |
106 client.SetUrl(command.GetUrl()); | |
107 client.SetMethod(command.GetMethod()); | |
108 client.SetTimeout(command.GetTimeout()); | |
109 | |
110 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
111 | |
1079
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
112 if (command.HasCredentials()) |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
113 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
114 client.SetCredentials(command.GetUsername().c_str(), command.GetPassword().c_str()); |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
115 } |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
116 |
1077 | 117 if (command.GetMethod() == Orthanc::HttpMethod_Post || |
118 command.GetMethod() == Orthanc::HttpMethod_Put) | |
119 { | |
120 client.SetBody(command.GetBody()); | |
121 } | |
122 | |
123 std::string answer; | |
124 Orthanc::HttpClient::HttpHeaders answerHeaders; | |
125 client.ApplyAndThrowException(answer, answerHeaders); | |
126 | |
127 DecodeAnswer(answer, answerHeaders); | |
128 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
129 return new HttpCommand::SuccessMessage(command, answerHeaders, answer); |
1077 | 130 } |
131 | |
132 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
133 static IMessage* Execute(const Orthanc::WebServiceParameters& orthanc, |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
134 const OrthancRestApiCommand& command) |
1077 | 135 { |
136 Orthanc::HttpClient client(orthanc, command.GetUri()); | |
137 client.SetMethod(command.GetMethod()); | |
138 client.SetTimeout(command.GetTimeout()); | |
139 | |
140 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
141 | |
142 if (command.GetMethod() == Orthanc::HttpMethod_Post || | |
143 command.GetMethod() == Orthanc::HttpMethod_Put) | |
144 { | |
145 client.SetBody(command.GetBody()); | |
146 } | |
147 | |
148 std::string answer; | |
149 Orthanc::HttpClient::HttpHeaders answerHeaders; | |
150 client.ApplyAndThrowException(answer, answerHeaders); | |
151 | |
152 DecodeAnswer(answer, answerHeaders); | |
153 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
154 return new OrthancRestApiCommand::SuccessMessage(command, answerHeaders, answer); |
1077 | 155 } |
156 | |
157 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
158 static IMessage* Execute(const Orthanc::WebServiceParameters& orthanc, |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
159 const GetOrthancImageCommand& command) |
1077 | 160 { |
161 Orthanc::HttpClient client(orthanc, command.GetUri()); | |
162 client.SetTimeout(command.GetTimeout()); | |
163 | |
164 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
165 | |
166 std::string answer; | |
167 Orthanc::HttpClient::HttpHeaders answerHeaders; | |
168 client.ApplyAndThrowException(answer, answerHeaders); | |
169 | |
170 DecodeAnswer(answer, answerHeaders); | |
171 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
172 return command.ProcessHttpAnswer(answer, answerHeaders); |
1077 | 173 } |
174 | |
175 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
176 static IMessage* Execute(const Orthanc::WebServiceParameters& orthanc, |
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
177 const GetOrthancWebViewerJpegCommand& command) |
1077 | 178 { |
179 Orthanc::HttpClient client(orthanc, command.GetUri()); | |
180 client.SetTimeout(command.GetTimeout()); | |
181 | |
182 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
183 | |
184 std::string answer; | |
185 Orthanc::HttpClient::HttpHeaders answerHeaders; | |
186 client.ApplyAndThrowException(answer, answerHeaders); | |
187 | |
188 DecodeAnswer(answer, answerHeaders); | |
189 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
190 return command.ProcessHttpAnswer(answer); |
1077 | 191 } |
192 | |
193 | |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
194 static std::string GetPath(const std::string& root, |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
195 const std::string& file) |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
196 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
197 boost::filesystem::path a(root); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
198 boost::filesystem::path b(file); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
199 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
200 boost::filesystem::path c; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
201 if (b.is_absolute()) |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
202 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
203 c = b; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
204 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
205 else |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
206 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
207 c = a / b; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
208 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
209 |
1111
3730956f41a5
ParseDicomFileCommand::GetDicomDirPath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
210 LOG(TRACE) << "Oracle reading file: " << c.string(); |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
211 return c.string(); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
212 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
213 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
214 |
1104 | 215 static IMessage* Execute(const std::string& root, |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
216 ReadFileCommand& command) |
1104 | 217 { |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
218 std::string path = GetPath(root, command.GetPath()); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
219 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
220 std::string content; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
221 Orthanc::SystemToolbox::ReadFile(content, path, true /* log */); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
222 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
223 return new ReadFileCommand::SuccessMessage(command, content); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
224 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
225 |
1104 | 226 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
227 #if ORTHANC_ENABLE_DCMTK == 1 |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
228 static ParseDicomFileCommand::SuccessMessage* Execute(const std::string& root, |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
229 const ParseDicomFileCommand& command) |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
230 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
231 std::string path = GetPath(root, command.GetPath()); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
232 |
1116
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
233 if (!Orthanc::SystemToolbox::IsRegularFile(path)) |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
234 { |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
235 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentFile); |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
236 } |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
237 |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
238 uint64_t fileSize = Orthanc::SystemToolbox::GetFileSize(path); |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
239 |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
240 // Check for 32bit systems |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
241 if (fileSize != static_cast<uint64_t>(static_cast<size_t>(fileSize))) |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
242 { |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
243 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); |
a08699daf78b
ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
244 } |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
245 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
246 DcmFileFormat dicom; |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
247 bool ok; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
248 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
249 if (command.IsPixelDataIncluded()) |
1104 | 250 { |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
251 ok = dicom.loadFile(path.c_str()).good(); |
1104 | 252 } |
253 else | |
254 { | |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
255 #if DCMTK_VERSION_NUMBER >= 362 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
256 // NB : We could stop at (0x3007, 0x0000) instead of |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
257 // DCM_PixelData, cf. the Orthanc::DICOM_TAG_* constants |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
258 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
259 static const DcmTagKey STOP = DCM_PixelData; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
260 //static const DcmTagKey STOP(0x3007, 0x0000); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
261 |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
262 ok = dicom.loadFileUntilTag(path.c_str(), EXS_Unknown, EGL_noChange, |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
263 DCM_MaxReadLength, ERM_autoDetect, STOP).good(); |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
264 #else |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
265 // The primitive "loadFileUntilTag" was introduced in DCMTK 3.6.2 |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
266 ok = dicom.loadFile(path.c_str()).good(); |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
267 #endif |
1104 | 268 } |
269 | |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
270 printf("Reading %s\n", path.c_str()); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
271 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
272 if (ok) |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
273 { |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
274 return new ParseDicomFileCommand::SuccessMessage |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
275 (command, dicom, static_cast<size_t>(fileSize), command.IsPixelDataIncluded()); |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
276 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
277 else |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
278 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
279 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
280 "Cannot parse file: " + path); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
281 } |
1104 | 282 } |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
283 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
284 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
285 static ParseDicomFileCommand::SuccessMessage* Execute(boost::shared_ptr<ParsedDicomFileCache> cache, |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
286 const std::string& root, |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
287 const ParseDicomFileCommand& command) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
288 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
289 #if 0 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
290 // The code to use the cache is buggy in multithreaded environments => TODO FIX |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
291 if (cache.get()) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
292 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
293 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
294 ParsedDicomFileCache::Reader reader(*cache, command.GetPath()); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
295 if (reader.IsValid() && |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
296 (!command.IsPixelDataIncluded() || |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
297 reader.HasPixelData())) |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
298 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
299 // Reuse the DICOM file from the cache |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
300 return new ParseDicomFileCommand::SuccessMessage( |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
301 command, reader.GetDicom(), reader.GetFileSize(), reader.HasPixelData()); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
302 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
303 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
304 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
305 // Not in the cache, first read and parse the DICOM file |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
306 std::auto_ptr<ParseDicomFileCommand::SuccessMessage> message(Execute(root, command)); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
307 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
308 // Secondly, store it into the cache for future use |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
309 assert(&message->GetOrigin() == &command); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
310 cache->Acquire(message->GetOrigin().GetPath(), message->GetDicom(), |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
311 message->GetFileSize(), message->HasPixelData()); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
312 |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
313 return message.release(); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
314 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
315 else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
316 { |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
317 // No cache available |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
318 return Execute(root, command); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
319 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
320 #else |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
321 return Execute(root, command); |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
322 #endif |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
323 } |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
324 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
325 #endif |
1104 | 326 |
327 | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
328 IMessage* GenericOracleRunner::Run(IOracleCommand& command) |
1077 | 329 { |
330 try | |
331 { | |
332 switch (command.GetType()) | |
333 { | |
334 case IOracleCommand::Type_Sleep: | |
335 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType, | |
336 "Sleep command cannot be executed by the runner"); | |
337 | |
338 case IOracleCommand::Type_Http: | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
339 return Execute(dynamic_cast<const HttpCommand&>(command)); |
1077 | 340 |
341 case IOracleCommand::Type_OrthancRestApi: | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
342 return Execute(orthanc_, dynamic_cast<const OrthancRestApiCommand&>(command)); |
1077 | 343 |
344 case IOracleCommand::Type_GetOrthancImage: | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
345 return Execute(orthanc_, dynamic_cast<const GetOrthancImageCommand&>(command)); |
1077 | 346 |
347 case IOracleCommand::Type_GetOrthancWebViewerJpeg: | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
348 return Execute(orthanc_, dynamic_cast<const GetOrthancWebViewerJpegCommand&>(command)); |
1077 | 349 |
1104 | 350 case IOracleCommand::Type_ReadFile: |
1128
8e3763d1736a
removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
351 return Execute(rootDirectory_, dynamic_cast<ReadFileCommand&>(command)); |
1104 | 352 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
353 case IOracleCommand::Type_ParseDicomFile: |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
354 #if ORTHANC_ENABLE_DCMTK == 1 |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
355 return Execute(dicomCache_, rootDirectory_, |
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
356 dynamic_cast<const ParseDicomFileCommand&>(command)); |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
357 #else |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
358 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
359 "DCMTK must be enabled to parse DICOM files"); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
360 #endif |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
361 |
1077 | 362 default: |
363 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
364 } | |
365 } | |
366 catch (Orthanc::OrthancException& e) | |
367 { | |
368 LOG(ERROR) << "Exception within the oracle: " << e.What(); | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
369 return new OracleCommandExceptionMessage(command, e); |
1077 | 370 } |
371 catch (...) | |
372 { | |
373 LOG(ERROR) << "Threaded exception within the oracle"; | |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1079
diff
changeset
|
374 return new OracleCommandExceptionMessage(command, Orthanc::ErrorCode_InternalError); |
1077 | 375 } |
376 } | |
377 } |