comparison OrthancServer/Sources/Database/FindRequest.h @ 5554:12d8a1a266e9 find-refactoring

introduction of FindRequest and FindResponse
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Apr 2024 16:13:24 +0200
parents
children def06a42e5ef
comparison
equal deleted inserted replaced
5549:dcbf0c776945 5554:12d8a1a266e9
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #pragma once
24
25 #include "../../../OrthancFramework/Sources/DicomFormat/DicomTag.h"
26 #include "../ServerEnumerations.h"
27 #include "OrthancIdentifiers.h"
28
29 #include <deque>
30 #include <map>
31 #include <set>
32
33
34 namespace Orthanc
35 {
36 class FindRequest : public boost::noncopyable
37 {
38 public:
39 enum ResponseType
40 {
41 ResponseType_OrthancIdentifiers,
42 ResponseType_DicomMap
43 };
44
45 enum ConstraintType
46 {
47 ConstraintType_Mandatory,
48 ConstraintType_Equality,
49 ConstraintType_Range,
50 ConstraintType_Wildcard,
51 ConstraintType_List
52 };
53
54 enum MetadataMode
55 {
56 MetadataMode_None,
57 MetadataMode_List,
58 MetadataMode_Retrieve
59 };
60
61 enum Ordering
62 {
63 Ordering_Ascending,
64 Ordering_Descending,
65 Ordering_None
66 };
67
68
69 class TagConstraint : public boost::noncopyable
70 {
71 private:
72 DicomTag tag_;
73
74 public:
75 TagConstraint(DicomTag tag) :
76 tag_(tag)
77 {
78 }
79
80 virtual ~TagConstraint()
81 {
82 }
83
84 virtual DicomTag GetTag() const
85 {
86 return tag_;
87 }
88
89 virtual ConstraintType GetType() const = 0;
90
91 virtual bool IsCaseSensitive() const = 0; // Needed for PN VR
92 };
93
94
95 class MandatoryConstraint : public TagConstraint
96 {
97 public:
98 virtual ConstraintType GetType() const ORTHANC_OVERRIDE
99 {
100 return ConstraintType_Mandatory;
101 }
102 };
103
104
105 class StringConstraint : public TagConstraint
106 {
107 private:
108 bool caseSensitive_;
109
110 public:
111 StringConstraint(DicomTag tag,
112 bool caseSensitive) :
113 TagConstraint(tag),
114 caseSensitive_(caseSensitive)
115 {
116 }
117
118 bool IsCaseSensitive() const
119 {
120 return caseSensitive_;
121 }
122 };
123
124
125 class EqualityConstraint : public StringConstraint
126 {
127 private:
128 std::string value_;
129
130 public:
131 explicit EqualityConstraint(DicomTag tag,
132 bool caseSensitive,
133 const std::string& value) :
134 StringConstraint(tag, caseSensitive),
135 value_(value)
136 {
137 }
138
139 virtual ConstraintType GetType() const ORTHANC_OVERRIDE
140 {
141 return ConstraintType_Equality;
142 }
143
144 const std::string& GetValue() const
145 {
146 return value_;
147 }
148 };
149
150
151 class RangeConstraint : public StringConstraint
152 {
153 private:
154 std::string start_;
155 std::string end_; // Inclusive
156
157 public:
158 RangeConstraint(DicomTag tag,
159 bool caseSensitive,
160 const std::string& start,
161 const std::string& end) :
162 StringConstraint(tag, caseSensitive),
163 start_(start),
164 end_(end)
165 {
166 }
167
168 virtual ConstraintType GetType() const ORTHANC_OVERRIDE
169 {
170 return ConstraintType_Range;
171 }
172
173 const std::string& GetStart() const
174 {
175 return start_;
176 }
177
178 const std::string& GetEnd() const
179 {
180 return end_;
181 }
182 };
183
184
185 class WildcardConstraint : public StringConstraint
186 {
187 private:
188 std::string value_;
189
190 public:
191 explicit WildcardConstraint(DicomTag& tag,
192 bool caseSensitive,
193 const std::string& value) :
194 StringConstraint(tag, caseSensitive),
195 value_(value)
196 {
197 }
198
199 virtual ConstraintType GetType() const ORTHANC_OVERRIDE
200 {
201 return ConstraintType_Wildcard;
202 }
203
204 const std::string& GetValue() const
205 {
206 return value_;
207 }
208 };
209
210
211 class ListConstraint : public StringConstraint
212 {
213 private:
214 std::set<std::string> values_;
215
216 public:
217 ListConstraint(DicomTag tag,
218 bool caseSensitive) :
219 StringConstraint(tag, caseSensitive)
220 {
221 }
222
223 virtual ConstraintType GetType() const ORTHANC_OVERRIDE
224 {
225 return ConstraintType_List;
226 }
227
228 const std::set<std::string>& GetValues() const
229 {
230 return values_;
231 }
232 };
233
234
235 private:
236 ResourceType level_;
237 ResponseType responseType_;
238 OrthancIdentifiers orthancIdentifiers_;
239 std::deque<TagConstraint*> tagConstraints_;
240 bool hasLimits_;
241 uint64_t limitsSince_;
242 uint64_t limitsCount_;
243 MetadataMode metadataMode_;
244 bool retrievePatientTags_;
245 bool retrieveStudyTags_;
246 bool retrieveSeriesTags_;
247 bool retrieveInstanceTags_;
248 std::map<DicomTag, Ordering> tagOrdering_;
249 std::set<std::string> labels_;
250 std::map<MetadataType, std::string> metadataConstraints_;
251
252 bool IsCompatibleLevel(ResourceType levelOfInterest) const;
253
254 public:
255 FindRequest(ResourceType level);
256
257 ~FindRequest();
258
259 ResourceType GetLevel() const
260 {
261 return level_;
262 }
263
264 void SetResponseType(ResponseType type)
265 {
266 responseType_ = type;
267 }
268
269 ResponseType GetResponseType() const
270 {
271 return responseType_;
272 }
273
274 void SetOrthancPatientId(const std::string& id)
275 {
276 orthancIdentifiers_.SetPatientId(id);
277 }
278
279 void SetOrthancStudyId(const std::string& id)
280 {
281 orthancIdentifiers_.SetStudyId(id);
282 }
283
284 void SetOrthancSeriesId(const std::string& id)
285 {
286 orthancIdentifiers_.SetSeriesId(id);
287 }
288
289 void SetOrthancInstanceId(const std::string& id)
290 {
291 orthancIdentifiers_.SetInstanceId(id);
292 }
293
294 const OrthancIdentifiers& GetOrthancIdentifiers() const
295 {
296 return orthancIdentifiers_;
297 }
298
299 void AddTagConstraint(TagConstraint* constraint /* takes ownership */);
300
301 size_t GetTagConstraintsCount() const
302 {
303 return tagConstraints_.size();
304 }
305
306 const TagConstraint& GetTagConstraint(size_t index) const;
307
308 void SetLimits(uint64_t since,
309 uint64_t count);
310
311 bool HasLimits() const
312 {
313 return hasLimits_;
314 }
315
316 uint64_t GetLimitsSince() const;
317
318 uint64_t GetLimitsCount() const;
319
320 void SetMetadataMode(MetadataMode mode)
321 {
322 metadataMode_ = mode;
323 }
324
325 MetadataMode GetMetadataMode() const
326 {
327 return metadataMode_;
328 }
329
330 void SetRetrieveTagsAtLevel(ResourceType levelOfInterest,
331 bool retrieve);
332
333 bool IsRetrieveTagsAtLevel(ResourceType levelOfInterest) const;
334
335 void SetTagOrdering(DicomTag tag,
336 Ordering ordering);
337
338 const std::map<DicomTag, Ordering>& GetTagOrdering() const
339 {
340 return tagOrdering_;
341 }
342
343 void AddLabel(const std::string& label)
344 {
345 labels_.insert(label);
346 }
347
348 const std::set<std::string>& GetLabels() const
349 {
350 return labels_;
351 }
352
353 void AddMetadataConstraint(MetadataType metadata,
354 const std::string& value);
355
356 const std::map<MetadataType, std::string>& GetMetadataConstraints() const
357 {
358 return metadataConstraints_;
359 }
360 };
361 }