Mercurial > hg > orthanc
comparison Plugins/Engine/PluginsHttpHandler.cpp @ 1067:ace99e272203
access metadata in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Jul 2014 11:09:03 +0200 |
parents | bb82e5e818e9 |
children | a91b4900f06a |
comparison
equal
deleted
inserted
replaced
1066:bb82e5e818e9 | 1067:ace99e272203 |
---|---|
593 throw OrthancException(ErrorCode_UnknownResource); | 593 throw OrthancException(ErrorCode_UnknownResource); |
594 } | 594 } |
595 } | 595 } |
596 | 596 |
597 | 597 |
598 static void AccessInstanceMetadataInternal(bool checkExistence, | |
599 const _OrthancPluginAccessDicomInstance& params, | |
600 const DicomInstanceToStore& instance) | |
601 { | |
602 MetadataType metadata; | |
603 | |
604 try | |
605 { | |
606 metadata = StringToMetadata(params.key); | |
607 } | |
608 catch (OrthancException&) | |
609 { | |
610 // Unknown metadata | |
611 if (checkExistence) | |
612 { | |
613 *params.resultInt64 = -1; | |
614 } | |
615 else | |
616 { | |
617 *params.resultString = NULL; | |
618 } | |
619 | |
620 return; | |
621 } | |
622 | |
623 ServerIndex::MetadataMap::const_iterator it = | |
624 instance.GetMetadata().find(std::make_pair(ResourceType_Instance, metadata)); | |
625 | |
626 if (checkExistence) | |
627 { | |
628 if (it != instance.GetMetadata().end()) | |
629 { | |
630 *params.resultInt64 = 1; | |
631 } | |
632 else | |
633 { | |
634 *params.resultInt64 = 0; | |
635 } | |
636 } | |
637 else | |
638 { | |
639 if (it != instance.GetMetadata().end()) | |
640 { | |
641 *params.resultString = it->second.c_str(); | |
642 } | |
643 else | |
644 { | |
645 // Error: Missing metadata | |
646 *params.resultString = NULL; | |
647 } | |
648 } | |
649 } | |
650 | |
651 | |
598 static void AccessDicomInstance(_OrthancPluginService service, | 652 static void AccessDicomInstance(_OrthancPluginService service, |
599 const void* parameters) | 653 const void* parameters) |
600 { | 654 { |
601 const _OrthancPluginAccessDicomInstance& p = | 655 const _OrthancPluginAccessDicomInstance& p = |
602 *reinterpret_cast<const _OrthancPluginAccessDicomInstance*>(parameters); | 656 *reinterpret_cast<const _OrthancPluginAccessDicomInstance*>(parameters); |
614 *p.resultInt64 = instance.GetBufferSize(); | 668 *p.resultInt64 = instance.GetBufferSize(); |
615 return; | 669 return; |
616 | 670 |
617 case _OrthancPluginService_GetInstanceData: | 671 case _OrthancPluginService_GetInstanceData: |
618 *p.resultString = instance.GetBufferData(); | 672 *p.resultString = instance.GetBufferData(); |
673 return; | |
674 | |
675 case _OrthancPluginService_HasInstanceMetadata: | |
676 AccessInstanceMetadataInternal(true, p, instance); | |
677 return; | |
678 | |
679 case _OrthancPluginService_GetInstanceMetadata: | |
680 AccessInstanceMetadataInternal(false, p, instance); | |
619 return; | 681 return; |
620 | 682 |
621 case _OrthancPluginService_GetInstanceJson: | 683 case _OrthancPluginService_GetInstanceJson: |
622 case _OrthancPluginService_GetInstanceSimplifiedJson: | 684 case _OrthancPluginService_GetInstanceSimplifiedJson: |
623 { | 685 { |
725 case _OrthancPluginService_GetInstanceRemoteAet: | 787 case _OrthancPluginService_GetInstanceRemoteAet: |
726 case _OrthancPluginService_GetInstanceSize: | 788 case _OrthancPluginService_GetInstanceSize: |
727 case _OrthancPluginService_GetInstanceData: | 789 case _OrthancPluginService_GetInstanceData: |
728 case _OrthancPluginService_GetInstanceJson: | 790 case _OrthancPluginService_GetInstanceJson: |
729 case _OrthancPluginService_GetInstanceSimplifiedJson: | 791 case _OrthancPluginService_GetInstanceSimplifiedJson: |
792 case _OrthancPluginService_HasInstanceMetadata: | |
793 case _OrthancPluginService_GetInstanceMetadata: | |
730 AccessDicomInstance(service, parameters); | 794 AccessDicomInstance(service, parameters); |
731 return true; | 795 return true; |
732 | 796 |
733 default: | 797 default: |
734 return false; | 798 return false; |