Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPluginDatabase.cpp @ 3189:6f89d22a6ec0
New extensions in the database SDK: LookupResourceAndParent and GetAllMetadata
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 04 Feb 2019 15:47:56 +0100 |
parents | 4bbadcd03966 |
children | f451e93cd58b |
comparison
equal
deleted
inserted
replaced
3188:70356580e310 | 3189:6f89d22a6ec0 |
---|---|
133 answerChanges_ = NULL; | 133 answerChanges_ = NULL; |
134 answerExportedResources_ = NULL; | 134 answerExportedResources_ = NULL; |
135 answerDone_ = NULL; | 135 answerDone_ = NULL; |
136 answerMatchingResources_ = NULL; | 136 answerMatchingResources_ = NULL; |
137 answerMatchingInstances_ = NULL; | 137 answerMatchingInstances_ = NULL; |
138 answerMetadata_ = NULL; | |
138 } | 139 } |
139 | 140 |
140 | 141 |
141 void OrthancPluginDatabase::ForwardAnswers(std::list<int64_t>& target) | 142 void OrthancPluginDatabase::ForwardAnswers(std::list<int64_t>& target) |
142 { | 143 { |
388 | 389 |
389 | 390 |
390 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target, | 391 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target, |
391 int64_t id) | 392 int64_t id) |
392 { | 393 { |
393 // TODO - Add primitive in SDK | 394 if (extensions_.getAllMetadata == NULL) |
394 | 395 { |
395 target.clear(); | 396 // Fallback implementation if extension is missing |
396 | 397 target.clear(); |
397 ResetAnswers(); | 398 |
398 CheckSuccess(backend_.listAvailableMetadata(GetContext(), payload_, id)); | 399 ResetAnswers(); |
399 | 400 CheckSuccess(backend_.listAvailableMetadata(GetContext(), payload_, id)); |
400 if (type_ != _OrthancPluginDatabaseAnswerType_None && | 401 |
401 type_ != _OrthancPluginDatabaseAnswerType_Int32) | 402 if (type_ != _OrthancPluginDatabaseAnswerType_None && |
402 { | 403 type_ != _OrthancPluginDatabaseAnswerType_Int32) |
403 throw OrthancException(ErrorCode_DatabasePlugin); | 404 { |
404 } | 405 throw OrthancException(ErrorCode_DatabasePlugin); |
405 | 406 } |
406 target.clear(); | 407 |
407 | 408 target.clear(); |
408 if (type_ == _OrthancPluginDatabaseAnswerType_Int32) | 409 |
409 { | 410 if (type_ == _OrthancPluginDatabaseAnswerType_Int32) |
410 for (std::list<int32_t>::const_iterator | 411 { |
411 it = answerInt32_.begin(); it != answerInt32_.end(); ++it) | 412 for (std::list<int32_t>::const_iterator |
412 { | 413 it = answerInt32_.begin(); it != answerInt32_.end(); ++it) |
413 MetadataType type = static_cast<MetadataType>(*it); | 414 { |
414 | 415 MetadataType type = static_cast<MetadataType>(*it); |
415 std::string value; | 416 |
416 if (LookupMetadata(value, id, type)) | 417 std::string value; |
417 { | 418 if (LookupMetadata(value, id, type)) |
418 target[type] = value; | 419 { |
419 } | 420 target[type] = value; |
421 } | |
422 } | |
423 } | |
424 } | |
425 else | |
426 { | |
427 ResetAnswers(); | |
428 | |
429 answerMetadata_ = ⌖ | |
430 target.clear(); | |
431 | |
432 CheckSuccess(extensions_.getAllMetadata(GetContext(), payload_, id)); | |
433 | |
434 if (type_ != _OrthancPluginDatabaseAnswerType_None && | |
435 type_ != _OrthancPluginDatabaseAnswerType_Metadata) | |
436 { | |
437 throw OrthancException(ErrorCode_DatabasePlugin); | |
420 } | 438 } |
421 } | 439 } |
422 } | 440 } |
423 | 441 |
424 | 442 |
1004 if (answerMatchingInstances_ != NULL) | 1022 if (answerMatchingInstances_ != NULL) |
1005 { | 1023 { |
1006 answerMatchingInstances_->clear(); | 1024 answerMatchingInstances_->clear(); |
1007 } | 1025 } |
1008 | 1026 |
1027 break; | |
1028 | |
1029 case _OrthancPluginDatabaseAnswerType_Metadata: | |
1030 assert(answerMetadata_ != NULL); | |
1031 answerMetadata_->clear(); | |
1009 break; | 1032 break; |
1010 | 1033 |
1011 default: | 1034 default: |
1012 throw OrthancException(ErrorCode_DatabasePlugin, | 1035 throw OrthancException(ErrorCode_DatabasePlugin, |
1013 "Unhandled type of answer for custom index plugin: " + | 1036 "Unhandled type of answer for custom index plugin: " + |
1161 } | 1184 } |
1162 | 1185 |
1163 break; | 1186 break; |
1164 } | 1187 } |
1165 | 1188 |
1189 case _OrthancPluginDatabaseAnswerType_Metadata: | |
1190 { | |
1191 const OrthancPluginResourcesContentMetadata& metadata = | |
1192 *reinterpret_cast<const OrthancPluginResourcesContentMetadata*>(answer.valueGeneric); | |
1193 | |
1194 MetadataType type = static_cast<MetadataType>(metadata.metadata); | |
1195 | |
1196 if (metadata.value == NULL) | |
1197 { | |
1198 throw OrthancException(ErrorCode_DatabasePlugin); | |
1199 } | |
1200 | |
1201 assert(answerMetadata_ != NULL && | |
1202 answerMetadata_->find(type) == answerMetadata_->end()); | |
1203 (*answerMetadata_) [type] = metadata.value; | |
1204 break; | |
1205 } | |
1206 | |
1166 default: | 1207 default: |
1167 throw OrthancException(ErrorCode_DatabasePlugin, | 1208 throw OrthancException(ErrorCode_DatabasePlugin, |
1168 "Unhandled type of answer for custom index plugin: " + | 1209 "Unhandled type of answer for custom index plugin: " + |
1169 boost::lexical_cast<std::string>(answer.type)); | 1210 boost::lexical_cast<std::string>(answer.type)); |
1170 } | 1211 } |
1424 bool OrthancPluginDatabase::LookupResourceAndParent(int64_t& id, | 1465 bool OrthancPluginDatabase::LookupResourceAndParent(int64_t& id, |
1425 ResourceType& type, | 1466 ResourceType& type, |
1426 std::string& parentPublicId, | 1467 std::string& parentPublicId, |
1427 const std::string& publicId) | 1468 const std::string& publicId) |
1428 { | 1469 { |
1429 // TODO - Add primitive in SDK | 1470 if (extensions_.lookupResourceAndParent == NULL) |
1430 return ILookupResourceAndParent::Apply(*this, id, type, parentPublicId, publicId); | 1471 { |
1472 return ILookupResourceAndParent::Apply(*this, id, type, parentPublicId, publicId); | |
1473 } | |
1474 else | |
1475 { | |
1476 std::list<std::string> parent; | |
1477 | |
1478 uint8_t isExisting; | |
1479 OrthancPluginResourceType pluginType = OrthancPluginResourceType_Patient; | |
1480 | |
1481 ResetAnswers(); | |
1482 CheckSuccess(extensions_.lookupResourceAndParent | |
1483 (GetContext(), &isExisting, &id, &pluginType, payload_, publicId.c_str())); | |
1484 ForwardAnswers(parent); | |
1485 | |
1486 if (isExisting) | |
1487 { | |
1488 type = Plugins::Convert(pluginType); | |
1489 | |
1490 if (parent.empty()) | |
1491 { | |
1492 if (type != ResourceType_Patient) | |
1493 { | |
1494 throw OrthancException(ErrorCode_DatabasePlugin); | |
1495 } | |
1496 } | |
1497 else if (parent.size() == 1) | |
1498 { | |
1499 if ((type != ResourceType_Study && | |
1500 type != ResourceType_Series && | |
1501 type != ResourceType_Instance) || | |
1502 parent.front().empty()) | |
1503 { | |
1504 throw OrthancException(ErrorCode_DatabasePlugin); | |
1505 } | |
1506 | |
1507 parentPublicId = parent.front(); | |
1508 } | |
1509 else | |
1510 { | |
1511 throw OrthancException(ErrorCode_DatabasePlugin); | |
1512 } | |
1513 | |
1514 return true; | |
1515 } | |
1516 else | |
1517 { | |
1518 return false; | |
1519 } | |
1520 } | |
1431 } | 1521 } |
1432 } | 1522 } |