Skip to content

Commit

Permalink
fix dicom header with the original study and series uids
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-rfj committed Jul 8, 2024
1 parent c019beb commit 3ca64a6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/slicer/MONAILabel/MONAILabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import vtk
import vtkSegmentationCore
from MONAILabelLib import GenericAnatomyColors, MONAILabelClient
from pydicom import dcmread
from slicer.i18n import tr as _
from slicer.i18n import translate
from slicer.ScriptedLoadableModule import *
Expand Down Expand Up @@ -1414,6 +1415,10 @@ def onUploadImage(self, init_sample=True, session=False):
start = time.time()
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
volumeShItemID = shNode.GetItemByDataNode(volumeNode)

seriesInstanceUID = shNode.GetItemUID(volumeShItemID, 'DICOM')
instUids = slicer.dicomDatabase.instancesForSeries(seriesInstanceUID)
studyInstanceUID = slicer.dicomDatabase.instanceValue(instUids[0], "0020,000D")

exporter = DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()
exportables = exporter.examineForExport(volumeShItemID)
Expand All @@ -1434,6 +1439,12 @@ def onUploadImage(self, init_sample=True, session=False):
dcm_filenames = self.get_dicom_files()
report_progress_increment = round(last_report_progress / len(dcm_filenames), 1)
for dcm_fullpath in dcm_filenames:
# set original study and series UIDs
dcm = dcmread(dcm_fullpath)
dcm.StudyInstanceUID = studyInstanceUID
dcm.SeriesInstanceUID = seriesInstanceUID
dcm.save_as(dcm_fullpath)

dcm_filename = dcm_fullpath.split("/")[-1]
dcm_filename = ".".join(dcm_filename.split(".")[:-1])
self.logic.upload_image(dcm_fullpath, dcm_filename)
Expand Down

0 comments on commit 3ca64a6

Please sign in to comment.