comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 963:81134ea872ff

retrieve values of modules
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Jun 2014 16:42:05 +0200
parents abac5c83134f
children cc7a4ae474c1
comparison
equal deleted inserted replaced
962:b39c4837966e 963:81134ea872ff
689 } 689 }
690 } 690 }
691 } 691 }
692 692
693 693
694 template <enum ResourceType resourceType, bool simplify>
695 static void GetModule(RestApi::GetCall& call)
696 {
697 ServerContext& context = OrthancRestApi::GetContext(call);
698 std::string publicId = call.GetUriComponent("id", "");
699
700 typedef std::set<DicomTag> Module;
701 Module module;
702 DicomTag::GetTagsForModule(module, resourceType);
703
704 Json::Value tags;
705
706 if (resourceType != ResourceType_Instance)
707 {
708 // Retrieve all the instances of this patient/study/series
709 typedef std::list<std::string> Instances;
710 Instances instances;
711 context.GetIndex().GetChildInstances(instances, publicId);
712
713 if (instances.empty())
714 {
715 return; // Error: No instance (should never happen)
716 }
717
718 // Select one child instance
719 publicId = instances.front();
720 }
721
722 context.ReadJson(tags, publicId);
723
724 // Filter the tags of the instance according to the module
725 Json::Value result = Json::objectValue;
726 for (Module::const_iterator it = module.begin(); it != module.end(); it++)
727 {
728 std::string s = it->Format();
729 if (tags.isMember(s))
730 {
731 result[s] = tags[s];
732 }
733 }
734
735 if (simplify)
736 {
737 Json::Value simplified;
738 SimplifyTags(simplified, result);
739 call.GetOutput().AnswerJson(simplified);
740 }
741 else
742 {
743 call.GetOutput().AnswerJson(result);
744 }
745 }
746
747
694 void OrthancRestApi::RegisterResources() 748 void OrthancRestApi::RegisterResources()
695 { 749 {
696 Register("/instances", ListResources<ResourceType_Instance>); 750 Register("/instances", ListResources<ResourceType_Instance>);
697 Register("/patients", ListResources<ResourceType_Patient>); 751 Register("/patients", ListResources<ResourceType_Patient>);
698 Register("/series", ListResources<ResourceType_Series>); 752 Register("/series", ListResources<ResourceType_Series>);
716 Register("/patients/{id}/simplified-shared-tags", GetSharedTags<true>); 770 Register("/patients/{id}/simplified-shared-tags", GetSharedTags<true>);
717 Register("/series/{id}/shared-tags", GetSharedTags<false>); 771 Register("/series/{id}/shared-tags", GetSharedTags<false>);
718 Register("/series/{id}/simplified-shared-tags", GetSharedTags<true>); 772 Register("/series/{id}/simplified-shared-tags", GetSharedTags<true>);
719 Register("/studies/{id}/shared-tags", GetSharedTags<false>); 773 Register("/studies/{id}/shared-tags", GetSharedTags<false>);
720 Register("/studies/{id}/simplified-shared-tags", GetSharedTags<true>); 774 Register("/studies/{id}/simplified-shared-tags", GetSharedTags<true>);
775
776 Register("/instances/{id}/module", GetModule<ResourceType_Instance, false>);
777 Register("/patients/{id}/module", GetModule<ResourceType_Patient, false>);
778 Register("/series/{id}/module", GetModule<ResourceType_Series, false>);
779 Register("/studies/{id}/module", GetModule<ResourceType_Study, false>);
780 Register("/instances/{id}/simplified-module", GetModule<ResourceType_Instance, true>);
781 Register("/patients/{id}/simplified-module", GetModule<ResourceType_Patient, true>);
782 Register("/series/{id}/simplified-module", GetModule<ResourceType_Series, true>);
783 Register("/studies/{id}/simplified-module", GetModule<ResourceType_Study, true>);
721 784
722 Register("/instances/{id}/file", GetInstanceFile); 785 Register("/instances/{id}/file", GetInstanceFile);
723 Register("/instances/{id}/export", ExportInstanceFile); 786 Register("/instances/{id}/export", ExportInstanceFile);
724 Register("/instances/{id}/tags", GetInstanceTags<false>); 787 Register("/instances/{id}/tags", GetInstanceTags<false>);
725 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); 788 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>);