# HG changeset patch # User Sebastien Jodogne # Date 1481302923 -3600 # Node ID 7bcff7bb7cbf30863f032fb36d83b772f5f8b288 # Parent e3fd5bc429a2349db1462c4c606e222273e85099 OrthancPluginFindMatcher diff -r e3fd5bc429a2 -r 7bcff7bb7cbf Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Fri Dec 09 17:20:21 2016 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Fri Dec 09 18:02:03 2016 +0100 @@ -2592,6 +2592,49 @@ return true; } + case _OrthancPluginService_CreateFindMatcher: + { + const _OrthancPluginCreateFindMatcher& p = + *reinterpret_cast(parameters); + ParsedDicomFile query(p.query, p.size); + *(p.target) = reinterpret_cast + (new HierarchicalMatcher(query, Configuration::GetGlobalBoolParameter("CaseSensitivePN", false))); + return true; + } + + case _OrthancPluginService_FreeFindMatcher: + { + const _OrthancPluginFreeFindMatcher& p = + *reinterpret_cast(parameters); + + if (p.matcher == NULL) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + else + { + delete reinterpret_cast(p.matcher); + return true; + } + } + + case _OrthancPluginService_FindMatcherIsMatch: + { + const _OrthancPluginFindMatcherIsMatch& p = + *reinterpret_cast(parameters); + + if (p.matcher == NULL) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + else + { + ParsedDicomFile query(p.dicom, p.size); + reinterpret_cast(p.matcher)->Match(query); + return true; + } + } + default: return false; } diff -r e3fd5bc429a2 -r 7bcff7bb7cbf Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Fri Dec 09 17:20:21 2016 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Fri Dec 09 18:02:03 2016 +0100 @@ -501,6 +501,9 @@ _OrthancPluginService_GetFindQueryTag = 7007, _OrthancPluginService_GetFindQueryTagName = 7008, _OrthancPluginService_GetFindQueryValue = 7009, + _OrthancPluginService_CreateFindMatcher = 7010, + _OrthancPluginService_FreeFindMatcher = 7011, + _OrthancPluginService_FindMatcherIsMatch = 7012, _OrthancPluginService_INTERNAL = 0x7fffffff } _OrthancPluginService; @@ -856,6 +859,14 @@ /** + * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query. + * @ingroup Toolbox + **/ + typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindMatcher; + + + + /** * @brief Signature of a callback function that answers to a REST request. * @ingroup Callbacks **/ @@ -5412,6 +5423,123 @@ + typedef struct + { + OrthancPluginFindMatcher** target; + const void* query; + uint32_t size; + } _OrthancPluginCreateFindMatcher; + + + /** + * @brief Create a C-Find matcher. + * + * This function creates a "matcher" object that can be used to + * check whether a DICOM instance matches a C-Find query. The C-Find + * query must be expressed as a DICOM buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param query The C-Find DICOM query. + * @param size The size of the DICOM query. + * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher( + OrthancPluginContext* context, + const void* query, + uint32_t size) + { + OrthancPluginFindMatcher* target = NULL; + + _OrthancPluginCreateFindMatcher params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.query = query; + params.size = size; + + if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + typedef struct + { + OrthancPluginFindMatcher* matcher; + } _OrthancPluginFreeFindMatcher; + + /** + * @brief Free a C-Find matcher. + * + * This function frees a matcher that was created using OrthancPluginCreateFindMatcher(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param matcher The matcher of interest. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher( + OrthancPluginContext* context, + OrthancPluginFindMatcher* matcher) + { + _OrthancPluginFreeFindMatcher params; + params.matcher = matcher; + + context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, ¶ms); + } + + + typedef struct + { + const OrthancPluginFindMatcher* matcher; + const void* dicom; + uint32_t size; + int32_t* isMatch; + } _OrthancPluginFindMatcherIsMatch; + + /** + * @brief Test whether a DICOM instance matches a C-Find query. + * + * This function checks whether one DICOM instance matches C-Find + * matcher that was previously allocated using + * OrthancPluginCreateFindMatcher(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param matcher The matcher of interest. + * @param dicom The DICOM instance to be matched. + * @param size The size of the DICOM instance. + * @return 1 if the DICOM instance matches the query, 0 otherwise. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch( + OrthancPluginContext* context, + const OrthancPluginFindMatcher* matcher, + const void* dicom, + uint32_t size) + { + int32_t isMatch = 0; + + _OrthancPluginFindMatcherIsMatch params; + params.matcher = matcher; + params.dicom = dicom; + params.size = size; + params.isMatch = &isMatch; + + if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, ¶ms) == OrthancPluginErrorCode_Success) + { + return isMatch; + } + else + { + /* Error: Assume non-match */ + return 0; + } + } + #ifdef __cplusplus }