Example #1
0
def _compare_states(
        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 = {}

    states = readers.get_rdr_match_values(
        project, validation_dataset, consts.ID_MATCH_TABLE, concept_id
    )

    pii_states = readers.get_location_pii(
        project,
        rdr_dataset,
        pii_dataset,
        hpo,
        consts.PII_ADDRESS_TABLE,
        pii_field
    )

    for person_id, pii_state in pii_states:
        rdr_state = states.get(person_id)

        if rdr_state is None or pii_state is None:
            match_str = consts.MISSING
        else:
            rdr_state = normalizer.normalize_state(rdr_state)
            pii_state = normalizer.normalize_state(pii_state)
            match_str = consts.MATCH if rdr_state == pii_state else consts.MISMATCH

        match_values[person_id] = match_str

    return match_values
Example #2
0
def _compare_states(project, validation_dataset, rdr_dataset, pii_dataset, hpo,
                    concept_id, pii_field, pii_tables):
    """
    Compare state 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 = {}
    table_name = hpo + consts.PII_ADDRESS_TABLE

    if table_name in pii_tables:
        states = readers.get_rdr_match_values(project, validation_dataset,
                                              consts.ID_MATCH_TABLE,
                                              concept_id)

        try:
            pii_states = 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_state in pii_states:
            rdr_state = states.get(person_id)

            if rdr_state is None or pii_state is None:
                match_str = consts.MISSING
            else:
                rdr_state = normalizer.normalize_state(rdr_state)
                pii_state = normalizer.normalize_state(pii_state)
                match_str = consts.MATCH if rdr_state == pii_state else consts.MISMATCH

            match_values[person_id] = match_str
    else:
        raise RuntimeError('Table {} doesnt exist.'.format(table_name))

    return match_values
Example #3
0
    def test_normalize_full_state_name(self):
        # test
        actual = normalizer.normalize_state('Colorado')

        #post condition
        expected = ''
        self.assertEqual(actual, expected)
Example #4
0
    def test_normalize_mixed_case_state(self):
        #test
        actual = normalizer.normalize_state('aL')

        # post condition
        expected = 'al'
        self.assertEqual(actual, expected)
Example #5
0
    def test_normalize_non_string_state(self):
        # test
        actual = normalizer.normalize_state(1492.0)

        # post condition
        expected = ''
        self.assertEqual(actual, expected)
Example #6
0
    def test_normalize_None_state(self):
        # test
        actual = normalizer.normalize_state(None)

        # post condition
        expected = ''
        self.assertEqual(actual, expected)