Skip to content

Commit 0596c93

Browse files
authored
Merge pull request #158 from blairconrad/bad-privates
Limit private tag anonymization to Mitra global patient ID
2 parents 57abcb6 + 5edcd09 commit 0596c93

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/dicognito/idanonymizer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,11 @@ def _anonymize_mitra_global_patient_id(
9090
mitra_global_patient_id_element = 0x0020
9191
if (
9292
data_element.tag.group == mitra_linked_attributes_group
93-
and data_element.tag.element % mitra_global_patient_id_element == 0
93+
and data_element.tag.element & 0x00FF == mitra_global_patient_id_element
9494
):
9595
private_tag_group = data_element.tag.element >> 8
96-
if (
97-
dataset[(mitra_linked_attributes_group << 16) + private_tag_group].value
98-
== "MITRA LINKED ATTRIBUTES 1.0"
99-
):
96+
element = dataset.get((mitra_linked_attributes_group, private_tag_group), None)
97+
if element and element.value == "MITRA LINKED ATTRIBUTES 1.0":
10098
# For pydicom 2.2.0 and above (at least to 2.2.2) the Mitra global patient ID tag
10199
# can be misidentified as VR IS, instead of its proper LO. This causes
102100
# the anonymize action to fail because most values can't be converted.

src/dicognito/release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
### Fixed
55
- Version table format has bad separator ([#147](https://github.com/blairconrad/dicognito/issues/147))
6+
- Private creator 0031,0020 breaks anonymization ([#157](https://github.com/blairconrad/dicognito/issues/157))
67

78
## 0.16.0a1
89

tests/test_anonymize_private_tags.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dicognito.anonymizer import Anonymizer
2+
from pydicom import Dataset
23

34
from .data_for_tests import load_dcm
45

@@ -16,3 +17,29 @@ def test_mitra_global_patient_id_is_updated():
1617
actual = block[0x20].value
1718

1819
assert actual != "GPIYMBB54"
20+
21+
22+
def test_0031_0040_is_not_updated():
23+
with Dataset() as dataset:
24+
dataset.ensure_file_meta()
25+
dataset.add_new(0x00310040, "LO", "Some value")
26+
expected = dataset[0x0031, 0x0040]
27+
28+
anonymizer = Anonymizer()
29+
anonymizer.anonymize(dataset)
30+
31+
actual = dataset[0x0031, 0x0040]
32+
assert actual == expected
33+
34+
35+
def test_private_creator_0031_0020_is_not_updated():
36+
with Dataset() as dataset:
37+
dataset.ensure_file_meta()
38+
dataset.add_new(0x00310020, "LO", "Another value")
39+
expected = dataset[0x0031, 0x0020]
40+
41+
anonymizer = Anonymizer()
42+
anonymizer.anonymize(dataset)
43+
44+
actual = dataset[0x0031, 0x0020]
45+
assert actual == expected

0 commit comments

Comments
 (0)