3

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

Han
  • 3,052
  • 2
  • 22
  • 31
TCulos
  • 183
  • 3
  • 13
  • I have not used ClearCanvas before, but my first thought would be that the text has the group and element in Hexadecimal, while the ushort's are parsing them as decimal. Maybe try ushort.Parse with a HexNumber Number Style? https://msdn.microsoft.com/en-us/library/kbaxyssf(v=vs.110).aspx – rkh Aug 05 '15 at 01:14

2 Answers2

2

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

rkh
  • 1,761
  • 1
  • 20
  • 30
1

I use the following to either edit or create non-existent tags in Clear Canvas:

Platform.Log(LogLevel.Info, "Setting Tag: " + "0x" + Stats.g_TaglistTag1 + " to value of: " + Stats.g_tbTagList1);
AC_To_Coerce[Convert.ToUInt32("0x" + Stats.g_TaglistTag1, 16)].SetStringValue(Stats.g_tbTagList1);

AC_To_Coerce is a DicomAttributeCollection object. Stats.g_TaglistTag1 is a hex string for the DICOM tag, Stats.g_tbTagList1 is the value for the tag. This could also be used to set a tag value for a DicomFile object, or DicomMessage object with simple modification.

This sets or creates and sets the value and logs the following line for example:

2015-09-18 21:02:24,944 [6704] [7] INFO - Setting Tag: 0x00100010 to value of: Test

Jake
  • 397
  • 2
  • 15