.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_metadata_processing_plot_add_dict_entries.py: ===================================================== Add dictionary items in the standard DICOM dictionary ===================================================== This examples illustrates how to add dictionary items to the 'standard' DICOM dictionary dynamically. .. warning:: Note that this is not a recommended solution in general but it is useful as a demonstration or for in-house programs only, or to get around elements missing from pydicom's DICOM dictionaries. .. rst-class:: sphx-glr-script-out Out: .. code-block:: none (1001, 1001) Test One UL: 42 (1001, 1002) Test Two OB: '12345' (1001, 1003) Test Three UI: 1.2.3.4.5 | .. code-block:: python # authors : Darcy Mason # Guillaume Lemaitre # license : MIT from __future__ import print_function from pydicom.datadict import DicomDictionary, keyword_dict from pydicom.dataset import Dataset print(__doc__) # Define items as (VR, VM, description, is_retired flag, keyword) # Leave is_retired flag blank. new_dict_items = { 0x10011001: ('UL', '1', "Test One", '', 'TestOne'), 0x10011002: ('OB', '1', "Test Two", '', 'TestTwo'), 0x10011003: ('UI', '1', "Test Three", '', 'TestThree'), } # Update the dictionary itself DicomDictionary.update(new_dict_items) # Update the reverse mapping from name to tag new_names_dict = dict([(val[4], tag) for tag, val in new_dict_items.items()]) keyword_dict.update(new_names_dict) # Test that it is working ds = Dataset() # or could get one from dcmread, etc ds.TestOne = 42 ds.TestTwo = '12345' ds.TestThree = '1.2.3.4.5' print(ds.top()) **Total running time of the script:** ( 0 minutes 0.001 seconds) .. _sphx_glr_download_auto_examples_metadata_processing_plot_add_dict_entries.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_add_dict_entries.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_add_dict_entries.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_