# How to read nested DICOM metadata

**URL:** <https://discourse.slicer.org/t/how-to-read-nested-dicom-metadata/3617>\
**Category:** Support\
**Tags:** extensions-manager\
**Created:** [July 31, 2018, 10:20am UTC](https://discourse.slicer.org/t/how-to-read-nested-dicom-metadata/3617 "2018-07-31T10:20:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominicrushforth](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dominicrushforth](https://discourse.slicer.org/u/dominicrushforth)\
**Post date:** [July 31, 2018, 10:20am UTC](https://discourse.slicer.org/t/how-to-read-nested-dicom-metadata/3617/1 "2018-07-31T10:20:11Z")

</div>

I’m new to slicer and python. Currently I’m trying to write an extension that involves reading nested dicom files. I can read normal files using this code…

```auto
instUids=dicomData.split()
filename=slicer.dicomDatabase.fileForInstance(instUids[0])
aquisitionModality[volumeNumber] = slicer.dicomDatabase.fileValue(filename,'0008,0060')

```

but I have been unable to read nested tags such as (0008,1032) (fffe,e000) (0008,0104) - where the tags are labelled in this order in the DICOM File Metadata display. I’m sure I must be missing something very simple…

---

<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:** [July 31, 2018, 10:45am UTC](https://discourse.slicer.org/t/how-to-read-nested-dicom-metadata/3617/2 "2018-07-31T10:45:36Z")

</div>

To access DICOM tags within sequence (SQ) tags, you can get the DICOM filename as described [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#DICOM_2), then use [pydicom](https://pydicom.github.io/pydicom/0.9/getting_started.html) (bundled with Slicer) to read the file and retrieve any values.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [February 15, 2019, 3:17pm UTC](https://discourse.slicer.org/t/how-to-read-nested-dicom-metadata/3617/3 "2019-02-15T15:17:59Z")

</div>

this has no direct answer but here it is how to do it using pydicom

```python
import dicom
instUids=dicomData.split()
filename=slicer.dicomDatabase.fileForInstance(instUids[0])
plan = dicom.read_file(filename)
aquisitionModality[volumeNumber] = float(plan[0x08,0x1032][0][0x08,0x0104].value)

```

You have to nest the tags, the (fffe,e000) accounts for the list so unravel using [0]
