comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 1276:6164f7200c43

refactoring modules
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Jan 2015 14:42:33 +0100
parents 09aa7c126be9
children 8dac11c78d71
comparison
equal deleted inserted replaced
1275:4287285709d1 1276:6164f7200c43
711 } 711 }
712 712
713 713
714 static void GetModuleInternal(RestApiGetCall& call, 714 static void GetModuleInternal(RestApiGetCall& call,
715 ResourceType resourceType, 715 ResourceType resourceType,
716 ResourceType queryLevel) 716 DicomModule module)
717 { 717 {
718 if (resourceType != queryLevel && 718 if (!((resourceType == ResourceType_Patient && module == DicomModule_Patient) ||
719 !(resourceType == ResourceType_Study && queryLevel == ResourceType_Patient)) 719 (resourceType == ResourceType_Study && module == DicomModule_Patient) ||
720 (resourceType == ResourceType_Study && module == DicomModule_Study) ||
721 (resourceType == ResourceType_Series && module == DicomModule_Series) ||
722 (resourceType == ResourceType_Instance && module == DicomModule_Instance) ||
723 (resourceType == ResourceType_Instance && module == DicomModule_Image)))
720 { 724 {
721 throw OrthancException(ErrorCode_NotImplemented); 725 throw OrthancException(ErrorCode_NotImplemented);
722 } 726 }
723 727
724 ServerContext& context = OrthancRestApi::GetContext(call); 728 ServerContext& context = OrthancRestApi::GetContext(call);
725 std::string publicId = call.GetUriComponent("id", ""); 729 std::string publicId = call.GetUriComponent("id", "");
726 bool simplify = call.HasArgument("simplify"); 730 bool simplify = call.HasArgument("simplify");
727 731
728 typedef std::set<DicomTag> Module; 732 typedef std::set<DicomTag> ModuleTags;
729 Module module; 733 ModuleTags moduleTags;
730 DicomTag::GetTagsForModule(module, queryLevel); 734 DicomTag::GetTagsForModule(moduleTags, module);
731 735
732 Json::Value tags; 736 Json::Value tags;
733 737
734 if (resourceType != ResourceType_Instance) 738 if (resourceType != ResourceType_Instance)
735 { 739 {
749 753
750 context.ReadJson(tags, publicId); 754 context.ReadJson(tags, publicId);
751 755
752 // Filter the tags of the instance according to the module 756 // Filter the tags of the instance according to the module
753 Json::Value result = Json::objectValue; 757 Json::Value result = Json::objectValue;
754 for (Module::const_iterator it = module.begin(); it != module.end(); it++) 758 for (ModuleTags::const_iterator tag = moduleTags.begin(); tag != moduleTags.end(); tag++)
755 { 759 {
756 std::string s = it->Format(); 760 std::string s = tag->Format();
757 if (tags.isMember(s)) 761 if (tags.isMember(s))
758 { 762 {
759 result[s] = tags[s]; 763 result[s] = tags[s];
760 } 764 }
761 } 765 }
772 } 776 }
773 } 777 }
774 778
775 779
776 780
777 template <enum ResourceType resourceType> 781 template <enum ResourceType resourceType,
782 enum DicomModule module>
778 static void GetModule(RestApiGetCall& call) 783 static void GetModule(RestApiGetCall& call)
779 { 784 {
780 GetModuleInternal(call, resourceType, resourceType); 785 GetModuleInternal(call, resourceType, module);
781 }
782
783
784 static void GetPatientModuleForStudy(RestApiGetCall& call)
785 {
786 GetModuleInternal(call, ResourceType_Study, ResourceType_Patient);
787 } 786 }
788 787
789 788
790 static void Lookup(RestApiPostCall& call) 789 static void Lookup(RestApiPostCall& call)
791 { 790 {
936 935
937 Register("/patients/{id}/shared-tags", GetSharedTags); 936 Register("/patients/{id}/shared-tags", GetSharedTags);
938 Register("/series/{id}/shared-tags", GetSharedTags); 937 Register("/series/{id}/shared-tags", GetSharedTags);
939 Register("/studies/{id}/shared-tags", GetSharedTags); 938 Register("/studies/{id}/shared-tags", GetSharedTags);
940 939
941 Register("/instances/{id}/module", GetModule<ResourceType_Instance>); 940 Register("/instances/{id}/module", GetModule<ResourceType_Instance, DicomModule_Instance>);
942 Register("/patients/{id}/module", GetModule<ResourceType_Patient>); 941 Register("/patients/{id}/module", GetModule<ResourceType_Patient, DicomModule_Patient>);
943 Register("/series/{id}/module", GetModule<ResourceType_Series>); 942 Register("/series/{id}/module", GetModule<ResourceType_Series, DicomModule_Series>);
944 Register("/studies/{id}/module", GetModule<ResourceType_Study>); 943 Register("/studies/{id}/module", GetModule<ResourceType_Study, DicomModule_Study>);
945 Register("/studies/{id}/module-patient", GetPatientModuleForStudy); 944 Register("/studies/{id}/module-patient", GetModule<ResourceType_Study, DicomModule_Patient>);
946 945
947 Register("/instances/{id}/file", GetInstanceFile); 946 Register("/instances/{id}/file", GetInstanceFile);
948 Register("/instances/{id}/export", ExportInstanceFile); 947 Register("/instances/{id}/export", ExportInstanceFile);
949 Register("/instances/{id}/tags", GetInstanceTagsBis); 948 Register("/instances/{id}/tags", GetInstanceTagsBis);
950 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); 949 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>);