Modify and create new Tags in a dicom series

Hi,

I’m developing an extension that has to add to the series Metadata a tag that indicates a URL and also update some other tags, like actual Date or Time.

My issue is that I can read without any problem the metadata with a extract of code like the following:

    db = slicer.dicomDatabase

    patientList = db.patients()
    studyList = db.studiesForPatient(patientList[0])
    seriesList = db.seriesForStudy(studyList[0])
    fileList = db.filesForSeries(seriesList[0])

    accn = db.fileValue(fileList[0], "0008,0050")
    stuyInstanceUID = db.fileValue(fileList[0], "0020,000D")
    patientID = db.fileValue(fileList[0], "0010,0020")
    patientName = db.fileValue(fileList[0], "0010,0010")
    patientBirthdate = db.fileValue(fileList[0], "0010,0030")

But when I want to modify and existing tag or create a new one, as I need to save my URL, I don’t know how to do.

In order to modify tags, I have tried things like:

    from pydicom import dcmread
    ds = dcmread(fileList[0])
    ds[0x0010, 0x0020].value = 'New name'

But it doesn’t modify. I know that there is a ‘setTag’ method in pydicom but I dont know with which object can I use it. I have checked the Script repository but I haven’t seen anything that I can use. If anyone can help me it would be great.

Thank you very much,

You can have a look at the DICOMParser for ideas.

1 Like

DICOM standard does not let you modify an instance that was made available outside your software. No modification of an existing instance is allowed, because an instance UID must uniquely identify the entire content. Therefore, if you received a DICOM file from somewhere and want to make changes then you must create a new instance (with new instance UIDs), preferably add references to the original UIDs, and then hide or delete the original version.

The DICOM patcher in Slicer can modify an instance without regenerating UIDs, but this is for cases when the input data has already violated the DICOM standard.

Ok, I haven’t been working on it lately but I have started again. I searched and i didn’t find anything about creating a new instance from the DICOM file I originally had. Is it possible? Being able to create a duplicate with a different UID and some other different parameters would solve my problem.

Thank you very much.

Creating valid dicom files is a complex topic, and everything depend on what you are really trying to accomplish. Have a look at the export methods in some of the plugins for examples.