Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into other-vr-jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
wetzelj committed Jul 7, 2021
2 parents e2d3704 + 1379150 commit 0f53f9b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Referenced versions in headers are tagged on Github, in parentheses are for pypi
- updated pydicom dependency from 1.3.0 to 2.1.1 [#171] (https://github.com/pydicom/deid/issues/171) (0.2.25)
- bug fix for multivalued fields in %values lists [#174](https://github.com/pydicom/deid/issues/174)
- allowing other VR types for jitter [#175](https://github.com/pydicom/deid/issues/175)
- ensuring that an add/replace of an existing value is also updated in fields [#173](https://github.com/pydicom/deid/issues/173)
- change to correct issue with deidentifying RGB images [#165](https://github.com/pydicom/deid/issues/165) (0.2.24)
- removing verbosity of debug logger (0.2.23)
- changing iteration technique through fields to properly add nested uids [#153](https://github.com/pydicom/deid/issues/153) (0.2.22)
Expand Down
1 change: 0 additions & 1 deletion deid/dicom/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def replace_identifiers(
and saving new files. If you want to replace sequences, they need
to be extracted with get_identifiers and expand_sequences to True.
"""

if not isinstance(dicom_files, list):
dicom_files = [dicom_files]

Expand Down
8 changes: 8 additions & 0 deletions deid/dicom/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def add_field(self, field, value):
while not hasattr(element, "value"):
element = element.element
element.value = value
self.dicom.add(element)

else:
element = DataElement(tag["tag"], tag["VR"], value)
Expand Down Expand Up @@ -426,6 +427,13 @@ def _run_action(self, field, action, value=None):
)
if value is not None:

# Cut out early if the field isn't in the dicom
if field.name not in self.dicom:
return

# Preserve the old value in case we need to update
old_value = self.dicom[field.name].value

# Jitter the field by the supplied value
new_val = jitter_timestamp(field=field, value=value)
self.replace_field(field, new_val)
Expand Down
35 changes: 35 additions & 0 deletions deid/tests/test_replace_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,41 @@ def test_replace_with_constant(self):
self.assertEqual(newvalue1, result[0][newfield1].value)
self.assertEqual(newvalue2, result[0][newfield2].value)

def test_jitter_replace_compounding(self):
"""RECIPE RULE
JITTER AcquisitonDate 1
REPLACE AcquisitionDate 20210330
"""

print("Test replace tags with constant values")
dicom_file = get_file(self.dataset)

newfield1 = "AcquisitionDate"
newvalue1 = "20210330"

actions = [
{"action": "JITTER", "field": newfield1, "value": "1"},
{"action": "REPLACE", "field": newfield1, "value": newvalue1},
]
recipe = create_recipe(actions)

inputfile = read_file(dicom_file)
currentValue = inputfile[newfield1].value

self.assertNotEqual(newvalue1, currentValue)

result = replace_identifiers(
dicom_files=dicom_file,
deid=recipe,
save=True,
remove_private=False,
strip_sequences=False,
)

outputfile = read_file(result[0])
self.assertEqual(1, len(result))
self.assertEqual(newvalue1, outputfile[newfield1].value)

def test_remove(self):
"""RECIPE RULE
REMOVE InstitutionName
Expand Down

0 comments on commit 0f53f9b

Please sign in to comment.