The Structure of DICOMDIR

DICOMDIR acts as a “Directory” for DICOM file sets and holds a full 4 level hierarchy (PATIENT –> STUDY –> SERIES –> IMAGE) as shown below:

DICOMDIR files can be read using DicomDataSets.ReadDirectory method in DicomObjects and the complex structure of linked lists with offsets is held in a single DicomDataSet object.

When accessing the DICOMDIR, you may bear in mind that different DICOM attributes (or Tags) belong to different levels, for example PatientName is a Patient Level attribute, StudyUID is a Study Level attribute, Modality is Series Level and Image Number is Image Level.

The following sample code demonstrates how to loop through the entire structure and extract some attributes of each level.

DicomObjects.NET

   
DicomDataSet dir = new DicomDataSet("Your DICOMDIR file");
foreach (var patient in dir.Children)
{
    string patientName = patient.Name;
    foreach (var study in patient.Children)
    {
        string studyUID = study.InstanceUID;
        foreach (var series in study.Children)
        {
            string seriesUID = series.InstanceUID;
            string modality = series[Keyword.Modality].Value as string;
            foreach (var instance in series.Children)
            {
                string instanceUID = instance.InstanceUID;
                string sopclassUID = instance.SOPClass;
                string imageNo = instance[Keyword.InstanceNumber].Value as string;
            }
        }
    }
}

DicomObjects.COM

Dim d As New DicomDataSet
Dim ds As New DicomDataSets
Dim patient As DicomDataSet
Dim study As DicomDataSet
Dim series As DicomDataSet
Dim image As DicomDataSet
Dim PatientName, StudyUID, Modality, ImageNo As String

d = ds.ReadDirectory("Your DICOMDIR") ' Read in the DicomDIR file into DicomDataSet Object
For Each patient in d.Children ' For each Patient in the DICOMDIR
   PatientName = patient.Name
   For Each study in patient.Children ' For each study in patient
     StudyUID = study.StudyUID
     For Each series in study.Children ' For each series in study
       Modality = series.Attributes(&H8, &H60).Value
       For Each image in series.Children ' For each image in series
         ImageNo= image.Attributes(&H20,&H13).Value
       Next
    Next
  Next
Next

Private attributes are allowed to be added at each level in DICOMDIR but they should be ignored when reading the DICOMDIR.
Images can be added to DICOMDIR by using DicomDataSet.AddToDirectory method.

A sample DICOM DIR Reader/Writer program in C# can be downloaded from the samples page.