comparison Framework/Plugins/OrthancCppDatabasePlugin.h @ 117:ca0ecd412988 OrthancMySQL-2.0

Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Feb 2019 16:03:17 +0100
parents eb08ec14fb04
children 260fc55f10cd 3424a54ca2ee
comparison
equal deleted inserted replaced
116:569e17419eae 117:ca0ecd412988
80 AllowedAnswers_Attachment, 80 AllowedAnswers_Attachment,
81 AllowedAnswers_Change, 81 AllowedAnswers_Change,
82 AllowedAnswers_DicomTag, 82 AllowedAnswers_DicomTag,
83 AllowedAnswers_ExportedResource, 83 AllowedAnswers_ExportedResource,
84 AllowedAnswers_MatchingResource, 84 AllowedAnswers_MatchingResource,
85 AllowedAnswers_String 85 AllowedAnswers_String,
86 AllowedAnswers_Metadata
86 }; 87 };
87 88
88 OrthancPluginContext* context_; 89 OrthancPluginContext* context_;
89 OrthancPluginDatabaseContext* database_; 90 OrthancPluginDatabaseContext* database_;
90 AllowedAnswers allowedAnswers_; 91 AllowedAnswers allowedAnswers_;
532 int32_t metadata) = 0; 533 int32_t metadata) = 0;
533 534
534 virtual int64_t GetLastChangeIndex() = 0; 535 virtual int64_t GetLastChangeIndex() = 0;
535 536
536 virtual void TagMostRecentPatient(int64_t patientId) = 0; 537 virtual void TagMostRecentPatient(int64_t patientId) = 0;
538
539 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
540 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
541 // NB: "parentPublicId" must be cleared if the resource has no parent
542 virtual bool LookupResourceAndParent(int64_t& id,
543 OrthancPluginResourceType& type,
544 std::string& parentPublicId,
545 const char* publicId) = 0;
546 # endif
547 #endif
548
549 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
550 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
551 virtual void GetAllMetadata(std::map<int32_t, std::string>& result,
552 int64_t id) = 0;
553 # endif
554 #endif
537 }; 555 };
538 556
539 557
540 558
541 /** 559 /**
1646 backend->TagMostRecentPatient(patientId); 1664 backend->TagMostRecentPatient(patientId);
1647 return OrthancPluginErrorCode_Success; 1665 return OrthancPluginErrorCode_Success;
1648 } 1666 }
1649 ORTHANC_PLUGINS_DATABASE_CATCH 1667 ORTHANC_PLUGINS_DATABASE_CATCH
1650 } 1668 }
1669
1670
1671 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
1672 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
1673 // New primitive since Orthanc 1.5.4
1674 static OrthancPluginErrorCode GetAllMetadata(OrthancPluginDatabaseContext* context,
1675 void* payload,
1676 int64_t resourceId)
1677 {
1678 IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
1679 backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Metadata);
1680
1681 try
1682 {
1683 std::map<int32_t, std::string> result;
1684 backend->GetAllMetadata(result, resourceId);
1685
1686 for (std::map<int32_t, std::string>::const_iterator
1687 it = result.begin(); it != result.end(); ++it)
1688 {
1689 OrthancPluginDatabaseAnswerMetadata(backend->GetOutput().context_,
1690 backend->GetOutput().database_,
1691 resourceId, it->first, it->second.c_str());
1692 }
1693
1694 return OrthancPluginErrorCode_Success;
1695 }
1696 ORTHANC_PLUGINS_DATABASE_CATCH
1697 }
1698 # endif
1699 #endif
1700
1701
1702 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
1703 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
1704 // New primitive since Orthanc 1.5.4
1705 static OrthancPluginErrorCode LookupResourceAndParent(OrthancPluginDatabaseContext* context,
1706 uint8_t* isExisting,
1707 int64_t* id,
1708 OrthancPluginResourceType* type,
1709 void* payload,
1710 const char* publicId)
1711 {
1712 IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
1713 backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_String);
1714
1715 try
1716 {
1717 std::string parent;
1718 if (backend->LookupResourceAndParent(*id, *type, parent, publicId))
1719 {
1720 *isExisting = 1;
1721
1722 if (!parent.empty())
1723 {
1724 OrthancPluginDatabaseAnswerString(backend->GetOutput().context_,
1725 backend->GetOutput().database_,
1726 parent.c_str());
1727 }
1728 }
1729 else
1730 {
1731 *isExisting = 0;
1732 }
1733
1734 return OrthancPluginErrorCode_Success;
1735 }
1736 ORTHANC_PLUGINS_DATABASE_CATCH
1737 }
1738 # endif
1739 #endif
1651 1740
1652 1741
1653 public: 1742 public:
1654 /** 1743 /**
1655 * Register a custom database back-end written in C++. 1744 * Register a custom database back-end written in C++.
1739 1828
1740 if (backend.HasCreateInstance()) 1829 if (backend.HasCreateInstance())
1741 { 1830 {
1742 extensions.createInstance = CreateInstance; // Fast creation of resources 1831 extensions.createInstance = CreateInstance; // Fast creation of resources
1743 } 1832 }
1744 1833 #endif
1834
1835 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
1836 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
1837 // Optimizations brought by Orthanc 1.5.4
1838 extensions.lookupResourceAndParent = LookupResourceAndParent;
1839 extensions.getAllMetadata = GetAllMetadata;
1745 performanceWarning = false; 1840 performanceWarning = false;
1746 #endif 1841 # endif
1747 1842 #endif
1748 if (performanceWarning) 1843
1844 if (performanceWarning)
1749 { 1845 {
1750 char info[1024]; 1846 char info[1024];
1751 sprintf(info, 1847 sprintf(info,
1752 "Performance warning: The database index plugin was compiled " 1848 "Performance warning: The database index plugin was compiled "
1753 "against an old version of the Orthanc SDK (%d.%d.%d): " 1849 "against an old version of the Orthanc SDK (%d.%d.%d): "