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