def _compare_zip_codes( project, validation_dataset, rdr_dataset, pii_dataset, hpo, concept_id, pii_field ): """ Compare email addresses from hpo PII table and OMOP observation table. :param project: project to search for the datasets :param validation_dataset: the auto generated match validation dataset created in this module. queried to get the location value to identify a location field :param rdr_dataset: contains datasets from the rdr group :param pii_dataset: dataset created from submitted hpo sites. the pii tables :param hpo: string identifier of hpo :param concept_id: integer value of concept id for concept in the rdr_dataset :param pii_field: string value of field name with data matching the concept_id. used to extract the correct values from the pii tables :return: a match_value dictionary. """ match_values = {} zip_codes = readers.get_rdr_match_values( project, validation_dataset, consts.ID_MATCH_TABLE, concept_id ) pii_zip_codes = readers.get_location_pii( project, rdr_dataset, pii_dataset, hpo, consts.PII_ADDRESS_TABLE, pii_field ) for person_id, pii_zip_code in pii_zip_codes: rdr_zip = zip_codes.get(person_id) if rdr_zip is None or pii_zip_code is None: match_str = consts.MISSING else: rdr_zip = normalizer.normalize_zip(rdr_zip) pii_zip = normalizer.normalize_zip(pii_zip_code) match_str = consts.MATCH if rdr_zip == pii_zip else consts.MISMATCH match_values[person_id] = match_str return match_values
def _compare_zip_codes(project, validation_dataset, rdr_dataset, pii_dataset, hpo, concept_id, pii_field, pii_tables): """ Compare zip codes from hpo PII table and OMOP observation table. :param project: project to search for the datasets :param validation_dataset: the auto generated match validation dataset created in this module. queried to get the location value to identify a location field :param rdr_dataset: contains datasets from the rdr group :param pii_dataset: dataset created from submitted hpo sites. the pii tables :param hpo: string identifier of hpo :param concept_id: integer value of concept id for concept in the rdr_dataset :param pii_field: string value of field name with data matching the concept_id. used to extract the correct values from the pii tables :return: a match_value dictionary. """ match_values = {} table_name = hpo + consts.PII_ADDRESS_TABLE if table_name in pii_tables: zip_codes = readers.get_rdr_match_values(project, validation_dataset, consts.ID_MATCH_TABLE, concept_id) try: pii_zip_codes = readers.get_location_pii(project, rdr_dataset, pii_dataset, hpo, consts.PII_ADDRESS_TABLE, pii_field) except (oauth2client.client.HttpAccessTokenRefreshError, googleapiclient.errors.HttpError): LOGGER.exception( f"Unable to read PII for: {hpo}\tdata field:\t{pii_field}") raise for person_id, pii_zip_code in pii_zip_codes: rdr_zip = zip_codes.get(person_id) if rdr_zip is None or pii_zip_code is None: match_str = consts.MISSING else: rdr_zip = normalizer.normalize_zip(rdr_zip) pii_zip = normalizer.normalize_zip(pii_zip_code) match_str = consts.MATCH if rdr_zip == pii_zip else consts.MISMATCH match_values[person_id] = match_str else: raise RuntimeError('Table {} doesnt exist.'.format(table_name)) return match_values
def test_normalize_short_zip(self): # test actual = normalizer.normalize_zip('370') #post condition expected = '00370' self.assertEqual(actual, expected)
def test_normalize_spaced_zip(self): # test actual = normalizer.normalize_zip('37010 1112') #post condition expected = '37010' self.assertEqual(actual, expected)
def test_normalize_non_string_zip(self): # test actual = normalizer.normalize_zip(35401) # post condition expected = '35401' self.assertEqual(actual, expected)
def test_normalize_None_zip(self): # test actual = normalizer.normalize_zip(None) # post condition expected = '' self.assertEqual(actual, expected)