# HG changeset patch # User Sebastien Jodogne # Date 1623413361 -7200 # Node ID cd70d23f34bc2d1cff8f4fc44c347198f3b2126e # Parent daf07750e9019ce3bd930a343413f63077b4f9a1 Lookup DICOM dictionary in Python scripts diff -r daf07750e901 -r cd70d23f34bc Sphinx/source/plugins/python.rst --- a/Sphinx/source/plugins/python.rst Fri Jun 11 12:44:56 2021 +0200 +++ b/Sphinx/source/plugins/python.rst Fri Jun 11 14:09:21 2021 +0200 @@ -479,8 +479,6 @@ .. literalinclude:: python/authorization-2.py :language: python -.. highlight:: javascript - This filter could be used together with the following Web service implemented using `Node.js `__: @@ -489,6 +487,34 @@ :language: javascript +.. _python_lookup_dictionary: + +Lookup DICOM dictionary (new in 3.2) +.................................... + +Python plugins can access the dictionary of the DICOM tags that are +handled by Orthanc: + +.. literalinclude:: python/lookup-dictionary.py + :language: python + +.. highlight:: text + +Note how Python introspection is used in order to map the values in +enumeration ``orthanc.ValueRepresentation`` to a string description of +the value representation. If started, the plugin above would output +the following information in the Orthanc logs:: + + W0611 14:04:08.563957 PluginsManager.cpp:168] Entry in the dictionary: { + "Element": 32, + "Group": 16, + "MaxMultiplicity": 1, + "MinMultiplicity": 1, + "ValueRepresentation": 11 + } + W0611 14:04:08.563975 PluginsManager.cpp:168] Name of the value representation: LO + + .. _python_create_dicom: Creating DICOM instances (new in 3.2) diff -r daf07750e901 -r cd70d23f34bc Sphinx/source/plugins/python/lookup-dictionary.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sphinx/source/plugins/python/lookup-dictionary.py Fri Jun 11 14:09:21 2021 +0200 @@ -0,0 +1,18 @@ +import json +import orthanc + +# Create a dictionary mapping the numeric values in enumeration +# "orthanc.ValueRepresentation" to the name of the corresponding VR +VR_NAMES = {} +for name in dir(orthanc.ValueRepresentation): + if not name.startswith('_'): + value = getattr(orthanc.ValueRepresentation, name) + VR_NAMES[value] = name + +entry = orthanc.LookupDictionary('PatientID') + +orthanc.LogWarning('Entry in the dictionary: %s' % + json.dumps(entry, indent = 4, sort_keys = True)) + +orthanc.LogWarning('Name of the value representation: %s' % + VR_NAMES[entry['ValueRepresentation']])