comparison Plugins/Engine/OrthancPluginDatabase.cpp @ 3187:4bbadcd03966

refactoring retrieval of metadata from database
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Feb 2019 12:06:19 +0100
parents c0d7aee8c3f8
children 6f89d22a6ec0
comparison
equal deleted inserted replaced
3184:5d1f5984dc41 3187:4bbadcd03966
388 388
389 389
390 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target, 390 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target,
391 int64_t id) 391 int64_t id)
392 { 392 {
393 std::list<MetadataType> metadata; 393 // TODO - Add primitive in SDK
394 ListAvailableMetadata(metadata, id);
395 394
396 target.clear(); 395 target.clear();
397 396
398 for (std::list<MetadataType>::const_iterator 397 ResetAnswers();
399 it = metadata.begin(); it != metadata.end(); ++it) 398 CheckSuccess(backend_.listAvailableMetadata(GetContext(), payload_, id));
400 { 399
401 std::string value; 400 if (type_ != _OrthancPluginDatabaseAnswerType_None &&
402 if (!LookupMetadata(value, id, *it)) 401 type_ != _OrthancPluginDatabaseAnswerType_Int32)
403 { 402 {
404 throw OrthancException(ErrorCode_DatabasePlugin); 403 throw OrthancException(ErrorCode_DatabasePlugin);
405 } 404 }
406 405
407 target[*it] = value; 406 target.clear();
407
408 if (type_ == _OrthancPluginDatabaseAnswerType_Int32)
409 {
410 for (std::list<int32_t>::const_iterator
411 it = answerInt32_.begin(); it != answerInt32_.end(); ++it)
412 {
413 MetadataType type = static_cast<MetadataType>(*it);
414
415 std::string value;
416 if (LookupMetadata(value, id, type))
417 {
418 target[type] = value;
419 }
420 }
408 } 421 }
409 } 422 }
410 423
411 424
412 void OrthancPluginDatabase::GetAllInternalIds(std::list<int64_t>& target, 425 void OrthancPluginDatabase::GetAllInternalIds(std::list<int64_t>& target,
619 bool OrthancPluginDatabase::IsProtectedPatient(int64_t internalId) 632 bool OrthancPluginDatabase::IsProtectedPatient(int64_t internalId)
620 { 633 {
621 int32_t isProtected; 634 int32_t isProtected;
622 CheckSuccess(backend_.isProtectedPatient(&isProtected, payload_, internalId)); 635 CheckSuccess(backend_.isProtectedPatient(&isProtected, payload_, internalId));
623 return (isProtected != 0); 636 return (isProtected != 0);
624 }
625
626
627 void OrthancPluginDatabase::ListAvailableMetadata(std::list<MetadataType>& target,
628 int64_t id)
629 {
630 ResetAnswers();
631 CheckSuccess(backend_.listAvailableMetadata(GetContext(), payload_, id));
632
633 if (type_ != _OrthancPluginDatabaseAnswerType_None &&
634 type_ != _OrthancPluginDatabaseAnswerType_Int32)
635 {
636 throw OrthancException(ErrorCode_DatabasePlugin);
637 }
638
639 target.clear();
640
641 if (type_ == _OrthancPluginDatabaseAnswerType_Int32)
642 {
643 for (std::list<int32_t>::const_iterator
644 it = answerInt32_.begin(); it != answerInt32_.end(); ++it)
645 {
646 target.push_back(static_cast<MetadataType>(*it));
647 }
648 }
649 } 637 }
650 638
651 639
652 void OrthancPluginDatabase::ListAvailableAttachments(std::list<FileContentType>& target, 640 void OrthancPluginDatabase::ListAvailableAttachments(std::list<FileContentType>& target,
653 int64_t id) 641 int64_t id)
1429 if (extensions_.tagMostRecentPatient != NULL) 1417 if (extensions_.tagMostRecentPatient != NULL)
1430 { 1418 {
1431 CheckSuccess(extensions_.tagMostRecentPatient(payload_, patient)); 1419 CheckSuccess(extensions_.tagMostRecentPatient(payload_, patient));
1432 } 1420 }
1433 } 1421 }
1422
1423
1424 bool OrthancPluginDatabase::LookupResourceAndParent(int64_t& id,
1425 ResourceType& type,
1426 std::string& parentPublicId,
1427 const std::string& publicId)
1428 {
1429 // TODO - Add primitive in SDK
1430 return ILookupResourceAndParent::Apply(*this, id, type, parentPublicId, publicId);
1431 }
1434 } 1432 }