# Modify and create new Tags in a dicom series

**URL:** <https://discourse.slicer.org/t/modify-and-create-new-tags-in-a-dicom-series/23553>\
**Category:** Development\
**Tags:** extensions-manager, dicom, python\
**Created:** [May 24, 2022, 9:52am UTC](https://discourse.slicer.org/t/modify-and-create-new-tags-in-a-dicom-series/23553 "2022-05-24T09:52:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergioReinosa](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@SergioReinosa](https://discourse.slicer.org/u/SergioReinosa)\
**Post date:** [May 24, 2022, 9:52am UTC](https://discourse.slicer.org/t/modify-and-create-new-tags-in-a-dicom-series/23553/1 "2022-05-24T09:52:52Z")

</div>

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:

```auto
    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:

```auto
    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,

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 24, 2022, 12:25pm UTC](https://discourse.slicer.org/t/modify-and-create-new-tags-in-a-dicom-series/23553/2 "2022-05-24T12:25:29Z")

</div>

You can have a look at the DICOMParser for ideas.

> <https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMPatcher/DICOMPatcher.py>

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 24, 2022, 12:51pm UTC](https://discourse.slicer.org/t/modify-and-create-new-tags-in-a-dicom-series/23553/3 "2022-05-24T12:51:21Z")

</div>

> [@SergioReinosa](#):
>
> But it doesn’t modify.

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.

---

<div class="post-metadata">

**Author:** ![SergioReinosa](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@SergioReinosa](https://discourse.slicer.org/u/SergioReinosa)\
**Post date:** [June 23, 2022, 9:30am UTC](https://discourse.slicer.org/t/modify-and-create-new-tags-in-a-dicom-series/23553/4 "2022-06-23T09:30:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 23, 2022, 2:33pm UTC](https://discourse.slicer.org/t/modify-and-create-new-tags-in-a-dicom-series/23553/5 "2022-06-23T14:33:28Z")

</div>

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.

> **[Slicer/Modules/Scripted/DICOMPlugins at master · Slicer/Slicer](https://github.com/Slicer/Slicer/tree/master/Modules/Scripted/DICOMPlugins)**
>
> master/Modules/Scripted/DICOMPlugins
