Reputation: 271
After extracting information out of a radiation therapy plan stored as a DICOM-File, my issue is now a different one.
I know, that I can add or update items in an existing plan with (e.g.)
file.Dataset.AddOrUpdate(Dicom.DicomTag.PatientAge,23);
Even handling DicomTags in a sequence is not the problem with (e.g.)
file.Dataset.Get<Dicom.DicomSequence>(Dicom.DicomTag.BeamSequence).Items[1].
Get<Dicom.DicomSequence>(Dicom.DicomTag.ControlPointSequence).Items[0].
Get<Dicom.DicomSequence>(Dicom.DicomTag.BeamLimitingDevicePositionSequence).Items[2].
AddOrUpdate(Dicom.DicomTag.LeafJawPositions, "-30\\30");
But now I am wondering if it is possible to create a complete new sequence and store information in it? I know that wanting this forces me to create not only one item, but much more information arround this item, cause there is no sequence in the plans I looked through which have this.
In the fo-dicom API documentation I found the Dicom.IO.Writer
Namespace. I looked through but didn't find what i expected to find. Following my first instinct, I would have written this
string filename = "output.dcm";
DicomWriter file = new DicomWriter(@filename);
... trying to create TagElements
Also the other command line DicomFileWriter file = new DicomFileWriter(...);
doesn't work because the constructor only wants to receive options. The other DicomWriter()
constructor is similar to this.
I also checked the file.Dataset
possibilities for writing new tags, but without succes. So I hope one of you can give me a hint where I did a wrong step.
Upvotes: 4
Views: 4728
Reputation: 86
This is one way of doing it:
string filename = "output.dcm";
DicomDataset ds = new DicomDataset(); //Main dataset
ds.Add(DicomTag.SpecificCharacterSet, "ISO_IR 100"); //Add some items
ds.Add(DicomTag.PatientID, "191212121212");
DicomDataset sqContent = new DicomDataset(); //Content of the sequence
sqContent.Add(DicomTag.Modality, "US");
sqContent.Add(DicomTag.ScheduledProcedureStepStartDate, DateTime.Now.Date);
DicomSequence sq = new DicomSequence(DicomTag.ScheduledProcedureStepSequence, sqContent); // Create sequence, add content
ds.Add(sq); //Add sequence to main dataset
DicomFile file = new DicomFile();
file.Dataset.Add(ds); //Add main dataset to DicomFile
file.FileMetaInfo.TransferSyntax = DicomTransferSyntax.ImplicitVRLittleEndian; //Specify transfer syntax
file.Save(filename); //Save file to disk
Upvotes: 7