millenniumThalken
millenniumThalken

Reputation: 47

How to Modify Dicom Tags Using fo-dicom

I am creating a console application that will modify dicom tags. I will load up a single dicom file and update the PatientID tag.

I can not seem to to get anything to modify. I am able to read tags, but updating/adding does not seem to work for me. Previously I have used the DICOM ToolKit on powershell and it is very straight forward and easy, but I want to start developing in c# and so far I am failing.

using System;
using System.IO;
using SpiromicsImporterPrep.FileMethods;
using Dicom;

namespace SpiromicsImporterPrep
{
    class Program
    {
        static void Main(string[] args)
        {
            string filename = @"Z:\SPIROMICS\Human_Scans\Dispatch_Received\NO_BACKUP_DONE_HERE\MIFAR\FORCE\JH114062-FU4\119755500\Non_Con_FRC__0.75__Qr40__5_7094\IM001139";
            var file = DicomFile.Open(filename, readOption: FileReadOption.ReadAll);
            var dicomDataset = file.Dataset;
            dicomDataset.AddOrUpdate(DicomTag.PatientID, "TEST-PATIENT");

        }
    }
}

I expect after running the code when I look at the Dicom Header tags for this file with ImageJ or and other dicom reader that the value for the PatientID tag will be "TEST-PATIENT" The code runs with no errors but nothing seems to be updated or changed when I look at the dicom header.

Upvotes: 3

Views: 3903

Answers (1)

sync
sync

Reputation: 259

you should invoke DicomFile.Save() Method.

            string[] files = System.IO.Directory.GetFiles(@"D:\AcquiredImages\20191107\1.2.826.0.1.3680043.2.461.11107149.3266627937\1.2.276.0.7230010.3.1.3.3632557514.6848.1573106796.739");

            foreach (var item in files)
            {
                DicomFile dicomFile = DicomFile.Open(item,FileReadOption.ReadAll);             

                dicomFile.Dataset.AddOrUpdate<string>(DicomTag.PatientName, "abc");

                dicomFile.Save(item);
            }

FileReadOption.ReadAll is required.

Upvotes: 4

Related Questions