Repository: blairconrad/dicognito

Issue:
Anonymize Mitra Global Patient ID
e.g.

```
0031 0011       28 | private_creator                      | LO |   1 | "MITRA LINKED ATTRIBUTES 1.0"
0031 1120       10 | Unknown element                      | Unkn |  ?  | "GPIAPCB136"
```

Comments:

Patch:
diff --git a/src/dicognito/idanonymizer.py b/src/dicognito/idanonymizer.py
index d7aa019..24d37e5 100644
--- a/src/dicognito/idanonymizer.py
+++ b/src/dicognito/idanonymizer.py
@@ -54,16 +54,32 @@ class IDAnonymizer:
         True if the element was anonymized, or False if not.
         """
         if data_element.tag in self.id_tags:
-            if isinstance(data_element.value, pydicom.multival.MultiValue):
-                data_element.value = [self._new_id(id) for id in data_element.value]
-            else:
-                data_element.value = self._new_id(data_element.value)
+            self._replace_id(data_element)
             return True
+
+        if self._anonymize_mitra_global_patient_id(dataset, data_element):
+            return True
+
         if data_element.tag == self.issuer_tag and data_element.value:
             data_element.value = "DICOGNITO"
             return True
         return False
 
+    def _anonymize_mitra_global_patient_id(self, dataset, data_element):
+        if data_element.tag.group == 0x0031 and data_element.tag.element % 0x0020 == 0:
+            private_tag_group = data_element.tag.element >> 8
+            if dataset[(0x0031 << 16) + private_tag_group].value == "MITRA LINKED ATTRIBUTES 1.0":
+                self._replace_id(data_element)
+                data_element.value = data_element.value.encode()
+                return True
+        return False
+
+    def _replace_id(self, data_element):
+        if isinstance(data_element.value, pydicom.multival.MultiValue):
+            data_element.value = [self._new_id(id) for id in data_element.value]
+        else:
+            data_element.value = self._new_id(data_element.value)
+
     def _new_id(self, original_value):
         indexes = self.randomizer.get_ints_from_ranges(original_value, *self._indices_for_randomizer)
         id_root = "".join([self._alphabet[i] for i in indexes])
diff --git a/src/dicognito/release_notes.md b/src/dicognito/release_notes.md
index 1ee3fec..5e319e3 100644
--- a/src/dicognito/release_notes.md
+++ b/src/dicognito/release_notes.md
@@ -6,6 +6,7 @@
 ### New
 
 - Anonymize placer- and filler-order numbers ([#58](https://github.com/blairconrad/dicognito/issues/58))
+- Anonymize Mitra Global Patient IDs ([#60](https://github.com/blairconrad/dicognito/issues/60))
 
 ### Fixed
 


Test patch:
diff --git a/tests/test_anonymize_private_tags.py b/tests/test_anonymize_private_tags.py
new file mode 100644
index 0000000..af8ec28
--- /dev/null
+++ b/tests/test_anonymize_private_tags.py
@@ -0,0 +1,18 @@
+from dicognito.anonymizer import Anonymizer
+
+from .data_for_tests import load_test_instance
+
+
+def test_mitra_global_patient_id_is_updated():
+    with load_test_instance() as dataset:
+
+        block = dataset.private_block(0x0031, "MITRA LINKED ATTRIBUTES 1.0", create=True)
+        block.add_new(0x20, "LO", "GPIYMBB54")
+
+        anonymizer = Anonymizer()
+        anonymizer.anonymize(dataset)
+
+        block = dataset.private_block(0x0031, "MITRA LINKED ATTRIBUTES 1.0")
+        actual = block[0x20].value
+
+        assert actual != "GPIYMBB54"