I would like to update (300A,004A) and (300A,00B8) dicom tags both are type string strings.
The challenge is that it is nested and multiple instances of these Tags.
Here is my code:
string[] files = Directory.GetFiles(dirPath);
foreach (var item in files)
{
DicomFile dicomFile = DicomFile.Open(item, FileReadOption.ReadAll);
var dicomDataset = dicomFile.Dataset;
//Count number of items found in the sequence
int count = dicomDataset.GetSequence(DicomTag.ToleranceTableSequence).Items[0].GetSequence(DicomTag.BeamLimitingDeviceToleranceSequence).Items.Count();
//go thru items until you find the correct one that contains "ASYMX
for (int i = 0; i < count; i++)
{
var Dev1 = dicomDataset.GetSequence(DicomTag.ToleranceTableSequence).Items[0].GetSequence(DicomTag.BeamLimitingDeviceToleranceSequence).Items[i].GetSingleValueOrDefault<string>(DicomTag.RTBeamLimitingDeviceType, "");
if (Dev1 == "ASYMX")
{
//Code works up to here because it found the item that contains ASYMX
//Now, I need to update those tags
dicomFile.Dataset.AddOrUpdate<string>(DicomTag.BeamLimitingDevicePositionTolerance, "Valu1");
dicomFile.Dataset.AddOrUpdate<string>(DicomTag.RTBeamLimitingDeviceType, "ASYMX2");
dicomFile.Save(item);
}
}
}
else
{
//Console.WriteLine("TBD");
}
The code compiles correctly but file does not update
Question answered by MrBean
https://stackoverflow.com/questions/78258496/update-dicom-tags-in-a-nested-sequence