def test_parse_action(self): print("Testing parse action") from deid.dicom.utils import perform_action dicom = get_dicom(self.dataset) print("Case 1: Testing ADD action") self.assertTrue("PatientIdentityRemoved" not in dicom) ADD = { "action": "ADD", "field": "PatientIdentityRemoved", "value": "Yes" } dicom = perform_action(dicom=dicom, action=ADD) self.assertTrue("PatientIdentityRemoved" in dicom) self.assertEqual(dicom.get("PatientIdentityRemoved"), "Yes") print("Case 2: Testing REPLACE action with string") REPLACE = { "action": "REPLACE", "field": "PatientIdentityRemoved", "value": "No" } dicom = perform_action(dicom=dicom, action=REPLACE) self.assertTrue("PatientIdentityRemoved" in dicom) self.assertEqual(dicom.get("PatientIdentityRemoved"), "No") print("Case 3: Testing REPLACE action with variable") item = {"fish": "stick"} REPLACE = { "action": "REPLACE", "field": "PatientIdentityRemoved", "value": "var:fish" } dicom = perform_action(dicom=dicom, action=REPLACE, item=item) self.assertEqual(dicom.get("PatientIdentityRemoved"), "stick") print("Case 4: Testing REPLACE action with non-existing variable") REPLACE = { "action": "REPLACE", "field": "PatientIdentityRemoved", "value": "var:gummybear" } updated = perform_action(dicom=dicom, action=REPLACE, item=item) self.assertEqual(updated, None) print("Case 5: Testing REMOVE action") REMOVE = {"action": "REMOVE", "field": "PatientIdentityRemoved"} dicom = perform_action(dicom=dicom, action=REMOVE) self.assertTrue("PatientIdentityRemoved" not in dicom) print("Case 6: Testing invalid action") RUN = {"action": "RUN", "field": "PatientIdentityRemoved"} updated = perform_action(dicom=dicom, action=RUN) self.assertEqual(updated, None)
def test_item_timestamp(self): from deid.dicom.utils import get_item_timestamp print("Test test_item_timestamp") print("Case 1: field is empty returns None") dicom = get_dicom(self.dataset) ts = get_item_timestamp(dicom) self.assertEqual(ts,None) print("Case 2: field not empty") from deid.dicom.utils import perform_action ADD = {"action":"ADD", "field":"InstanceCreationDate", "value":"1/1/2010"} dicom = perform_action(action=ADD,dicom=dicom) ts = get_item_timestamp(dicom) self.assertEqual(ts,'2010-01-01T00:00:00Z')