Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp @ 5834:79a497908b04 attach-custom-data tip
merged find-refactoring -> attach-custom-data
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Wed, 09 Oct 2024 11:06:20 +0200 |
parents | a856763e5736 22623aa8e6fc |
children |
comparison
equal
deleted
inserted
replaced
5824:79ac3924eff8 | 5834:79a497908b04 |
---|---|
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 |
135 source.sop_instance_uid()); | 136 source.sop_instance_uid()); |
136 } | 137 } |
137 | 138 |
138 | 139 |
139 static void Convert(DatabasePluginMessages::DatabaseConstraint& target, | 140 static void Convert(DatabasePluginMessages::DatabaseConstraint& target, |
140 const DatabaseConstraint& source) | 141 const DatabaseDicomTagConstraint& source) |
141 { | 142 { |
142 target.set_level(Convert(source.GetLevel())); | 143 target.set_level(Convert(source.GetLevel())); |
143 target.set_tag_group(source.GetTag().GetGroup()); | 144 target.set_tag_group(source.GetTag().GetGroup()); |
144 target.set_tag_element(source.GetTag().GetElement()); | 145 target.set_tag_element(source.GetTag().GetElement()); |
145 target.set_is_identifier_tag(source.IsIdentifier()); | 146 target.set_is_identifier_tag(source.IsIdentifier()); |
177 default: | 178 default: |
178 throw OrthancException(ErrorCode_ParameterOutOfRange); | 179 throw OrthancException(ErrorCode_ParameterOutOfRange); |
179 } | 180 } |
180 } | 181 } |
181 | 182 |
183 | |
184 static void Convert(DatabasePluginMessages::DatabaseMetadataConstraint& target, | |
185 const DatabaseMetadataConstraint& source) | |
186 { | |
187 target.set_metadata(source.GetMetadata()); | |
188 target.set_is_case_sensitive(source.IsCaseSensitive()); | |
189 target.set_is_mandatory(source.IsMandatory()); | |
190 | |
191 target.mutable_values()->Reserve(source.GetValuesCount()); | |
192 for (size_t j = 0; j < source.GetValuesCount(); j++) | |
193 { | |
194 target.add_values(source.GetValue(j)); | |
195 } | |
196 | |
197 switch (source.GetConstraintType()) | |
198 { | |
199 case ConstraintType_Equal: | |
200 target.set_type(DatabasePluginMessages::CONSTRAINT_EQUAL); | |
201 break; | |
202 | |
203 case ConstraintType_SmallerOrEqual: | |
204 target.set_type(DatabasePluginMessages::CONSTRAINT_SMALLER_OR_EQUAL); | |
205 break; | |
206 | |
207 case ConstraintType_GreaterOrEqual: | |
208 target.set_type(DatabasePluginMessages::CONSTRAINT_GREATER_OR_EQUAL); | |
209 break; | |
210 | |
211 case ConstraintType_Wildcard: | |
212 target.set_type(DatabasePluginMessages::CONSTRAINT_WILDCARD); | |
213 break; | |
214 | |
215 case ConstraintType_List: | |
216 target.set_type(DatabasePluginMessages::CONSTRAINT_LIST); | |
217 break; | |
218 | |
219 default: | |
220 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
221 } | |
222 } | |
223 | |
224 | |
225 static void Convert(DatabasePluginMessages::Find_Request_Ordering& target, | |
226 const FindRequest::Ordering& source) | |
227 { | |
228 switch (source.GetKeyType()) | |
229 { | |
230 case FindRequest::KeyType_DicomTag: | |
231 { | |
232 ResourceType tagLevel; | |
233 DicomTagType tagType; | |
234 MainDicomTagsRegistry registry; | |
235 | |
236 registry.LookupTag(tagLevel, tagType, source.GetDicomTag()); | |
237 | |
238 target.set_key_type(DatabasePluginMessages::ORDERING_KEY_TYPE_DICOM_TAG); | |
239 target.set_tag_group(source.GetDicomTag().GetGroup()); | |
240 target.set_tag_element(source.GetDicomTag().GetElement()); | |
241 target.set_is_identifier_tag(tagType == DicomTagType_Identifier); | |
242 target.set_tag_level(Convert(tagLevel)); | |
243 | |
244 }; break; | |
245 | |
246 case FindRequest::KeyType_Metadata: | |
247 target.set_key_type(DatabasePluginMessages::ORDERING_KEY_TYPE_METADATA); | |
248 target.set_metadata(source.GetMetadataType()); | |
249 | |
250 break; | |
251 | |
252 default: | |
253 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
254 } | |
255 | |
256 switch (source.GetDirection()) | |
257 { | |
258 case FindRequest::OrderingDirection_Ascending: | |
259 target.set_direction(DatabasePluginMessages::ORDERING_DIRECTION_ASC); | |
260 break; | |
261 | |
262 case FindRequest::OrderingDirection_Descending: | |
263 target.set_direction(DatabasePluginMessages::ORDERING_DIRECTION_DESC); | |
264 | |
265 break; | |
266 | |
267 default: | |
268 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
269 } | |
270 } | |
182 | 271 |
183 static DatabasePluginMessages::LabelsConstraintType Convert(LabelsConstraint constraint) | 272 static DatabasePluginMessages::LabelsConstraintType Convert(LabelsConstraint constraint) |
184 { | 273 { |
185 switch (constraint) | 274 switch (constraint) |
186 { | 275 { |
1137 } | 1226 } |
1138 | 1227 |
1139 | 1228 |
1140 virtual void ApplyLookupResources(std::list<std::string>& resourcesId, | 1229 virtual void ApplyLookupResources(std::list<std::string>& resourcesId, |
1141 std::list<std::string>* instancesId, // Can be NULL if not needed | 1230 std::list<std::string>* instancesId, // Can be NULL if not needed |
1142 const DatabaseConstraints& lookup, | 1231 const DatabaseDicomTagConstraints& lookup, |
1143 ResourceType queryLevel, | 1232 ResourceType queryLevel, |
1144 const std::set<std::string>& labels, | 1233 const std::set<std::string>& labels, |
1145 LabelsConstraint labelsConstraint, | 1234 LabelsConstraint labelsConstraint, |
1146 uint32_t limit) ORTHANC_OVERRIDE | 1235 uint32_t limit) ORTHANC_OVERRIDE |
1147 { | 1236 { |
1420 for (size_t i = 0; i < request.GetDicomTagConstraints().GetSize(); i++) | 1509 for (size_t i = 0; i < request.GetDicomTagConstraints().GetSize(); i++) |
1421 { | 1510 { |
1422 Convert(*dbRequest.mutable_find()->add_dicom_tag_constraints(), request.GetDicomTagConstraints().GetConstraint(i)); | 1511 Convert(*dbRequest.mutable_find()->add_dicom_tag_constraints(), request.GetDicomTagConstraints().GetConstraint(i)); |
1423 } | 1512 } |
1424 | 1513 |
1514 for (std::deque<DatabaseMetadataConstraint*>::const_iterator it = request.GetMetadataConstraint().begin(); it != request.GetMetadataConstraint().end(); ++it) | |
1515 { | |
1516 Convert(*dbRequest.mutable_find()->add_metadata_constraints(), *(*it)); | |
1517 } | |
1518 | |
1519 for (std::deque<FindRequest::Ordering*>::const_iterator it = request.GetOrdering().begin(); it != request.GetOrdering().end(); ++it) | |
1520 { | |
1521 Convert(*dbRequest.mutable_find()->add_ordering(), *(*it)); | |
1522 } | |
1523 | |
1425 if (request.HasLimits()) | 1524 if (request.HasLimits()) |
1426 { | 1525 { |
1427 dbRequest.mutable_find()->mutable_limits()->set_since(request.GetLimitsSince()); | 1526 dbRequest.mutable_find()->mutable_limits()->set_since(request.GetLimitsSince()); |
1428 dbRequest.mutable_find()->mutable_limits()->set_count(request.GetLimitsCount()); | 1527 dbRequest.mutable_find()->mutable_limits()->set_count(request.GetLimitsCount()); |
1429 } | 1528 } |
1432 { | 1531 { |
1433 dbRequest.mutable_find()->add_labels(*it); | 1532 dbRequest.mutable_find()->add_labels(*it); |
1434 } | 1533 } |
1435 | 1534 |
1436 dbRequest.mutable_find()->set_labels_constraint(Convert(request.GetLabelsConstraint())); | 1535 dbRequest.mutable_find()->set_labels_constraint(Convert(request.GetLabelsConstraint())); |
1437 | |
1438 // TODO-FIND: ordering_ | |
1439 // TODO-FIND: metadataConstraints__ | |
1440 | 1536 |
1441 dbRequest.mutable_find()->set_retrieve_main_dicom_tags(request.IsRetrieveMainDicomTags()); | 1537 dbRequest.mutable_find()->set_retrieve_main_dicom_tags(request.IsRetrieveMainDicomTags()); |
1442 dbRequest.mutable_find()->set_retrieve_metadata(request.IsRetrieveMetadata()); | 1538 dbRequest.mutable_find()->set_retrieve_metadata(request.IsRetrieveMetadata()); |
1443 dbRequest.mutable_find()->set_retrieve_labels(request.IsRetrieveLabels()); | 1539 dbRequest.mutable_find()->set_retrieve_labels(request.IsRetrieveLabels()); |
1444 dbRequest.mutable_find()->set_retrieve_attachments(request.IsRetrieveAttachments()); | 1540 dbRequest.mutable_find()->set_retrieve_attachments(request.IsRetrieveAttachments()); |