Adding additional attributes when using AddToDirectory

Only the mandatory elements (and one or two others we’ve been talked into adding) are put into the DICOMDIR by the AddToDirectory (.NET version) or AddToDirectory (COM version) method, but you can add others yourself very easily.

The AddToDirectory method returns a 4 item DicomDataSetCollection (.NET) or DicomDataSets collection(COM), and the 4 items are references to the 4 datasets referred to (existing or created as necessary) by that method call. They represent (in numerical order)

  1. PATIENT level
  2. STUDY level
  3. SERIES level
  4. IMAGE/INSTANCE level

You can then add any additional attributes you wish to any of these levels. You do not need to worry about adding them multiple times (if the item already exists) as they will simply over-write the (presumably identical) existing copy.

The code below shows how to add the patient sex (which is not added by default) using DicomObjects.

.NET version

 DicomDirLevels = Directory.AddToDirectory(Image, FileName, TransferSyntax, 0); 
 DicomDirLevels[0].Sex = Image.Sex;

Of course, exactly the same could be achieved (and must be done this way) for attributes which do not have convenient shortcuts:

DicomDirLevels = Directory.AddToDirectory(Image, FileName, TransferSyntax, 0); 
DicomDirLevels[1].Attributes.Add(Keyword.PatientSex, Image.Attributes(Keyword.PatientSex).Value);
Note: In DicomObjects.NET, the numbering starts at 0, not 1

.COM version

Dim dir As New DicomDataSet
Dim dirLevels As DicomDataSets
    
Set dirLevels = dir.AddToDirectory(image, "\IMAGES\1", image.ReceivedSyntax, 0)
dirLevels(1).Sex = image.Sex
' alternatively attribute can be added by group and element numbers
dirLevels(1).Attributes.Add &H10, &H40, image.Sex


We use cookies to give you the best possible experience on our website. By continuing to use this website, you agree with our use of cookies. for more information please click HERE