Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/FindRequest.cpp @ 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 #include "FindRequest.h" | |
24 | |
25 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
26 | |
27 | |
28 #include <cassert> | |
29 | |
30 namespace Orthanc | |
31 { | |
32 bool FindRequest::IsCompatibleLevel(ResourceType levelOfInterest) const | |
33 { | |
34 switch (level_) | |
35 { | |
36 case ResourceType_Patient: | |
37 return (levelOfInterest == ResourceType_Patient); | |
38 | |
39 case ResourceType_Study: | |
40 return (levelOfInterest == ResourceType_Patient || | |
41 levelOfInterest == ResourceType_Study); | |
42 | |
43 case ResourceType_Series: | |
44 return (levelOfInterest == ResourceType_Patient || | |
45 levelOfInterest == ResourceType_Study || | |
46 levelOfInterest == ResourceType_Series); | |
47 | |
48 case ResourceType_Instance: | |
49 return (levelOfInterest == ResourceType_Patient || | |
50 levelOfInterest == ResourceType_Study || | |
51 levelOfInterest == ResourceType_Series || | |
52 levelOfInterest == ResourceType_Instance); | |
53 | |
54 default: | |
55 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
56 } | |
57 } | |
58 | |
59 | |
60 FindRequest::FindRequest(ResourceType level) : | |
61 level_(level), | |
62 responseType_(ResponseType_OrthancIdentifiers), | |
63 hasLimits_(false), | |
64 limitsSince_(0), | |
65 limitsCount_(0), | |
66 metadataMode_(MetadataMode_None), | |
67 retrievePatientTags_(false), | |
68 retrieveStudyTags_(false), | |
69 retrieveSeriesTags_(false), | |
70 retrieveInstanceTags_(false) | |
71 { | |
72 } | |
73 | |
74 | |
75 FindRequest::~FindRequest() | |
76 { | |
77 for (std::deque<TagConstraint*>::iterator it = tagConstraints_.begin(); it != tagConstraints_.end(); ++it) | |
78 { | |
79 assert(*it != NULL); | |
80 delete *it; | |
81 } | |
82 } | |
83 | |
84 | |
85 void FindRequest::AddTagConstraint(TagConstraint* constraint /* takes ownership */) | |
86 { | |
87 if (constraint == NULL) | |
88 { | |
89 throw OrthancException(ErrorCode_NullPointer); | |
90 } | |
91 else | |
92 { | |
93 tagConstraints_.push_back(constraint); | |
94 } | |
95 } | |
96 | |
97 | |
98 const FindRequest::TagConstraint& FindRequest::GetTagConstraint(size_t index) const | |
99 { | |
100 if (index >= tagConstraints_.size()) | |
101 { | |
102 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
103 } | |
104 else | |
105 { | |
106 assert(tagConstraints_[index] != NULL); | |
107 return *tagConstraints_[index]; | |
108 } | |
109 } | |
110 | |
111 | |
112 void FindRequest::SetLimits(uint64_t since, | |
113 uint64_t count) | |
114 { | |
115 if (hasLimits_) | |
116 { | |
117 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
118 } | |
119 else | |
120 { | |
121 hasLimits_ = true; | |
122 limitsSince_ = since; | |
123 limitsCount_ = count; | |
124 } | |
125 } | |
126 | |
127 | |
128 uint64_t FindRequest::GetLimitsSince() const | |
129 { | |
130 if (hasLimits_) | |
131 { | |
132 return limitsSince_; | |
133 } | |
134 else | |
135 { | |
136 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
137 } | |
138 } | |
139 | |
140 | |
141 uint64_t FindRequest::GetLimitsCount() const | |
142 { | |
143 if (hasLimits_) | |
144 { | |
145 return limitsCount_; | |
146 } | |
147 else | |
148 { | |
149 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
150 } | |
151 } | |
152 | |
153 | |
154 void FindRequest::SetRetrieveTagsAtLevel(ResourceType levelOfInterest, | |
155 bool retrieve) | |
156 { | |
157 if (!IsCompatibleLevel(levelOfInterest)) | |
158 { | |
159 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
160 } | |
161 | |
162 switch (levelOfInterest) | |
163 { | |
164 case ResourceType_Patient: | |
165 retrievePatientTags_ = true; | |
166 break; | |
167 | |
168 case ResourceType_Study: | |
169 retrieveStudyTags_ = true; | |
170 break; | |
171 | |
172 case ResourceType_Series: | |
173 retrieveSeriesTags_ = true; | |
174 break; | |
175 | |
176 case ResourceType_Instance: | |
177 retrieveInstanceTags_ = true; | |
178 break; | |
179 | |
180 default: | |
181 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
182 } | |
183 } | |
184 | |
185 | |
186 bool FindRequest::IsRetrieveTagsAtLevel(ResourceType levelOfInterest) const | |
187 { | |
188 switch (levelOfInterest) | |
189 { | |
190 case ResourceType_Patient: | |
191 return retrievePatientTags_; | |
192 | |
193 case ResourceType_Study: | |
194 return retrieveStudyTags_; | |
195 | |
196 case ResourceType_Series: | |
197 return retrieveSeriesTags_; | |
198 | |
199 case ResourceType_Instance: | |
200 return retrieveInstanceTags_; | |
201 | |
202 default: | |
203 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
204 } | |
205 } | |
206 | |
207 | |
208 void FindRequest::SetTagOrdering(DicomTag tag, | |
209 Ordering ordering) | |
210 { | |
211 switch (ordering) | |
212 { | |
213 case Ordering_None: | |
214 tagOrdering_.erase(tag); | |
215 break; | |
216 | |
217 case Ordering_Ascending: | |
218 tagOrdering_[tag] = Ordering_Ascending; | |
219 break; | |
220 | |
221 case Ordering_Descending: | |
222 tagOrdering_[tag] = Ordering_Descending; | |
223 break; | |
224 | |
225 default: | |
226 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
227 } | |
228 } | |
229 | |
230 | |
231 void FindRequest::AddMetadataConstraint(MetadataType metadata, | |
232 const std::string& value) | |
233 { | |
234 if (metadataConstraints_.find(metadata) == metadataConstraints_.end()) | |
235 { | |
236 metadataConstraints_[metadata] = value; | |
237 } | |
238 else | |
239 { | |
240 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
241 } | |
242 } | |
243 } |