Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp @ 5831:22623aa8e6fc find-refactoring tip
DB SDK: ordering + metadata constraints
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 08 Oct 2024 17:53:06 +0200 |
parents | 7030fa489669 |
children |
comparison
equal
deleted
inserted
replaced
5830:40f236ad829c | 5831:22623aa8e6fc |
---|---|
34 #include "../../Sources/Database/Compatibility/GenericFind.h" | 34 #include "../../Sources/Database/Compatibility/GenericFind.h" |
35 #include "../../Sources/Database/ResourcesContent.h" | 35 #include "../../Sources/Database/ResourcesContent.h" |
36 #include "../../Sources/Database/VoidDatabaseListener.h" | 36 #include "../../Sources/Database/VoidDatabaseListener.h" |
37 #include "../../Sources/ServerToolbox.h" | 37 #include "../../Sources/ServerToolbox.h" |
38 #include "PluginsEnumerations.h" | 38 #include "PluginsEnumerations.h" |
39 #include "../../Sources/Database/MainDicomTagsRegistry.h" | |
39 | 40 |
40 #include "OrthancDatabasePlugin.pb.h" // Auto-generated file | 41 #include "OrthancDatabasePlugin.pb.h" // Auto-generated file |
41 | 42 |
42 #include <cassert> | 43 #include <cassert> |
43 | 44 |
176 default: | 177 default: |
177 throw OrthancException(ErrorCode_ParameterOutOfRange); | 178 throw OrthancException(ErrorCode_ParameterOutOfRange); |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
182 | |
183 static void Convert(DatabasePluginMessages::DatabaseMetadataConstraint& target, | |
184 const DatabaseMetadataConstraint& source) | |
185 { | |
186 target.set_metadata(source.GetMetadata()); | |
187 target.set_is_case_sensitive(source.IsCaseSensitive()); | |
188 target.set_is_mandatory(source.IsMandatory()); | |
189 | |
190 target.mutable_values()->Reserve(source.GetValuesCount()); | |
191 for (size_t j = 0; j < source.GetValuesCount(); j++) | |
192 { | |
193 target.add_values(source.GetValue(j)); | |
194 } | |
195 | |
196 switch (source.GetConstraintType()) | |
197 { | |
198 case ConstraintType_Equal: | |
199 target.set_type(DatabasePluginMessages::CONSTRAINT_EQUAL); | |
200 break; | |
201 | |
202 case ConstraintType_SmallerOrEqual: | |
203 target.set_type(DatabasePluginMessages::CONSTRAINT_SMALLER_OR_EQUAL); | |
204 break; | |
205 | |
206 case ConstraintType_GreaterOrEqual: | |
207 target.set_type(DatabasePluginMessages::CONSTRAINT_GREATER_OR_EQUAL); | |
208 break; | |
209 | |
210 case ConstraintType_Wildcard: | |
211 target.set_type(DatabasePluginMessages::CONSTRAINT_WILDCARD); | |
212 break; | |
213 | |
214 case ConstraintType_List: | |
215 target.set_type(DatabasePluginMessages::CONSTRAINT_LIST); | |
216 break; | |
217 | |
218 default: | |
219 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
220 } | |
221 } | |
222 | |
223 | |
224 static void Convert(DatabasePluginMessages::Find_Request_Ordering& target, | |
225 const FindRequest::Ordering& source) | |
226 { | |
227 switch (source.GetKeyType()) | |
228 { | |
229 case FindRequest::KeyType_DicomTag: | |
230 { | |
231 ResourceType tagLevel; | |
232 DicomTagType tagType; | |
233 MainDicomTagsRegistry registry; | |
234 | |
235 registry.LookupTag(tagLevel, tagType, source.GetDicomTag()); | |
236 | |
237 target.set_key_type(DatabasePluginMessages::ORDERING_KEY_TYPE_DICOM_TAG); | |
238 target.set_tag_group(source.GetDicomTag().GetGroup()); | |
239 target.set_tag_element(source.GetDicomTag().GetElement()); | |
240 target.set_is_identifier_tag(tagType == DicomTagType_Identifier); | |
241 target.set_tag_level(Convert(tagLevel)); | |
242 | |
243 }; break; | |
244 | |
245 case FindRequest::KeyType_Metadata: | |
246 target.set_key_type(DatabasePluginMessages::ORDERING_KEY_TYPE_METADATA); | |
247 target.set_metadata(source.GetMetadataType()); | |
248 | |
249 break; | |
250 | |
251 default: | |
252 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
253 } | |
254 | |
255 switch (source.GetDirection()) | |
256 { | |
257 case FindRequest::OrderingDirection_Ascending: | |
258 target.set_direction(DatabasePluginMessages::ORDERING_DIRECTION_ASC); | |
259 break; | |
260 | |
261 case FindRequest::OrderingDirection_Descending: | |
262 target.set_direction(DatabasePluginMessages::ORDERING_DIRECTION_DESC); | |
263 | |
264 break; | |
265 | |
266 default: | |
267 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
268 } | |
269 } | |
181 | 270 |
182 static DatabasePluginMessages::LabelsConstraintType Convert(LabelsConstraint constraint) | 271 static DatabasePluginMessages::LabelsConstraintType Convert(LabelsConstraint constraint) |
183 { | 272 { |
184 switch (constraint) | 273 switch (constraint) |
185 { | 274 { |
1418 for (size_t i = 0; i < request.GetDicomTagConstraints().GetSize(); i++) | 1507 for (size_t i = 0; i < request.GetDicomTagConstraints().GetSize(); i++) |
1419 { | 1508 { |
1420 Convert(*dbRequest.mutable_find()->add_dicom_tag_constraints(), request.GetDicomTagConstraints().GetConstraint(i)); | 1509 Convert(*dbRequest.mutable_find()->add_dicom_tag_constraints(), request.GetDicomTagConstraints().GetConstraint(i)); |
1421 } | 1510 } |
1422 | 1511 |
1512 for (std::deque<DatabaseMetadataConstraint*>::const_iterator it = request.GetMetadataConstraint().begin(); it != request.GetMetadataConstraint().end(); ++it) | |
1513 { | |
1514 Convert(*dbRequest.mutable_find()->add_metadata_constraints(), *(*it)); | |
1515 } | |
1516 | |
1517 for (std::deque<FindRequest::Ordering*>::const_iterator it = request.GetOrdering().begin(); it != request.GetOrdering().end(); ++it) | |
1518 { | |
1519 Convert(*dbRequest.mutable_find()->add_ordering(), *(*it)); | |
1520 } | |
1521 | |
1423 if (request.HasLimits()) | 1522 if (request.HasLimits()) |
1424 { | 1523 { |
1425 dbRequest.mutable_find()->mutable_limits()->set_since(request.GetLimitsSince()); | 1524 dbRequest.mutable_find()->mutable_limits()->set_since(request.GetLimitsSince()); |
1426 dbRequest.mutable_find()->mutable_limits()->set_count(request.GetLimitsCount()); | 1525 dbRequest.mutable_find()->mutable_limits()->set_count(request.GetLimitsCount()); |
1427 } | 1526 } |
1430 { | 1529 { |
1431 dbRequest.mutable_find()->add_labels(*it); | 1530 dbRequest.mutable_find()->add_labels(*it); |
1432 } | 1531 } |
1433 | 1532 |
1434 dbRequest.mutable_find()->set_labels_constraint(Convert(request.GetLabelsConstraint())); | 1533 dbRequest.mutable_find()->set_labels_constraint(Convert(request.GetLabelsConstraint())); |
1435 | |
1436 // TODO-FIND: ordering_ | |
1437 // TODO-FIND: metadataConstraints__ | |
1438 | 1534 |
1439 dbRequest.mutable_find()->set_retrieve_main_dicom_tags(request.IsRetrieveMainDicomTags()); | 1535 dbRequest.mutable_find()->set_retrieve_main_dicom_tags(request.IsRetrieveMainDicomTags()); |
1440 dbRequest.mutable_find()->set_retrieve_metadata(request.IsRetrieveMetadata()); | 1536 dbRequest.mutable_find()->set_retrieve_metadata(request.IsRetrieveMetadata()); |
1441 dbRequest.mutable_find()->set_retrieve_labels(request.IsRetrieveLabels()); | 1537 dbRequest.mutable_find()->set_retrieve_labels(request.IsRetrieveLabels()); |
1442 dbRequest.mutable_find()->set_retrieve_attachments(request.IsRetrieveAttachments()); | 1538 dbRequest.mutable_find()->set_retrieve_attachments(request.IsRetrieveAttachments()); |