Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 958:1fbe89dc18b5
extraction of the shared tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Jun 2014 21:48:16 +0200 |
parents | 87791ebc1f50 |
children | bd5659f2a50a |
comparison
equal
deleted
inserted
replaced
957:63973b76a51f | 958:1fbe89dc18b5 |
---|---|
589 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); | 589 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri()); |
590 } | 590 } |
591 | 591 |
592 | 592 |
593 | 593 |
594 static void GetSharedTags(RestApi::GetCall& call) | |
595 { | |
596 ServerContext& context = OrthancRestApi::GetContext(call); | |
597 std::string publicId = call.GetUriComponent("id", ""); | |
598 | |
599 // Retrieve all the instances of this patient/study/series | |
600 typedef std::list<std::string> Instances; | |
601 Instances instances; | |
602 context.GetIndex().GetChildInstances(instances, publicId); | |
603 | |
604 // Loop over the instances | |
605 bool isFirst = true; | |
606 Json::Value shared = Json::objectValue; | |
607 | |
608 for (Instances::const_iterator it = instances.begin(); | |
609 it != instances.end(); it++) | |
610 { | |
611 // Get the tags of the current instance, in the simplified format | |
612 Json::Value full, simplified; | |
613 context.ReadJson(full, *it); | |
614 SimplifyTags(simplified, full); | |
615 | |
616 if (simplified.type() != Json::objectValue) | |
617 { | |
618 return; // Error | |
619 } | |
620 | |
621 // Only keep the tags that are mapped to a string | |
622 Json::Value::Members members = simplified.getMemberNames(); | |
623 for (size_t i = 0; i < members.size(); i++) | |
624 { | |
625 Json::ValueType type = simplified[members[i]].type(); | |
626 if (type != Json::stringValue) | |
627 { | |
628 simplified.removeMember(members[i]); | |
629 } | |
630 } | |
631 | |
632 if (isFirst) | |
633 { | |
634 // This is the first instance, keep its tags as such | |
635 shared = simplified; | |
636 isFirst = false; | |
637 } | |
638 else | |
639 { | |
640 // Loop over all the members of the shared tags extracted so | |
641 // far. If the value of one of these tags does not match its | |
642 // value in the current instance, remove it. | |
643 members = shared.getMemberNames(); | |
644 for (size_t i = 0; i < members.size(); i++) | |
645 { | |
646 if (!simplified.isMember(members[i]) || | |
647 simplified[members[i]].asString() != shared[members[i]].asString()) | |
648 { | |
649 shared.removeMember(members[i]); | |
650 } | |
651 } | |
652 } | |
653 } | |
654 | |
655 // Success: Send the value of the shared tags | |
656 call.GetOutput().AnswerJson(shared); | |
657 } | |
658 | |
659 | |
594 void OrthancRestApi::RegisterResources() | 660 void OrthancRestApi::RegisterResources() |
595 { | 661 { |
596 Register("/instances", ListResources<ResourceType_Instance>); | 662 Register("/instances", ListResources<ResourceType_Instance>); |
597 Register("/patients", ListResources<ResourceType_Patient>); | 663 Register("/patients", ListResources<ResourceType_Patient>); |
598 Register("/series", ListResources<ResourceType_Series>); | 664 Register("/series", ListResources<ResourceType_Series>); |
609 | 675 |
610 Register("/instances/{id}/statistics", GetResourceStatistics); | 676 Register("/instances/{id}/statistics", GetResourceStatistics); |
611 Register("/patients/{id}/statistics", GetResourceStatistics); | 677 Register("/patients/{id}/statistics", GetResourceStatistics); |
612 Register("/studies/{id}/statistics", GetResourceStatistics); | 678 Register("/studies/{id}/statistics", GetResourceStatistics); |
613 Register("/series/{id}/statistics", GetResourceStatistics); | 679 Register("/series/{id}/statistics", GetResourceStatistics); |
680 | |
681 Register("/patients/{id}/shared-tags", GetSharedTags); | |
682 Register("/series/{id}/shared-tags", GetSharedTags); | |
683 Register("/studies/{id}/shared-tags", GetSharedTags); | |
614 | 684 |
615 Register("/instances/{id}/file", GetInstanceFile); | 685 Register("/instances/{id}/file", GetInstanceFile); |
616 Register("/instances/{id}/export", ExportInstanceFile); | 686 Register("/instances/{id}/export", ExportInstanceFile); |
617 Register("/instances/{id}/tags", GetInstanceTags<false>); | 687 Register("/instances/{id}/tags", GetInstanceTags<false>); |
618 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); | 688 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); |