I have a lot of DICOM data sets that have a private tag in them that contain information that I do not want to keep in the header. The value for this tag changes for each dataset, so I do not know the value. Here is an example of the PRIVATE CREATOR and the Private Tag I want to be updated or removed.
0033,0010 ---: MITRA OBJECT UTF8 ATTRIBUTES 1.0
0033,1016 ---: Dummy^Data^G^
I want to be able to either completely remove 0033,1016
or update it with a new value. Everything I have tried either does nothing or will add another 0033,1016
tag, creating two 0033,1016
tag. One is the original and one that was added when I tried to update the original.
0033,0010 ---: MITRA OBJECT UTF8 ATTRIBUTES 1.0
0033,1016 ---: Dummy^Data^G^
0033,1016 ---: FOO
If I run the code again, I can update the 0033,1016
that has the value FOO
, but I can never change the 0033,1016
tag with the value Dummy^Data^G^
.
Following is my code:
string main_path = @"C:\Users\pthalken\Desktop\foo";
DirectoryInfo foo = new DirectoryInfo(main_path);
FileInfo[] dicomFiles = foo.GetFiles();
foreach(FileInfo files in dicomFiles)
{
DicomFile openedDicom = DicomFile.Open(files.FullName, FileReadOption.ReadAll);
//getting the private tag that I want to change or remove
var remove = DicomTag.Parse("0033,1016");
var test = DicomTag.Parse("0010,0010");
//this method will work for public tags as expected, but with private tags it will juist add another tag
//it will not update the orignial tag. If ran again it will change the recently inputted tag but still not touch the original
openedDicom.Dataset.AddOrUpdate(remove, "FOO");
//Does not update original tag, will add another 0033,1016 tag with value HOT
openedDicom.Dataset.AddOrUpdate(new DicomCodeString(openedDicom.Dataset.GetPrivateTag(new DicomTag(0x0033, 0x1016)), "HOT"));
//Does not update original tag, will add another 0033,1016 tag with value HOT CHEETO
openedDicom.Dataset.AddOrUpdate(new DicomCodeString(openedDicom.Dataset.GetPrivateTag(remove), "HOT CHEETO"));
//does not remove the orignial tag
openedDicom.Dataset.Remove(remove);
openedDicom.Save(files.FullName);
}