Adding additional attributes when using AddToDirectory

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

The AddToDirectory method returns a 4 item DicomDataSets collection, 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

Note: In DicomObjects.NET, the numbering starts at 0, not 1

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!

e.g. to add the sex (which is not added by default)

DicomDirLevels = Directory.AddToDirectory(Image, FileName, TransferSyntax, 0); 
DicomDirLevels(1).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 &h10, &h40, Image.Attributes(&h10,&h40).Value
Relevance: