Mercurial > hg > orthanc
changeset 3074:495c5edce708 db-changes
new extension for database plugin SDK: lookupResources
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 02 Jan 2019 15:50:44 +0100 |
parents | 0e9d1731b1b0 |
children | ead8576a02ef |
files | CMakeLists.txt OrthancServer/Search/DatabaseConstraint.cpp OrthancServer/Search/DatabaseConstraint.h Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/PluginsEnumerations.cpp Plugins/Engine/PluginsEnumerations.h Plugins/Include/orthanc/OrthancCDatabasePlugin.h Plugins/Include/orthanc/OrthancCPlugin.h |
diffstat | 8 files changed, 250 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Wed Jan 02 13:44:18 2019 +0100 +++ b/CMakeLists.txt Wed Jan 02 15:50:44 2019 +0100 @@ -124,6 +124,8 @@ if (ENABLE_PLUGINS) + include_directories(${CMAKE_SOURCE_DIR}/Plugins/Include) + list(APPEND ORTHANC_SERVER_SOURCES Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPlugins.cpp @@ -229,8 +231,6 @@ endif() -include_directories(${CMAKE_SOURCE_DIR}/Plugins/Include) - add_definitions( -DORTHANC_BUILD_UNIT_TESTS=1 -DORTHANC_ENABLE_LOGGING_PLUGIN=0
--- a/OrthancServer/Search/DatabaseConstraint.cpp Wed Jan 02 13:44:18 2019 +0100 +++ b/OrthancServer/Search/DatabaseConstraint.cpp Wed Jan 02 15:50:44 2019 +0100 @@ -36,6 +36,11 @@ #include "../../Core/OrthancException.h" +#if ORTHANC_ENABLE_PLUGINS == 1 +# include "../../Plugins/Engine/PluginsEnumerations.h" +#endif + + namespace Orthanc { DatabaseConstraint::DatabaseConstraint(ResourceType level, @@ -61,6 +66,31 @@ } +#if ORTHANC_ENABLE_PLUGINS == 1 + DatabaseConstraint::DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint) : + level_(Plugins::Convert(constraint.level)), + tag_(constraint.tagGroup, constraint.tagElement), + isIdentifier_(constraint.isIdentifierTag), + constraintType_(Plugins::Convert(constraint.type)), + caseSensitive_(constraint.isCaseSensitive), + mandatory_(constraint.isMandatory) + { + if (constraintType_ != ConstraintType_List && + values_.size() != 1) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + values_.resize(constraint.valuesCount); + + for (uint32_t i = 0; i < constraint.valuesCount; i++) + { + values_[i].assign(constraint.values[i]); + } + } +#endif + + const std::string& DatabaseConstraint::GetValue(size_t index) const { if (index >= values_.size()) @@ -85,4 +115,29 @@ return values_[0]; } } + + +#if ORTHANC_ENABLE_PLUGINS == 1 + void DatabaseConstraint::EncodeForPlugins(OrthancPluginDatabaseConstraint& constraint, + std::vector<const char*>& tmpValues) const + { + memset(&constraint, 0, sizeof(constraint)); + + constraint.level = Plugins::Convert(level_); + constraint.tagGroup = tag_.GetGroup(); + constraint.tagElement = tag_.GetElement(); + constraint.isIdentifierTag = isIdentifier_; + constraint.isCaseSensitive = caseSensitive_; + constraint.isMandatory = mandatory_; + constraint.type = Plugins::Convert(constraintType_); + constraint.valuesCount = values_.size(); + + tmpValues.resize(values_.size()); + + for (size_t i = 0; i < values_.size(); i++) + { + tmpValues[i] = values_[i].c_str(); + } + } +#endif }
--- a/OrthancServer/Search/DatabaseConstraint.h Wed Jan 02 13:44:18 2019 +0100 +++ b/OrthancServer/Search/DatabaseConstraint.h Wed Jan 02 15:50:44 2019 +0100 @@ -36,6 +36,10 @@ #include "../../Core/DicomFormat/DicomMap.h" #include "../ServerEnumerations.h" +#if ORTHANC_ENABLE_PLUGINS == 1 +# include "../../Plugins/Include/orthanc/OrthancCDatabasePlugin.h" +#endif + namespace Orthanc { // This class is also used by the "orthanc-databases" project @@ -58,6 +62,10 @@ const std::vector<std::string>& values, bool caseSensitive, bool mandatory); + +#if ORTHANC_ENABLE_PLUGINS == 1 + DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint); +#endif ResourceType GetLevel() const { @@ -99,5 +107,10 @@ } bool IsMatch(const DicomMap& dicom) const; + +#if ORTHANC_ENABLE_PLUGINS == 1 + void EncodeForPlugins(OrthancPluginDatabaseConstraint& constraint, + std::vector<const char*>& tmpValues) const; +#endif }; }
--- a/Plugins/Engine/OrthancPluginDatabase.cpp Wed Jan 02 13:44:18 2019 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Wed Jan 02 15:50:44 2019 +0100 @@ -1129,7 +1129,7 @@ ResetAnswers(); CheckSuccess(extensions_.lookupIdentifier3(GetContext(), payload_, Plugins::Convert(level), - &tmp, Plugins::Convert(type))); + &tmp, Compatibility::Convert(type))); ForwardAnswers(result); }
--- a/Plugins/Engine/PluginsEnumerations.cpp Wed Jan 02 13:44:18 2019 +0100 +++ b/Plugins/Engine/PluginsEnumerations.cpp Wed Jan 02 15:50:44 2019 +0100 @@ -43,6 +43,53 @@ namespace Orthanc { + namespace Compatibility + { + OrthancPluginIdentifierConstraint Convert(IdentifierConstraintType constraint) + { + switch (constraint) + { + case Compatibility::IdentifierConstraintType_Equal: + return OrthancPluginIdentifierConstraint_Equal; + + case Compatibility::IdentifierConstraintType_GreaterOrEqual: + return OrthancPluginIdentifierConstraint_GreaterOrEqual; + + case Compatibility::IdentifierConstraintType_SmallerOrEqual: + return OrthancPluginIdentifierConstraint_SmallerOrEqual; + + case Compatibility::IdentifierConstraintType_Wildcard: + return OrthancPluginIdentifierConstraint_Wildcard; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + + IdentifierConstraintType Convert(OrthancPluginIdentifierConstraint constraint) + { + switch (constraint) + { + case OrthancPluginIdentifierConstraint_Equal: + return Compatibility::IdentifierConstraintType_Equal; + + case OrthancPluginIdentifierConstraint_GreaterOrEqual: + return Compatibility::IdentifierConstraintType_GreaterOrEqual; + + case OrthancPluginIdentifierConstraint_SmallerOrEqual: + return Compatibility::IdentifierConstraintType_SmallerOrEqual; + + case OrthancPluginIdentifierConstraint_Wildcard: + return Compatibility::IdentifierConstraintType_Wildcard; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + } + + namespace Plugins { OrthancPluginResourceType Convert(ResourceType type) @@ -266,50 +313,6 @@ } - OrthancPluginIdentifierConstraint Convert(Compatibility::IdentifierConstraintType constraint) - { - switch (constraint) - { - case Compatibility::IdentifierConstraintType_Equal: - return OrthancPluginIdentifierConstraint_Equal; - - case Compatibility::IdentifierConstraintType_GreaterOrEqual: - return OrthancPluginIdentifierConstraint_GreaterOrEqual; - - case Compatibility::IdentifierConstraintType_SmallerOrEqual: - return OrthancPluginIdentifierConstraint_SmallerOrEqual; - - case Compatibility::IdentifierConstraintType_Wildcard: - return OrthancPluginIdentifierConstraint_Wildcard; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - } - - - Compatibility::IdentifierConstraintType Convert(OrthancPluginIdentifierConstraint constraint) - { - switch (constraint) - { - case OrthancPluginIdentifierConstraint_Equal: - return Compatibility::IdentifierConstraintType_Equal; - - case OrthancPluginIdentifierConstraint_GreaterOrEqual: - return Compatibility::IdentifierConstraintType_GreaterOrEqual; - - case OrthancPluginIdentifierConstraint_SmallerOrEqual: - return Compatibility::IdentifierConstraintType_SmallerOrEqual; - - case OrthancPluginIdentifierConstraint_Wildcard: - return Compatibility::IdentifierConstraintType_Wildcard; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - } - - OrthancPluginInstanceOrigin Convert(RequestOrigin origin) { switch (origin) @@ -590,5 +593,55 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } } + + + OrthancPluginConstraintType Convert(ConstraintType constraint) + { + switch (constraint) + { + case ConstraintType_Equal: + return OrthancPluginConstraintType_Equal; + + case ConstraintType_GreaterOrEqual: + return OrthancPluginConstraintType_GreaterOrEqual; + + case ConstraintType_SmallerOrEqual: + return OrthancPluginConstraintType_SmallerOrEqual; + + case ConstraintType_Wildcard: + return OrthancPluginConstraintType_Wildcard; + + case ConstraintType_List: + return OrthancPluginConstraintType_List; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + + ConstraintType Convert(OrthancPluginConstraintType constraint) + { + switch (constraint) + { + case OrthancPluginConstraintType_Equal: + return ConstraintType_Equal; + + case OrthancPluginConstraintType_GreaterOrEqual: + return ConstraintType_GreaterOrEqual; + + case OrthancPluginConstraintType_SmallerOrEqual: + return ConstraintType_SmallerOrEqual; + + case OrthancPluginConstraintType_Wildcard: + return ConstraintType_Wildcard; + + case OrthancPluginConstraintType_List: + return ConstraintType_List; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } } }
--- a/Plugins/Engine/PluginsEnumerations.h Wed Jan 02 13:44:18 2019 +0100 +++ b/Plugins/Engine/PluginsEnumerations.h Wed Jan 02 15:50:44 2019 +0100 @@ -41,6 +41,13 @@ namespace Orthanc { + namespace Compatibility + { + OrthancPluginIdentifierConstraint Convert(IdentifierConstraintType constraint); + + IdentifierConstraintType Convert(OrthancPluginIdentifierConstraint constraint); + } + namespace Plugins { OrthancPluginResourceType Convert(ResourceType type); @@ -59,10 +66,6 @@ DicomToJsonFormat Convert(OrthancPluginDicomToJsonFormat format); - OrthancPluginIdentifierConstraint Convert(Compatibility::IdentifierConstraintType constraint); - - Compatibility::IdentifierConstraintType Convert(OrthancPluginIdentifierConstraint constraint); - OrthancPluginInstanceOrigin Convert(RequestOrigin origin); OrthancPluginHttpMethod Convert(HttpMethod method); @@ -74,6 +77,10 @@ OrthancPluginJobStepStatus Convert(JobStepCode step); JobStepCode Convert(OrthancPluginJobStepStatus step); + + OrthancPluginConstraintType Convert(ConstraintType constraint); + + ConstraintType Convert(OrthancPluginConstraintType constraint); } }
--- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Wed Jan 02 13:44:18 2019 +0100 +++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Wed Jan 02 15:50:44 2019 +0100 @@ -75,6 +75,7 @@ _OrthancPluginDatabaseAnswerType_Int64 = 15, _OrthancPluginDatabaseAnswerType_Resource = 16, _OrthancPluginDatabaseAnswerType_String = 17, + _OrthancPluginDatabaseAnswerType_MatchingResource = 18, /* New in Orthanc 1.5.2 */ _OrthancPluginDatabaseAnswerType_INTERNAL = 0x7fffffff } _OrthancPluginDatabaseAnswerType; @@ -120,6 +121,25 @@ const char* sopInstanceUid; } OrthancPluginExportedResource; + typedef struct + { + OrthancPluginResourceType level; + uint16_t tagGroup; + uint16_t tagElement; + uint8_t isIdentifierTag; + uint8_t isCaseSensitive; + uint8_t isMandatory; + OrthancPluginConstraintType type; + uint32_t valuesCount; + const char* const* values; + } OrthancPluginDatabaseConstraint; + + typedef struct + { + const char* resourceId; + const char* someInstanceId; /* Can be NULL if not requested */ + } OrthancPluginMatchingResource; + typedef struct { @@ -272,6 +292,19 @@ context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); } + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerMatchingResource( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const OrthancPluginMatchingResource* match) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_MatchingResource; + params.valueGeneric = match; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalDeletedAttachment( OrthancPluginContext* context, OrthancPluginDatabaseContext* database, @@ -694,6 +727,24 @@ uint16_t element, const char* start, const char* end); + + + /** + * Extensions since Orthanc 1.5.2 + **/ + + /* Ouput: Use OrthancPluginDatabaseAnswerMatchingResource */ + OrthancPluginErrorCode (*lookupResources) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + uint32_t constraintsCount, + const OrthancPluginDatabaseConstraint* const* constraints, + OrthancPluginResourceType queryLevel, + uint32_t limit, + uint8_t requestSomeInstance); + } OrthancPluginDatabaseExtensions; /*<! @endcond */
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Wed Jan 02 13:44:18 2019 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Wed Jan 02 15:50:44 2019 +0100 @@ -119,7 +119,7 @@ #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 5 -#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 0 +#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 2 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) @@ -821,6 +821,7 @@ /** * The constraints on the DICOM identifiers that must be supported * by the database plugins. + * @deprecated Plugins using OrthancPluginConstraintType will be faster **/ typedef enum { @@ -834,6 +835,22 @@ /** + * The constraints on the tags (main DICOM tags and identifier tags) + * that must be supported by the database plugins. + **/ + typedef enum + { + OrthancPluginConstraintType_Equal = 1, /*!< Equal */ + OrthancPluginConstraintType_SmallerOrEqual = 2, /*!< Less or equal */ + OrthancPluginConstraintType_GreaterOrEqual = 3, /*!< More or equal */ + OrthancPluginConstraintType_Wildcard = 4, /*!< Wildcard matching */ + OrthancPluginConstraintType_List = 5, /*!< List of values */ + + _OrthancPluginConstraintType_INTERNAL = 0x7fffffff + } OrthancPluginConstraintType; + + + /** * The origin of a DICOM instance that has been received by Orthanc. **/ typedef enum @@ -1513,7 +1530,8 @@ sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) || sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) || - sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus)) + sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus) || + sizeof(int32_t) != sizeof(OrthancPluginConstraintType)) { /* Mismatch in the size of the enumerations */ return 0;