3

im trying to add a new tag to my DicomFile.DataSet in ClearCanvas.

I notice there is the method "DicomFile.DataSet.RemoveAttribute" but no "AddAtribute" method. So I have been looking at the method "LoadDicomFields" & "SaveDicomFields" but so far can't seem to get them to work. Ive tried to pass in a "DicomFieldAttribute" to these methods, but to no avail.

What am I missing here? Or what do I need to do to add a new tag to the DataSet.

DicomFieldAttribute c = new DicomFieldAttribute(tag);
List<DicomFieldAttribute> cs = new List<DicomFieldAttribute>();
cs.Add(c);
DicomFile.DataSet.LoadDicomFields(cs);
DicomFile.DataSet.SaveDicomFields(cs);
if(DicomFile.DataSet.Contains(tag))
{
   tag = 0; //BreakPoint never reached here
}

Or I tried this as well::

DicomFieldAttribute c = new DicomFieldAttribute(tag);
DicomFile.DataSet.LoadDicomFields(c);
DicomFile.DataSet.SaveDicomFields(c);
if(DicomFile.DataSet.Contains(tag))
{
   tag = 0; //BreakPoint never reached here
}

Ive been stuck on what would seem to be a trivial task.

Steve Wranovsky
  • 5,503
  • 4
  • 34
  • 52
zezba9000
  • 3,247
  • 1
  • 29
  • 51

1 Answers1

2

You're confusing a bit the use of attributes. The DicomFiledAttribute is a .NET attribute that can be placed on members of a class so that the class is automatically populated with values from a DicomAttributeCollection or or to have the class automatically populated with values from the DicomAttribute Collection. Ie, given a test class like this:


public class TestClass
{
    [DicomField(DicomTags.SopClassUid, DefaultValue = DicomFieldDefault.Default)]
    public DicomUid SopClassUid = null;

    [DicomField(DicomTags.SopInstanceUid, DefaultValue = DicomFieldDefault.Default)]
    public DicomUid SOPInstanceUID = null;

    [DicomField(DicomTags.StudyDate, DefaultValue = DicomFieldDefault.Default)]
    public DateTime StudyDate;
}

You could populate an instance of the class like this:


DicomFile file = new DicomFile("filename.dcm");
file.Load();
TestClass testInstance = new TestClass();

file.DataSet.LoadDicomFields(testInstance);
// testInstance should now be populated with the values from file

If you're interested in just populating some DICOM tags, the DicomAttributeCollection has an indexer in it. The indexer will automatically create a DicomAttribute instance if it doesn't already exist, for the tag requested via the indexer. So, to populate a value, you can do soemthing like this:



DicomFile file = new DicomFile("filename.dcm");

file.DataSet[DicomTags.SopInstanceUid].SetStringValue("1.1.1");

If you want to create the DicomAttribute yourself, you can do something like this:


DicomAttribute attrib = new DicomAttributeUI(DicomTags.SopInstanceUid);
attrib.SetStringValue("1.1.1");

DicomFile file = new DicomFile("filename.dcm");
file.DataSet[DicomTags.SopInstanceUid] = attrib;

Steve Wranovsky
  • 5,503
  • 4
  • 34
  • 52
  • "file.DataSet[DicomTags.SopInstanceUid].SetStringValue("1.1.1");" Works fine, but when I try something like:: "file.DataSet[1610690560].SetStringValue("1.1.1");" it throws the err (Invalid tag: 60013000). Also the reason i'm doing this is because I want to add a new Overlay(60xx). I notice there is no method like "SetByteArrayValue" that I can use to set the new Overlay data in, which is an array of bytes. Tnx for the answer btw. – zezba9000 Feb 16 '11 at 22:53
  • 60013000 is considered a private tag, since its an odd group. There is a different form of the indexer that uses a DicomTag object. You may have to create a DicomTag object for the tag you want and use that to access the indexer. – Steve Wranovsky Feb 17 '11 at 15:52