Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 960:abac5c83134f
simplified and extensive shared-tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 26 Jun 2014 14:37:56 +0200 |
parents | bd5659f2a50a |
children | 81134ea872ff |
comparison
equal
deleted
inserted
replaced
959:bd5659f2a50a | 960:abac5c83134f |
---|---|
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) | 594 static bool ExtractSharedTags(Json::Value& shared, |
595 { | 595 ServerContext& context, |
596 ServerContext& context = OrthancRestApi::GetContext(call); | 596 const std::string& publicId) |
597 std::string publicId = call.GetUriComponent("id", ""); | 597 { |
598 | |
599 // Retrieve all the instances of this patient/study/series | 598 // Retrieve all the instances of this patient/study/series |
600 typedef std::list<std::string> Instances; | 599 typedef std::list<std::string> Instances; |
601 Instances instances; | 600 Instances instances; |
602 context.GetIndex().GetChildInstances(instances, publicId); // (*) | 601 context.GetIndex().GetChildInstances(instances, publicId); // (*) |
603 | 602 |
604 // Loop over the instances | 603 // Loop over the instances |
605 bool isFirst = true; | 604 bool isFirst = true; |
606 Json::Value shared = Json::objectValue; | 605 shared = Json::objectValue; |
607 | 606 |
608 for (Instances::const_iterator it = instances.begin(); | 607 for (Instances::const_iterator it = instances.begin(); |
609 it != instances.end(); it++) | 608 it != instances.end(); it++) |
610 { | 609 { |
611 // Get the tags of the current instance, in the simplified format | 610 // Get the tags of the current instance, in the simplified format |
612 Json::Value full, simplified; | 611 Json::Value tags; |
613 | 612 |
614 try | 613 try |
615 { | 614 { |
616 context.ReadJson(full, *it); | 615 context.ReadJson(tags, *it); |
617 } | 616 } |
618 catch (OrthancException&) | 617 catch (OrthancException&) |
619 { | 618 { |
620 // Race condition: This instance has been removed since | 619 // Race condition: This instance has been removed since |
621 // (*). Ignore this instance. | 620 // (*). Ignore this instance. |
622 continue; | 621 continue; |
623 } | 622 } |
624 | 623 |
625 SimplifyTags(simplified, full); | 624 if (tags.type() != Json::objectValue) |
626 | 625 { |
627 if (simplified.type() != Json::objectValue) | 626 return false; // Error |
628 { | |
629 return; // Error | |
630 } | 627 } |
631 | 628 |
632 // Only keep the tags that are mapped to a string | 629 // Only keep the tags that are mapped to a string |
633 Json::Value::Members members = simplified.getMemberNames(); | 630 Json::Value::Members members = tags.getMemberNames(); |
634 for (size_t i = 0; i < members.size(); i++) | 631 for (size_t i = 0; i < members.size(); i++) |
635 { | 632 { |
636 Json::ValueType type = simplified[members[i]].type(); | 633 const Json::Value& tag = tags[members[i]]; |
637 if (type != Json::stringValue) | 634 if (tag.type() != Json::objectValue || |
635 tag["Type"].type() != Json::stringValue || | |
636 tag["Type"].asString() != "String") | |
638 { | 637 { |
639 simplified.removeMember(members[i]); | 638 tags.removeMember(members[i]); |
640 } | 639 } |
641 } | 640 } |
642 | 641 |
643 if (isFirst) | 642 if (isFirst) |
644 { | 643 { |
645 // This is the first instance, keep its tags as such | 644 // This is the first instance, keep its tags as such |
646 shared = simplified; | 645 shared = tags; |
647 isFirst = false; | 646 isFirst = false; |
648 } | 647 } |
649 else | 648 else |
650 { | 649 { |
651 // Loop over all the members of the shared tags extracted so | 650 // Loop over all the members of the shared tags extracted so |
652 // far. If the value of one of these tags does not match its | 651 // far. If the value of one of these tags does not match its |
653 // value in the current instance, remove it. | 652 // value in the current instance, remove it. |
654 members = shared.getMemberNames(); | 653 members = shared.getMemberNames(); |
655 for (size_t i = 0; i < members.size(); i++) | 654 for (size_t i = 0; i < members.size(); i++) |
656 { | 655 { |
657 if (!simplified.isMember(members[i]) || | 656 if (!tags.isMember(members[i]) || |
658 simplified[members[i]].asString() != shared[members[i]].asString()) | 657 tags[members[i]]["Value"].asString() != shared[members[i]]["Value"].asString()) |
659 { | 658 { |
660 shared.removeMember(members[i]); | 659 shared.removeMember(members[i]); |
661 } | 660 } |
662 } | 661 } |
663 } | 662 } |
664 } | 663 } |
665 | 664 |
666 // Success: Send the value of the shared tags | 665 return true; |
667 call.GetOutput().AnswerJson(shared); | 666 } |
667 | |
668 | |
669 | |
670 template <bool simplify> | |
671 static void GetSharedTags(RestApi::GetCall& call) | |
672 { | |
673 ServerContext& context = OrthancRestApi::GetContext(call); | |
674 std::string publicId = call.GetUriComponent("id", ""); | |
675 | |
676 Json::Value sharedTags; | |
677 if (ExtractSharedTags(sharedTags, context, publicId)) | |
678 { | |
679 // Success: Send the value of the shared tags | |
680 if (simplify) | |
681 { | |
682 Json::Value simplified; | |
683 SimplifyTags(simplified, sharedTags); | |
684 call.GetOutput().AnswerJson(simplified); | |
685 } | |
686 else | |
687 { | |
688 call.GetOutput().AnswerJson(sharedTags); | |
689 } | |
690 } | |
668 } | 691 } |
669 | 692 |
670 | 693 |
671 void OrthancRestApi::RegisterResources() | 694 void OrthancRestApi::RegisterResources() |
672 { | 695 { |
687 Register("/instances/{id}/statistics", GetResourceStatistics); | 710 Register("/instances/{id}/statistics", GetResourceStatistics); |
688 Register("/patients/{id}/statistics", GetResourceStatistics); | 711 Register("/patients/{id}/statistics", GetResourceStatistics); |
689 Register("/studies/{id}/statistics", GetResourceStatistics); | 712 Register("/studies/{id}/statistics", GetResourceStatistics); |
690 Register("/series/{id}/statistics", GetResourceStatistics); | 713 Register("/series/{id}/statistics", GetResourceStatistics); |
691 | 714 |
692 Register("/patients/{id}/shared-tags", GetSharedTags); | 715 Register("/patients/{id}/shared-tags", GetSharedTags<false>); |
693 Register("/series/{id}/shared-tags", GetSharedTags); | 716 Register("/patients/{id}/simplified-shared-tags", GetSharedTags<true>); |
694 Register("/studies/{id}/shared-tags", GetSharedTags); | 717 Register("/series/{id}/shared-tags", GetSharedTags<false>); |
718 Register("/series/{id}/simplified-shared-tags", GetSharedTags<true>); | |
719 Register("/studies/{id}/shared-tags", GetSharedTags<false>); | |
720 Register("/studies/{id}/simplified-shared-tags", GetSharedTags<true>); | |
695 | 721 |
696 Register("/instances/{id}/file", GetInstanceFile); | 722 Register("/instances/{id}/file", GetInstanceFile); |
697 Register("/instances/{id}/export", ExportInstanceFile); | 723 Register("/instances/{id}/export", ExportInstanceFile); |
698 Register("/instances/{id}/tags", GetInstanceTags<false>); | 724 Register("/instances/{id}/tags", GetInstanceTags<false>); |
699 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); | 725 Register("/instances/{id}/simplified-tags", GetInstanceTags<true>); |