Mercurial > hg > orthanc-python
changeset 66:6fc445793796
new wrapped function: orthanc.LookupDictionary()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 Jun 2021 14:03:12 +0200 |
parents | 4da5ce3468b4 |
children | 9d0460d0f15b |
files | CodeAnalysis/ParseOrthancSDK.py NEWS Sources/Plugin.cpp |
diffstat | 3 files changed, 50 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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',
--- 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()
--- 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); }