Search code examples
c#dicomclearcanvas

Get ClearCanvas DicomTag from the dicom group and element numbers


I'm trying to read dicom tags from a text file as (####,####) and create the corresponding DicomTag from the clear canvas library

//parsing txt string to find the corresponding dicomtag
foreach (String elem in settings)
{
    String tag = elem.Replace("(", "").Replace(")", "");
    String[] arr = tag.Split(',');
    DicomTag dTag = DicomTagDictionary.GetDicomTag(ushort.Parse(arr[0]), ushort.Parse(arr[1]));

    if (dTag != null)
    {
        toRemove.Add(dTag);
    }
    else
    {
        MessageBox.Show("Tag: (" + arr[0] + "," + arr[1] + ") is not valid");
    }
}

Some of the time even though a tag does exist the DicomTagDictionary.GetDicomTag(ushort group, ushort element) method cannot find the tag, for example (0008,0008) works but the tag (0008,1070) doesn't work.

the tags can be found here: http://medical.nema.org/Dicom/2011/11_06pu.pdf

the clear canvas equivalent can be found here: https://github.com/ClearCanvas/ClearCanvas/blob/master/Dicom/DicomTags.cs


Solution

  • I think the text file has the group and element in Hexadecimal, while the ushort's are parsing them as decimal. 0008, 1070 as decimal is 0x0008, 0x042E in hex, which is not a valid dicom tag (at least according to dicomlookup.com)

    If you specify ushort.Parse with a HexNumber Number Style, that should parse the value from the text file correctly.

    msdn.microsoft.com/en-us/library/kbaxyssf(v=vs.110).aspx