# HG changeset patch # User Sebastien Jodogne # Date 1406538543 -7200 # Node ID ace99e2722037171e4cacf1336db5634ff72bb52 # Parent bb82e5e818e96bea9ccb8fe2906e31d5f3f25217 access metadata in plugins diff -r bb82e5e818e9 -r ace99e272203 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Fri Jul 25 18:39:02 2014 +0200 +++ b/OrthancServer/ServerContext.cpp Mon Jul 28 11:09:03 2014 +0200 @@ -306,10 +306,20 @@ attachments.push_back(dicomInfo); attachments.push_back(jsonInfo); - std::map instanceMetadata; + typedef std::map InstanceMetadata; + InstanceMetadata instanceMetadata; StoreStatus status = index_.Store(instanceMetadata, dicom.GetSummary(), attachments, dicom.GetRemoteAet(), dicom.GetMetadata()); + dicom.GetMetadata().clear(); + + for (InstanceMetadata::const_iterator it = instanceMetadata.begin(); + it != instanceMetadata.end(); it++) + { + dicom.GetMetadata().insert(std::make_pair(std::make_pair(ResourceType_Instance, it->first), + it->second)); + } + if (status != StoreStatus_Success) { storage_.Remove(dicomInfo.GetUuid()); diff -r bb82e5e818e9 -r ace99e272203 Plugins/Engine/PluginsHttpHandler.cpp --- a/Plugins/Engine/PluginsHttpHandler.cpp Fri Jul 25 18:39:02 2014 +0200 +++ b/Plugins/Engine/PluginsHttpHandler.cpp Mon Jul 28 11:09:03 2014 +0200 @@ -595,6 +595,60 @@ } + static void AccessInstanceMetadataInternal(bool checkExistence, + const _OrthancPluginAccessDicomInstance& params, + const DicomInstanceToStore& instance) + { + MetadataType metadata; + + try + { + metadata = StringToMetadata(params.key); + } + catch (OrthancException&) + { + // Unknown metadata + if (checkExistence) + { + *params.resultInt64 = -1; + } + else + { + *params.resultString = NULL; + } + + return; + } + + ServerIndex::MetadataMap::const_iterator it = + instance.GetMetadata().find(std::make_pair(ResourceType_Instance, metadata)); + + if (checkExistence) + { + if (it != instance.GetMetadata().end()) + { + *params.resultInt64 = 1; + } + else + { + *params.resultInt64 = 0; + } + } + else + { + if (it != instance.GetMetadata().end()) + { + *params.resultString = it->second.c_str(); + } + else + { + // Error: Missing metadata + *params.resultString = NULL; + } + } + } + + static void AccessDicomInstance(_OrthancPluginService service, const void* parameters) { @@ -618,6 +672,14 @@ *p.resultString = instance.GetBufferData(); return; + case _OrthancPluginService_HasInstanceMetadata: + AccessInstanceMetadataInternal(true, p, instance); + return; + + case _OrthancPluginService_GetInstanceMetadata: + AccessInstanceMetadataInternal(false, p, instance); + return; + case _OrthancPluginService_GetInstanceJson: case _OrthancPluginService_GetInstanceSimplifiedJson: { @@ -727,6 +789,8 @@ case _OrthancPluginService_GetInstanceData: case _OrthancPluginService_GetInstanceJson: case _OrthancPluginService_GetInstanceSimplifiedJson: + case _OrthancPluginService_HasInstanceMetadata: + case _OrthancPluginService_GetInstanceMetadata: AccessDicomInstance(service, parameters); return true; diff -r bb82e5e818e9 -r ace99e272203 Plugins/OrthancCPlugin/OrthancCPlugin.h --- a/Plugins/OrthancCPlugin/OrthancCPlugin.h Fri Jul 25 18:39:02 2014 +0200 +++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h Mon Jul 28 11:09:03 2014 +0200 @@ -265,9 +265,9 @@ _OrthancPluginService_GetInstanceSize = 4001, _OrthancPluginService_GetInstanceData = 4002, _OrthancPluginService_GetInstanceJson = 4003, - _OrthancPluginService_GetInstanceSimplifiedJson = 4004 - - /* + METADATA !!! */ + _OrthancPluginService_GetInstanceSimplifiedJson = 4004, + _OrthancPluginService_HasInstanceMetadata = 4005, + _OrthancPluginService_GetInstanceMetadata = 4006 } _OrthancPluginService; @@ -889,6 +889,7 @@ if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms)) { + /* Error */ return NULL; } else @@ -920,6 +921,7 @@ if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms)) { + /* Error */ return NULL; } else @@ -951,6 +953,7 @@ if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms)) { + /* Error */ return NULL; } else @@ -982,6 +985,7 @@ if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms)) { + /* Error */ return NULL; } else @@ -1122,6 +1126,7 @@ if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, ¶ms)) { + /* Error */ return NULL; } else @@ -1144,6 +1149,7 @@ if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, ¶ms)) { + /* Error */ return -1; } else @@ -1166,6 +1172,7 @@ if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, ¶ms)) { + /* Error */ return NULL; } else @@ -1188,6 +1195,7 @@ if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, ¶ms)) { + /* Error */ return NULL; } else @@ -1210,6 +1218,57 @@ if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, ¶ms)) { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance, + const char* key) + { + int64_t result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultInt64 = &result; + params.instance = instance; + params.key = key; + + if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, ¶ms)) + { + /* Error */ + return -1; + } + else + { + return (result != 0); + } + } + + + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance, + const char* key) + { + const char* result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultString = &result; + params.instance = instance; + params.key = key; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, ¶ms)) + { + /* Error */ return NULL; } else @@ -1220,13 +1279,6 @@ - - /* - TODO : METADATA !!! - TODO : DOCUMENTATION !!! - */ - - #ifdef __cplusplus } #endif diff -r bb82e5e818e9 -r ace99e272203 Plugins/Samples/Basic/Plugin.c --- a/Plugins/Samples/Basic/Plugin.c Fri Jul 25 18:39:02 2014 +0200 +++ b/Plugins/Samples/Basic/Plugin.c Mon Jul 28 11:09:03 2014 +0200 @@ -187,6 +187,15 @@ printf("[%s]\n", json); OrthancPluginFreeString(context, json); + if (OrthancPluginHasInstanceMetadata(context, instance, "ReceptionDate")) + { + printf("Received on [%s]\n", OrthancPluginGetInstanceMetadata(context, instance, "ReceptionDate")); + } + else + { + OrthancPluginLogError(context, "Instance has no reception date, should never happen!"); + } + return 0; }