Search code examples
c#dicomclearcanvas

clearcanvas read dicomdir


I'm reading attributes from each dicom file in directory and it takes a lot of time. My code :

       var patient_id = k_di_.DataSet.GetAttribute(DicomTags.PatientId);

How can i do the same, but reading only in dicomdir?


Solution

  • The ClearCanvas library has a DicomDirectory class for reading and writing DICOMDIRs. You can traverse a DICOMDIR and read the Patient ID something like this:

    
    DicomDirectory reader = new DicomDirectory("DICOMDIR");
    reader.Load("DICOMDIR Filename");
    DirectoryRecordSequenceItem record = reader.RootDirectoryRecord;
    while (record != null)
    {
        var patientId = record[DicomTags.PatientId];
        record = record.NextDirectoryRecord;
    }