# HG changeset patch # User Sebastien Jodogne # Date 1405513777 -7200 # Node ID 6208ab500ffda9432d027d680ef8ac5604449eb4 # Parent bd17030db6d48a23c0da96746419563d17183f50 LookupResource service in plugin SDK diff -r bd17030db6d4 -r 6208ab500ffd Plugins/Engine/PluginsHttpHandler.cpp --- a/Plugins/Engine/PluginsHttpHandler.cpp Thu Jul 10 16:22:59 2014 +0200 +++ b/Plugins/Engine/PluginsHttpHandler.cpp Wed Jul 16 14:29:37 2014 +0200 @@ -442,6 +442,70 @@ } + void PluginsHttpHandler::LookupResource(ResourceType level, + const void* parameters) + { + const _OrthancPluginLookupResource& p = + *reinterpret_cast(parameters); + + DicomTag tag(0, 0); + switch (level) + { + case ResourceType_Patient: + tag = DICOM_TAG_PATIENT_ID; + break; + + case ResourceType_Study: + tag = DICOM_TAG_STUDY_INSTANCE_UID; + break; + + case ResourceType_Series: + tag = DICOM_TAG_SERIES_INSTANCE_UID; + break; + + case ResourceType_Instance: + tag = DICOM_TAG_SOP_INSTANCE_UID; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + std::list result; + pimpl_->context_.GetIndex().LookupTagValue(result, tag, p.identifier, level); + + if (result.size() == 1) + { + *p.result = CopyString(result.front()); + } + else + { + throw OrthancException(ErrorCode_UnknownResource); + } + } + + + char* PluginsHttpHandler::CopyString(const std::string& str) const + { + char *result = reinterpret_cast(malloc(str.size() + 1)); + if (result == NULL) + { + throw OrthancException(ErrorCode_NotEnoughMemory); + } + + if (str.size() == 0) + { + result[0] = '\0'; + } + else + { + memcpy(result, &str[0], str.size() + 1); + } + + return result; + } + + bool PluginsHttpHandler::InvokeService(_OrthancPluginService service, const void* parameters) { @@ -483,6 +547,22 @@ Redirect(parameters); return true; + case _OrthancPluginService_LookupPatient: + LookupResource(ResourceType_Patient, parameters); + return true; + + case _OrthancPluginService_LookupStudy: + LookupResource(ResourceType_Study, parameters); + return true; + + case _OrthancPluginService_LookupSeries: + LookupResource(ResourceType_Series, parameters); + return true; + + case _OrthancPluginService_LookupInstance: + LookupResource(ResourceType_Instance, parameters); + return true; + default: return false; } diff -r bd17030db6d4 -r 6208ab500ffd Plugins/Engine/PluginsHttpHandler.h --- a/Plugins/Engine/PluginsHttpHandler.h Thu Jul 10 16:22:59 2014 +0200 +++ b/Plugins/Engine/PluginsHttpHandler.h Wed Jul 16 14:29:37 2014 +0200 @@ -50,6 +50,8 @@ boost::shared_ptr pimpl_; + char* CopyString(const std::string& str) const; + void RegisterRestCallback(const void* parameters); void AnswerBuffer(const void* parameters); @@ -66,6 +68,9 @@ void RestApiDelete(const void* parameters); + void LookupResource(ResourceType level, + const void* parameters); + public: PluginsHttpHandler(ServerContext& context); diff -r bd17030db6d4 -r 6208ab500ffd Plugins/OrthancCPlugin/OrthancCPlugin.h --- a/Plugins/OrthancCPlugin/OrthancCPlugin.h Thu Jul 10 16:22:59 2014 +0200 +++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h Wed Jul 16 14:29:37 2014 +0200 @@ -220,7 +220,11 @@ _OrthancPluginService_RestApiGet = 3001, _OrthancPluginService_RestApiPost = 3002, _OrthancPluginService_RestApiDelete = 3003, - _OrthancPluginService_RestApiPut = 3004 + _OrthancPluginService_RestApiPut = 3004, + _OrthancPluginService_LookupPatient = 3005, + _OrthancPluginService_LookupStudy = 3006, + _OrthancPluginService_LookupSeries = 3007, + _OrthancPluginService_LookupInstance = 3008 } _OrthancPluginService; @@ -337,7 +341,10 @@ OrthancPluginContext* context, char* str) { - context->Free(str); + if (str != NULL) + { + context->Free(str); + } } @@ -693,6 +700,137 @@ } + + typedef struct + { + char** result; + const char* identifier; + } _OrthancPluginLookupResource; + + /** + * @brief Look for a patient. + * + * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param patientID The Patient ID of interest. + * @return The NULL string if the patient is non-existent, or a string containing the + * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient( + OrthancPluginContext* context, + const char* patientID) + { + char* result; + + _OrthancPluginLookupResource params; + params.result = &result; + params.identifier = patientID; + + if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms)) + { + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Look for a study. + * + * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param studyUID The Study Instance UID of interest. + * @return The NULL string if the study is non-existent, or a string containing the + * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy( + OrthancPluginContext* context, + const char* studyUID) + { + char* result; + + _OrthancPluginLookupResource params; + params.result = &result; + params.identifier = studyUID; + + if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms)) + { + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Look for a series. + * + * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param seriesUID The Series Instance UID of interest. + * @return The NULL string if the series is non-existent, or a string containing the + * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries( + OrthancPluginContext* context, + const char* seriesUID) + { + char* result; + + _OrthancPluginLookupResource params; + params.result = &result; + params.identifier = seriesUID; + + if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms)) + { + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Look for an instance. + * + * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param sopInstanceUID The SOP Instance UID of interest. + * @return The NULL string if the instance is non-existent, or a string containing the + * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance( + OrthancPluginContext* context, + const char* sopInstanceUID) + { + char* result; + + _OrthancPluginLookupResource params; + params.result = &result; + params.identifier = sopInstanceUID; + + if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms)) + { + return NULL; + } + else + { + return result; + } + } + + #ifdef __cplusplus } #endif