tags:

views:

56

answers:

3

I'm learning C# programming. I try to read for example: patient id or patient name from dicom tags. I tried like that:

    string tag = "";
    string op = "";
    string val_rep = "";
    string war = "";

      if (DicomFile.IsDicomFile(f))
       {
           Sequence se = plik.GetJointDataSets().GetJointSubsequences();


           foreach (DataElement el in se)
           {


               tag = el.Tag.ToString(); //tag group and element
               op = el.VR.Tag.GetDictionaryEntry().Description;//tag description
               val_rep = el.VR.ToString();//value representative
               war = el.Value.ToString();// 

             }
         }

Why it doesn't give me values what i want? sq = sequence.
How can i read what is patient id?

+3  A: 

It's not clear to me what you are doing exactly but the code you have posted is obviously not going to work. The problem is that you are declaring a local variable called var, assigning a value to it, and then immediately that value goes out of scope. Effectively the code is doing nothing.

You also don't need to first assign null and then reassign. This is a simpler way to write your code:

foreach (DataElement el in sq)
{
    string var = elementy.Value.ToString();
}

I'd also suggest that you try to avoid var as a variable name. It says nothing about what the variable actually contains and it can easily be confused with the var contextual keyword.

Mark Byers
A: 

Well there's not much to work with, but try it like this:

List<string> nameList = new List<string>();
foreach (DataElement el in sq) 
{ 
   nameList.Add(el.Value as string); 
}
naacal
A: 

The Element and Group for Patient ID is 0x0010, 0x0020. You can foreach through the elements as you are, and stop the iteration when you find the values you're looking for.

string tag = "";
string op = "";
string val_rep = "";
string war = "";

if (DicomFile.IsDicomFile(f))
{
    Sequence se = plik.GetJointDataSets().GetJointSubsequences();

    foreach (DataElement el in se)
    {
        if (el.Tag.Element == "0010" && el.Tag.Group == "0020")
        {
            tag = el.Tag.ToString(); //tag group and element
            op = el.VR.Tag.GetDictionaryEntry().Description;//tag description
            val_rep = el.VR.ToString();//value representative
            war = el.Value.ToString();// 
            break;
        }
    }
}

That should set the tag, op, val_rep, and war variables for you when it finds the Patient ID tag, and then break out of the foreach.

As I've mentioned several times on here, I'm not incredibly well versed with the openDicom library, but assuming the rest of your code is correct this should get you what you want. The openDICOM documentation for the Group and Element properties of the Tag class are somewhat strange, "Element is a hexadecimal string value of format 'eeee'.", so I'm assuming here that the compared values should be in that format, but there's a small possibility that the formatting won't be correct.

I will say that if you are just learning C#, and DICOM isn't something that you're being forced to do, find something easier to start with, because learning to use the DICOM standard can be at LEAST as confusing as learning a new programming language, and combining them at the same time is something I wouldn't recommend to ANYONE.

md5sum
Thanks for answer, but it doesn't get a value of a patient id.
luc