Mercurial > hg > orthanc
comparison OrthancServer/Sources/Search/ISqlLookupFormatter.cpp @ 5826:d73dfb4548c6 find-refactoring
tools/find: ParentPatient and co ..
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 07 Oct 2024 10:51:27 +0200 |
parents | 881cd0965146 |
children | 976872a99d39 |
comparison
equal
deleted
inserted
replaced
5825:881cd0965146 | 5826:d73dfb4548c6 |
---|---|
55 | 55 |
56 default: | 56 default: |
57 throw OrthancException(ErrorCode_InternalError); | 57 throw OrthancException(ErrorCode_InternalError); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 static std::string FormatLevel(const char* prefix, ResourceType level) | |
62 { | |
63 switch (level) | |
64 { | |
65 case ResourceType_Patient: | |
66 return std::string(prefix) + "patients"; | |
67 | |
68 case ResourceType_Study: | |
69 return std::string(prefix) + "studies"; | |
70 | |
71 case ResourceType_Series: | |
72 return std::string(prefix) + "series"; | |
73 | |
74 case ResourceType_Instance: | |
75 return std::string(prefix) + "instances"; | |
76 | |
77 default: | |
78 throw OrthancException(ErrorCode_InternalError); | |
79 } | |
80 } | |
81 | |
61 | 82 |
62 static bool FormatComparison(std::string& target, | 83 static bool FormatComparison(std::string& target, |
63 ISqlLookupFormatter& formatter, | 84 ISqlLookupFormatter& formatter, |
64 const DatabaseConstraint& constraint, | 85 const DatabaseConstraint& constraint, |
65 size_t index, | 86 size_t index, |
743 " FROM Resources AS " + strQueryLevel); | 764 " FROM Resources AS " + strQueryLevel); |
744 | 765 |
745 | 766 |
746 std::string joins, comparisons; | 767 std::string joins, comparisons; |
747 | 768 |
748 if (request.GetOrthancIdentifiers().IsDefined() && request.GetOrthancIdentifiers().DetectLevel() <= queryLevel) | 769 { |
749 { | 770 // handle parent constraints |
750 // single child resource matching, there should not be other constraints (at least for now) | 771 if (request.GetOrthancIdentifiers().IsDefined() && request.GetOrthancIdentifiers().DetectLevel() <= queryLevel) |
751 assert(request.GetDicomTagConstraints().GetSize() == 0); | 772 { |
752 assert(request.GetLabels().size() == 0); | 773 ResourceType topParentLevel = request.GetOrthancIdentifiers().DetectLevel(); |
753 assert(request.HasLimits() == false); | 774 |
754 | 775 if (topParentLevel == queryLevel) |
755 ResourceType topParentLevel = request.GetOrthancIdentifiers().DetectLevel(); | 776 { |
756 const std::string& strTopParentLevel = FormatLevel(topParentLevel); | 777 comparisons += " AND " + FormatLevel(topParentLevel) + ".publicId = " + formatter.GenerateParameter(request.GetOrthancIdentifiers().GetLevel(topParentLevel)); |
757 | 778 } |
758 comparisons = " AND " + strTopParentLevel + ".publicId = " + formatter.GenerateParameter(request.GetOrthancIdentifiers().GetLevel(topParentLevel)); | 779 else |
759 | 780 { |
760 for (int level = queryLevel; level > topParentLevel; level--) | 781 comparisons += " AND " + FormatLevel("parent", topParentLevel) + ".publicId = " + formatter.GenerateParameter(request.GetOrthancIdentifiers().GetLevel(topParentLevel)); |
761 { | 782 |
762 sql += (" INNER JOIN Resources " + | 783 for (int level = queryLevel; level > topParentLevel; level--) |
763 FormatLevel(static_cast<ResourceType>(level - 1)) + " ON " + | 784 { |
764 FormatLevel(static_cast<ResourceType>(level - 1)) + ".internalId=" + | 785 joins += " INNER JOIN Resources " + |
765 FormatLevel(static_cast<ResourceType>(level)) + ".parentId"); | 786 FormatLevel("parent", static_cast<ResourceType>(level - 1)) + " ON " + |
766 } | 787 FormatLevel("parent", static_cast<ResourceType>(level - 1)) + ".internalId = "; |
767 } | 788 if (level == queryLevel) |
768 else | 789 { |
769 { | 790 joins += FormatLevel(static_cast<ResourceType>(level)) + ".parentId"; |
791 } | |
792 else | |
793 { | |
794 joins += FormatLevel("parent", static_cast<ResourceType>(level)) + ".parentId"; | |
795 } | |
796 } | |
797 } | |
798 } | |
799 | |
770 size_t count = 0; | 800 size_t count = 0; |
771 | 801 |
772 const DatabaseConstraints& dicomTagsConstraints = request.GetDicomTagConstraints(); | 802 const DatabaseConstraints& dicomTagsConstraints = request.GetDicomTagConstraints(); |
773 for (size_t i = 0; i < dicomTagsConstraints.GetSize(); i++) | 803 for (size_t i = 0; i < dicomTagsConstraints.GetSize(); i++) |
774 { | 804 { |