Skip to content

Commit

Permalink
ENH: Make characterset modifier DICOM patcher rule stronger (#7683)
Browse files Browse the repository at this point in the history
Previously DICOM patcher's rule that modified a character set only changed those files that did not have any encoding set. However, files emerged that contained incorrectly set "ISO_IR 100" encoding value. So, the rule is now set to force setting the requested encoding for all files, except if the encoding is already UTF8.

See https://discourse.slicer.org/t/patientname-and-rus-language-trouble/28870/4 for details.
  • Loading branch information
lassoan committed Apr 7, 2024
1 parent 4bda6b1 commit 75e2595
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Modules/Scripted/DICOMPatcher/DICOMPatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def setup(self):
self.specifyCharacterSetCheckBox.checked = False
self.specifyCharacterSetCheckBox.setToolTip(
"If checked, then SpecificCharacterSet is set to the specified value in all DICOM files"
" where the character set is not specified already. It is recommended to enable this if patient name does not show up correctly.")
" where the character set is not UTF8 (ISO_IR 192) already. It is recommended to enable this if patient name does not show up correctly.")
characterSetLayout.addWidget(self.specifyCharacterSetCheckBox)

self.specifyCharacterSetLineEdit = qt.QLineEdit()
Expand Down Expand Up @@ -518,12 +518,21 @@ class UseCharacterSet(DICOMPatcherRule):
"""

def processDataSet(self, ds):
if not self.parameters["CharacterSet"]:
characterSet = self.parameters.get("CharacterSet")
if not characterSet:
raise RuntimeError("'CharacterSet' parameter must be specified")
if not hasattr(ds, "SpecificCharacterSet"):
ds.SpecificCharacterSet = self.parameters["CharacterSet"]
ds.decode()
ds.SpecificCharacterSet = "ISO_IR 192"

if hasattr(ds, "SpecificCharacterSet") and ds.SpecificCharacterSet == "ISO_IR 192":
# UTF8 is assumed to be correct (the software that created the instance
# is aware of UTF8), therefore character set is not modified
self.addLog("Character set is already UTF8 (ISO_IR 192), keep it as is.")
return

self.addLog(f"Set character set to {characterSet}.")
ds.SpecificCharacterSet = characterSet
ds.decode()
ds.SpecificCharacterSet = "ISO_IR 192"
slicer.ds = ds


#
Expand Down

0 comments on commit 75e2595

Please sign in to comment.