Mercurial > hg > orthanc-databases
comparison Framework/Plugins/OrthancCppDatabasePlugin.h @ 69:19764fc60ade db-changes
compatibility with Orthanc SDDK 0.9.5
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 03 Jan 2019 10:07:27 +0100 |
parents | 714c5d2bee76 |
children | e6c13ddd26d9 |
comparison
equal
deleted
inserted
replaced
68:babc1e0eb7f2 | 69:19764fc60ade |
---|---|
30 | 30 |
31 #if HAS_ORTHANC_EXCEPTION != 1 | 31 #if HAS_ORTHANC_EXCEPTION != 1 |
32 # error HAS_ORTHANC_EXCEPTION must be set to 1 | 32 # error HAS_ORTHANC_EXCEPTION must be set to 1 |
33 #endif | 33 #endif |
34 | 34 |
35 | 35 #if ORTHANC_ENABLE_PLUGINS != 1 |
36 #include <orthanc/OrthancCDatabasePlugin.h> | 36 # error ORTHANC_ENABLE_PLUGINS must be set to 1 |
37 #endif | |
38 | |
39 | |
37 #include <Core/OrthancException.h> | 40 #include <Core/OrthancException.h> |
41 #include <OrthancServer/Search/DatabaseConstraint.h> | |
42 | |
38 | 43 |
39 | 44 |
40 #define ORTHANC_PLUGINS_DATABASE_CATCH \ | 45 #define ORTHANC_PLUGINS_DATABASE_CATCH \ |
41 catch (::Orthanc::OrthancException& e) \ | 46 catch (::Orthanc::OrthancException& e) \ |
42 { \ | 47 { \ |
73 AllowedAnswers_All, | 78 AllowedAnswers_All, |
74 AllowedAnswers_None, | 79 AllowedAnswers_None, |
75 AllowedAnswers_Attachment, | 80 AllowedAnswers_Attachment, |
76 AllowedAnswers_Change, | 81 AllowedAnswers_Change, |
77 AllowedAnswers_DicomTag, | 82 AllowedAnswers_DicomTag, |
78 AllowedAnswers_ExportedResource | 83 AllowedAnswers_ExportedResource, |
84 AllowedAnswers_MatchingResource | |
79 }; | 85 }; |
80 | 86 |
81 OrthancPluginContext* context_; | 87 OrthancPluginContext* context_; |
82 OrthancPluginDatabaseContext* database_; | 88 OrthancPluginDatabaseContext* database_; |
83 AllowedAnswers allowedAnswers_; | 89 AllowedAnswers allowedAnswers_; |
241 exported.seriesInstanceUid = seriesInstanceUid.c_str(); | 247 exported.seriesInstanceUid = seriesInstanceUid.c_str(); |
242 exported.sopInstanceUid = sopInstanceUid.c_str(); | 248 exported.sopInstanceUid = sopInstanceUid.c_str(); |
243 | 249 |
244 OrthancPluginDatabaseAnswerExportedResource(context_, database_, &exported); | 250 OrthancPluginDatabaseAnswerExportedResource(context_, database_, &exported); |
245 } | 251 } |
252 | |
253 | |
254 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 | |
255 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 2) | |
256 void AnswerMatchingResource(const std::string& resourceId) | |
257 { | |
258 if (allowedAnswers_ != AllowedAnswers_All && | |
259 allowedAnswers_ != AllowedAnswers_MatchingResource) | |
260 { | |
261 throw std::runtime_error("Cannot answer with an exported resource in the current state"); | |
262 } | |
263 | |
264 OrthancPluginMatchingResource match; | |
265 match.resourceId = resourceId.c_str(); | |
266 match.someInstanceId = NULL; | |
267 | |
268 OrthancPluginDatabaseAnswerMatchingResource(context_, database_, &match); | |
269 } | |
270 | |
271 | |
272 void AnswerMatchingResource(const std::string& resourceId, | |
273 const std::string& someInstanceId) | |
274 { | |
275 if (allowedAnswers_ != AllowedAnswers_All && | |
276 allowedAnswers_ != AllowedAnswers_MatchingResource) | |
277 { | |
278 throw std::runtime_error("Cannot answer with an exported resource in the current state"); | |
279 } | |
280 | |
281 OrthancPluginMatchingResource match; | |
282 match.resourceId = resourceId.c_str(); | |
283 match.someInstanceId = someInstanceId.c_str(); | |
284 | |
285 OrthancPluginDatabaseAnswerMatchingResource(context_, database_, &match); | |
286 } | |
287 # endif | |
288 #endif | |
246 }; | 289 }; |
247 | 290 |
248 | 291 |
249 /** | 292 /** |
250 * @ingroup Callbacks | 293 * @ingroup Callbacks |
445 **/ | 488 **/ |
446 virtual void UpgradeDatabase(uint32_t targetVersion, | 489 virtual void UpgradeDatabase(uint32_t targetVersion, |
447 OrthancPluginStorageArea* storageArea) = 0; | 490 OrthancPluginStorageArea* storageArea) = 0; |
448 | 491 |
449 virtual void ClearMainDicomTags(int64_t internalId) = 0; | 492 virtual void ClearMainDicomTags(int64_t internalId) = 0; |
493 | |
494 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
495 virtual void LookupResources(const std::vector<Orthanc::DatabaseConstraint>& lookup, | |
496 OrthancPluginResourceType queryLevel, | |
497 uint32_t limit, | |
498 bool requestSomeInstance) = 0; | |
499 #endif | |
450 }; | 500 }; |
451 | 501 |
452 | 502 |
453 | 503 |
454 /** | 504 /** |
1418 backend->ClearMainDicomTags(internalId); | 1468 backend->ClearMainDicomTags(internalId); |
1419 return OrthancPluginErrorCode_Success; | 1469 return OrthancPluginErrorCode_Success; |
1420 } | 1470 } |
1421 ORTHANC_PLUGINS_DATABASE_CATCH | 1471 ORTHANC_PLUGINS_DATABASE_CATCH |
1422 } | 1472 } |
1473 | |
1474 | |
1475 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
1476 /* Use GetOutput().AnswerResource() */ | |
1477 static OrthancPluginErrorCode LookupResources( | |
1478 OrthancPluginDatabaseContext* context, | |
1479 void* payload, | |
1480 uint32_t constraintsCount, | |
1481 const OrthancPluginDatabaseConstraint* constraints, | |
1482 OrthancPluginResourceType queryLevel, | |
1483 uint32_t limit, | |
1484 uint8_t requestSomeInstance) | |
1485 { | |
1486 IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); | |
1487 backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_MatchingResource); | |
1488 | |
1489 try | |
1490 { | |
1491 std::vector<Orthanc::DatabaseConstraint> lookup; | |
1492 lookup.reserve(constraintsCount); | |
1493 | |
1494 for (uint32_t i = 0; i < constraintsCount; i++) | |
1495 { | |
1496 lookup.push_back(Orthanc::DatabaseConstraint(constraints[i])); | |
1497 } | |
1498 | |
1499 backend->LookupResources(lookup, queryLevel, limit, (requestSomeInstance != 0)); | |
1500 return OrthancPluginErrorCode_Success; | |
1501 } | |
1502 ORTHANC_PLUGINS_DATABASE_CATCH | |
1503 } | |
1504 #endif | |
1423 | 1505 |
1424 | 1506 |
1425 public: | 1507 public: |
1426 /** | 1508 /** |
1427 * Register a custom database back-end written in C++. | 1509 * Register a custom database back-end written in C++. |
1466 params.listAvailableAttachments = ListAvailableAttachments; | 1548 params.listAvailableAttachments = ListAvailableAttachments; |
1467 params.logChange = LogChange; | 1549 params.logChange = LogChange; |
1468 params.logExportedResource = LogExportedResource; | 1550 params.logExportedResource = LogExportedResource; |
1469 params.lookupAttachment = LookupAttachment; | 1551 params.lookupAttachment = LookupAttachment; |
1470 params.lookupGlobalProperty = LookupGlobalProperty; | 1552 params.lookupGlobalProperty = LookupGlobalProperty; |
1471 params.lookupIdentifier = NULL; // Unused starting with Orthanc 0.9.5 (db v6) | 1553 params.lookupIdentifier = NULL; // Unused starting with Orthanc 0.9.5 (db v6) |
1472 params.lookupIdentifier2 = NULL; // Unused starting with Orthanc 0.9.5 (db v6) | 1554 params.lookupIdentifier2 = NULL; // Unused starting with Orthanc 0.9.5 (db v6) |
1473 params.lookupMetadata = LookupMetadata; | 1555 params.lookupMetadata = LookupMetadata; |
1474 params.lookupParent = LookupParent; | 1556 params.lookupParent = LookupParent; |
1475 params.lookupResource = LookupResource; | 1557 params.lookupResource = LookupResource; |
1476 params.selectPatientToRecycle = SelectPatientToRecycle; | 1558 params.selectPatientToRecycle = SelectPatientToRecycle; |
1488 | 1570 |
1489 extensions.getAllPublicIdsWithLimit = GetAllPublicIdsWithLimit; | 1571 extensions.getAllPublicIdsWithLimit = GetAllPublicIdsWithLimit; |
1490 extensions.getDatabaseVersion = GetDatabaseVersion; | 1572 extensions.getDatabaseVersion = GetDatabaseVersion; |
1491 extensions.upgradeDatabase = UpgradeDatabase; | 1573 extensions.upgradeDatabase = UpgradeDatabase; |
1492 extensions.clearMainDicomTags = ClearMainDicomTags; | 1574 extensions.clearMainDicomTags = ClearMainDicomTags; |
1493 extensions.getAllInternalIds = GetAllInternalIds; // New in Orthanc 0.9.5 (db v6) | 1575 extensions.getAllInternalIds = GetAllInternalIds; // New in Orthanc 0.9.5 (db v6) |
1494 extensions.lookupIdentifier3 = LookupIdentifier3; // New in Orthanc 0.9.5 (db v6) | 1576 extensions.lookupIdentifier3 = LookupIdentifier3; // New in Orthanc 0.9.5 (db v6) |
1495 | 1577 |
1496 bool performanceWarning = true; | 1578 bool performanceWarning = true; |
1497 | 1579 |
1498 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 | 1580 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
1499 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 4, 0) | 1581 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 4, 0) |
1500 extensions.lookupIdentifierRange = LookupIdentifierRange; // New in Orthanc 1.4.0 | 1582 extensions.lookupIdentifierRange = LookupIdentifierRange; // New in Orthanc 1.4.0 |
1501 performanceWarning = false; | |
1502 # endif | 1583 # endif |
1503 #endif | 1584 #endif |
1585 | |
1586 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | |
1587 extensions.lookupResources = LookupResources; // New in Orthanc 1.5.2 (fast lookup) | |
1588 performanceWarning = false; | |
1589 #endif | |
1504 | 1590 |
1505 if (performanceWarning) | 1591 if (performanceWarning) |
1506 { | 1592 { |
1507 char info[1024]; | 1593 char info[1024]; |
1508 sprintf(info, | 1594 sprintf(info, |
1509 "Performance warning: The database index plugin was compiled " | 1595 "Performance warning: The database index plugin was compiled " |
1510 "against an old version of the Orthanc SDK (%d.%d.%d): " | 1596 "against an old version of the Orthanc SDK (%d.%d.%d): " |
1511 "Consider upgrading to version 1.4.0 of the Orthanc SDK", | 1597 "Consider upgrading to version 1.5.2 of the Orthanc SDK", |
1512 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | 1598 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
1513 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | 1599 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
1514 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | 1600 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
1515 | 1601 |
1516 OrthancPluginLogWarning(context, info); | 1602 OrthancPluginLogWarning(context, info); |