Search code examples
c#dicomfo-dicom

How to create a DICOMDIR properly with fo-dicom?


I've been trying to find a way to use fo-dicom to create a DICOMDIR file, and have it reference several files that contain image series, but so far I can't.

I've successfully read DICOMDIRs, series and even rendered images. From that, I was able to understand that the DicomDirectory has a RootDirectoryRecordCollection for Patients, and from there you have LowerLevelDirectoryRecordCollection for Studies, then Series, and then Images. But when it comes to building that structure (for example, to create DICOMDIR and Series files for new studies) I can't find a way to set those LowerLeverDirectoryRecords; RootDirectoryRecordCollection has an Add method, but it takes a DicomItem, so I take it it's for DicomDataset or DicomTag/Value, and its property LowerLevelDirectoryRecordCollection is an IEnumerable, so no Add there. I've also seen the AddFile method, but there's no hierarchy there, so I supposed that's for the series files.

Has anybody succesfully created a DICOMDIR and had it reference several series files with fo-dicom? How? Thanks


Solution

  • It should be as easy as:

    var dicomDir = new DicomDirectory();
    foreach (var file in dirInfo.GetFiles("*.*", SearchOption.AllDirectories))
    {
        var dicomFile = Dicom.DicomFile.Open(file.FullName);
        dicomDir.AddFile(dicomFile, String.Format(@"000001\{0}", file.Name));
    }
    dicomDir.Save(dicomDirPath);
    

    All the internal hierachial structure is added automatically. I took this example from the fo-dicom-samples repository: https://github.com/fo-dicom/fo-dicom-samples/blob/master/Desktop/DICOM%20Media/Program.cs