DICOM tag and FileDataset ds

89 views
Skip to first unread message

Normand Robert

unread,
Jun 2, 2022, 1:38:54 PM6/2/22
to pydicom
I am writing a utility so some DICOM tags values are processed and changed in the same way as in another program I wrote that does it on actual files and saves them.  We want this to see how values would be changed "stand alone"

So I am making a "ds" instance and it looks like I need to specify a filename even though I have no plans to ever save a file nor does it look anything gets written out because I am not saving?
Is this a good way?

Regards

 Do I even need to bother with all this UID stuff?

suffix = '.dcm'
filename_little_endian = tempfile.NamedTemporaryFile(suffix=suffix).name
filename_big_endian = tempfile.NamedTemporaryFile(suffix=suffix).name

# Populate required values for file meta information
# pydicom version >=2.0 feature.
file_meta = FileMetaDataset()
file_meta.MediaStorageSOPClassUID = UID('1.2.840.10008.5.1.4.1.1.2')
file_meta.MediaStorageSOPInstanceUID = UID("1.2.3")
file_meta.ImplementationClassUID = UID("1.2.3.4")
# Create the FileDataset instance (initially no data elements, but file_meta
# supplied)
# Yes this is unfortunate but you need to set a filename to create a ds as it is a FileDataset
ds = FileDataset(filename_little_endian, {},
file_meta=file_meta, preamble=b"\0" * 128)

# Add the data elements users want to see changed in this utility
ds.PatientName = patientName
ds.PatientID = patientID
# Leveraging function used elsewhere to actually modify files so we have the same behaviour
dicomTagsToEdit.processTags(self._dicomTagsToProcess, ds, self._verboseValue)

return ds.PatientName, ds.PatientID
Reply all
Reply to author
Forward
0 new messages