# To get a list of specific filters under a group recipe.get_filters('blacklist') ################################################################################ # Header Actions # A header action is a step (e.g., replace, remove, blank) to be applied to # a dicom image header. The headers are also part of the deid recipe, and you # don't need to necessarily use header actions and filters at the same time. ################################################################################ # For the example we were doing above, the recipe didn't have a header section. # Let's load one that does. recipe = DeidRecipe() # We can get a complete list of actions recipe.get_actions() # We can filter to an action type recipe.get_actions(action='ADD') #[{'action': 'ADD', # 'field': 'IssuerOfPatientID', # 'value': 'STARR. In an effort to remove PHI all dates are offset from their original values.'}, # {'action': 'ADD', # 'field': 'PatientBirthDate', # 'value': 'var:entity_timestamp'}, # {'action': 'ADD', 'field': 'StudyDate', 'value': 'var:item_timestamp'}, # {'action': 'ADD', 'field': 'PatientID', 'value': 'var:entity_id'}, # {'action': 'ADD', 'field': 'AccessionNumber', 'value': 'var:item_id'}, # {'action': 'ADD', 'field': 'PatientIdentityRemoved', 'value': 'Yes'}]
################################## # Create the DeidRecipe Instance from deid.dicom from deid.config import DeidRecipe recipe = DeidRecipe("deid.dicom") # To see an entire (raw in a dictionary) recipe just look at recipe.deid # What is the format? recipe.get_format() # dicom # What actions do we want to do on the header? recipe.get_actions() """ [{'action': 'REPLACE', 'field': 'StudyInstanceUID', 'value': 'func:generate_uid'}, {'action': 'REPLACE', 'field': 'SeriesInstanceUID', 'value': 'func:generate_uid'}, {'action': 'REPLACE', 'field': 'FrameOfReferenceUID', 'value': 'func:generate_uid'}] """ # We can filter to an action type (not useful here, we only have one type) recipe.get_actions(action="REPLACE")
################################## # Create the DeidRecipe Instance from deid.dicom from deid.config import DeidRecipe recipe = DeidRecipe('deid.dicom') # To see an entire (raw in a dictionary) recipe just look at recipe.deid # What is the format? recipe.get_format() # dicom # What actions do we want to do on the header? recipe.get_actions() ''' [{'action': 'REPLACE', 'field': 'StudyInstanceUID', 'value': 'func:generate_uid'}, {'action': 'REPLACE', 'field': 'SeriesInstanceUID', 'value': 'func:generate_uid'}, {'action': 'REPLACE', 'field': 'FrameOfReferenceUID', 'value': 'func:generate_uid'}] ''' # We can filter to an action type (not useful here, we only have one type) recipe.get_actions(action='REPLACE')
# To get a list of specific filters under a group recipe.get_filters("blacklist") ################################################################################ # Header Actions # A header action is a step (e.g., replace, remove, blank) to be applied to # a dicom image header. The headers are also part of the deid recipe, and you # don't need to necessarily use header actions and filters at the same time. ################################################################################ # For the example we were doing above, the recipe didn't have a header section. # Let's load one that does. recipe = DeidRecipe() # We can get a complete list of actions recipe.get_actions() # We can filter to an action type recipe.get_actions(action="ADD") # [{'action': 'ADD', # 'field': 'IssuerOfPatientID', # 'value': 'STARR. In an effort to remove PHI all dates are offset from their original values.'}, # {'action': 'ADD', # 'field': 'PatientBirthDate', # 'value': 'var:entity_timestamp'}, # {'action': 'ADD', 'field': 'StudyDate', 'value': 'var:item_timestamp'}, # {'action': 'ADD', 'field': 'PatientID', 'value': 'var:entity_id'}, # {'action': 'ADD', 'field': 'AccessionNumber', 'value': 'var:item_id'}, # {'action': 'ADD', 'field': 'PatientIdentityRemoved', 'value': 'Yes'}]
def test_get_functions(self): recipe = DeidRecipe(self.deid) # Format self.assertEqual(recipe.get_format(), "dicom") # Actions for header print("Testing get_actions") actions = recipe.get_actions() self.assertTrue(isinstance(actions, list)) for key in ["action", "field", "value"]: self.assertTrue(key in actions[0]) self.assertTrue(recipe.has_actions()) # Filters print("Testing get_filters") filters = recipe.get_filters() self.assertTrue(isinstance(filters, dict)) # whitelist, blacklist, graylist for key in recipe.ls_filters(): self.assertTrue(key in filters) recipe = DeidRecipe() filters = recipe.get_filters() self.assertTrue(isinstance(filters["whitelist"], list)) # Test that each filter has a set of filters, coords, name for key in ["filters", "coordinates", "name"]: self.assertTrue(key in filters["whitelist"][0]) # Each filter is a list of actions, name is string, coords are list self.assertTrue(isinstance(filters["whitelist"][0]["filters"], list)) self.assertTrue(isinstance(filters["whitelist"][0]["name"], str)) self.assertTrue( isinstance(filters["whitelist"][0]["coordinates"], list)) # Check content of the first filter for key in ["action", "field", "operator", "InnerOperators", "value"]: self.assertTrue(key in filters["whitelist"][0]["filters"][0]) # Fields and Values print("Testing get_fields_lists and get_values_lists") self.assertEqual(recipe.get_fields_lists(), None) self.assertEqual(recipe.get_values_lists(), None) self.assertEqual(recipe.ls_fieldlists(), []) self.assertEqual(recipe.ls_valuelists(), []) self.assertTrue(not recipe.has_fields_lists()) self.assertTrue(not recipe.has_values_lists()) # Load in recipe with values and fields deid = os.path.abspath("%s/../examples/deid/deid.dicom-groups" % self.pwd) recipe = DeidRecipe(deid) assert "values" in recipe.deid assert "fields" in recipe.deid self.assertTrue(isinstance(recipe.deid["values"], dict)) self.assertTrue(isinstance(recipe.deid["fields"], dict)) self.assertTrue(recipe.get_fields_lists() is not None) self.assertTrue(recipe.get_values_lists() is not None) self.assertEqual(recipe.ls_fieldlists(), ["instance_fields"]) self.assertEqual(recipe.ls_valuelists(), ["cookie_names", "operator_names"]) self.assertTrue(recipe.has_fields_lists()) self.assertTrue(recipe.has_values_lists())