Mercurial > hg > orthanc-databases
annotate Framework/Plugins/IndexBackend.cpp @ 203:2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 18 Mar 2021 18:15:34 +0100 |
parents | 42990b2dd51b |
children | 13a3863df7fa |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 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 "IndexBackend.h" | |
23 | |
152 | 24 #include "../../Resources/Orthanc/Databases/ISqlLookupFormatter.h" |
0 | 25 #include "../Common/BinaryStringValue.h" |
26 #include "../Common/Integer64Value.h" | |
27 #include "../Common/Utf8StringValue.h" | |
28 #include "GlobalProperties.h" | |
29 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
30 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 31 #include <Logging.h> |
32 #include <OrthancException.h> | |
0 | 33 |
34 | |
35 namespace OrthancDatabases | |
36 { | |
37 static std::string ConvertWildcardToLike(const std::string& query) | |
38 { | |
39 std::string s = query; | |
40 | |
41 for (size_t i = 0; i < s.size(); i++) | |
42 { | |
43 if (s[i] == '*') | |
44 { | |
45 s[i] = '%'; | |
46 } | |
47 else if (s[i] == '?') | |
48 { | |
49 s[i] = '_'; | |
50 } | |
51 } | |
52 | |
65 | 53 // TODO Escape underscores and percents |
54 | |
0 | 55 return s; |
56 } | |
57 | |
58 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
59 int64_t IndexBackend::ReadInteger64(const DatabaseManager::StatementBase& statement, |
0 | 60 size_t field) |
61 { | |
62 if (statement.IsDone()) | |
63 { | |
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
65 } | |
66 | |
67 const IValue& value = statement.GetResultField(field); | |
68 | |
69 switch (value.GetType()) | |
70 { | |
71 case ValueType_Integer64: | |
72 return dynamic_cast<const Integer64Value&>(value).GetValue(); | |
73 | |
74 default: | |
75 //LOG(ERROR) << value.Format(); | |
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
77 } | |
78 } | |
79 | |
80 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
81 int32_t IndexBackend::ReadInteger32(const DatabaseManager::StatementBase& statement, |
0 | 82 size_t field) |
83 { | |
84 if (statement.IsDone()) | |
85 { | |
86 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
87 } | |
88 | |
89 int64_t value = ReadInteger64(statement, field); | |
90 | |
91 if (value != static_cast<int64_t>(static_cast<int32_t>(value))) | |
92 { | |
93 LOG(ERROR) << "Integer overflow"; | |
94 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
95 } | |
96 else | |
97 { | |
98 return static_cast<int32_t>(value); | |
99 } | |
100 } | |
101 | |
102 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
103 std::string IndexBackend::ReadString(const DatabaseManager::StatementBase& statement, |
0 | 104 size_t field) |
105 { | |
106 const IValue& value = statement.GetResultField(field); | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
107 |
0 | 108 switch (value.GetType()) |
109 { | |
110 case ValueType_BinaryString: | |
111 return dynamic_cast<const BinaryStringValue&>(value).GetContent(); | |
112 | |
113 case ValueType_Utf8String: | |
114 return dynamic_cast<const Utf8StringValue&>(value).GetContent(); | |
115 | |
116 default: | |
117 //LOG(ERROR) << value.Format(); | |
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
119 } | |
120 } | |
121 | |
122 | |
123 template <typename T> | |
124 void IndexBackend::ReadListOfIntegers(std::list<T>& target, | |
125 DatabaseManager::CachedStatement& statement, | |
126 const Dictionary& args) | |
127 { | |
128 statement.Execute(args); | |
129 | |
130 target.clear(); | |
131 | |
132 if (!statement.IsDone()) | |
133 { | |
134 if (statement.GetResultFieldsCount() != 1) | |
135 { | |
136 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
137 } | |
138 | |
139 statement.SetResultFieldType(0, ValueType_Integer64); | |
140 | |
141 while (!statement.IsDone()) | |
142 { | |
143 target.push_back(static_cast<T>(ReadInteger64(statement, 0))); | |
144 statement.Next(); | |
145 } | |
146 } | |
147 } | |
148 | |
149 | |
150 void IndexBackend::ReadListOfStrings(std::list<std::string>& target, | |
151 DatabaseManager::CachedStatement& statement, | |
152 const Dictionary& args) | |
153 { | |
154 statement.Execute(args); | |
155 | |
156 target.clear(); | |
157 | |
158 if (!statement.IsDone()) | |
159 { | |
160 if (statement.GetResultFieldsCount() != 1) | |
161 { | |
162 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
163 } | |
164 | |
165 while (!statement.IsDone()) | |
166 { | |
167 target.push_back(ReadString(statement, 0)); | |
168 statement.Next(); | |
169 } | |
170 } | |
171 } | |
172 | |
173 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
174 void IndexBackend::ReadChangesInternal(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
175 bool& done, |
0 | 176 DatabaseManager::CachedStatement& statement, |
177 const Dictionary& args, | |
178 uint32_t maxResults) | |
179 { | |
180 statement.Execute(args); | |
181 | |
182 uint32_t count = 0; | |
183 | |
184 while (count < maxResults && | |
185 !statement.IsDone()) | |
186 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
187 output.AnswerChange( |
0 | 188 ReadInteger64(statement, 0), |
189 ReadInteger32(statement, 1), | |
190 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 3)), | |
191 GetPublicId(ReadInteger64(statement, 2)), | |
192 ReadString(statement, 4)); | |
193 | |
194 statement.Next(); | |
195 count++; | |
196 } | |
197 | |
198 done = (count < maxResults || | |
199 statement.IsDone()); | |
200 } | |
201 | |
202 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
203 void IndexBackend::ReadExportedResourcesInternal(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
204 bool& done, |
0 | 205 DatabaseManager::CachedStatement& statement, |
206 const Dictionary& args, | |
207 uint32_t maxResults) | |
208 { | |
209 statement.Execute(args); | |
210 | |
211 uint32_t count = 0; | |
212 | |
213 while (count < maxResults && | |
214 !statement.IsDone()) | |
215 { | |
216 int64_t seq = ReadInteger64(statement, 0); | |
217 OrthancPluginResourceType resourceType = | |
218 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1)); | |
219 std::string publicId = ReadString(statement, 2); | |
220 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
221 output.AnswerExportedResource(seq, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
222 resourceType, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
223 publicId, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
224 ReadString(statement, 3), // modality |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
225 ReadString(statement, 8), // date |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
226 ReadString(statement, 4), // patient ID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
227 ReadString(statement, 5), // study instance UID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
228 ReadString(statement, 6), // series instance UID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
229 ReadString(statement, 7)); // sop instance UID |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
230 |
0 | 231 statement.Next(); |
232 count++; | |
233 } | |
234 | |
235 done = (count < maxResults || | |
236 statement.IsDone()); | |
237 } | |
238 | |
239 | |
240 void IndexBackend::ClearDeletedFiles() | |
241 { | |
242 DatabaseManager::CachedStatement statement( | |
243 STATEMENT_FROM_HERE, manager_, | |
244 "DELETE FROM DeletedFiles"); | |
245 | |
246 statement.Execute(); | |
247 } | |
248 | |
249 | |
250 void IndexBackend::ClearDeletedResources() | |
251 { | |
252 DatabaseManager::CachedStatement statement( | |
253 STATEMENT_FROM_HERE, manager_, | |
254 "DELETE FROM DeletedResources"); | |
255 | |
256 statement.Execute(); | |
257 } | |
258 | |
259 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
260 void IndexBackend::SignalDeletedFiles(IDatabaseBackendOutput& output) |
0 | 261 { |
262 DatabaseManager::CachedStatement statement( | |
263 STATEMENT_FROM_HERE, manager_, | |
264 "SELECT * FROM DeletedFiles"); | |
265 | |
266 statement.SetReadOnly(true); | |
267 statement.Execute(); | |
268 | |
269 while (!statement.IsDone()) | |
270 { | |
271 std::string a = ReadString(statement, 0); | |
272 std::string b = ReadString(statement, 5); | |
273 std::string c = ReadString(statement, 6); | |
274 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
275 output.SignalDeletedAttachment(a.c_str(), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
276 ReadInteger32(statement, 1), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
277 ReadInteger64(statement, 3), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
278 b.c_str(), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
279 ReadInteger32(statement, 4), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
280 ReadInteger64(statement, 2), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
281 c.c_str()); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
282 |
0 | 283 statement.Next(); |
284 } | |
285 } | |
286 | |
287 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
288 void IndexBackend::SignalDeletedResources(IDatabaseBackendOutput& output) |
0 | 289 { |
290 DatabaseManager::CachedStatement statement( | |
291 STATEMENT_FROM_HERE, manager_, | |
292 "SELECT * FROM DeletedResources"); | |
293 | |
294 statement.SetReadOnly(true); | |
295 statement.Execute(); | |
296 | |
297 while (!statement.IsDone()) | |
298 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
299 output.SignalDeletedResource( |
0 | 300 ReadString(statement, 1), |
301 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0))); | |
302 | |
303 statement.Next(); | |
304 } | |
305 } | |
306 | |
307 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
308 IndexBackend::IndexBackend(OrthancPluginContext* context, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
309 IDatabaseFactory* factory) : |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
310 context_(context), |
0 | 311 manager_(factory) |
312 { | |
313 } | |
314 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
315 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
316 void IndexBackend::SetOutputFactory(IDatabaseBackendOutput::IFactory* factory) |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
317 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
318 if (factory == NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
319 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
320 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
321 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
322 else if (outputFactory_.get() != NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
323 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
324 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
325 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
326 else |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
327 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
328 outputFactory_.reset(factory); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
329 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
330 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
331 |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
332 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
333 IDatabaseBackendOutput* IndexBackend::CreateOutput() |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
334 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
335 if (outputFactory_.get() == NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
336 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
337 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
338 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
339 else |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
340 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
341 return outputFactory_->CreateOutput(); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
342 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
343 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
344 |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
345 |
0 | 346 void IndexBackend::AddAttachment(int64_t id, |
347 const OrthancPluginAttachment& attachment) | |
348 { | |
349 DatabaseManager::CachedStatement statement( | |
350 STATEMENT_FROM_HERE, manager_, | |
351 "INSERT INTO AttachedFiles VALUES(${id}, ${type}, ${uuid}, " | |
352 "${compressed}, ${uncompressed}, ${compression}, ${hash}, ${hash-compressed})"); | |
353 | |
354 statement.SetParameterType("id", ValueType_Integer64); | |
355 statement.SetParameterType("type", ValueType_Integer64); | |
356 statement.SetParameterType("uuid", ValueType_Utf8String); | |
357 statement.SetParameterType("compressed", ValueType_Integer64); | |
358 statement.SetParameterType("uncompressed", ValueType_Integer64); | |
359 statement.SetParameterType("compression", ValueType_Integer64); | |
360 statement.SetParameterType("hash", ValueType_Utf8String); | |
361 statement.SetParameterType("hash-compressed", ValueType_Utf8String); | |
362 | |
363 Dictionary args; | |
364 args.SetIntegerValue("id", id); | |
365 args.SetIntegerValue("type", attachment.contentType); | |
366 args.SetUtf8Value("uuid", attachment.uuid); | |
367 args.SetIntegerValue("compressed", attachment.compressedSize); | |
368 args.SetIntegerValue("uncompressed", attachment.uncompressedSize); | |
369 args.SetIntegerValue("compression", attachment.compressionType); | |
370 args.SetUtf8Value("hash", attachment.uncompressedHash); | |
371 args.SetUtf8Value("hash-compressed", attachment.compressedHash); | |
372 | |
373 statement.Execute(args); | |
374 } | |
375 | |
376 | |
377 void IndexBackend::AttachChild(int64_t parent, | |
378 int64_t child) | |
379 { | |
380 DatabaseManager::CachedStatement statement( | |
381 STATEMENT_FROM_HERE, manager_, | |
382 "UPDATE Resources SET parentId = ${parent} WHERE internalId = ${child}"); | |
383 | |
384 statement.SetParameterType("parent", ValueType_Integer64); | |
385 statement.SetParameterType("child", ValueType_Integer64); | |
386 | |
387 Dictionary args; | |
388 args.SetIntegerValue("parent", parent); | |
389 args.SetIntegerValue("child", child); | |
390 | |
391 statement.Execute(args); | |
392 } | |
393 | |
394 | |
395 void IndexBackend::ClearChanges() | |
396 { | |
397 DatabaseManager::CachedStatement statement( | |
398 STATEMENT_FROM_HERE, manager_, | |
399 "DELETE FROM Changes"); | |
400 | |
401 statement.Execute(); | |
402 } | |
403 | |
404 | |
405 void IndexBackend::ClearExportedResources() | |
406 { | |
407 DatabaseManager::CachedStatement statement( | |
408 STATEMENT_FROM_HERE, manager_, | |
409 "DELETE FROM ExportedResources"); | |
410 | |
411 statement.Execute(); | |
412 } | |
413 | |
414 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
415 void IndexBackend::DeleteAttachment(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
416 int64_t id, |
0 | 417 int32_t attachment) |
418 { | |
419 ClearDeletedFiles(); | |
420 | |
421 { | |
422 DatabaseManager::CachedStatement statement( | |
423 STATEMENT_FROM_HERE, manager_, | |
424 "DELETE FROM AttachedFiles WHERE id=${id} AND fileType=${type}"); | |
425 | |
426 statement.SetParameterType("id", ValueType_Integer64); | |
427 statement.SetParameterType("type", ValueType_Integer64); | |
428 | |
429 Dictionary args; | |
430 args.SetIntegerValue("id", id); | |
431 args.SetIntegerValue("type", static_cast<int>(attachment)); | |
432 | |
433 statement.Execute(args); | |
434 } | |
435 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
436 SignalDeletedFiles(output); |
0 | 437 } |
438 | |
439 | |
440 void IndexBackend::DeleteMetadata(int64_t id, | |
441 int32_t metadataType) | |
442 { | |
443 DatabaseManager::CachedStatement statement( | |
444 STATEMENT_FROM_HERE, manager_, | |
445 "DELETE FROM Metadata WHERE id=${id} and type=${type}"); | |
446 | |
447 statement.SetParameterType("id", ValueType_Integer64); | |
448 statement.SetParameterType("type", ValueType_Integer64); | |
449 | |
450 Dictionary args; | |
451 args.SetIntegerValue("id", id); | |
452 args.SetIntegerValue("type", static_cast<int>(metadataType)); | |
453 | |
454 statement.Execute(args); | |
455 } | |
456 | |
457 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
458 void IndexBackend::DeleteResource(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
459 int64_t id) |
0 | 460 { |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
461 assert(manager_.GetDialect() != Dialect_MySQL); |
0 | 462 |
463 ClearDeletedFiles(); | |
464 ClearDeletedResources(); | |
465 | |
466 { | |
467 DatabaseManager::CachedStatement statement( | |
468 STATEMENT_FROM_HERE, GetManager(), | |
469 "DELETE FROM RemainingAncestor"); | |
470 | |
471 statement.Execute(); | |
472 } | |
473 | |
474 { | |
475 DatabaseManager::CachedStatement statement( | |
476 STATEMENT_FROM_HERE, GetManager(), | |
477 "DELETE FROM Resources WHERE internalId=${id}"); | |
478 | |
479 statement.SetParameterType("id", ValueType_Integer64); | |
480 | |
481 Dictionary args; | |
482 args.SetIntegerValue("id", id); | |
483 | |
484 statement.Execute(args); | |
485 } | |
486 | |
487 | |
488 { | |
489 DatabaseManager::CachedStatement statement( | |
490 STATEMENT_FROM_HERE, GetManager(), | |
491 "SELECT * FROM RemainingAncestor"); | |
492 | |
493 statement.Execute(); | |
494 | |
495 if (!statement.IsDone()) | |
496 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
497 output.SignalRemainingAncestor( |
0 | 498 ReadString(statement, 1), |
499 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0))); | |
500 | |
501 // There is at most 1 remaining ancestor | |
502 assert((statement.Next(), statement.IsDone())); | |
503 } | |
504 } | |
505 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
506 SignalDeletedFiles(output); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
507 SignalDeletedResources(output); |
0 | 508 } |
509 | |
510 | |
511 void IndexBackend::GetAllInternalIds(std::list<int64_t>& target, | |
512 OrthancPluginResourceType resourceType) | |
513 { | |
514 DatabaseManager::CachedStatement statement( | |
515 STATEMENT_FROM_HERE, manager_, | |
516 "SELECT internalId FROM Resources WHERE resourceType=${type}"); | |
517 | |
518 statement.SetReadOnly(true); | |
519 statement.SetParameterType("type", ValueType_Integer64); | |
520 | |
521 Dictionary args; | |
522 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
523 | |
524 ReadListOfIntegers<int64_t>(target, statement, args); | |
525 } | |
526 | |
527 | |
528 void IndexBackend::GetAllPublicIds(std::list<std::string>& target, | |
529 OrthancPluginResourceType resourceType) | |
530 { | |
531 DatabaseManager::CachedStatement statement( | |
532 STATEMENT_FROM_HERE, manager_, | |
533 "SELECT publicId FROM Resources WHERE resourceType=${type}"); | |
534 | |
535 statement.SetReadOnly(true); | |
536 statement.SetParameterType("type", ValueType_Integer64); | |
537 | |
538 Dictionary args; | |
539 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
540 | |
541 ReadListOfStrings(target, statement, args); | |
542 } | |
543 | |
544 | |
545 void IndexBackend::GetAllPublicIds(std::list<std::string>& target, | |
546 OrthancPluginResourceType resourceType, | |
547 uint64_t since, | |
548 uint64_t limit) | |
549 { | |
550 DatabaseManager::CachedStatement statement( | |
551 STATEMENT_FROM_HERE, manager_, | |
552 "SELECT publicId FROM (SELECT publicId FROM Resources " | |
553 "WHERE resourceType=${type}) AS tmp " | |
554 "ORDER BY tmp.publicId LIMIT ${limit} OFFSET ${since}"); | |
555 | |
556 statement.SetReadOnly(true); | |
557 statement.SetParameterType("type", ValueType_Integer64); | |
558 statement.SetParameterType("limit", ValueType_Integer64); | |
559 statement.SetParameterType("since", ValueType_Integer64); | |
560 | |
561 Dictionary args; | |
562 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
563 args.SetIntegerValue("limit", limit); | |
564 args.SetIntegerValue("since", since); | |
565 | |
566 ReadListOfStrings(target, statement, args); | |
567 } | |
568 | |
569 | |
570 /* Use GetOutput().AnswerChange() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
571 void IndexBackend::GetChanges(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
572 bool& done /*out*/, |
0 | 573 int64_t since, |
574 uint32_t maxResults) | |
575 { | |
576 DatabaseManager::CachedStatement statement( | |
577 STATEMENT_FROM_HERE, manager_, | |
578 "SELECT * FROM Changes WHERE seq>${since} ORDER BY seq LIMIT ${limit}"); | |
579 | |
580 statement.SetReadOnly(true); | |
581 statement.SetParameterType("limit", ValueType_Integer64); | |
582 statement.SetParameterType("since", ValueType_Integer64); | |
583 | |
584 Dictionary args; | |
585 args.SetIntegerValue("limit", maxResults + 1); | |
586 args.SetIntegerValue("since", since); | |
587 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
588 ReadChangesInternal(output, done, statement, args, maxResults); |
0 | 589 } |
590 | |
591 | |
592 void IndexBackend::GetChildrenInternalId(std::list<int64_t>& target /*out*/, | |
593 int64_t id) | |
594 { | |
595 DatabaseManager::CachedStatement statement( | |
596 STATEMENT_FROM_HERE, manager_, | |
597 "SELECT a.internalId FROM Resources AS a, Resources AS b " | |
598 "WHERE a.parentId = b.internalId AND b.internalId = ${id}"); | |
599 | |
600 statement.SetReadOnly(true); | |
601 statement.SetParameterType("id", ValueType_Integer64); | |
602 | |
603 Dictionary args; | |
604 args.SetIntegerValue("id", id); | |
605 | |
606 ReadListOfIntegers<int64_t>(target, statement, args); | |
607 } | |
608 | |
609 | |
610 void IndexBackend::GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
611 int64_t id) | |
612 { | |
613 DatabaseManager::CachedStatement statement( | |
614 STATEMENT_FROM_HERE, manager_, | |
615 "SELECT a.publicId FROM Resources AS a, Resources AS b " | |
616 "WHERE a.parentId = b.internalId AND b.internalId = ${id}"); | |
617 | |
618 statement.SetReadOnly(true); | |
619 statement.SetParameterType("id", ValueType_Integer64); | |
620 | |
621 Dictionary args; | |
622 args.SetIntegerValue("id", id); | |
623 | |
624 ReadListOfStrings(target, statement, args); | |
625 } | |
626 | |
627 | |
628 /* Use GetOutput().AnswerExportedResource() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
629 void IndexBackend::GetExportedResources(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
630 bool& done /*out*/, |
0 | 631 int64_t since, |
632 uint32_t maxResults) | |
633 { | |
634 DatabaseManager::CachedStatement statement( | |
635 STATEMENT_FROM_HERE, manager_, | |
636 "SELECT * FROM ExportedResources WHERE seq>${since} ORDER BY seq LIMIT ${limit}"); | |
637 | |
638 statement.SetReadOnly(true); | |
639 statement.SetParameterType("limit", ValueType_Integer64); | |
640 statement.SetParameterType("since", ValueType_Integer64); | |
641 | |
642 Dictionary args; | |
643 args.SetIntegerValue("limit", maxResults + 1); | |
644 args.SetIntegerValue("since", since); | |
645 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
646 ReadExportedResourcesInternal(output, done, statement, args, maxResults); |
0 | 647 } |
648 | |
649 | |
650 /* Use GetOutput().AnswerChange() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
651 void IndexBackend::GetLastChange(IDatabaseBackendOutput& output) |
0 | 652 { |
653 DatabaseManager::CachedStatement statement( | |
654 STATEMENT_FROM_HERE, manager_, | |
655 "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1"); | |
656 | |
657 statement.SetReadOnly(true); | |
658 | |
659 Dictionary args; | |
660 | |
661 bool done; // Ignored | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
662 ReadChangesInternal(output, done, statement, args, 1); |
0 | 663 } |
664 | |
665 | |
666 /* Use GetOutput().AnswerExportedResource() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
667 void IndexBackend::GetLastExportedResource(IDatabaseBackendOutput& output) |
0 | 668 { |
669 DatabaseManager::CachedStatement statement( | |
670 STATEMENT_FROM_HERE, manager_, | |
671 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1"); | |
672 | |
673 statement.SetReadOnly(true); | |
674 | |
675 Dictionary args; | |
676 | |
677 bool done; // Ignored | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
678 ReadExportedResourcesInternal(output, done, statement, args, 1); |
0 | 679 } |
680 | |
681 | |
682 /* Use GetOutput().AnswerDicomTag() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
683 void IndexBackend::GetMainDicomTags(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
684 int64_t id) |
0 | 685 { |
686 DatabaseManager::CachedStatement statement( | |
687 STATEMENT_FROM_HERE, manager_, | |
688 "SELECT * FROM MainDicomTags WHERE id=${id}"); | |
689 | |
690 statement.SetReadOnly(true); | |
691 statement.SetParameterType("id", ValueType_Integer64); | |
692 | |
693 Dictionary args; | |
694 args.SetIntegerValue("id", id); | |
695 | |
696 statement.Execute(args); | |
697 | |
698 while (!statement.IsDone()) | |
699 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
700 output.AnswerDicomTag(static_cast<uint16_t>(ReadInteger64(statement, 1)), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
701 static_cast<uint16_t>(ReadInteger64(statement, 2)), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
702 ReadString(statement, 3)); |
0 | 703 statement.Next(); |
704 } | |
705 } | |
706 | |
707 | |
708 std::string IndexBackend::GetPublicId(int64_t resourceId) | |
709 { | |
710 DatabaseManager::CachedStatement statement( | |
711 STATEMENT_FROM_HERE, manager_, | |
712 "SELECT publicId FROM Resources WHERE internalId=${id}"); | |
713 | |
714 statement.SetReadOnly(true); | |
715 statement.SetParameterType("id", ValueType_Integer64); | |
716 | |
717 Dictionary args; | |
718 args.SetIntegerValue("id", resourceId); | |
719 | |
720 statement.Execute(args); | |
721 | |
722 if (statement.IsDone()) | |
723 { | |
724 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
725 } | |
726 else | |
727 { | |
728 return ReadString(statement, 0); | |
729 } | |
730 } | |
731 | |
732 | |
733 uint64_t IndexBackend::GetResourceCount(OrthancPluginResourceType resourceType) | |
734 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
735 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 736 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
737 switch (manager_.GetDialect()) |
0 | 738 { |
739 case Dialect_MySQL: | |
740 statement.reset(new DatabaseManager::CachedStatement( | |
741 STATEMENT_FROM_HERE, GetManager(), | |
742 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources WHERE resourceType=${type}")); | |
743 break; | |
744 | |
745 case Dialect_PostgreSQL: | |
746 statement.reset(new DatabaseManager::CachedStatement( | |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
747 STATEMENT_FROM_HERE, GetManager(), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
748 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources WHERE resourceType=${type}")); |
0 | 749 break; |
750 | |
751 case Dialect_SQLite: | |
752 statement.reset(new DatabaseManager::CachedStatement( | |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
753 STATEMENT_FROM_HERE, GetManager(), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
754 "SELECT COUNT(*) FROM Resources WHERE resourceType=${type}")); |
0 | 755 break; |
756 | |
757 default: | |
758 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
759 } | |
760 | |
761 statement->SetReadOnly(true); | |
762 statement->SetParameterType("type", ValueType_Integer64); | |
763 | |
764 Dictionary args; | |
765 args.SetIntegerValue("type", resourceType); | |
766 | |
767 statement->Execute(args); | |
768 | |
769 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
770 } | |
771 | |
772 | |
773 OrthancPluginResourceType IndexBackend::GetResourceType(int64_t resourceId) | |
774 { | |
775 DatabaseManager::CachedStatement statement( | |
776 STATEMENT_FROM_HERE, manager_, | |
777 "SELECT resourceType FROM Resources WHERE internalId=${id}"); | |
778 | |
779 statement.SetReadOnly(true); | |
780 statement.SetParameterType("id", ValueType_Integer64); | |
781 | |
782 Dictionary args; | |
783 args.SetIntegerValue("id", resourceId); | |
784 | |
785 statement.Execute(args); | |
786 | |
787 if (statement.IsDone()) | |
788 { | |
789 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
790 } | |
791 else | |
792 { | |
793 return static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0)); | |
794 } | |
795 } | |
796 | |
797 | |
798 uint64_t IndexBackend::GetTotalCompressedSize() | |
799 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
800 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 801 |
802 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty | |
803 | |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
804 switch (manager_.GetDialect()) |
0 | 805 { |
806 case Dialect_MySQL: | |
807 statement.reset(new DatabaseManager::CachedStatement( | |
808 STATEMENT_FROM_HERE, GetManager(), | |
809 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles")); | |
810 break; | |
811 | |
812 case Dialect_PostgreSQL: | |
813 statement.reset(new DatabaseManager::CachedStatement( | |
814 STATEMENT_FROM_HERE, GetManager(), | |
815 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS BIGINT) FROM AttachedFiles")); | |
816 break; | |
817 | |
818 case Dialect_SQLite: | |
819 statement.reset(new DatabaseManager::CachedStatement( | |
820 STATEMENT_FROM_HERE, GetManager(), | |
821 "SELECT COALESCE(SUM(compressedSize), 0) FROM AttachedFiles")); | |
822 break; | |
823 | |
824 default: | |
825 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
826 } | |
827 | |
828 statement->SetReadOnly(true); | |
829 statement->Execute(); | |
830 | |
831 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
832 } | |
833 | |
834 | |
835 uint64_t IndexBackend::GetTotalUncompressedSize() | |
836 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
837 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 838 |
839 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty | |
840 | |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
841 switch (manager_.GetDialect()) |
0 | 842 { |
843 case Dialect_MySQL: | |
844 statement.reset(new DatabaseManager::CachedStatement( | |
845 STATEMENT_FROM_HERE, GetManager(), | |
846 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles")); | |
847 break; | |
848 | |
849 case Dialect_PostgreSQL: | |
850 statement.reset(new DatabaseManager::CachedStatement( | |
851 STATEMENT_FROM_HERE, GetManager(), | |
852 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS BIGINT) FROM AttachedFiles")); | |
853 break; | |
854 | |
855 case Dialect_SQLite: | |
856 statement.reset(new DatabaseManager::CachedStatement( | |
857 STATEMENT_FROM_HERE, GetManager(), | |
858 "SELECT COALESCE(SUM(uncompressedSize), 0) FROM AttachedFiles")); | |
859 break; | |
860 | |
861 default: | |
862 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
863 } | |
864 | |
865 statement->SetReadOnly(true); | |
866 statement->Execute(); | |
867 | |
868 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
869 } | |
870 | |
871 | |
872 bool IndexBackend::IsExistingResource(int64_t internalId) | |
873 { | |
874 DatabaseManager::CachedStatement statement( | |
875 STATEMENT_FROM_HERE, manager_, | |
876 "SELECT * FROM Resources WHERE internalId=${id}"); | |
877 | |
878 statement.SetReadOnly(true); | |
879 statement.SetParameterType("id", ValueType_Integer64); | |
880 | |
881 Dictionary args; | |
882 args.SetIntegerValue("id", internalId); | |
883 | |
884 statement.Execute(args); | |
885 | |
886 return !statement.IsDone(); | |
887 } | |
888 | |
889 | |
890 bool IndexBackend::IsProtectedPatient(int64_t internalId) | |
891 { | |
892 DatabaseManager::CachedStatement statement( | |
893 STATEMENT_FROM_HERE, manager_, | |
894 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ${id}"); | |
895 | |
896 statement.SetReadOnly(true); | |
897 statement.SetParameterType("id", ValueType_Integer64); | |
898 | |
899 Dictionary args; | |
900 args.SetIntegerValue("id", internalId); | |
901 | |
902 statement.Execute(args); | |
903 | |
904 return statement.IsDone(); | |
905 } | |
906 | |
907 | |
908 void IndexBackend::ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
909 int64_t id) | |
910 { | |
911 DatabaseManager::CachedStatement statement( | |
912 STATEMENT_FROM_HERE, manager_, | |
913 "SELECT type FROM Metadata WHERE id=${id}"); | |
914 | |
915 statement.SetReadOnly(true); | |
916 statement.SetParameterType("id", ValueType_Integer64); | |
917 | |
918 Dictionary args; | |
919 args.SetIntegerValue("id", id); | |
920 | |
921 ReadListOfIntegers<int32_t>(target, statement, args); | |
922 } | |
923 | |
924 | |
925 void IndexBackend::ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
926 int64_t id) | |
927 { | |
928 DatabaseManager::CachedStatement statement( | |
929 STATEMENT_FROM_HERE, manager_, | |
930 "SELECT fileType FROM AttachedFiles WHERE id=${id}"); | |
931 | |
932 statement.SetReadOnly(true); | |
933 statement.SetParameterType("id", ValueType_Integer64); | |
934 | |
935 Dictionary args; | |
936 args.SetIntegerValue("id", id); | |
937 | |
938 ReadListOfIntegers<int32_t>(target, statement, args); | |
939 } | |
940 | |
941 | |
942 void IndexBackend::LogChange(const OrthancPluginChange& change) | |
943 { | |
944 int64_t id; | |
945 OrthancPluginResourceType type; | |
946 if (!LookupResource(id, type, change.publicId) || | |
947 type != change.resourceType) | |
948 { | |
949 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
950 } | |
951 | |
952 DatabaseManager::CachedStatement statement( | |
953 STATEMENT_FROM_HERE, manager_, | |
954 "INSERT INTO Changes VALUES(${}, ${changeType}, ${id}, ${resourceType}, ${date})"); | |
955 | |
956 statement.SetParameterType("changeType", ValueType_Integer64); | |
957 statement.SetParameterType("id", ValueType_Integer64); | |
958 statement.SetParameterType("resourceType", ValueType_Integer64); | |
959 statement.SetParameterType("date", ValueType_Utf8String); | |
960 | |
961 Dictionary args; | |
962 args.SetIntegerValue("changeType", change.changeType); | |
963 args.SetIntegerValue("id", id); | |
964 args.SetIntegerValue("resourceType", change.resourceType); | |
965 args.SetUtf8Value("date", change.date); | |
966 | |
967 statement.Execute(args); | |
968 } | |
969 | |
970 | |
971 void IndexBackend::LogExportedResource(const OrthancPluginExportedResource& resource) | |
972 { | |
973 DatabaseManager::CachedStatement statement( | |
974 STATEMENT_FROM_HERE, manager_, | |
975 "INSERT INTO ExportedResources VALUES(${}, ${type}, ${publicId}, " | |
976 "${modality}, ${patient}, ${study}, ${series}, ${instance}, ${date})"); | |
977 | |
978 statement.SetParameterType("type", ValueType_Integer64); | |
979 statement.SetParameterType("publicId", ValueType_Utf8String); | |
980 statement.SetParameterType("modality", ValueType_Utf8String); | |
981 statement.SetParameterType("patient", ValueType_Utf8String); | |
982 statement.SetParameterType("study", ValueType_Utf8String); | |
983 statement.SetParameterType("series", ValueType_Utf8String); | |
984 statement.SetParameterType("instance", ValueType_Utf8String); | |
985 statement.SetParameterType("date", ValueType_Utf8String); | |
986 | |
987 Dictionary args; | |
988 args.SetIntegerValue("type", resource.resourceType); | |
989 args.SetUtf8Value("publicId", resource.publicId); | |
990 args.SetUtf8Value("modality", resource.modality); | |
991 args.SetUtf8Value("patient", resource.patientId); | |
992 args.SetUtf8Value("study", resource.studyInstanceUid); | |
993 args.SetUtf8Value("series", resource.seriesInstanceUid); | |
994 args.SetUtf8Value("instance", resource.sopInstanceUid); | |
995 args.SetUtf8Value("date", resource.date); | |
996 | |
997 statement.Execute(args); | |
998 } | |
999 | |
1000 | |
1001 /* Use GetOutput().AnswerAttachment() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
1002 bool IndexBackend::LookupAttachment(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1003 int64_t id, |
0 | 1004 int32_t contentType) |
1005 { | |
1006 DatabaseManager::CachedStatement statement( | |
1007 STATEMENT_FROM_HERE, manager_, | |
1008 "SELECT uuid, uncompressedSize, compressionType, compressedSize, " | |
1009 "uncompressedHash, compressedHash FROM AttachedFiles WHERE id=${id} AND fileType=${type}"); | |
1010 | |
1011 statement.SetReadOnly(true); | |
1012 statement.SetParameterType("id", ValueType_Integer64); | |
1013 statement.SetParameterType("type", ValueType_Integer64); | |
1014 | |
1015 Dictionary args; | |
1016 args.SetIntegerValue("id", id); | |
1017 args.SetIntegerValue("type", static_cast<int>(contentType)); | |
1018 | |
1019 statement.Execute(args); | |
1020 | |
1021 if (statement.IsDone()) | |
1022 { | |
1023 return false; | |
1024 } | |
1025 else | |
1026 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1027 output.AnswerAttachment(ReadString(statement, 0), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1028 contentType, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1029 ReadInteger64(statement, 1), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1030 ReadString(statement, 4), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1031 ReadInteger32(statement, 2), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1032 ReadInteger64(statement, 3), |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1033 ReadString(statement, 5)); |
0 | 1034 return true; |
1035 } | |
1036 } | |
1037 | |
1038 | |
1039 bool IndexBackend::LookupGlobalProperty(std::string& target /*out*/, | |
1040 int32_t property) | |
1041 { | |
1042 return ::OrthancDatabases::LookupGlobalProperty(target, manager_, static_cast<Orthanc::GlobalProperty>(property)); | |
1043 } | |
1044 | |
1045 | |
1046 void IndexBackend::LookupIdentifier(std::list<int64_t>& target /*out*/, | |
1047 OrthancPluginResourceType resourceType, | |
1048 uint16_t group, | |
1049 uint16_t element, | |
1050 OrthancPluginIdentifierConstraint constraint, | |
1051 const char* value) | |
1052 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1053 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1054 |
1055 std::string header = | |
1056 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " | |
1057 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} " | |
1058 "AND d.tagElement=${element} AND "; | |
1059 | |
1060 switch (constraint) | |
1061 { | |
1062 case OrthancPluginIdentifierConstraint_Equal: | |
1063 header += "d.value = ${value}"; | |
1064 statement.reset(new DatabaseManager::CachedStatement( | |
1065 STATEMENT_FROM_HERE, manager_, header.c_str())); | |
1066 break; | |
1067 | |
1068 case OrthancPluginIdentifierConstraint_SmallerOrEqual: | |
1069 header += "d.value <= ${value}"; | |
1070 statement.reset(new DatabaseManager::CachedStatement( | |
1071 STATEMENT_FROM_HERE, manager_, header.c_str())); | |
1072 break; | |
1073 | |
1074 case OrthancPluginIdentifierConstraint_GreaterOrEqual: | |
1075 header += "d.value >= ${value}"; | |
1076 statement.reset(new DatabaseManager::CachedStatement( | |
1077 STATEMENT_FROM_HERE, manager_, header.c_str())); | |
1078 break; | |
1079 | |
1080 case OrthancPluginIdentifierConstraint_Wildcard: | |
1081 header += "d.value LIKE ${value}"; | |
1082 statement.reset(new DatabaseManager::CachedStatement( | |
1083 STATEMENT_FROM_HERE, manager_, header.c_str())); | |
1084 break; | |
1085 | |
1086 default: | |
1087 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
1088 } | |
1089 | |
1090 statement->SetReadOnly(true); | |
1091 statement->SetParameterType("type", ValueType_Integer64); | |
1092 statement->SetParameterType("group", ValueType_Integer64); | |
1093 statement->SetParameterType("element", ValueType_Integer64); | |
1094 statement->SetParameterType("value", ValueType_Utf8String); | |
1095 | |
1096 Dictionary args; | |
1097 args.SetIntegerValue("type", resourceType); | |
1098 args.SetIntegerValue("group", group); | |
1099 args.SetIntegerValue("element", element); | |
1100 | |
1101 if (constraint == OrthancPluginIdentifierConstraint_Wildcard) | |
1102 { | |
1103 args.SetUtf8Value("value", ConvertWildcardToLike(value)); | |
1104 } | |
1105 else | |
1106 { | |
1107 args.SetUtf8Value("value", value); | |
1108 } | |
1109 | |
1110 statement->Execute(args); | |
1111 | |
1112 target.clear(); | |
1113 while (!statement->IsDone()) | |
1114 { | |
1115 target.push_back(ReadInteger64(*statement, 0)); | |
1116 statement->Next(); | |
1117 } | |
1118 } | |
1119 | |
1120 | |
1121 void IndexBackend::LookupIdentifierRange(std::list<int64_t>& target /*out*/, | |
1122 OrthancPluginResourceType resourceType, | |
1123 uint16_t group, | |
1124 uint16_t element, | |
1125 const char* start, | |
1126 const char* end) | |
1127 { | |
1128 DatabaseManager::CachedStatement statement( | |
1129 STATEMENT_FROM_HERE, manager_, | |
1130 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " | |
1131 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} " | |
1132 "AND d.tagElement=${element} AND d.value>=${start} AND d.value<=${end}"); | |
1133 | |
1134 statement.SetReadOnly(true); | |
1135 statement.SetParameterType("type", ValueType_Integer64); | |
1136 statement.SetParameterType("group", ValueType_Integer64); | |
1137 statement.SetParameterType("element", ValueType_Integer64); | |
1138 statement.SetParameterType("start", ValueType_Utf8String); | |
1139 statement.SetParameterType("end", ValueType_Utf8String); | |
1140 | |
1141 Dictionary args; | |
1142 args.SetIntegerValue("type", resourceType); | |
1143 args.SetIntegerValue("group", group); | |
1144 args.SetIntegerValue("element", element); | |
1145 args.SetUtf8Value("start", start); | |
1146 args.SetUtf8Value("end", end); | |
1147 | |
1148 statement.Execute(args); | |
1149 | |
1150 target.clear(); | |
1151 while (!statement.IsDone()) | |
1152 { | |
1153 target.push_back(ReadInteger64(statement, 0)); | |
1154 statement.Next(); | |
1155 } | |
1156 } | |
1157 | |
1158 | |
1159 bool IndexBackend::LookupMetadata(std::string& target /*out*/, | |
1160 int64_t id, | |
1161 int32_t metadataType) | |
1162 { | |
1163 DatabaseManager::CachedStatement statement( | |
1164 STATEMENT_FROM_HERE, manager_, | |
1165 "SELECT value FROM Metadata WHERE id=${id} and type=${type}"); | |
1166 | |
1167 statement.SetReadOnly(true); | |
1168 statement.SetParameterType("id", ValueType_Integer64); | |
1169 statement.SetParameterType("type", ValueType_Integer64); | |
1170 | |
1171 Dictionary args; | |
1172 args.SetIntegerValue("id", id); | |
1173 args.SetIntegerValue("type", metadataType); | |
1174 | |
1175 statement.Execute(args); | |
1176 | |
1177 if (statement.IsDone()) | |
1178 { | |
1179 return false; | |
1180 } | |
1181 else | |
1182 { | |
1183 target = ReadString(statement, 0); | |
1184 return true; | |
1185 } | |
1186 } | |
1187 | |
1188 | |
1189 bool IndexBackend::LookupParent(int64_t& parentId /*out*/, | |
1190 int64_t resourceId) | |
1191 { | |
1192 DatabaseManager::CachedStatement statement( | |
1193 STATEMENT_FROM_HERE, manager_, | |
1194 "SELECT parentId FROM Resources WHERE internalId=${id}"); | |
1195 | |
1196 statement.SetReadOnly(true); | |
1197 statement.SetParameterType("id", ValueType_Integer64); | |
1198 | |
1199 Dictionary args; | |
1200 args.SetIntegerValue("id", resourceId); | |
1201 | |
1202 statement.Execute(args); | |
1203 | |
1204 if (statement.IsDone() || | |
1205 statement.GetResultField(0).GetType() == ValueType_Null) | |
1206 { | |
1207 return false; | |
1208 } | |
1209 else | |
1210 { | |
1211 parentId = ReadInteger64(statement, 0); | |
1212 return true; | |
1213 } | |
1214 } | |
1215 | |
1216 | |
1217 bool IndexBackend::LookupResource(int64_t& id /*out*/, | |
1218 OrthancPluginResourceType& type /*out*/, | |
1219 const char* publicId) | |
1220 { | |
1221 DatabaseManager::CachedStatement statement( | |
1222 STATEMENT_FROM_HERE, manager_, | |
1223 "SELECT internalId, resourceType FROM Resources WHERE publicId=${id}"); | |
1224 | |
1225 statement.SetReadOnly(true); | |
1226 statement.SetParameterType("id", ValueType_Utf8String); | |
1227 | |
1228 Dictionary args; | |
1229 args.SetUtf8Value("id", publicId); | |
1230 | |
1231 statement.Execute(args); | |
1232 | |
1233 if (statement.IsDone()) | |
1234 { | |
1235 return false; | |
1236 } | |
1237 else | |
1238 { | |
1239 id = ReadInteger64(statement, 0); | |
1240 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1)); | |
1241 return true; | |
1242 } | |
1243 } | |
1244 | |
1245 | |
1246 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/) | |
1247 { | |
1248 DatabaseManager::CachedStatement statement( | |
1249 STATEMENT_FROM_HERE, manager_, | |
1250 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1"); | |
1251 | |
1252 statement.SetReadOnly(true); | |
1253 statement.Execute(); | |
1254 | |
1255 if (statement.IsDone()) | |
1256 { | |
1257 return false; | |
1258 } | |
1259 else | |
1260 { | |
1261 internalId = ReadInteger64(statement, 0); | |
1262 return true; | |
1263 } | |
1264 } | |
1265 | |
1266 | |
1267 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/, | |
1268 int64_t patientIdToAvoid) | |
1269 { | |
1270 DatabaseManager::CachedStatement statement( | |
1271 STATEMENT_FROM_HERE, manager_, | |
1272 "SELECT patientId FROM PatientRecyclingOrder " | |
1273 "WHERE patientId != ${id} ORDER BY seq ASC LIMIT 1"); | |
1274 | |
1275 statement.SetReadOnly(true); | |
1276 statement.SetParameterType("id", ValueType_Integer64); | |
1277 | |
1278 Dictionary args; | |
1279 args.SetIntegerValue("id", patientIdToAvoid); | |
1280 | |
1281 statement.Execute(args); | |
1282 | |
1283 if (statement.IsDone()) | |
1284 { | |
1285 return false; | |
1286 } | |
1287 else | |
1288 { | |
1289 internalId = ReadInteger64(statement, 0); | |
1290 return true; | |
1291 } | |
1292 } | |
1293 | |
1294 | |
1295 void IndexBackend::SetGlobalProperty(int32_t property, | |
1296 const char* value) | |
1297 { | |
1298 return ::OrthancDatabases::SetGlobalProperty(manager_, static_cast<Orthanc::GlobalProperty>(property), value); | |
1299 } | |
1300 | |
1301 | |
1302 static void ExecuteSetTag(DatabaseManager::CachedStatement& statement, | |
1303 int64_t id, | |
1304 uint16_t group, | |
1305 uint16_t element, | |
1306 const char* value) | |
1307 { | |
1308 statement.SetParameterType("id", ValueType_Integer64); | |
1309 statement.SetParameterType("group", ValueType_Integer64); | |
1310 statement.SetParameterType("element", ValueType_Integer64); | |
1311 statement.SetParameterType("value", ValueType_Utf8String); | |
1312 | |
1313 Dictionary args; | |
1314 args.SetIntegerValue("id", id); | |
1315 args.SetIntegerValue("group", group); | |
1316 args.SetIntegerValue("element", element); | |
1317 args.SetUtf8Value("value", value); | |
1318 | |
1319 statement.Execute(args); | |
1320 } | |
1321 | |
1322 | |
1323 void IndexBackend::SetMainDicomTag(int64_t id, | |
1324 uint16_t group, | |
1325 uint16_t element, | |
1326 const char* value) | |
1327 { | |
1328 DatabaseManager::CachedStatement statement( | |
1329 STATEMENT_FROM_HERE, manager_, | |
1330 "INSERT INTO MainDicomTags VALUES(${id}, ${group}, ${element}, ${value})"); | |
1331 | |
1332 ExecuteSetTag(statement, id, group, element, value); | |
1333 } | |
1334 | |
1335 | |
1336 void IndexBackend::SetIdentifierTag(int64_t id, | |
1337 uint16_t group, | |
1338 uint16_t element, | |
1339 const char* value) | |
1340 { | |
1341 DatabaseManager::CachedStatement statement( | |
1342 STATEMENT_FROM_HERE, manager_, | |
1343 "INSERT INTO DicomIdentifiers VALUES(${id}, ${group}, ${element}, ${value})"); | |
1344 | |
1345 ExecuteSetTag(statement, id, group, element, value); | |
1346 } | |
1347 | |
1348 | |
1349 void IndexBackend::SetMetadata(int64_t id, | |
1350 int32_t metadataType, | |
1351 const char* value) | |
1352 { | |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
1353 if (manager_.GetDialect() == Dialect_SQLite) |
0 | 1354 { |
1355 DatabaseManager::CachedStatement statement( | |
1356 STATEMENT_FROM_HERE, manager_, | |
1357 "INSERT OR REPLACE INTO Metadata VALUES (${id}, ${type}, ${value})"); | |
1358 | |
1359 statement.SetParameterType("id", ValueType_Integer64); | |
1360 statement.SetParameterType("type", ValueType_Integer64); | |
1361 statement.SetParameterType("value", ValueType_Utf8String); | |
1362 | |
1363 Dictionary args; | |
1364 args.SetIntegerValue("id", id); | |
1365 args.SetIntegerValue("type", metadataType); | |
1366 args.SetUtf8Value("value", value); | |
1367 | |
1368 statement.Execute(args); | |
1369 } | |
1370 else | |
1371 { | |
1372 { | |
1373 DatabaseManager::CachedStatement statement( | |
1374 STATEMENT_FROM_HERE, manager_, | |
1375 "DELETE FROM Metadata WHERE id=${id} AND type=${type}"); | |
1376 | |
1377 statement.SetParameterType("id", ValueType_Integer64); | |
1378 statement.SetParameterType("type", ValueType_Integer64); | |
1379 | |
1380 Dictionary args; | |
1381 args.SetIntegerValue("id", id); | |
1382 args.SetIntegerValue("type", metadataType); | |
1383 | |
1384 statement.Execute(args); | |
1385 } | |
1386 | |
1387 { | |
1388 DatabaseManager::CachedStatement statement( | |
1389 STATEMENT_FROM_HERE, manager_, | |
1390 "INSERT INTO Metadata VALUES (${id}, ${type}, ${value})"); | |
1391 | |
1392 statement.SetParameterType("id", ValueType_Integer64); | |
1393 statement.SetParameterType("type", ValueType_Integer64); | |
1394 statement.SetParameterType("value", ValueType_Utf8String); | |
1395 | |
1396 Dictionary args; | |
1397 args.SetIntegerValue("id", id); | |
1398 args.SetIntegerValue("type", metadataType); | |
1399 args.SetUtf8Value("value", value); | |
1400 | |
1401 statement.Execute(args); | |
1402 } | |
1403 } | |
1404 } | |
1405 | |
1406 | |
1407 void IndexBackend::SetProtectedPatient(int64_t internalId, | |
1408 bool isProtected) | |
1409 { | |
1410 if (isProtected) | |
1411 { | |
1412 DatabaseManager::CachedStatement statement( | |
1413 STATEMENT_FROM_HERE, manager_, | |
1414 "DELETE FROM PatientRecyclingOrder WHERE patientId=${id}"); | |
1415 | |
1416 statement.SetParameterType("id", ValueType_Integer64); | |
1417 | |
1418 Dictionary args; | |
1419 args.SetIntegerValue("id", internalId); | |
1420 | |
1421 statement.Execute(args); | |
1422 } | |
1423 else if (IsProtectedPatient(internalId)) | |
1424 { | |
1425 DatabaseManager::CachedStatement statement( | |
1426 STATEMENT_FROM_HERE, manager_, | |
1427 "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})"); | |
1428 | |
1429 statement.SetParameterType("id", ValueType_Integer64); | |
1430 | |
1431 Dictionary args; | |
1432 args.SetIntegerValue("id", internalId); | |
1433 | |
1434 statement.Execute(args); | |
1435 } | |
1436 else | |
1437 { | |
1438 // Nothing to do: The patient is already unprotected | |
1439 } | |
1440 } | |
1441 | |
1442 | |
1443 uint32_t IndexBackend::GetDatabaseVersion() | |
1444 { | |
1445 std::string version = "unknown"; | |
1446 | |
1447 if (LookupGlobalProperty(version, Orthanc::GlobalProperty_DatabaseSchemaVersion)) | |
1448 { | |
1449 try | |
1450 { | |
1451 return boost::lexical_cast<unsigned int>(version); | |
1452 } | |
1453 catch (boost::bad_lexical_cast&) | |
1454 { | |
1455 } | |
1456 } | |
1457 | |
1458 LOG(ERROR) << "The database is corrupted. Drop it manually for Orthanc to recreate it"; | |
1459 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
1460 } | |
1461 | |
1462 | |
1463 /** | |
1464 * Upgrade the database to the specified version of the database | |
1465 * schema. The upgrade script is allowed to make calls to | |
1466 * OrthancPluginReconstructMainDicomTags(). | |
1467 **/ | |
1468 void IndexBackend::UpgradeDatabase(uint32_t targetVersion, | |
1469 OrthancPluginStorageArea* storageArea) | |
1470 { | |
1471 LOG(ERROR) << "Upgrading database is not implemented by this plugin"; | |
1472 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1473 } | |
1474 | |
1475 | |
1476 void IndexBackend::ClearMainDicomTags(int64_t internalId) | |
1477 { | |
1478 { | |
1479 DatabaseManager::CachedStatement statement( | |
1480 STATEMENT_FROM_HERE, manager_, | |
1481 "DELETE FROM MainDicomTags WHERE id=${id}"); | |
1482 | |
1483 statement.SetParameterType("id", ValueType_Integer64); | |
1484 | |
1485 Dictionary args; | |
1486 args.SetIntegerValue("id", internalId); | |
1487 | |
1488 statement.Execute(args); | |
1489 } | |
1490 | |
1491 { | |
1492 DatabaseManager::CachedStatement statement( | |
1493 STATEMENT_FROM_HERE, manager_, | |
1494 "DELETE FROM DicomIdentifiers WHERE id=${id}"); | |
1495 | |
1496 statement.SetParameterType("id", ValueType_Integer64); | |
1497 | |
1498 Dictionary args; | |
1499 args.SetIntegerValue("id", internalId); | |
1500 | |
1501 statement.Execute(args); | |
1502 } | |
1503 } | |
1504 | |
1505 | |
1506 // For unit testing only! | |
1507 uint64_t IndexBackend::GetResourcesCount() | |
1508 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1509 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1510 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
1511 switch (manager_.GetDialect()) |
0 | 1512 { |
1513 case Dialect_MySQL: | |
1514 statement.reset(new DatabaseManager::CachedStatement( | |
1515 STATEMENT_FROM_HERE, GetManager(), | |
1516 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources")); | |
1517 break; | |
1518 | |
1519 case Dialect_PostgreSQL: | |
1520 statement.reset(new DatabaseManager::CachedStatement( | |
1521 STATEMENT_FROM_HERE, GetManager(), | |
1522 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources")); | |
1523 break; | |
1524 | |
1525 case Dialect_SQLite: | |
1526 statement.reset(new DatabaseManager::CachedStatement( | |
1527 STATEMENT_FROM_HERE, GetManager(), | |
1528 "SELECT COUNT(*) FROM Resources")); | |
1529 break; | |
1530 | |
1531 default: | |
1532 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1533 } | |
1534 | |
1535 statement->SetReadOnly(true); | |
1536 statement->Execute(); | |
1537 | |
1538 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
1539 } | |
1540 | |
1541 | |
1542 // For unit testing only! | |
1543 uint64_t IndexBackend::GetUnprotectedPatientsCount() | |
1544 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1545 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1546 |
1
d17b2631bb67
starting StorageBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
1547 switch (manager_.GetDialect()) |
0 | 1548 { |
1549 case Dialect_MySQL: | |
1550 statement.reset(new DatabaseManager::CachedStatement( | |
1551 STATEMENT_FROM_HERE, GetManager(), | |
1552 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM PatientRecyclingOrder")); | |
1553 break; | |
1554 | |
1555 case Dialect_PostgreSQL: | |
1556 statement.reset(new DatabaseManager::CachedStatement( | |
1557 STATEMENT_FROM_HERE, GetManager(), | |
1558 "SELECT CAST(COUNT(*) AS BIGINT) FROM PatientRecyclingOrder")); | |
1559 break; | |
1560 | |
1561 case Dialect_SQLite: | |
1562 statement.reset(new DatabaseManager::CachedStatement( | |
1563 STATEMENT_FROM_HERE, GetManager(), | |
1564 "SELECT COUNT(*) FROM PatientRecyclingOrder")); | |
1565 break; | |
1566 | |
1567 default: | |
1568 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1569 } | |
1570 | |
1571 statement->SetReadOnly(true); | |
1572 statement->Execute(); | |
1573 | |
1574 return static_cast<uint64_t>(ReadInteger64(*statement, 0)); | |
1575 } | |
1576 | |
1577 | |
1578 // For unit testing only! | |
1579 bool IndexBackend::GetParentPublicId(std::string& target, | |
1580 int64_t id) | |
1581 { | |
1582 DatabaseManager::CachedStatement statement( | |
1583 STATEMENT_FROM_HERE, GetManager(), | |
1584 "SELECT a.publicId FROM Resources AS a, Resources AS b " | |
1585 "WHERE a.internalId = b.parentId AND b.internalId = ${id}"); | |
1586 | |
1587 statement.SetReadOnly(true); | |
1588 statement.SetParameterType("id", ValueType_Integer64); | |
1589 | |
1590 Dictionary args; | |
1591 args.SetIntegerValue("id", id); | |
1592 | |
1593 statement.Execute(args); | |
1594 | |
1595 if (statement.IsDone()) | |
1596 { | |
1597 return false; | |
1598 } | |
1599 else | |
1600 { | |
1601 target = ReadString(statement, 0); | |
1602 return true; | |
1603 } | |
1604 } | |
1605 | |
1606 | |
1607 // For unit tests only! | |
1608 void IndexBackend::GetChildren(std::list<std::string>& childrenPublicIds, | |
1609 int64_t id) | |
1610 { | |
1611 DatabaseManager::CachedStatement statement( | |
1612 STATEMENT_FROM_HERE, GetManager(), | |
1613 "SELECT publicId FROM Resources WHERE parentId=${id}"); | |
1614 | |
1615 statement.SetReadOnly(true); | |
1616 statement.SetParameterType("id", ValueType_Integer64); | |
1617 | |
1618 Dictionary args; | |
1619 args.SetIntegerValue("id", id); | |
1620 | |
1621 ReadListOfStrings(childrenPublicIds, statement, args); | |
1622 } | |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1623 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1624 |
78 | 1625 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1626 class IndexBackend::LookupFormatter : public Orthanc::ISqlLookupFormatter |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1627 { |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1628 private: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1629 Dialect dialect_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1630 size_t count_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1631 Dictionary dictionary_; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1632 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1633 static std::string FormatParameter(size_t index) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1634 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1635 return "p" + boost::lexical_cast<std::string>(index); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1636 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1637 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1638 public: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1639 LookupFormatter(Dialect dialect) : |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1640 dialect_(dialect), |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1641 count_(0) |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1642 { |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1643 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1644 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1645 virtual std::string GenerateParameter(const std::string& value) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1646 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1647 const std::string key = FormatParameter(count_); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1648 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1649 count_ ++; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1650 dictionary_.SetUtf8Value(key, value); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1651 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1652 return "${" + key + "}"; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1653 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1654 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1655 virtual std::string FormatResourceType(Orthanc::ResourceType level) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1656 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1657 return boost::lexical_cast<std::string>(Orthanc::Plugins::Convert(level)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1658 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1659 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1660 virtual std::string FormatWildcardEscape() |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1661 { |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1662 switch (dialect_) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1663 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1664 case Dialect_SQLite: |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1665 case Dialect_PostgreSQL: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1666 return "ESCAPE '\\'"; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1667 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1668 case Dialect_MySQL: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1669 return "ESCAPE '\\\\'"; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1670 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1671 default: |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1672 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1673 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1674 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1675 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1676 void PrepareStatement(DatabaseManager::StandaloneStatement& statement) const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1677 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1678 statement.SetReadOnly(true); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1679 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1680 for (size_t i = 0; i < count_; i++) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1681 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1682 statement.SetParameterType(FormatParameter(i), ValueType_Utf8String); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1683 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1684 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1685 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1686 const Dictionary& GetDictionary() const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1687 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1688 return dictionary_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1689 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1690 }; |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1691 #endif |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1692 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1693 |
78 | 1694 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1695 // New primitive since Orthanc 1.5.2 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
1696 void IndexBackend::LookupResources(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1697 const std::vector<Orthanc::DatabaseConstraint>& lookup, |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1698 OrthancPluginResourceType queryLevel, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1699 uint32_t limit, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1700 bool requestSomeInstance) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1701 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1702 LookupFormatter formatter(manager_.GetDialect()); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1703 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1704 std::string sql; |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1705 Orthanc::ISqlLookupFormatter::Apply(sql, formatter, lookup, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1706 Orthanc::Plugins::Convert(queryLevel), limit); |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1707 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1708 if (requestSomeInstance) |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1709 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1710 // Composite query to find some instance if requested |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1711 switch (queryLevel) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1712 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1713 case OrthancPluginResourceType_Patient: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1714 sql = ("SELECT patients.publicId, MIN(instances.publicId) FROM (" + sql + ") patients " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1715 "INNER JOIN Resources studies ON studies.parentId = patients.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1716 "INNER JOIN Resources series ON series.parentId = studies.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1717 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1718 "GROUP BY patients.publicId"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1719 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1720 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1721 case OrthancPluginResourceType_Study: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1722 sql = ("SELECT studies.publicId, MIN(instances.publicId) FROM (" + sql + ") studies " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1723 "INNER JOIN Resources series ON series.parentId = studies.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1724 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1725 "GROUP BY studies.publicId"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1726 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1727 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1728 case OrthancPluginResourceType_Series: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1729 sql = ("SELECT series.publicId, MIN(instances.publicId) FROM (" + sql + ") series " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1730 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1731 "GROUP BY series.publicId"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1732 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1733 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1734 case OrthancPluginResourceType_Instance: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1735 sql = ("SELECT instances.publicId, instances.publicId FROM (" + sql + ") instances"); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1736 break; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1737 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1738 default: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1739 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1740 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1741 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1742 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1743 DatabaseManager::StandaloneStatement statement(GetManager(), sql); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1744 formatter.PrepareStatement(statement); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1745 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1746 statement.Execute(formatter.GetDictionary()); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1747 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1748 while (!statement.IsDone()) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1749 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1750 if (requestSomeInstance) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1751 { |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1752 output.AnswerMatchingResource(ReadString(statement, 0), ReadString(statement, 1)); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1753 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1754 else |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1755 { |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1756 output.AnswerMatchingResource(ReadString(statement, 0)); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1757 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1758 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1759 statement.Next(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
1760 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1761 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1762 #endif |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1763 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1764 |
78 | 1765 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1766 static void ExecuteSetResourcesContentTags( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1767 DatabaseManager& manager, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1768 const std::string& table, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1769 const std::string& variablePrefix, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1770 uint32_t count, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1771 const OrthancPluginResourcesContentTags* tags) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1772 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1773 std::string sql; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1774 Dictionary args; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1775 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1776 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1777 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1778 std::string name = variablePrefix + boost::lexical_cast<std::string>(i); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1779 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1780 args.SetUtf8Value(name, tags[i].value); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1781 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1782 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " + |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1783 boost::lexical_cast<std::string>(tags[i].group) + ", " + |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1784 boost::lexical_cast<std::string>(tags[i].element) + ", " + |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1785 "${" + name + "})"); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1786 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1787 if (sql.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1788 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1789 sql = "INSERT INTO " + table + " VALUES " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1790 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1791 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1792 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1793 sql += ", " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1794 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1795 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1796 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1797 if (!sql.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1798 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1799 DatabaseManager::StandaloneStatement statement(manager, sql); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1800 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1801 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1802 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1803 statement.SetParameterType(variablePrefix + boost::lexical_cast<std::string>(i), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1804 ValueType_Utf8String); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1805 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1806 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1807 statement.Execute(args); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1808 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1809 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1810 #endif |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1811 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1812 |
78 | 1813 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1814 static void ExecuteSetResourcesContentMetadata( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1815 DatabaseManager& manager, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1816 uint32_t count, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1817 const OrthancPluginResourcesContentMetadata* metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1818 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1819 std::string sqlRemove; // To overwrite |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1820 std::string sqlInsert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1821 Dictionary args; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1822 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1823 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1824 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1825 std::string name = "m" + boost::lexical_cast<std::string>(i); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1826 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1827 args.SetUtf8Value(name, metadata[i].value); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1828 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1829 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " + |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1830 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " + |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1831 "${" + name + "})"); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1832 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1833 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) + |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1834 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1835 + ")"); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1836 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1837 if (sqlInsert.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1838 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1839 sqlInsert = "INSERT INTO Metadata VALUES " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1840 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1841 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1842 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1843 sqlInsert += ", " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1844 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1845 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1846 if (sqlRemove.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1847 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1848 sqlRemove = "DELETE FROM Metadata WHERE " + remove; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1849 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1850 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1851 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1852 sqlRemove += " OR " + remove; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1853 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1854 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1855 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1856 if (!sqlRemove.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1857 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1858 DatabaseManager::StandaloneStatement statement(manager, sqlRemove); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1859 statement.Execute(); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1860 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1861 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1862 if (!sqlInsert.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1863 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1864 DatabaseManager::StandaloneStatement statement(manager, sqlInsert); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1865 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1866 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1867 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1868 statement.SetParameterType("m" + boost::lexical_cast<std::string>(i), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1869 ValueType_Utf8String); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1870 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1871 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1872 statement.Execute(args); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1873 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1874 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1875 #endif |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1876 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1877 |
78 | 1878 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1879 // New primitive since Orthanc 1.5.2 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1880 void IndexBackend::SetResourcesContent( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1881 uint32_t countIdentifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1882 const OrthancPluginResourcesContentTags* identifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1883 uint32_t countMainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1884 const OrthancPluginResourcesContentTags* mainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1885 uint32_t countMetadata, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1886 const OrthancPluginResourcesContentMetadata* metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1887 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1888 /** |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1889 * TODO - PostgreSQL doesn't allow multiple commands in a prepared |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1890 * statement, so we execute 3 separate commands (for identifiers, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1891 * main tags and metadata). Maybe MySQL does not suffer from the |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1892 * same limitation, to check. |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1893 **/ |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1894 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1895 ExecuteSetResourcesContentTags(GetManager(), "DicomIdentifiers", "i", |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1896 countIdentifierTags, identifierTags); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1897 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1898 ExecuteSetResourcesContentTags(GetManager(), "MainDicomTags", "t", |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1899 countMainDicomTags, mainDicomTags); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1900 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1901 ExecuteSetResourcesContentMetadata(GetManager(), countMetadata, metadata); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1902 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
1903 #endif |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1904 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1905 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1906 // New primitive since Orthanc 1.5.2 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1907 void IndexBackend::GetChildrenMetadata(std::list<std::string>& target, |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1908 int64_t resourceId, |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1909 int32_t metadata) |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1910 { |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1911 DatabaseManager::CachedStatement statement( |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1912 STATEMENT_FROM_HERE, manager_, |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1913 "SELECT value FROM Metadata WHERE type=${metadata} AND " |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1914 "id IN (SELECT internalId FROM Resources WHERE parentId=${id})"); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1915 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1916 statement.SetReadOnly(true); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1917 statement.SetParameterType("id", ValueType_Integer64); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1918 statement.SetParameterType("metadata", ValueType_Integer64); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1919 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1920 Dictionary args; |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1921 args.SetIntegerValue("id", static_cast<int>(resourceId)); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1922 args.SetIntegerValue("metadata", static_cast<int>(metadata)); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1923 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1924 ReadListOfStrings(target, statement, args); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
1925 } |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1926 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1927 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1928 // New primitive since Orthanc 1.5.2 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1929 void IndexBackend::TagMostRecentPatient(int64_t patient) |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1930 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1931 int64_t seq; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1932 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1933 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1934 DatabaseManager::CachedStatement statement( |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1935 STATEMENT_FROM_HERE, manager_, |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1936 "SELECT * FROM PatientRecyclingOrder WHERE seq >= " |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1937 "(SELECT seq FROM PatientRecyclingOrder WHERE patientid=${id}) ORDER BY seq LIMIT 2"); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1938 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1939 statement.SetReadOnly(true); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1940 statement.SetParameterType("id", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1941 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1942 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1943 args.SetIntegerValue("id", patient); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1944 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1945 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1946 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1947 if (statement.IsDone()) |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1948 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1949 // The patient is protected, don't add it to the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1950 return; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1951 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1952 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1953 seq = ReadInteger64(statement, 0); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1954 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1955 statement.Next(); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1956 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1957 if (statement.IsDone()) |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1958 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1959 // The patient is already at the end of the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1960 // (because of the "LIMIT 2" above), no need to modify the table |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1961 return; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1962 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1963 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1964 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1965 // Delete the old position of the patient in the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1966 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1967 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1968 DatabaseManager::CachedStatement statement( |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1969 STATEMENT_FROM_HERE, manager_, |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1970 "DELETE FROM PatientRecyclingOrder WHERE seq=${seq}"); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1971 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1972 statement.SetParameterType("seq", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1973 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1974 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1975 args.SetIntegerValue("seq", seq); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1976 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1977 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1978 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1979 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1980 // Add the patient to the end of the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1981 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1982 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1983 DatabaseManager::CachedStatement statement( |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1984 STATEMENT_FROM_HERE, manager_, |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1985 "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})"); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1986 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1987 statement.SetParameterType("id", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1988 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1989 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1990 args.SetIntegerValue("id", patient); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1991 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1992 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1993 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
1994 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1995 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1996 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1997 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1998 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
1999 // New primitive since Orthanc 1.5.4 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2000 bool IndexBackend::LookupResourceAndParent(int64_t& id, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2001 OrthancPluginResourceType& type, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2002 std::string& parentPublicId, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2003 const char* publicId) |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2004 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2005 DatabaseManager::CachedStatement statement( |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2006 STATEMENT_FROM_HERE, manager_, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2007 "SELECT resource.internalId, resource.resourceType, parent.publicId " |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2008 "FROM Resources AS resource LEFT JOIN Resources parent ON parent.internalId=resource.parentId " |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2009 "WHERE resource.publicId=${id}"); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2010 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2011 statement.SetParameterType("id", ValueType_Utf8String); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2012 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2013 Dictionary args; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2014 args.SetUtf8Value("id", publicId); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2015 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2016 statement.Execute(args); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2017 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2018 if (statement.IsDone()) |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2019 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2020 return false; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2021 } |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2022 else |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2023 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2024 if (statement.GetResultFieldsCount() != 3) |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2025 { |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2026 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2027 } |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2028 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2029 statement.SetResultFieldType(0, ValueType_Integer64); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2030 statement.SetResultFieldType(1, ValueType_Integer64); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2031 statement.SetResultFieldType(2, ValueType_Utf8String); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2032 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2033 id = ReadInteger64(statement, 0); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2034 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1)); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2035 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2036 const IValue& value = statement.GetResultField(2); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2037 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2038 switch (value.GetType()) |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2039 { |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2040 case ValueType_Null: |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2041 parentPublicId.clear(); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2042 break; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2043 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2044 case ValueType_Utf8String: |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2045 parentPublicId = dynamic_cast<const Utf8StringValue&>(value).GetContent(); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2046 break; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2047 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2048 default: |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2049 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2050 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2051 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2052 assert((statement.Next(), statement.IsDone())); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2053 return true; |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2054 } |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2055 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2056 # endif |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2057 #endif |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2058 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2059 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2060 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2061 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2062 // New primitive since Orthanc 1.5.4 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2063 void IndexBackend::GetAllMetadata(std::map<int32_t, std::string>& result, |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2064 int64_t id) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2065 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2066 DatabaseManager::CachedStatement statement( |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2067 STATEMENT_FROM_HERE, manager_, |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2068 "SELECT type, value FROM Metadata WHERE id=${id}"); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2069 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2070 statement.SetReadOnly(true); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2071 statement.SetParameterType("id", ValueType_Integer64); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2072 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2073 Dictionary args; |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2074 args.SetIntegerValue("id", id); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2075 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2076 statement.Execute(args); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2077 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2078 result.clear(); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2079 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2080 if (!statement.IsDone()) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2081 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2082 if (statement.GetResultFieldsCount() != 2) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2083 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2084 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2085 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2086 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2087 statement.SetResultFieldType(0, ValueType_Integer64); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2088 statement.SetResultFieldType(1, ValueType_Utf8String); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2089 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2090 while (!statement.IsDone()) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2091 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2092 result[ReadInteger32(statement, 0)] = ReadString(statement, 1); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2093 statement.Next(); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2094 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2095 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2096 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2097 # endif |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2098 #endif |
0 | 2099 } |