Mercurial > hg > orthanc
changeset 1037:6208ab500ffd
LookupResource service in plugin SDK
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Jul 2014 14:29:37 +0200 |
parents | bd17030db6d4 |
children | a53dc58edc5a |
files | Plugins/Engine/PluginsHttpHandler.cpp Plugins/Engine/PluginsHttpHandler.h Plugins/OrthancCPlugin/OrthancCPlugin.h |
diffstat | 3 files changed, 225 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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<const _OrthancPluginLookupResource*>(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<std::string> 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<char*>(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; }
--- 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> 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);
--- 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