def sanitize_fatality_entity(d): """ Clean up a fatality entity. Ensures that the values are all strings and removes the 'Deceased' field which does not contain relevant information anymore. :param dict d: the fatality to sanitize :return: A dictionary containing the details information about the fatality with sanitized entries. :rtype: dict """ # All values must be strings. for k, v in d.items(): if isinstance(v, list): d[k] = ' '.join(v) if d.get('Date'): d['Date'] = date_utils.clean_date_string(d['Date']) if d.get('DOB'): d['DOB'] = date_utils.clean_date_string(d['DOB'], True) # The 'Deceased' field is unnecessary. if d.get('Deceased'): del d['Deceased'] return d
def parse_deceased_field_common(split_deceased_field, fleg): """ Parse the deceased field. :param list split_deceased_field: [description] :param dict fleg: a dictionary containing First, Last, Ethnicity, Gender fields :return: a dictionary representing the deceased field. :rtype: dict """ # Populate FLEG. d = parse_fleg(fleg) # Extract and clean up DOB. raw_dob = split_deceased_field[-1].strip() d[Fields.DOB] = date_utils.clean_date_string(raw_dob, True) return d
def test_clean_date_string_00(date, dob, expected): """Ensure date string is properly formatted.""" assert date_utils.clean_date_string(date, dob) == expected