comparison Framework/Plugins/OrthancCppDatabasePlugin.h @ 119:260fc55f10cd OrthancMySQL-2.0

cancelling changesets 116 and 117 in OrthancMySQL-2.0 branch
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Feb 2019 16:32:45 +0100
parents ca0ecd412988
children
comparison
equal deleted inserted replaced
117:ca0ecd412988 119:260fc55f10cd
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
87 }; 86 };
88 87
89 OrthancPluginContext* context_; 88 OrthancPluginContext* context_;
90 OrthancPluginDatabaseContext* database_; 89 OrthancPluginDatabaseContext* database_;
91 AllowedAnswers allowedAnswers_; 90 AllowedAnswers allowedAnswers_;
533 int32_t metadata) = 0; 532 int32_t metadata) = 0;
534 533
535 virtual int64_t GetLastChangeIndex() = 0; 534 virtual int64_t GetLastChangeIndex() = 0;
536 535
537 virtual void TagMostRecentPatient(int64_t patientId) = 0; 536 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
555 }; 537 };
556 538
557 539
558 540
559 /** 541 /**
1664 backend->TagMostRecentPatient(patientId); 1646 backend->TagMostRecentPatient(patientId);
1665 return OrthancPluginErrorCode_Success; 1647 return OrthancPluginErrorCode_Success;
1666 } 1648 }
1667 ORTHANC_PLUGINS_DATABASE_CATCH 1649 ORTHANC_PLUGINS_DATABASE_CATCH
1668 } 1650 }
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
1740 1651
1741 1652
1742 public: 1653 public:
1743 /** 1654 /**
1744 * Register a custom database back-end written in C++. 1655 * Register a custom database back-end written in C++.
1828 1739
1829 if (backend.HasCreateInstance()) 1740 if (backend.HasCreateInstance())
1830 { 1741 {
1831 extensions.createInstance = CreateInstance; // Fast creation of resources 1742 extensions.createInstance = CreateInstance; // Fast creation of resources
1832 } 1743 }
1744
1745 performanceWarning = false;
1833 #endif 1746 #endif
1834 1747
1835 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 1748 if (performanceWarning)
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;
1840 performanceWarning = false;
1841 # endif
1842 #endif
1843
1844 if (performanceWarning)
1845 { 1749 {
1846 char info[1024]; 1750 char info[1024];
1847 sprintf(info, 1751 sprintf(info,
1848 "Performance warning: The database index plugin was compiled " 1752 "Performance warning: The database index plugin was compiled "
1849 "against an old version of the Orthanc SDK (%d.%d.%d): " 1753 "against an old version of the Orthanc SDK (%d.%d.%d): "