def test_blank_tag(self): # Note that outside of the controlled action # functions, user is limited on blanking # (eg could produce invalid dicom) print("Test deid.dicom.tags blank_tag") from deid.dicom.tags import blank_tag dicom = get_dicom(self.dataset) updated = blank_tag(dicom, field='PatientID') self.assertEqual(updated.get('PatientID'), "")
def _perform_action(dicom, field, action, value=None, item=None): """_perform_action is the base function for performing an action. perform_action (above) typically is called using a loaded deid, and perform_addition is typically done via an addition in a config Both result in a call to this function. If an action fails or is not done, None is returned, and the calling function should handle this. """ if field in dicom and action != "ADD": # Blank the value if action == "BLANK": dicom = blank_tag(dicom, field) # Code the value with something in the response elif action == "REPLACE": value = parse_value(item, value, field) if value is not None: # If we make it here, do the replacement dicom = update_tag(dicom, field=field, value=value) else: bot.warning("REPLACE %s unsuccessful" % field) # Code the value with something in the response elif action == "JITTER": value = parse_value(item, value, field) if value is not None: # Jitter the field by the supplied value dicom = jitter_timestamp(dicom=dicom, field=field, value=value) else: bot.warning("JITTER %s unsuccessful" % field) # elif "KEEP" --> Do nothing. Keep the original # Remove the field entirely elif action == "REMOVE": dicom = _remove_tag(dicom, item, field, value) elif action == "ADD": value = parse_value(item, value, field) if value is not None: dicom = add_tag(dicom, field, value, quiet=True)