Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/FindRequest.cpp @ 5809:023a99146dd0 attach-custom-data tip
merged find-refactoring -> attach-custom-data
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 24 Sep 2024 12:53:43 +0200 |
parents | f679ae844839 |
children |
comparison
equal
deleted
inserted
replaced
5808:63c025cf6958 | 5809:023a99146dd0 |
---|---|
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-2023 Osimis S.A., Belgium | |
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium | |
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
8 * | |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "FindRequest.h" | |
25 | |
26 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
27 | |
28 #include "MainDicomTagsRegistry.h" | |
29 | |
30 #include <cassert> | |
31 | |
32 | |
33 namespace Orthanc | |
34 { | |
35 FindRequest::ParentSpecification& FindRequest::GetParentSpecification(ResourceType level) | |
36 { | |
37 if (!IsResourceLevelAboveOrEqual(level, level_) || | |
38 level == level_) | |
39 { | |
40 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
41 } | |
42 | |
43 switch (level) | |
44 { | |
45 case ResourceType_Patient: | |
46 return retrieveParentPatient_; | |
47 | |
48 case ResourceType_Study: | |
49 return retrieveParentStudy_; | |
50 | |
51 case ResourceType_Series: | |
52 return retrieveParentSeries_; | |
53 | |
54 default: | |
55 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
56 } | |
57 } | |
58 | |
59 | |
60 FindRequest::ChildrenSpecification& FindRequest::GetChildrenSpecification(ResourceType level) | |
61 { | |
62 if (!IsResourceLevelAboveOrEqual(level_, level) || | |
63 level == level_) | |
64 { | |
65 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
66 } | |
67 | |
68 switch (level) | |
69 { | |
70 case ResourceType_Study: | |
71 return retrieveChildrenStudies_; | |
72 | |
73 case ResourceType_Series: | |
74 return retrieveChildrenSeries_; | |
75 | |
76 case ResourceType_Instance: | |
77 return retrieveChildrenInstances_; | |
78 | |
79 default: | |
80 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
81 } | |
82 } | |
83 | |
84 | |
85 FindRequest::FindRequest(ResourceType level) : | |
86 level_(level), | |
87 hasLimits_(false), | |
88 limitsSince_(0), | |
89 limitsCount_(0), | |
90 labelsConstraint_(LabelsConstraint_All), | |
91 retrieveMainDicomTags_(false), | |
92 retrieveMetadata_(false), | |
93 retrieveLabels_(false), | |
94 retrieveAttachments_(false), | |
95 retrieveParentIdentifier_(false), | |
96 retrieveOneInstanceMetadataAndAttachments_(false) | |
97 { | |
98 } | |
99 | |
100 | |
101 FindRequest::~FindRequest() | |
102 { | |
103 | |
104 for (std::deque<Ordering*>::iterator it = ordering_.begin(); it != ordering_.end(); ++it) | |
105 { | |
106 assert(*it != NULL); | |
107 delete *it; | |
108 } | |
109 } | |
110 | |
111 | |
112 void FindRequest::SetOrthancId(ResourceType level, | |
113 const std::string& id) | |
114 { | |
115 switch (level) | |
116 { | |
117 case ResourceType_Patient: | |
118 SetOrthancPatientId(id); | |
119 break; | |
120 | |
121 case ResourceType_Study: | |
122 SetOrthancStudyId(id); | |
123 break; | |
124 | |
125 case ResourceType_Series: | |
126 SetOrthancSeriesId(id); | |
127 break; | |
128 | |
129 case ResourceType_Instance: | |
130 SetOrthancInstanceId(id); | |
131 break; | |
132 | |
133 default: | |
134 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
135 } | |
136 } | |
137 | |
138 | |
139 void FindRequest::SetOrthancPatientId(const std::string& id) | |
140 { | |
141 orthancIdentifiers_.SetPatientId(id); | |
142 } | |
143 | |
144 | |
145 void FindRequest::SetOrthancStudyId(const std::string& id) | |
146 { | |
147 if (level_ == ResourceType_Patient) | |
148 { | |
149 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
150 } | |
151 else | |
152 { | |
153 orthancIdentifiers_.SetStudyId(id); | |
154 } | |
155 } | |
156 | |
157 | |
158 void FindRequest::SetOrthancSeriesId(const std::string& id) | |
159 { | |
160 if (level_ == ResourceType_Patient || | |
161 level_ == ResourceType_Study) | |
162 { | |
163 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
164 } | |
165 else | |
166 { | |
167 orthancIdentifiers_.SetSeriesId(id); | |
168 } | |
169 } | |
170 | |
171 | |
172 void FindRequest::SetOrthancInstanceId(const std::string& id) | |
173 { | |
174 if (level_ == ResourceType_Patient || | |
175 level_ == ResourceType_Study || | |
176 level_ == ResourceType_Series) | |
177 { | |
178 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
179 } | |
180 else | |
181 { | |
182 orthancIdentifiers_.SetInstanceId(id); | |
183 } | |
184 } | |
185 | |
186 | |
187 void FindRequest::SetLimits(uint64_t since, | |
188 uint64_t count) | |
189 { | |
190 hasLimits_ = true; | |
191 limitsSince_ = since; | |
192 limitsCount_ = count; | |
193 } | |
194 | |
195 | |
196 uint64_t FindRequest::GetLimitsSince() const | |
197 { | |
198 if (hasLimits_) | |
199 { | |
200 return limitsSince_; | |
201 } | |
202 else | |
203 { | |
204 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
205 } | |
206 } | |
207 | |
208 | |
209 uint64_t FindRequest::GetLimitsCount() const | |
210 { | |
211 if (hasLimits_) | |
212 { | |
213 return limitsCount_; | |
214 } | |
215 else | |
216 { | |
217 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
218 } | |
219 } | |
220 | |
221 | |
222 void FindRequest::AddOrdering(const DicomTag& tag, | |
223 OrderingDirection direction) | |
224 { | |
225 ordering_.push_back(new Ordering(Key(tag), direction)); | |
226 } | |
227 | |
228 | |
229 void FindRequest::AddOrdering(MetadataType metadataType, | |
230 OrderingDirection direction) | |
231 { | |
232 ordering_.push_back(new Ordering(Key(metadataType), direction)); | |
233 } | |
234 | |
235 | |
236 void FindRequest::SetRetrieveParentIdentifier(bool retrieve) | |
237 { | |
238 if (level_ == ResourceType_Patient) | |
239 { | |
240 throw OrthancException(ErrorCode_BadParameterType); | |
241 } | |
242 else | |
243 { | |
244 retrieveParentIdentifier_ = retrieve; | |
245 } | |
246 } | |
247 | |
248 | |
249 void FindRequest::SetRetrieveOneInstanceMetadataAndAttachments(bool retrieve) | |
250 { | |
251 if (level_ == ResourceType_Instance) | |
252 { | |
253 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
254 } | |
255 else | |
256 { | |
257 retrieveOneInstanceMetadataAndAttachments_ = retrieve; | |
258 } | |
259 } | |
260 | |
261 | |
262 bool FindRequest::IsRetrieveOneInstanceMetadataAndAttachments() const | |
263 { | |
264 if (level_ == ResourceType_Instance) | |
265 { | |
266 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
267 } | |
268 else | |
269 { | |
270 return retrieveOneInstanceMetadataAndAttachments_; | |
271 } | |
272 } | |
273 } |