|
33 | 33 | from deid.utils import get_installdir
|
34 | 34 | from deid.data import get_dataset
|
35 | 35 | from deid.dicom.parser import DicomParser
|
36 |
| -from deid.tests.common import get_file, create_recipe |
| 36 | +from deid.tests.common import get_file, get_same_file, create_recipe |
37 | 37 |
|
38 | 38 | uuid_regex = "[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"
|
39 | 39 |
|
@@ -111,6 +111,75 @@ def test_basic_uuid(self):
|
111 | 111 | print(parser.dicom["ReferringPhysicianName"].value)
|
112 | 112 | assert re.search(uuid_regex, str(parser.dicom["ReferringPhysicianName"].value))
|
113 | 113 |
|
| 114 | + def test_pydicom_uuid(self): |
| 115 | + """ |
| 116 | + %header |
| 117 | + REPLACE ReferringPhysicianName deid_func:pydicom_uuid |
| 118 | + """ |
| 119 | + print("Test deid_func:pydicom_uuid") |
| 120 | + |
| 121 | + dicom_file = get_file(self.dataset) |
| 122 | + actions = [ |
| 123 | + { |
| 124 | + "action": "REPLACE", |
| 125 | + "field": "ReferringPhysicianName", |
| 126 | + "value": "deid_func:pydicom_uuid", |
| 127 | + } |
| 128 | + ] |
| 129 | + recipe = create_recipe(actions) |
| 130 | + |
| 131 | + # Create a parser, define function for it |
| 132 | + parser = DicomParser(dicom_file, recipe=recipe) |
| 133 | + parser.parse() |
| 134 | + |
| 135 | + # Randomness is anything, but should be all numbers |
| 136 | + print(parser.dicom["ReferringPhysicianName"].value) |
| 137 | + name = str(parser.dicom["ReferringPhysicianName"].value) |
| 138 | + assert re.search("([0-9]|.)+", name) |
| 139 | + |
| 140 | + # This is the pydicom default, and we default to stable remapping |
| 141 | + assert ( |
| 142 | + name == "2.25.39101090714049289438893821151950032074223798085258118413707" |
| 143 | + ) |
| 144 | + |
| 145 | + # Add a custom prefix |
| 146 | + # must match '^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*\\.$' |
| 147 | + actions = [ |
| 148 | + { |
| 149 | + "action": "REPLACE", |
| 150 | + "field": "ReferringPhysicianName", |
| 151 | + "value": "deid_func:pydicom_uuid prefix=1.55.", |
| 152 | + } |
| 153 | + ] |
| 154 | + recipe = create_recipe(actions) |
| 155 | + parser = DicomParser(dicom_file, recipe=recipe) |
| 156 | + parser.parse() |
| 157 | + |
| 158 | + # Randomness is anything, but should be all numbers |
| 159 | + print(parser.dicom["ReferringPhysicianName"].value) |
| 160 | + name = str(parser.dicom["ReferringPhysicianName"].value) |
| 161 | + assert name.startswith("1.55.") |
| 162 | + |
| 163 | + # This should always be consistent if we use the original as entropy |
| 164 | + dicom_file = get_same_file(self.dataset) |
| 165 | + actions = [ |
| 166 | + { |
| 167 | + "action": "REPLACE", |
| 168 | + "field": "ReferringPhysicianName", |
| 169 | + "value": "deid_func:pydicom_uuid stable_remapping=false", |
| 170 | + } |
| 171 | + ] |
| 172 | + recipe = create_recipe(actions) |
| 173 | + parser = DicomParser(dicom_file, recipe=recipe) |
| 174 | + parser.parse() |
| 175 | + |
| 176 | + # Randomness is anything, but should be all numbers |
| 177 | + print(parser.dicom["ReferringPhysicianName"].value) |
| 178 | + name = str(parser.dicom["ReferringPhysicianName"].value) |
| 179 | + assert ( |
| 180 | + name != "2.25.39101090714049289438893821151950032074223798085258118413707" |
| 181 | + ) |
| 182 | + |
114 | 183 | def test_suffix_uuid(self):
|
115 | 184 | """
|
116 | 185 | %header
|
|
0 commit comments