Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPluginDatabase.cpp @ 1672:4c5a85c3ff43 db-changes
sample database plugin now working
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Oct 2015 12:20:49 +0200 |
parents | de1413733c97 |
children | 0bbcfd9695e5 |
comparison
equal
deleted
inserted
replaced
1671:2f2e2ec17bc4 | 1672:4c5a85c3ff43 |
---|---|
44 | 44 |
45 #include <cassert> | 45 #include <cassert> |
46 | 46 |
47 namespace Orthanc | 47 namespace Orthanc |
48 { | 48 { |
49 static OrthancPluginResourceType Convert(ResourceType type) | |
50 { | |
51 switch (type) | |
52 { | |
53 case ResourceType_Patient: | |
54 return OrthancPluginResourceType_Patient; | |
55 | |
56 case ResourceType_Study: | |
57 return OrthancPluginResourceType_Study; | |
58 | |
59 case ResourceType_Series: | |
60 return OrthancPluginResourceType_Series; | |
61 | |
62 case ResourceType_Instance: | |
63 return OrthancPluginResourceType_Instance; | |
64 | |
65 default: | |
66 throw OrthancException(ErrorCode_InternalError); | |
67 } | |
68 } | |
69 | |
70 | |
71 static ResourceType Convert(OrthancPluginResourceType type) | |
72 { | |
73 switch (type) | |
74 { | |
75 case OrthancPluginResourceType_Patient: | |
76 return ResourceType_Patient; | |
77 | |
78 case OrthancPluginResourceType_Study: | |
79 return ResourceType_Study; | |
80 | |
81 case OrthancPluginResourceType_Series: | |
82 return ResourceType_Series; | |
83 | |
84 case OrthancPluginResourceType_Instance: | |
85 return ResourceType_Instance; | |
86 | |
87 default: | |
88 throw OrthancException(ErrorCode_InternalError); | |
89 } | |
90 } | |
91 | |
92 | |
93 static FileInfo Convert(const OrthancPluginAttachment& attachment) | 49 static FileInfo Convert(const OrthancPluginAttachment& attachment) |
94 { | 50 { |
95 return FileInfo(attachment.uuid, | 51 return FileInfo(attachment.uuid, |
96 static_cast<FileContentType>(attachment.contentType), | 52 static_cast<FileContentType>(attachment.contentType), |
97 attachment.uncompressedSize, | 53 attachment.uncompressedSize, |
98 attachment.uncompressedHash, | 54 attachment.uncompressedHash, |
99 static_cast<CompressionType>(attachment.compressionType), | 55 static_cast<CompressionType>(attachment.compressionType), |
100 attachment.compressedSize, | 56 attachment.compressedSize, |
101 attachment.compressedHash); | 57 attachment.compressedHash); |
58 } | |
59 | |
60 | |
61 void OrthancPluginDatabase::CheckSuccess(OrthancPluginErrorCode code) | |
62 { | |
63 if (code != OrthancPluginErrorCode_Success) | |
64 { | |
65 errorDictionary_.LogError(code, true); | |
66 throw OrthancException(static_cast<ErrorCode>(code)); | |
67 } | |
102 } | 68 } |
103 | 69 |
104 | 70 |
105 void OrthancPluginDatabase::ResetAnswers() | 71 void OrthancPluginDatabase::ResetAnswers() |
106 { | 72 { |
232 tmp.uncompressedHash = attachment.GetUncompressedMD5().c_str(); | 198 tmp.uncompressedHash = attachment.GetUncompressedMD5().c_str(); |
233 tmp.compressionType = static_cast<int32_t>(attachment.GetCompressionType()); | 199 tmp.compressionType = static_cast<int32_t>(attachment.GetCompressionType()); |
234 tmp.compressedSize = attachment.GetCompressedSize(); | 200 tmp.compressedSize = attachment.GetCompressedSize(); |
235 tmp.compressedHash = attachment.GetCompressedMD5().c_str(); | 201 tmp.compressedHash = attachment.GetCompressedMD5().c_str(); |
236 | 202 |
237 OrthancPluginErrorCode error = backend_.addAttachment(payload_, id, &tmp); | 203 CheckSuccess(backend_.addAttachment(payload_, id, &tmp)); |
238 | |
239 if (error != OrthancPluginErrorCode_Success) | |
240 { | |
241 errorDictionary_.LogError(error, true); | |
242 throw OrthancException(static_cast<ErrorCode>(error)); | |
243 } | |
244 } | 204 } |
245 | 205 |
246 | 206 |
247 void OrthancPluginDatabase::AttachChild(int64_t parent, | 207 void OrthancPluginDatabase::AttachChild(int64_t parent, |
248 int64_t child) | 208 int64_t child) |
249 { | 209 { |
250 OrthancPluginErrorCode error = backend_.attachChild(payload_, parent, child); | 210 CheckSuccess(backend_.attachChild(payload_, parent, child)); |
251 | |
252 if (error != OrthancPluginErrorCode_Success) | |
253 { | |
254 errorDictionary_.LogError(error, true); | |
255 throw OrthancException(static_cast<ErrorCode>(error)); | |
256 } | |
257 } | 211 } |
258 | 212 |
259 | 213 |
260 void OrthancPluginDatabase::ClearChanges() | 214 void OrthancPluginDatabase::ClearChanges() |
261 { | 215 { |
262 OrthancPluginErrorCode error = backend_.clearChanges(payload_); | 216 CheckSuccess(backend_.clearChanges(payload_)); |
263 | |
264 if (error != OrthancPluginErrorCode_Success) | |
265 { | |
266 errorDictionary_.LogError(error, true); | |
267 throw OrthancException(static_cast<ErrorCode>(error)); | |
268 } | |
269 } | 217 } |
270 | 218 |
271 | 219 |
272 void OrthancPluginDatabase::ClearExportedResources() | 220 void OrthancPluginDatabase::ClearExportedResources() |
273 { | 221 { |
274 OrthancPluginErrorCode error = backend_.clearExportedResources(payload_); | 222 CheckSuccess(backend_.clearExportedResources(payload_)); |
275 | |
276 if (error != OrthancPluginErrorCode_Success) | |
277 { | |
278 errorDictionary_.LogError(error, true); | |
279 throw OrthancException(static_cast<ErrorCode>(error)); | |
280 } | |
281 } | 223 } |
282 | 224 |
283 | 225 |
284 int64_t OrthancPluginDatabase::CreateResource(const std::string& publicId, | 226 int64_t OrthancPluginDatabase::CreateResource(const std::string& publicId, |
285 ResourceType type) | 227 ResourceType type) |
286 { | 228 { |
287 int64_t id; | 229 int64_t id; |
288 | 230 CheckSuccess(backend_.createResource(&id, payload_, publicId.c_str(), Plugins::Convert(type))); |
289 OrthancPluginErrorCode error = backend_.createResource(&id, payload_, publicId.c_str(), Convert(type)); | |
290 | |
291 if (error != OrthancPluginErrorCode_Success) | |
292 { | |
293 errorDictionary_.LogError(error, true); | |
294 throw OrthancException(static_cast<ErrorCode>(error)); | |
295 } | |
296 | |
297 return id; | 231 return id; |
298 } | 232 } |
299 | 233 |
300 | 234 |
301 void OrthancPluginDatabase::DeleteAttachment(int64_t id, | 235 void OrthancPluginDatabase::DeleteAttachment(int64_t id, |
302 FileContentType attachment) | 236 FileContentType attachment) |
303 { | 237 { |
304 OrthancPluginErrorCode error = backend_.deleteAttachment(payload_, id, static_cast<int32_t>(attachment)); | 238 CheckSuccess(backend_.deleteAttachment(payload_, id, static_cast<int32_t>(attachment))); |
305 | |
306 if (error != OrthancPluginErrorCode_Success) | |
307 { | |
308 errorDictionary_.LogError(error, true); | |
309 throw OrthancException(static_cast<ErrorCode>(error)); | |
310 } | |
311 } | 239 } |
312 | 240 |
313 | 241 |
314 void OrthancPluginDatabase::DeleteMetadata(int64_t id, | 242 void OrthancPluginDatabase::DeleteMetadata(int64_t id, |
315 MetadataType type) | 243 MetadataType type) |
316 { | 244 { |
317 OrthancPluginErrorCode error = backend_.deleteMetadata(payload_, id, static_cast<int32_t>(type)); | 245 CheckSuccess(backend_.deleteMetadata(payload_, id, static_cast<int32_t>(type))); |
318 | |
319 if (error != OrthancPluginErrorCode_Success) | |
320 { | |
321 errorDictionary_.LogError(error, true); | |
322 throw OrthancException(static_cast<ErrorCode>(error)); | |
323 } | |
324 } | 246 } |
325 | 247 |
326 | 248 |
327 void OrthancPluginDatabase::DeleteResource(int64_t id) | 249 void OrthancPluginDatabase::DeleteResource(int64_t id) |
328 { | 250 { |
329 OrthancPluginErrorCode error = backend_.deleteResource(payload_, id); | 251 CheckSuccess(backend_.deleteResource(payload_, id)); |
330 | |
331 if (error != OrthancPluginErrorCode_Success) | |
332 { | |
333 errorDictionary_.LogError(error, true); | |
334 throw OrthancException(static_cast<ErrorCode>(error)); | |
335 } | |
336 } | 252 } |
337 | 253 |
338 | 254 |
339 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target, | 255 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target, |
340 int64_t id) | 256 int64_t id) |
360 | 276 |
361 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target, | 277 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target, |
362 ResourceType resourceType) | 278 ResourceType resourceType) |
363 { | 279 { |
364 ResetAnswers(); | 280 ResetAnswers(); |
365 | 281 CheckSuccess(backend_.getAllPublicIds(GetContext(), payload_, Plugins::Convert(resourceType))); |
366 OrthancPluginErrorCode error = backend_.getAllPublicIds(GetContext(), payload_, Convert(resourceType)); | |
367 | |
368 if (error != OrthancPluginErrorCode_Success) | |
369 { | |
370 errorDictionary_.LogError(error, true); | |
371 throw OrthancException(static_cast<ErrorCode>(error)); | |
372 } | |
373 | |
374 ForwardAnswers(target); | 282 ForwardAnswers(target); |
375 } | 283 } |
376 | 284 |
377 | 285 |
378 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target, | 286 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target, |
382 { | 290 { |
383 if (extensions_.getAllPublicIdsWithLimit != NULL) | 291 if (extensions_.getAllPublicIdsWithLimit != NULL) |
384 { | 292 { |
385 // This extension is available since Orthanc 0.9.4 | 293 // This extension is available since Orthanc 0.9.4 |
386 ResetAnswers(); | 294 ResetAnswers(); |
387 | 295 CheckSuccess(extensions_.getAllPublicIdsWithLimit |
388 OrthancPluginErrorCode error = extensions_.getAllPublicIdsWithLimit | 296 (GetContext(), payload_, Plugins::Convert(resourceType), since, limit)); |
389 (GetContext(), payload_, Convert(resourceType), since, limit); | |
390 | |
391 if (error != OrthancPluginErrorCode_Success) | |
392 { | |
393 errorDictionary_.LogError(error, true); | |
394 throw OrthancException(static_cast<ErrorCode>(error)); | |
395 } | |
396 | |
397 ForwardAnswers(target); | 297 ForwardAnswers(target); |
398 } | 298 } |
399 else | 299 else |
400 { | 300 { |
401 // The extension is not available in the database plugin, use a | 301 // The extension is not available in the database plugin, use a |
438 ResetAnswers(); | 338 ResetAnswers(); |
439 answerChanges_ = ⌖ | 339 answerChanges_ = ⌖ |
440 answerDone_ = &done; | 340 answerDone_ = &done; |
441 done = false; | 341 done = false; |
442 | 342 |
443 OrthancPluginErrorCode error = backend_.getChanges(GetContext(), payload_, since, maxResults); | 343 CheckSuccess(backend_.getChanges(GetContext(), payload_, since, maxResults)); |
444 | |
445 if (error != OrthancPluginErrorCode_Success) | |
446 { | |
447 errorDictionary_.LogError(error, true); | |
448 throw OrthancException(static_cast<ErrorCode>(error)); | |
449 } | |
450 } | 344 } |
451 | 345 |
452 | 346 |
453 void OrthancPluginDatabase::GetChildrenInternalId(std::list<int64_t>& target, | 347 void OrthancPluginDatabase::GetChildrenInternalId(std::list<int64_t>& target, |
454 int64_t id) | 348 int64_t id) |
455 { | 349 { |
456 ResetAnswers(); | 350 ResetAnswers(); |
457 | 351 CheckSuccess(backend_.getChildrenInternalId(GetContext(), payload_, id)); |
458 OrthancPluginErrorCode error = backend_.getChildrenInternalId(GetContext(), payload_, id); | |
459 | |
460 if (error != OrthancPluginErrorCode_Success) | |
461 { | |
462 errorDictionary_.LogError(error, true); | |
463 throw OrthancException(static_cast<ErrorCode>(error)); | |
464 } | |
465 | |
466 ForwardAnswers(target); | 352 ForwardAnswers(target); |
467 } | 353 } |
468 | 354 |
469 | 355 |
470 void OrthancPluginDatabase::GetChildrenPublicId(std::list<std::string>& target, | 356 void OrthancPluginDatabase::GetChildrenPublicId(std::list<std::string>& target, |
471 int64_t id) | 357 int64_t id) |
472 { | 358 { |
473 ResetAnswers(); | 359 ResetAnswers(); |
474 | 360 CheckSuccess(backend_.getChildrenPublicId(GetContext(), payload_, id)); |
475 OrthancPluginErrorCode error = backend_.getChildrenPublicId(GetContext(), payload_, id); | |
476 | |
477 if (error != OrthancPluginErrorCode_Success) | |
478 { | |
479 errorDictionary_.LogError(error, true); | |
480 throw OrthancException(static_cast<ErrorCode>(error)); | |
481 } | |
482 | |
483 ForwardAnswers(target); | 361 ForwardAnswers(target); |
484 } | 362 } |
485 | 363 |
486 | 364 |
487 void OrthancPluginDatabase::GetExportedResources(std::list<ExportedResource>& target /*out*/, | 365 void OrthancPluginDatabase::GetExportedResources(std::list<ExportedResource>& target /*out*/, |
492 ResetAnswers(); | 370 ResetAnswers(); |
493 answerExportedResources_ = ⌖ | 371 answerExportedResources_ = ⌖ |
494 answerDone_ = &done; | 372 answerDone_ = &done; |
495 done = false; | 373 done = false; |
496 | 374 |
497 OrthancPluginErrorCode error = backend_.getExportedResources(GetContext(), payload_, since, maxResults); | 375 CheckSuccess(backend_.getExportedResources(GetContext(), payload_, since, maxResults)); |
498 | |
499 if (error != OrthancPluginErrorCode_Success) | |
500 { | |
501 errorDictionary_.LogError(error, true); | |
502 throw OrthancException(static_cast<ErrorCode>(error)); | |
503 } | |
504 } | 376 } |
505 | 377 |
506 | 378 |
507 void OrthancPluginDatabase::GetLastChange(std::list<ServerIndexChange>& target /*out*/) | 379 void OrthancPluginDatabase::GetLastChange(std::list<ServerIndexChange>& target /*out*/) |
508 { | 380 { |
510 | 382 |
511 ResetAnswers(); | 383 ResetAnswers(); |
512 answerChanges_ = ⌖ | 384 answerChanges_ = ⌖ |
513 answerDone_ = &ignored; | 385 answerDone_ = &ignored; |
514 | 386 |
515 OrthancPluginErrorCode error = backend_.getLastChange(GetContext(), payload_); | 387 CheckSuccess(backend_.getLastChange(GetContext(), payload_)); |
516 | |
517 if (error != OrthancPluginErrorCode_Success) | |
518 { | |
519 errorDictionary_.LogError(error, true); | |
520 throw OrthancException(static_cast<ErrorCode>(error)); | |
521 } | |
522 } | 388 } |
523 | 389 |
524 | 390 |
525 void OrthancPluginDatabase::GetLastExportedResource(std::list<ExportedResource>& target /*out*/) | 391 void OrthancPluginDatabase::GetLastExportedResource(std::list<ExportedResource>& target /*out*/) |
526 { | 392 { |
528 | 394 |
529 ResetAnswers(); | 395 ResetAnswers(); |
530 answerExportedResources_ = ⌖ | 396 answerExportedResources_ = ⌖ |
531 answerDone_ = &ignored; | 397 answerDone_ = &ignored; |
532 | 398 |
533 OrthancPluginErrorCode error = backend_.getLastExportedResource(GetContext(), payload_); | 399 CheckSuccess(backend_.getLastExportedResource(GetContext(), payload_)); |
534 | |
535 if (error != OrthancPluginErrorCode_Success) | |
536 { | |
537 errorDictionary_.LogError(error, true); | |
538 throw OrthancException(static_cast<ErrorCode>(error)); | |
539 } | |
540 } | 400 } |
541 | 401 |
542 | 402 |
543 void OrthancPluginDatabase::GetMainDicomTags(DicomMap& map, | 403 void OrthancPluginDatabase::GetMainDicomTags(DicomMap& map, |
544 int64_t id) | 404 int64_t id) |
545 { | 405 { |
546 ResetAnswers(); | 406 ResetAnswers(); |
547 answerDicomMap_ = ↦ | 407 answerDicomMap_ = ↦ |
548 | 408 |
549 OrthancPluginErrorCode error = backend_.getMainDicomTags(GetContext(), payload_, id); | 409 CheckSuccess(backend_.getMainDicomTags(GetContext(), payload_, id)); |
550 | |
551 if (error != OrthancPluginErrorCode_Success) | |
552 { | |
553 errorDictionary_.LogError(error, true); | |
554 throw OrthancException(static_cast<ErrorCode>(error)); | |
555 } | |
556 } | 410 } |
557 | 411 |
558 | 412 |
559 std::string OrthancPluginDatabase::GetPublicId(int64_t resourceId) | 413 std::string OrthancPluginDatabase::GetPublicId(int64_t resourceId) |
560 { | 414 { |
561 ResetAnswers(); | 415 ResetAnswers(); |
562 std::string s; | 416 std::string s; |
563 | 417 |
564 OrthancPluginErrorCode error = backend_.getPublicId(GetContext(), payload_, resourceId); | 418 CheckSuccess(backend_.getPublicId(GetContext(), payload_, resourceId)); |
565 | 419 |
566 if (error != OrthancPluginErrorCode_Success) | |
567 { | |
568 errorDictionary_.LogError(error, true); | |
569 throw OrthancException(static_cast<ErrorCode>(error)); | |
570 } | |
571 | |
572 if (!ForwardSingleAnswer(s)) | 420 if (!ForwardSingleAnswer(s)) |
573 { | 421 { |
574 throw OrthancException(ErrorCode_DatabasePlugin); | 422 throw OrthancException(ErrorCode_DatabasePlugin); |
575 } | 423 } |
576 | 424 |
579 | 427 |
580 | 428 |
581 uint64_t OrthancPluginDatabase::GetResourceCount(ResourceType resourceType) | 429 uint64_t OrthancPluginDatabase::GetResourceCount(ResourceType resourceType) |
582 { | 430 { |
583 uint64_t count; | 431 uint64_t count; |
584 | 432 CheckSuccess(backend_.getResourceCount(&count, payload_, Plugins::Convert(resourceType))); |
585 OrthancPluginErrorCode error = backend_.getResourceCount(&count, payload_, Convert(resourceType)); | |
586 | |
587 if (error != OrthancPluginErrorCode_Success) | |
588 { | |
589 errorDictionary_.LogError(error, true); | |
590 throw OrthancException(static_cast<ErrorCode>(error)); | |
591 } | |
592 | |
593 return count; | 433 return count; |
594 } | 434 } |
595 | 435 |
596 | 436 |
597 ResourceType OrthancPluginDatabase::GetResourceType(int64_t resourceId) | 437 ResourceType OrthancPluginDatabase::GetResourceType(int64_t resourceId) |
598 { | 438 { |
599 OrthancPluginResourceType type; | 439 OrthancPluginResourceType type; |
600 | 440 CheckSuccess(backend_.getResourceType(&type, payload_, resourceId)); |
601 OrthancPluginErrorCode error = backend_.getResourceType(&type, payload_, resourceId); | 441 return Plugins::Convert(type); |
602 | |
603 if (error != OrthancPluginErrorCode_Success) | |
604 { | |
605 errorDictionary_.LogError(error, true); | |
606 throw OrthancException(static_cast<ErrorCode>(error)); | |
607 } | |
608 | |
609 return Convert(type); | |
610 } | 442 } |
611 | 443 |
612 | 444 |
613 uint64_t OrthancPluginDatabase::GetTotalCompressedSize() | 445 uint64_t OrthancPluginDatabase::GetTotalCompressedSize() |
614 { | 446 { |
615 uint64_t size; | 447 uint64_t size; |
616 | 448 CheckSuccess(backend_.getTotalCompressedSize(&size, payload_)); |
617 OrthancPluginErrorCode error = backend_.getTotalCompressedSize(&size, payload_); | |
618 | |
619 if (error != OrthancPluginErrorCode_Success) | |
620 { | |
621 errorDictionary_.LogError(error, true); | |
622 throw OrthancException(static_cast<ErrorCode>(error)); | |
623 } | |
624 | |
625 return size; | 449 return size; |
626 } | 450 } |
627 | 451 |
628 | 452 |
629 uint64_t OrthancPluginDatabase::GetTotalUncompressedSize() | 453 uint64_t OrthancPluginDatabase::GetTotalUncompressedSize() |
630 { | 454 { |
631 uint64_t size; | 455 uint64_t size; |
632 | 456 CheckSuccess(backend_.getTotalUncompressedSize(&size, payload_)); |
633 OrthancPluginErrorCode error = backend_.getTotalUncompressedSize(&size, payload_); | |
634 | |
635 if (error != OrthancPluginErrorCode_Success) | |
636 { | |
637 errorDictionary_.LogError(error, true); | |
638 throw OrthancException(static_cast<ErrorCode>(error)); | |
639 } | |
640 | |
641 return size; | 457 return size; |
642 } | 458 } |
643 | 459 |
644 | 460 |
645 bool OrthancPluginDatabase::IsExistingResource(int64_t internalId) | 461 bool OrthancPluginDatabase::IsExistingResource(int64_t internalId) |
646 { | 462 { |
647 int32_t existing; | 463 int32_t existing; |
648 | 464 CheckSuccess(backend_.isExistingResource(&existing, payload_, internalId)); |
649 OrthancPluginErrorCode error = backend_.isExistingResource(&existing, payload_, internalId); | |
650 | |
651 if (error != OrthancPluginErrorCode_Success) | |
652 { | |
653 errorDictionary_.LogError(error, true); | |
654 throw OrthancException(static_cast<ErrorCode>(error)); | |
655 } | |
656 | |
657 return (existing != 0); | 465 return (existing != 0); |
658 } | 466 } |
659 | 467 |
660 | 468 |
661 bool OrthancPluginDatabase::IsProtectedPatient(int64_t internalId) | 469 bool OrthancPluginDatabase::IsProtectedPatient(int64_t internalId) |
662 { | 470 { |
663 int32_t isProtected; | 471 int32_t isProtected; |
664 | 472 CheckSuccess(backend_.isProtectedPatient(&isProtected, payload_, internalId)); |
665 OrthancPluginErrorCode error = backend_.isProtectedPatient(&isProtected, payload_, internalId); | |
666 | |
667 if (error != OrthancPluginErrorCode_Success) | |
668 { | |
669 errorDictionary_.LogError(error, true); | |
670 throw OrthancException(static_cast<ErrorCode>(error)); | |
671 } | |
672 | |
673 return (isProtected != 0); | 473 return (isProtected != 0); |
674 } | 474 } |
675 | 475 |
676 | 476 |
677 void OrthancPluginDatabase::ListAvailableMetadata(std::list<MetadataType>& target, | 477 void OrthancPluginDatabase::ListAvailableMetadata(std::list<MetadataType>& target, |
678 int64_t id) | 478 int64_t id) |
679 { | 479 { |
680 ResetAnswers(); | 480 ResetAnswers(); |
681 | 481 CheckSuccess(backend_.listAvailableMetadata(GetContext(), payload_, id)); |
682 OrthancPluginErrorCode error = backend_.listAvailableMetadata(GetContext(), payload_, id); | |
683 | |
684 if (error != OrthancPluginErrorCode_Success) | |
685 { | |
686 errorDictionary_.LogError(error, true); | |
687 throw OrthancException(static_cast<ErrorCode>(error)); | |
688 } | |
689 | 482 |
690 if (type_ != _OrthancPluginDatabaseAnswerType_None && | 483 if (type_ != _OrthancPluginDatabaseAnswerType_None && |
691 type_ != _OrthancPluginDatabaseAnswerType_Int32) | 484 type_ != _OrthancPluginDatabaseAnswerType_Int32) |
692 { | 485 { |
693 throw OrthancException(ErrorCode_DatabasePlugin); | 486 throw OrthancException(ErrorCode_DatabasePlugin); |
709 void OrthancPluginDatabase::ListAvailableAttachments(std::list<FileContentType>& target, | 502 void OrthancPluginDatabase::ListAvailableAttachments(std::list<FileContentType>& target, |
710 int64_t id) | 503 int64_t id) |
711 { | 504 { |
712 ResetAnswers(); | 505 ResetAnswers(); |
713 | 506 |
714 OrthancPluginErrorCode error = backend_.listAvailableAttachments(GetContext(), payload_, id); | 507 CheckSuccess(backend_.listAvailableAttachments(GetContext(), payload_, id)); |
715 | |
716 if (error != OrthancPluginErrorCode_Success) | |
717 { | |
718 errorDictionary_.LogError(error, true); | |
719 throw OrthancException(static_cast<ErrorCode>(error)); | |
720 } | |
721 | 508 |
722 if (type_ != _OrthancPluginDatabaseAnswerType_None && | 509 if (type_ != _OrthancPluginDatabaseAnswerType_None && |
723 type_ != _OrthancPluginDatabaseAnswerType_Int32) | 510 type_ != _OrthancPluginDatabaseAnswerType_Int32) |
724 { | 511 { |
725 throw OrthancException(ErrorCode_DatabasePlugin); | 512 throw OrthancException(ErrorCode_DatabasePlugin); |
742 const ServerIndexChange& change) | 529 const ServerIndexChange& change) |
743 { | 530 { |
744 OrthancPluginChange tmp; | 531 OrthancPluginChange tmp; |
745 tmp.seq = change.GetSeq(); | 532 tmp.seq = change.GetSeq(); |
746 tmp.changeType = static_cast<int32_t>(change.GetChangeType()); | 533 tmp.changeType = static_cast<int32_t>(change.GetChangeType()); |
747 tmp.resourceType = Convert(change.GetResourceType()); | 534 tmp.resourceType = Plugins::Convert(change.GetResourceType()); |
748 tmp.publicId = change.GetPublicId().c_str(); | 535 tmp.publicId = change.GetPublicId().c_str(); |
749 tmp.date = change.GetDate().c_str(); | 536 tmp.date = change.GetDate().c_str(); |
750 | 537 |
751 OrthancPluginErrorCode error = backend_.logChange(payload_, &tmp); | 538 CheckSuccess(backend_.logChange(payload_, &tmp)); |
752 | |
753 if (error != OrthancPluginErrorCode_Success) | |
754 { | |
755 errorDictionary_.LogError(error, true); | |
756 throw OrthancException(static_cast<ErrorCode>(error)); | |
757 } | |
758 } | 539 } |
759 | 540 |
760 | 541 |
761 void OrthancPluginDatabase::LogExportedResource(const ExportedResource& resource) | 542 void OrthancPluginDatabase::LogExportedResource(const ExportedResource& resource) |
762 { | 543 { |
763 OrthancPluginExportedResource tmp; | 544 OrthancPluginExportedResource tmp; |
764 tmp.seq = resource.GetSeq(); | 545 tmp.seq = resource.GetSeq(); |
765 tmp.resourceType = Convert(resource.GetResourceType()); | 546 tmp.resourceType = Plugins::Convert(resource.GetResourceType()); |
766 tmp.publicId = resource.GetPublicId().c_str(); | 547 tmp.publicId = resource.GetPublicId().c_str(); |
767 tmp.modality = resource.GetModality().c_str(); | 548 tmp.modality = resource.GetModality().c_str(); |
768 tmp.date = resource.GetDate().c_str(); | 549 tmp.date = resource.GetDate().c_str(); |
769 tmp.patientId = resource.GetPatientId().c_str(); | 550 tmp.patientId = resource.GetPatientId().c_str(); |
770 tmp.studyInstanceUid = resource.GetStudyInstanceUid().c_str(); | 551 tmp.studyInstanceUid = resource.GetStudyInstanceUid().c_str(); |
771 tmp.seriesInstanceUid = resource.GetSeriesInstanceUid().c_str(); | 552 tmp.seriesInstanceUid = resource.GetSeriesInstanceUid().c_str(); |
772 tmp.sopInstanceUid = resource.GetSopInstanceUid().c_str(); | 553 tmp.sopInstanceUid = resource.GetSopInstanceUid().c_str(); |
773 | 554 |
774 OrthancPluginErrorCode error = backend_.logExportedResource(payload_, &tmp); | 555 CheckSuccess(backend_.logExportedResource(payload_, &tmp)); |
775 | |
776 if (error != OrthancPluginErrorCode_Success) | |
777 { | |
778 errorDictionary_.LogError(error, true); | |
779 throw OrthancException(static_cast<ErrorCode>(error)); | |
780 } | |
781 } | 556 } |
782 | 557 |
783 | 558 |
784 bool OrthancPluginDatabase::LookupAttachment(FileInfo& attachment, | 559 bool OrthancPluginDatabase::LookupAttachment(FileInfo& attachment, |
785 int64_t id, | 560 int64_t id, |
786 FileContentType contentType) | 561 FileContentType contentType) |
787 { | 562 { |
788 ResetAnswers(); | 563 ResetAnswers(); |
789 | 564 |
790 OrthancPluginErrorCode error = backend_.lookupAttachment | 565 CheckSuccess(backend_.lookupAttachment |
791 (GetContext(), payload_, id, static_cast<int32_t>(contentType)); | 566 (GetContext(), payload_, id, static_cast<int32_t>(contentType))); |
792 | |
793 if (error != OrthancPluginErrorCode_Success) | |
794 { | |
795 errorDictionary_.LogError(error, true); | |
796 throw OrthancException(static_cast<ErrorCode>(error)); | |
797 } | |
798 | 567 |
799 if (type_ == _OrthancPluginDatabaseAnswerType_None) | 568 if (type_ == _OrthancPluginDatabaseAnswerType_None) |
800 { | 569 { |
801 return false; | 570 return false; |
802 } | 571 } |
816 bool OrthancPluginDatabase::LookupGlobalProperty(std::string& target, | 585 bool OrthancPluginDatabase::LookupGlobalProperty(std::string& target, |
817 GlobalProperty property) | 586 GlobalProperty property) |
818 { | 587 { |
819 ResetAnswers(); | 588 ResetAnswers(); |
820 | 589 |
821 OrthancPluginErrorCode error = backend_.lookupGlobalProperty | 590 CheckSuccess(backend_.lookupGlobalProperty |
822 (GetContext(), payload_, static_cast<int32_t>(property)); | 591 (GetContext(), payload_, static_cast<int32_t>(property))); |
823 | |
824 if (error != OrthancPluginErrorCode_Success) | |
825 { | |
826 errorDictionary_.LogError(error, true); | |
827 throw OrthancException(static_cast<ErrorCode>(error)); | |
828 } | |
829 | 592 |
830 return ForwardSingleAnswer(target); | 593 return ForwardSingleAnswer(target); |
831 } | 594 } |
832 | 595 |
833 | 596 |
840 OrthancPluginDicomTag tmp; | 603 OrthancPluginDicomTag tmp; |
841 tmp.group = tag.GetGroup(); | 604 tmp.group = tag.GetGroup(); |
842 tmp.element = tag.GetElement(); | 605 tmp.element = tag.GetElement(); |
843 tmp.value = value.c_str(); | 606 tmp.value = value.c_str(); |
844 | 607 |
845 OrthancPluginErrorCode error = backend_.lookupIdentifier(GetContext(), payload_, &tmp); | 608 CheckSuccess(backend_.lookupIdentifier(GetContext(), payload_, &tmp)); |
846 | |
847 if (error != OrthancPluginErrorCode_Success) | |
848 { | |
849 errorDictionary_.LogError(error, true); | |
850 throw OrthancException(static_cast<ErrorCode>(error)); | |
851 } | |
852 | 609 |
853 ForwardAnswers(target); | 610 ForwardAnswers(target); |
854 } | 611 } |
855 | 612 |
856 | 613 |
857 void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& target, | 614 void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& target, |
858 const std::string& value) | 615 const std::string& value) |
859 { | 616 { |
860 ResetAnswers(); | 617 ResetAnswers(); |
861 | 618 CheckSuccess(backend_.lookupIdentifier2(GetContext(), payload_, value.c_str())); |
862 OrthancPluginErrorCode error = backend_.lookupIdentifier2(GetContext(), payload_, value.c_str()); | |
863 | |
864 if (error != OrthancPluginErrorCode_Success) | |
865 { | |
866 errorDictionary_.LogError(error, true); | |
867 throw OrthancException(static_cast<ErrorCode>(error)); | |
868 } | |
869 | |
870 ForwardAnswers(target); | 619 ForwardAnswers(target); |
871 } | 620 } |
872 | 621 |
873 | 622 |
874 bool OrthancPluginDatabase::LookupMetadata(std::string& target, | 623 bool OrthancPluginDatabase::LookupMetadata(std::string& target, |
875 int64_t id, | 624 int64_t id, |
876 MetadataType type) | 625 MetadataType type) |
877 { | 626 { |
878 ResetAnswers(); | 627 ResetAnswers(); |
879 | 628 CheckSuccess(backend_.lookupMetadata(GetContext(), payload_, id, static_cast<int32_t>(type))); |
880 OrthancPluginErrorCode error = backend_.lookupMetadata(GetContext(), payload_, id, static_cast<int32_t>(type)); | |
881 | |
882 if (error != OrthancPluginErrorCode_Success) | |
883 { | |
884 errorDictionary_.LogError(error, true); | |
885 throw OrthancException(static_cast<ErrorCode>(error)); | |
886 } | |
887 | |
888 return ForwardSingleAnswer(target); | 629 return ForwardSingleAnswer(target); |
889 } | 630 } |
890 | 631 |
891 | 632 |
892 bool OrthancPluginDatabase::LookupParent(int64_t& parentId, | 633 bool OrthancPluginDatabase::LookupParent(int64_t& parentId, |
893 int64_t resourceId) | 634 int64_t resourceId) |
894 { | 635 { |
895 ResetAnswers(); | 636 ResetAnswers(); |
896 | 637 CheckSuccess(backend_.lookupParent(GetContext(), payload_, resourceId)); |
897 OrthancPluginErrorCode error = backend_.lookupParent(GetContext(), payload_, resourceId); | |
898 | |
899 if (error != OrthancPluginErrorCode_Success) | |
900 { | |
901 errorDictionary_.LogError(error, true); | |
902 throw OrthancException(static_cast<ErrorCode>(error)); | |
903 } | |
904 | |
905 return ForwardSingleAnswer(parentId); | 638 return ForwardSingleAnswer(parentId); |
906 } | 639 } |
907 | 640 |
908 | 641 |
909 bool OrthancPluginDatabase::LookupResource(int64_t& id, | 642 bool OrthancPluginDatabase::LookupResource(int64_t& id, |
910 ResourceType& type, | 643 ResourceType& type, |
911 const std::string& publicId) | 644 const std::string& publicId) |
912 { | 645 { |
913 ResetAnswers(); | 646 ResetAnswers(); |
914 | 647 |
915 OrthancPluginErrorCode error = backend_.lookupResource(GetContext(), payload_, publicId.c_str()); | 648 CheckSuccess(backend_.lookupResource(GetContext(), payload_, publicId.c_str())); |
916 | |
917 if (error != OrthancPluginErrorCode_Success) | |
918 { | |
919 errorDictionary_.LogError(error, true); | |
920 throw OrthancException(static_cast<ErrorCode>(error)); | |
921 } | |
922 | 649 |
923 if (type_ == _OrthancPluginDatabaseAnswerType_None) | 650 if (type_ == _OrthancPluginDatabaseAnswerType_None) |
924 { | 651 { |
925 return false; | 652 return false; |
926 } | 653 } |
939 | 666 |
940 | 667 |
941 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId) | 668 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId) |
942 { | 669 { |
943 ResetAnswers(); | 670 ResetAnswers(); |
944 | 671 CheckSuccess(backend_.selectPatientToRecycle(GetContext(), payload_)); |
945 OrthancPluginErrorCode error = backend_.selectPatientToRecycle(GetContext(), payload_); | |
946 | |
947 if (error != OrthancPluginErrorCode_Success) | |
948 { | |
949 errorDictionary_.LogError(error, true); | |
950 throw OrthancException(static_cast<ErrorCode>(error)); | |
951 } | |
952 | |
953 return ForwardSingleAnswer(internalId); | 672 return ForwardSingleAnswer(internalId); |
954 } | 673 } |
955 | 674 |
956 | 675 |
957 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId, | 676 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId, |
958 int64_t patientIdToAvoid) | 677 int64_t patientIdToAvoid) |
959 { | 678 { |
960 ResetAnswers(); | 679 ResetAnswers(); |
961 | 680 CheckSuccess(backend_.selectPatientToRecycle2(GetContext(), payload_, patientIdToAvoid)); |
962 OrthancPluginErrorCode error = backend_.selectPatientToRecycle2(GetContext(), payload_, patientIdToAvoid); | |
963 | |
964 if (error != OrthancPluginErrorCode_Success) | |
965 { | |
966 errorDictionary_.LogError(error, true); | |
967 throw OrthancException(static_cast<ErrorCode>(error)); | |
968 } | |
969 | |
970 return ForwardSingleAnswer(internalId); | 681 return ForwardSingleAnswer(internalId); |
971 } | 682 } |
972 | 683 |
973 | 684 |
974 void OrthancPluginDatabase::SetGlobalProperty(GlobalProperty property, | 685 void OrthancPluginDatabase::SetGlobalProperty(GlobalProperty property, |
975 const std::string& value) | 686 const std::string& value) |
976 { | 687 { |
977 OrthancPluginErrorCode error = backend_.setGlobalProperty | 688 CheckSuccess(backend_.setGlobalProperty |
978 (payload_, static_cast<int32_t>(property), value.c_str()); | 689 (payload_, static_cast<int32_t>(property), value.c_str())); |
979 | |
980 if (error != OrthancPluginErrorCode_Success) | |
981 { | |
982 errorDictionary_.LogError(error, true); | |
983 throw OrthancException(static_cast<ErrorCode>(error)); | |
984 } | |
985 } | 690 } |
986 | 691 |
987 | 692 |
988 void OrthancPluginDatabase::ClearMainDicomTags(int64_t id) | 693 void OrthancPluginDatabase::ClearMainDicomTags(int64_t id) |
989 { | 694 { |
991 { | 696 { |
992 LOG(ERROR) << "Your custom index plugin does not implement the ClearMainDicomTags() extension"; | 697 LOG(ERROR) << "Your custom index plugin does not implement the ClearMainDicomTags() extension"; |
993 throw OrthancException(ErrorCode_DatabasePlugin); | 698 throw OrthancException(ErrorCode_DatabasePlugin); |
994 } | 699 } |
995 | 700 |
996 OrthancPluginErrorCode error = extensions_.clearMainDicomTags(payload_, id); | 701 CheckSuccess(extensions_.clearMainDicomTags(payload_, id)); |
997 | |
998 if (error != OrthancPluginErrorCode_Success) | |
999 { | |
1000 errorDictionary_.LogError(error, true); | |
1001 throw OrthancException(static_cast<ErrorCode>(error)); | |
1002 } | |
1003 } | 702 } |
1004 | 703 |
1005 | 704 |
1006 void OrthancPluginDatabase::SetMainDicomTag(int64_t id, | 705 void OrthancPluginDatabase::SetMainDicomTag(int64_t id, |
1007 const DicomTag& tag, | 706 const DicomTag& tag, |
1010 OrthancPluginDicomTag tmp; | 709 OrthancPluginDicomTag tmp; |
1011 tmp.group = tag.GetGroup(); | 710 tmp.group = tag.GetGroup(); |
1012 tmp.element = tag.GetElement(); | 711 tmp.element = tag.GetElement(); |
1013 tmp.value = value.c_str(); | 712 tmp.value = value.c_str(); |
1014 | 713 |
1015 OrthancPluginErrorCode error; | 714 OrthancPluginErrorCode code; |
1016 | 715 |
1017 if (tag.IsIdentifier()) | 716 if (tag.IsIdentifier()) |
1018 { | 717 { |
1019 error = backend_.setIdentifierTag(payload_, id, &tmp); | 718 code = backend_.setIdentifierTag(payload_, id, &tmp); |
1020 } | 719 } |
1021 else | 720 else |
1022 { | 721 { |
1023 error = backend_.setMainDicomTag(payload_, id, &tmp); | 722 code = backend_.setMainDicomTag(payload_, id, &tmp); |
1024 } | 723 } |
1025 | 724 |
1026 if (error != OrthancPluginErrorCode_Success) | 725 CheckSuccess(code); |
1027 { | |
1028 errorDictionary_.LogError(error, true); | |
1029 throw OrthancException(static_cast<ErrorCode>(error)); | |
1030 } | |
1031 } | 726 } |
1032 | 727 |
1033 | 728 |
1034 void OrthancPluginDatabase::SetMetadata(int64_t id, | 729 void OrthancPluginDatabase::SetMetadata(int64_t id, |
1035 MetadataType type, | 730 MetadataType type, |
1036 const std::string& value) | 731 const std::string& value) |
1037 { | 732 { |
1038 OrthancPluginErrorCode error = backend_.setMetadata | 733 CheckSuccess(backend_.setMetadata |
1039 (payload_, id, static_cast<int32_t>(type), value.c_str()); | 734 (payload_, id, static_cast<int32_t>(type), value.c_str())); |
1040 | |
1041 if (error != OrthancPluginErrorCode_Success) | |
1042 { | |
1043 errorDictionary_.LogError(error, true); | |
1044 throw OrthancException(static_cast<ErrorCode>(error)); | |
1045 } | |
1046 } | 735 } |
1047 | 736 |
1048 | 737 |
1049 void OrthancPluginDatabase::SetProtectedPatient(int64_t internalId, | 738 void OrthancPluginDatabase::SetProtectedPatient(int64_t internalId, |
1050 bool isProtected) | 739 bool isProtected) |
1051 { | 740 { |
1052 OrthancPluginErrorCode error = backend_.setProtectedPatient(payload_, internalId, isProtected); | 741 CheckSuccess(backend_.setProtectedPatient(payload_, internalId, isProtected)); |
1053 | |
1054 if (error != OrthancPluginErrorCode_Success) | |
1055 { | |
1056 errorDictionary_.LogError(error, true); | |
1057 throw OrthancException(static_cast<ErrorCode>(error)); | |
1058 } | |
1059 } | 742 } |
1060 | 743 |
1061 | 744 |
1062 class OrthancPluginDatabase::Transaction : public SQLite::ITransaction | 745 class OrthancPluginDatabase::Transaction : public SQLite::ITransaction |
1063 { | 746 { |
1064 private: | 747 private: |
1065 const OrthancPluginDatabaseBackend& backend_; | 748 const OrthancPluginDatabaseBackend& backend_; |
1066 void* payload_; | 749 void* payload_; |
1067 PluginsErrorDictionary& errorDictionary_; | 750 PluginsErrorDictionary& errorDictionary_; |
751 | |
752 void CheckSuccess(OrthancPluginErrorCode code) | |
753 { | |
754 if (code != OrthancPluginErrorCode_Success) | |
755 { | |
756 errorDictionary_.LogError(code, true); | |
757 throw OrthancException(static_cast<ErrorCode>(code)); | |
758 } | |
759 } | |
1068 | 760 |
1069 public: | 761 public: |
1070 Transaction(const OrthancPluginDatabaseBackend& backend, | 762 Transaction(const OrthancPluginDatabaseBackend& backend, |
1071 void* payload, | 763 void* payload, |
1072 PluginsErrorDictionary& errorDictionary) : | 764 PluginsErrorDictionary& errorDictionary) : |
1076 { | 768 { |
1077 } | 769 } |
1078 | 770 |
1079 virtual void Begin() | 771 virtual void Begin() |
1080 { | 772 { |
1081 OrthancPluginErrorCode error = backend_.startTransaction(payload_); | 773 CheckSuccess(backend_.startTransaction(payload_)); |
1082 | |
1083 if (error != OrthancPluginErrorCode_Success) | |
1084 { | |
1085 errorDictionary_.LogError(error, true); | |
1086 throw OrthancException(static_cast<ErrorCode>(error)); | |
1087 } | |
1088 } | 774 } |
1089 | 775 |
1090 virtual void Rollback() | 776 virtual void Rollback() |
1091 { | 777 { |
1092 OrthancPluginErrorCode error = backend_.rollbackTransaction(payload_); | 778 CheckSuccess(backend_.rollbackTransaction(payload_)); |
1093 | |
1094 if (error != OrthancPluginErrorCode_Success) | |
1095 { | |
1096 errorDictionary_.LogError(error, true); | |
1097 throw OrthancException(static_cast<ErrorCode>(error)); | |
1098 } | |
1099 } | 779 } |
1100 | 780 |
1101 virtual void Commit() | 781 virtual void Commit() |
1102 { | 782 { |
1103 OrthancPluginErrorCode error = backend_.commitTransaction(payload_); | 783 CheckSuccess(backend_.commitTransaction(payload_)); |
1104 | |
1105 if (error != OrthancPluginErrorCode_Success) | |
1106 { | |
1107 errorDictionary_.LogError(error, true); | |
1108 throw OrthancException(static_cast<ErrorCode>(error)); | |
1109 } | |
1110 } | 784 } |
1111 }; | 785 }; |
1112 | 786 |
1113 | 787 |
1114 SQLite::ITransaction* OrthancPluginDatabase::StartTransaction() | 788 SQLite::ITransaction* OrthancPluginDatabase::StartTransaction() |
1130 break; | 804 break; |
1131 } | 805 } |
1132 | 806 |
1133 case _OrthancPluginDatabaseAnswerType_RemainingAncestor: | 807 case _OrthancPluginDatabaseAnswerType_RemainingAncestor: |
1134 { | 808 { |
1135 ResourceType type = Convert(static_cast<OrthancPluginResourceType>(answer.valueInt32)); | 809 ResourceType type = Plugins::Convert(static_cast<OrthancPluginResourceType>(answer.valueInt32)); |
1136 listener.SignalRemainingAncestor(type, answer.valueString); | 810 listener.SignalRemainingAncestor(type, answer.valueString); |
1137 break; | 811 break; |
1138 } | 812 } |
1139 | 813 |
1140 case _OrthancPluginDatabaseAnswerType_DeletedResource: | 814 case _OrthancPluginDatabaseAnswerType_DeletedResource: |
1141 { | 815 { |
1142 ResourceType type = Convert(static_cast<OrthancPluginResourceType>(answer.valueInt32)); | 816 ResourceType type = Plugins::Convert(static_cast<OrthancPluginResourceType>(answer.valueInt32)); |
1143 ServerIndexChange change(ChangeType_Deleted, type, answer.valueString); | 817 ServerIndexChange change(ChangeType_Deleted, type, answer.valueString); |
1144 listener.SignalChange(change); | 818 listener.SignalChange(change); |
1145 break; | 819 break; |
1146 } | 820 } |
1147 | 821 |
1154 unsigned int OrthancPluginDatabase::GetDatabaseVersion() | 828 unsigned int OrthancPluginDatabase::GetDatabaseVersion() |
1155 { | 829 { |
1156 if (extensions_.getDatabaseVersion != NULL) | 830 if (extensions_.getDatabaseVersion != NULL) |
1157 { | 831 { |
1158 uint32_t version; | 832 uint32_t version; |
1159 OrthancPluginErrorCode error = extensions_.getDatabaseVersion(&version, payload_); | 833 CheckSuccess(extensions_.getDatabaseVersion(&version, payload_)); |
1160 | |
1161 if (error != OrthancPluginErrorCode_Success) | |
1162 { | |
1163 errorDictionary_.LogError(error, true); | |
1164 throw OrthancException(static_cast<ErrorCode>(error)); | |
1165 } | |
1166 | |
1167 return version; | 834 return version; |
1168 } | 835 } |
1169 else | 836 else |
1170 { | 837 { |
1171 // Before adding the "GetDatabaseVersion()" extension in plugins | 838 // Before adding the "GetDatabaseVersion()" extension in plugins |
1179 void OrthancPluginDatabase::Upgrade(unsigned int targetVersion, | 846 void OrthancPluginDatabase::Upgrade(unsigned int targetVersion, |
1180 IStorageArea& storageArea) | 847 IStorageArea& storageArea) |
1181 { | 848 { |
1182 if (extensions_.upgradeDatabase != NULL) | 849 if (extensions_.upgradeDatabase != NULL) |
1183 { | 850 { |
1184 OrthancPluginErrorCode error = extensions_.upgradeDatabase( | 851 CheckSuccess(extensions_.upgradeDatabase( |
1185 payload_, targetVersion, | 852 payload_, targetVersion, |
1186 reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)); | 853 reinterpret_cast<OrthancPluginStorageArea*>(&storageArea))); |
1187 | |
1188 if (error != OrthancPluginErrorCode_Success) | |
1189 { | |
1190 errorDictionary_.LogError(error, true); | |
1191 throw OrthancException(static_cast<ErrorCode>(error)); | |
1192 } | |
1193 } | 854 } |
1194 } | 855 } |
1195 | 856 |
1196 | 857 |
1197 void OrthancPluginDatabase::AnswerReceived(const _OrthancPluginDatabaseAnswer& answer) | 858 void OrthancPluginDatabase::AnswerReceived(const _OrthancPluginDatabaseAnswer& answer) |
1277 } | 938 } |
1278 | 939 |
1279 case _OrthancPluginDatabaseAnswerType_Resource: | 940 case _OrthancPluginDatabaseAnswerType_Resource: |
1280 { | 941 { |
1281 OrthancPluginResourceType type = static_cast<OrthancPluginResourceType>(answer.valueInt32); | 942 OrthancPluginResourceType type = static_cast<OrthancPluginResourceType>(answer.valueInt32); |
1282 answerResources_.push_back(std::make_pair(answer.valueInt64, Convert(type))); | 943 answerResources_.push_back(std::make_pair(answer.valueInt64, Plugins::Convert(type))); |
1283 break; | 944 break; |
1284 } | 945 } |
1285 | 946 |
1286 case _OrthancPluginDatabaseAnswerType_Attachment: | 947 case _OrthancPluginDatabaseAnswerType_Attachment: |
1287 { | 948 { |
1337 const OrthancPluginChange& change = *reinterpret_cast<const OrthancPluginChange*>(answer.valueGeneric); | 998 const OrthancPluginChange& change = *reinterpret_cast<const OrthancPluginChange*>(answer.valueGeneric); |
1338 assert(answerChanges_ != NULL); | 999 assert(answerChanges_ != NULL); |
1339 answerChanges_->push_back | 1000 answerChanges_->push_back |
1340 (ServerIndexChange(change.seq, | 1001 (ServerIndexChange(change.seq, |
1341 static_cast<ChangeType>(change.changeType), | 1002 static_cast<ChangeType>(change.changeType), |
1342 Convert(change.resourceType), | 1003 Plugins::Convert(change.resourceType), |
1343 change.publicId, | 1004 change.publicId, |
1344 change.date)); | 1005 change.date)); |
1345 } | 1006 } |
1346 | 1007 |
1347 break; | 1008 break; |
1363 const OrthancPluginExportedResource& exported = | 1024 const OrthancPluginExportedResource& exported = |
1364 *reinterpret_cast<const OrthancPluginExportedResource*>(answer.valueGeneric); | 1025 *reinterpret_cast<const OrthancPluginExportedResource*>(answer.valueGeneric); |
1365 assert(answerExportedResources_ != NULL); | 1026 assert(answerExportedResources_ != NULL); |
1366 answerExportedResources_->push_back | 1027 answerExportedResources_->push_back |
1367 (ExportedResource(exported.seq, | 1028 (ExportedResource(exported.seq, |
1368 Convert(exported.resourceType), | 1029 Plugins::Convert(exported.resourceType), |
1369 exported.publicId, | 1030 exported.publicId, |
1370 exported.modality, | 1031 exported.modality, |
1371 exported.date, | 1032 exported.date, |
1372 exported.patientId, | 1033 exported.patientId, |
1373 exported.studyInstanceUid, | 1034 exported.studyInstanceUid, |