Add new tag to existing DICOM file?

2,251 views
Skip to first unread message

E Friedmann

unread,
Sep 15, 2011, 10:53:24 AM9/15/11
to pydicom
I am trying to add a new tag to an existing DICOM file. The
information for the tag ( 0x0010,0x1000: "Other Patient IDs") exists
in the dictionary. Based upon a suggestion in this group, I've tried
the line "ds.OtherPatientIDs.value = new_value" but it fails with an
error that the dataset does not have this attribute. If I try to
access it directly "ds[0x0010,0x1000].value = new_value", the function
displays the hex tag and exits. Any suggestions?

Darcy Mason

unread,
Sep 15, 2011, 5:14:43 PM9/15/11
to pydicom
Since it is a new data element, you should use the add_new function:
ds.add_new(tag, VR, value)

If the tag does not exist in the dataset already, pydicom needs to
know the VR as well as the value, and this function puts everything
together.

-Darcy

Darcy Mason

unread,
Sep 15, 2011, 6:25:13 PM9/15/11
to pydicom
... I just reconsidered my previous answer -- pydicom does in fact
create a new tag for you if it is in the DICOM dictionary (so it can
look up the tag and VR). So you can do:

ds.OtherPatientIDs = "new value"

In your line above, you have ".value" on the end of the left side,
which is why it is giving an error. The .value is needed only when
accessing data elements by tag number.

-Darcy
Reply all
Reply to author
Forward
0 new messages