Mercurial > hg > orthanc
annotate OrthancServer/Search/LookupIdentifierQuery.h @ 2931:89f2c302fc37
Fix issue #114
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Nov 2018 17:50:03 +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:
2244
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 | |
34 #pragma once | |
35 | |
2121 | 36 #include "../ServerToolbox.h" |
1747 | 37 #include "../IDatabaseWrapper.h" |
1745 | 38 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
39 #include "SetOfResources.h" |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
40 |
1745 | 41 #include <vector> |
42 #include <boost/noncopyable.hpp> | |
43 | |
44 namespace Orthanc | |
45 { | |
46 /** | |
47 * Primitive for wildcard matching, as defined in DICOM: | |
48 * http://dicom.nema.org/dicom/2013/output/chtml/part04/sect_C.2.html#sect_C.2.2.2.4 | |
49 * | |
50 * "Any occurrence of an "*" or a "?", then "*" shall match any | |
51 * sequence of characters (including a zero length value) and "?" | |
52 * shall match any single character. This matching is case | |
53 * sensitive, except for Attributes with an PN Value | |
54 * Representation (e.g., Patient Name (0010,0010))." | |
55 * | |
56 * Pay attention to the fact that "*" (resp. "?") generally | |
57 * corresponds to "%" (resp. "_") in primitive LIKE of SQL. The | |
58 * values "%", "_", "\" should in the user request should | |
59 * respectively be escaped as "\%", "\_" and "\\". | |
1746 | 60 * |
1745 | 61 * This matching must be case sensitive: The special case of PN VR |
62 * is taken into consideration by normalizing the query string in | |
63 * method "NormalizeIdentifier()". | |
64 **/ | |
65 | |
66 class LookupIdentifierQuery : public boost::noncopyable | |
67 { | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
68 // This class encodes a conjunction ("AND") of disjunctions. Each |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
69 // disjunction represents an "OR" of several constraints. |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
70 |
1748 | 71 public: |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
72 class SingleConstraint |
1745 | 73 { |
1748 | 74 private: |
1745 | 75 DicomTag tag_; |
76 IdentifierConstraintType type_; | |
77 std::string value_; | |
78 | |
1748 | 79 public: |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
80 SingleConstraint(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
|
81 IdentifierConstraintType type, |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
82 const std::string& value) : |
1745 | 83 tag_(tag), |
84 type_(type), | |
2121 | 85 value_(ServerToolbox::NormalizeIdentifier(value)) |
1745 | 86 { |
87 } | |
1748 | 88 |
89 const DicomTag& GetTag() const | |
90 { | |
91 return tag_; | |
92 } | |
93 | |
94 IdentifierConstraintType GetType() const | |
95 { | |
96 return type_; | |
97 } | |
98 | |
99 const std::string& GetValue() const | |
100 { | |
101 return value_; | |
102 } | |
1745 | 103 }; |
104 | |
1748 | 105 |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
106 class RangeConstraint |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
107 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
108 private: |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
109 DicomTag tag_; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
110 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
|
111 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
|
112 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
113 public: |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
114 RangeConstraint(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
|
115 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
|
116 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
|
117 tag_(tag), |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
118 start_(ServerToolbox::NormalizeIdentifier(start)), |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
119 end_(ServerToolbox::NormalizeIdentifier(end)) |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
120 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
121 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
122 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
123 const DicomTag& GetTag() const |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
124 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
125 return tag_; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
126 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
127 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
128 const std::string& GetStart() const |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
129 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
130 return start_; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
131 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
132 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
133 const std::string& GetEnd() const |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
134 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
135 return end_; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
136 } |
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 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
139 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
140 class Disjunction : public boost::noncopyable |
1748 | 141 { |
142 private: | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
143 std::vector<SingleConstraint*> singleConstraints_; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
144 std::vector<RangeConstraint*> rangeConstraints_; |
1748 | 145 |
146 public: | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
147 ~Disjunction(); |
1748 | 148 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
149 void Add(const DicomTag& tag, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
150 IdentifierConstraintType type, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
151 const std::string& value); |
1748 | 152 |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
153 void 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
|
154 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
|
155 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
|
156 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
157 size_t GetSingleConstraintsCount() const |
1748 | 158 { |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
159 return singleConstraints_.size(); |
1748 | 160 } |
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 const SingleConstraint& GetSingleConstraint(size_t i) const |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
163 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
164 return *singleConstraints_[i]; |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
165 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
166 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
167 size_t GetRangeConstraintsCount() const |
1748 | 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 return rangeConstraints_.size(); |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
170 } |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
171 |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
172 const RangeConstraint& GetRangeConstraint(size_t i) const |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
173 { |
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
174 return *rangeConstraints_[i]; |
1748 | 175 } |
176 }; | |
177 | |
178 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
179 private: |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
180 typedef std::vector<Disjunction*> Disjunctions; |
1745 | 181 |
182 ResourceType level_; | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
183 Disjunctions disjunctions_; |
1745 | 184 |
185 public: | |
186 LookupIdentifierQuery(ResourceType level) : level_(level) | |
187 { | |
188 } | |
189 | |
190 ~LookupIdentifierQuery(); | |
191 | |
1748 | 192 bool IsIdentifier(const DicomTag& tag) |
193 { | |
2121 | 194 return ServerToolbox::IsIdentifier(tag, level_); |
1748 | 195 } |
1745 | 196 |
197 void AddConstraint(DicomTag tag, | |
198 IdentifierConstraintType type, | |
199 const std::string& value); | |
200 | |
2697
e583478e0c6c
New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2696
diff
changeset
|
201 void 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
|
202 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
|
203 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
|
204 |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
205 Disjunction& AddDisjunction(); |
1748 | 206 |
1746 | 207 ResourceType GetLevel() const |
208 { | |
209 return level_; | |
210 } | |
211 | |
1748 | 212 // The database must be locked |
213 void Apply(std::list<std::string>& result, | |
214 IDatabaseWrapper& database); | |
1745 | 215 |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
216 void Apply(SetOfResources& result, |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
217 IDatabaseWrapper& database); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
218 |
1758 | 219 void Print(std::ostream& s) const; |
1745 | 220 }; |
221 } |