Mercurial > hg > orthanc
annotate OrthancServer/Search/LookupIdentifierQuery.cpp @ 2958:bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Dec 2018 16:31:29 +0100 |
parents | e583478e0c6c |
children | 7695a9c81099 |
rev | line source |
---|---|
1745 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1745 | 4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1745 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
1747 | 34 #include "../PrecompiledHeadersServer.h" |
1745 | 35 #include "LookupIdentifierQuery.h" |
36 | |
1747 | 37 #include "../../Core/OrthancException.h" |
1746 | 38 #include "SetOfResources.h" |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
39 #include "../../Core/DicomParsing/FromDcmtkBridge.h" |
1745 | 40 |
41 #include <cassert> | |
42 | |
43 | |
44 | |
45 namespace Orthanc | |
46 { | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
47 LookupIdentifierQuery::Disjunction::~Disjunction() |
1748 | 48 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
49 for (size_t i = 0; i < singleConstraints_.size(); i++) |
1748 | 50 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
51 delete singleConstraints_[i]; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
52 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
53 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
54 for (size_t i = 0; i < rangeConstraints_.size(); i++) |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
55 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
56 delete rangeConstraints_[i]; |
1748 | 57 } |
58 } | |
59 | |
60 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
61 void LookupIdentifierQuery::Disjunction::Add(const DicomTag& tag, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
62 IdentifierConstraintType type, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
63 const std::string& value) |
1748 | 64 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
65 singleConstraints_.push_back(new SingleConstraint(tag, type, value)); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
66 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
67 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
68 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
69 void LookupIdentifierQuery::Disjunction::AddRange(const DicomTag& tag, |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
70 const std::string& start, |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
71 const std::string& end) |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
72 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
73 rangeConstraints_.push_back(new RangeConstraint(tag, start, end)); |
1748 | 74 } |
75 | |
1746 | 76 |
77 LookupIdentifierQuery::~LookupIdentifierQuery() | |
78 { | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
79 for (Disjunctions::iterator it = disjunctions_.begin(); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
80 it != disjunctions_.end(); ++it) |
1746 | 81 { |
82 delete *it; | |
83 } | |
84 } | |
85 | |
86 | |
1745 | 87 void LookupIdentifierQuery::AddConstraint(DicomTag tag, |
88 IdentifierConstraintType type, | |
89 const std::string& value) | |
90 { | |
91 assert(IsIdentifier(tag)); | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
92 disjunctions_.push_back(new Disjunction); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
93 disjunctions_.back()->Add(tag, type, value); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
94 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
95 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
96 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
97 void LookupIdentifierQuery::AddRange(DicomTag tag, |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
98 const std::string& start, |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
99 const std::string& end) |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
100 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
101 assert(IsIdentifier(tag)); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
102 disjunctions_.push_back(new Disjunction); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
103 disjunctions_.back()->AddRange(tag, start, end); |
1745 | 104 } |
105 | |
106 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
107 LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction() |
1745 | 108 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
109 disjunctions_.push_back(new Disjunction); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
110 return *disjunctions_.back(); |
1745 | 111 } |
112 | |
113 | |
1746 | 114 void LookupIdentifierQuery::Apply(std::list<std::string>& result, |
115 IDatabaseWrapper& database) | |
116 { | |
117 SetOfResources resources(database, level_); | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
118 Apply(resources, database); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
119 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
120 resources.Flatten(result); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
121 } |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
122 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
123 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
124 void LookupIdentifierQuery::Apply(SetOfResources& result, |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
125 IDatabaseWrapper& database) |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
126 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
127 for (size_t i = 0; i < disjunctions_.size(); i++) |
1746 | 128 { |
1748 | 129 std::list<int64_t> a; |
130 | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
131 for (size_t j = 0; j < disjunctions_[i]->GetSingleConstraintsCount(); j++) |
1748 | 132 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
133 const SingleConstraint& constraint = disjunctions_[i]->GetSingleConstraint(j); |
1748 | 134 std::list<int64_t> b; |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
135 database.LookupIdentifier(b, level_, constraint.GetTag(), |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
136 constraint.GetType(), constraint.GetValue()); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
137 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
138 a.splice(a.end(), b); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
139 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
140 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
141 for (size_t j = 0; j < disjunctions_[i]->GetRangeConstraintsCount(); j++) |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
142 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
143 const RangeConstraint& constraint = disjunctions_[i]->GetRangeConstraint(j); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
144 std::list<int64_t> b; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
145 database.LookupIdentifierRange(b, level_, constraint.GetTag(), |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
146 constraint.GetStart(), constraint.GetEnd()); |
1748 | 147 |
148 a.splice(a.end(), b); | |
149 } | |
150 | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
151 result.Intersect(a); |
1746 | 152 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
153 } |
1746 | 154 |
1758 | 155 |
156 void LookupIdentifierQuery::Print(std::ostream& s) const | |
157 { | |
158 s << "Constraint: " << std::endl; | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
159 for (Disjunctions::const_iterator |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
160 it = disjunctions_.begin(); it != disjunctions_.end(); ++it) |
1758 | 161 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
162 if (it == disjunctions_.begin()) |
1758 | 163 s << " "; |
164 else | |
165 s << "OR "; | |
166 | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
167 for (size_t j = 0; j < (*it)->GetSingleConstraintsCount(); j++) |
1758 | 168 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
169 const SingleConstraint& c = (*it)->GetSingleConstraint(j); |
2115
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
170 s << FromDcmtkBridge::GetTagName(c.GetTag(), ""); |
1758 | 171 |
172 switch (c.GetType()) | |
173 { | |
174 case IdentifierConstraintType_Equal: s << " == "; break; | |
175 case IdentifierConstraintType_SmallerOrEqual: s << " <= "; break; | |
176 case IdentifierConstraintType_GreaterOrEqual: s << " >= "; break; | |
177 case IdentifierConstraintType_Wildcard: s << " ~= "; break; | |
178 default: | |
179 s << " ? "; | |
180 } | |
181 | |
182 s << c.GetValue() << std::endl; | |
183 } | |
184 } | |
185 } | |
1745 | 186 } |