# HG changeset patch # User Sebastien Jodogne # Date 1623412992 -7200 # Node ID 6fc445793796afb267dafe54469ab68792393a7e # Parent 4da5ce3468b4b3ce95437eb9f364d3451ec6ea4b new wrapped function: orthanc.LookupDictionary() diff -r 4da5ce3468b4 -r 6fc445793796 CodeAnalysis/ParseOrthancSDK.py --- a/CodeAnalysis/ParseOrthancSDK.py Fri Jun 11 12:47:18 2021 +0200 +++ b/CodeAnalysis/ParseOrthancSDK.py Fri Jun 11 14:03:12 2021 +0200 @@ -40,6 +40,7 @@ 'OrthancPluginCreateImageAccessor', # Replaced by "orthanc.CreateImageFromBuffer()" 'OrthancPluginFreeMemoryBuffer', 'OrthancPluginFreeString', + 'OrthancPluginLookupDictionary', 'OrthancPluginRegisterFindCallback', 'OrthancPluginRegisterIncomingHttpRequestFilter', # Implemented through v2 'OrthancPluginRegisterIncomingHttpRequestFilter2', diff -r 4da5ce3468b4 -r 6fc445793796 NEWS --- a/NEWS Fri Jun 11 12:47:18 2021 +0200 +++ b/NEWS Fri Jun 11 14:03:12 2021 +0200 @@ -8,6 +8,7 @@ - orthanc.FindQuery.GetFindQueryTagElement() - orthanc.FindQuery.GetFindQueryTagGroup() - orthanc.Image.GetImageBuffer() + - orthanc.LookupDictionary() - orthanc.RegisterFindCallback() - orthanc.RegisterMoveCallback() - orthanc.RegisterWorklistCallback() diff -r 4da5ce3468b4 -r 6fc445793796 Sources/Plugin.cpp --- a/Sources/Plugin.cpp Fri Jun 11 12:47:18 2021 +0200 +++ b/Sources/Plugin.cpp Fri Jun 11 14:03:12 2021 +0200 @@ -50,6 +50,49 @@ #endif +#include "PythonString.h" + +PyObject* LookupDictionary(PyObject* module, PyObject* args) +{ + const char* name = NULL; + + if (!PyArg_ParseTuple(args, "s", &name)) + { + PyErr_SetString(PyExc_TypeError, "Please provide a string containing the name of the DICOM tag of interest"); + return NULL; + } + else + { + OrthancPluginDictionaryEntry entry; + + OrthancPluginErrorCode code = OrthancPluginLookupDictionary(OrthancPlugins::GetGlobalContext(), &entry, name); + if (code == OrthancPluginErrorCode_Success) + { + /** + * "PyGILState_Ensure()" can be invoked several times from the + * same thread, so no problem in creating a PythonLock even if + * the GIL is already locked. + **/ + PythonLock lock; + + PythonObject kw(lock, PyDict_New()); + PyDict_SetItemString(kw.GetPyObject(), "Group", PyLong_FromUnsignedLong(entry.group)); + PyDict_SetItemString(kw.GetPyObject(), "Element", PyLong_FromUnsignedLong(entry.element)); + PyDict_SetItemString(kw.GetPyObject(), "ValueRepresentation", PyLong_FromUnsignedLong(entry.vr)); + PyDict_SetItemString(kw.GetPyObject(), "MinMultiplicity", PyLong_FromUnsignedLong(entry.minMultiplicity)); + PyDict_SetItemString(kw.GetPyObject(), "MaxMultiplicity", PyLong_FromUnsignedLong(entry.maxMultiplicity)); + + return kw.Release(); + } + else + { + std::string message = "Unknown DICOM tag: " + std::string(name); + PyErr_SetString(PyExc_TypeError, message.c_str()); + return NULL; + } + } +} + PyObject* CreateDicom(PyObject* module, PyObject* args) { @@ -289,6 +332,11 @@ **/ { + PyMethodDef f = { "LookupDictionary", LookupDictionary, METH_VARARGS, "" }; + functions.push_back(f); + } + + { PyMethodDef f = { "CreateDicom", CreateDicom, METH_VARARGS, "" }; functions.push_back(f); }