Hierarchical SOP Instance

While DicomObjects can not create a Dicom Hierarchical SOP Instance dataset collection directly, however it can do much of the work for you. A Hierarchical SOP Instance Dataset collection are similar in structure to a DicomDir which DicomObjects can create automatically. Hierarchical SOP Instances are primarily used in the creation of Key Note Objects. The Structure of the Hierarchical SOP Instance is Study - Series - Instance (NO PATIENT)

The first Step is to organise all the objects of interest into a DicomDir by adding them to a DicomDataSet by using the AddToDirectory method.

DicomDataSet PseudoDicomDir = new DicomDataSet()
PseudoDicomDir.AddToDirectory(ThisObject, "", "");          // Add all the Objects to the DicomDir

We Should now check that only a references to a single patient have been made, the top level of a DicomDir is patient level therefore

if (PseudoDicomDir.Children.Count > 1)                     // if more than one member to the Top Level                           
  MessageBox.Show("ERROR - more than one patient ID");     // then we have more than one patient 

We can now extract the information required from the DicomDir into DicomDataSetCollection that represents a Hierarchical SOP Instances and can be added to(0040,A375).

DicomDataSetCollection StudySequence = new DicomDataSetCollection();// create a Study Level Sequence
foreach (DicomDataSet study in PseudoDicomDir.Children[0].Children) // for each Study in the dicomdir (only one patient allowed)
  DicomDataSet StudySequenceItem = StudySequence.AddNew();
  StudySequenceItem.StudyUID = study.StudyUID;                      // Unique identifier of a Series that is part of this Study 
  DicomDataSetCollection SeriesSequence = new DicomDataSetCollection();
  foreach (DicomDataSet series in study.Children)                   // for each series in each study
     DicomDataSet SeriesSequenceItem = SeriesSequence.AddNew();
     SeriesSequenceItem.SeriesUID = series.SeriesUID;               // Referenced Series Instance UID
     DicomDataSetCollection InstanceSequence = new DicomDataSetCollection();
     foreach (DicomDataSet Instance in series.Children)             // for each instance in each series
        DicomDataSet InstanceSequenceItem = InstanceSequence.AddNew();
        InstanceSequenceItem.Add(0x0008, 0x1150, Instance.Value(0x0004, 0x1510));       // Referenced SOP Class UID    
        InstanceSequenceItem.Add(0x0008, 0x1155, Instance.Value(0x0004, 0x1511));       // Referenced SOP Instance UID
     SeriesSequenceItem.Add(0x0008, 0x1199, InstanceSequence);      // add all the instance collection to the series
   StudySequenceItem.Add(0x0008, 0x1115, SeriesSequence);           // add the series collection to the study