Search code examples
c#dicomevil-dicom

Evil Dicom hw to check if a tag exists


I am working with DICOM RT data sets and the Frame of reference UID is common across all files except the RT structure file where it is called referenced frame of reference.

What I would like to do is to read each DICOM file and check if the file has the tag FrameOfReferenceUID or ReferencedFrameOfReferenceUID and act accordingly.

var dcm = DICOMFileReader.Read(file);
var sel = new DICOMSelector(dcm);

var refFOR = sel.ReferencedFrameOfReferenceUID.Data;

This las line throws an error when a file does not contain the tag FrameOfReferenceUID. Need to check if it exists first, can't seem to figure out how to do this.


Solution

  • var dcm = DICOMObject.Read(@"MyDICOMFile.dcm");
    var genericName = dcm.FindFirst(TagHelper.PATIENT_NAME) as AbstractElement<string>;
    if(genericName != null)
        var genValue = genericName.Data;
    

    Above code is copied from here.