Beispiel #1
0
    def test_batch_load_no_data(self, mock_config,
                                query_claims_from_teradata_batch_provider):
        """Test that when hide_sensitive_information is true, the rows are anonymized."""
        mock_config.get.side_effect = mocking_config.config_side_effect(
            {'hide_sensitive_information': False})
        query_claims_from_teradata_batch_provider.return_value = ([], None)

        reader = claim_reader.ClaimsDataReader()
        output = reader.load_batch_from_db(['tax_num'], ['npi_num'],
                                           datetime.date.today(),
                                           datetime.date.today())

        assert output == {}
    def test_get_headers_no_cookie(self, mock_config):
        """Verify headers are returned if no cookie is defined."""
        mock_config.get.side_effect = mocking_config.config_side_effect({
            'submission.api_token':
            'api_token',
            'submission.cookie':
            None,
            'submission.endpoint':
            'http://test_endpoint/no_submission/'
        })

        actual = api_submitter.get_headers()
        assert actual == self.no_cookie_header
    def test_get_headers_with_cookie(self, mock_config):
        """Verify cookie is included in header if present."""
        mock_config.get.side_effect = mocking_config.config_side_effect({
            'submission.api_token':
            'api_token',
            'submission.cookie':
            'cookie',
            'submission.endpoint':
            'http://test_endpoint'
        })

        actual = api_submitter.get_headers()
        assert actual == self.cookie_header
Beispiel #4
0
    def test_batch_load(self, mock_config,
                        query_claims_from_teradata_batch_provider):
        """Test that when hide_sensitive_information is true, the rows are anonymized."""
        mock_config.get.side_effect = mocking_config.config_side_effect(
            {'hide_sensitive_information': False})
        query_claims_from_teradata_batch_provider.return_value = row_handling.csv_to_query_output(
            TWO_CLAIMS_CSV_PATH)

        reader = claim_reader.ClaimsDataReader()
        output = reader.load_batch_from_db(['tax_num'], ['npi_num'],
                                           datetime.date.today(),
                                           datetime.date.today())

        assert len(output[('tax_num', 'npi_num')]) == 2
Beispiel #5
0
    def test_batch_query(self, mock_config, mock_execute):
        """Test batch_query."""
        mock_config.get.side_effect = mocking_config.config_side_effect(
            {'hide_sensitive_information': False})
        sample_rows = self.sample_rows * 50  # Need > 50 rows for anonymization to kick in.
        mock_execute.return_value = sample_rows
        output = claim_reader.query_claims_from_teradata_batch_provider(
            provider_tins=['tin'],
            provider_npis=['npi'],
            start_date=datetime.date.today(),
            end_date=datetime.date.today())

        assert len(output[1]) == len(sample_rows)
        assert output[1] == sample_rows
 def test_post_to_measurement_sets_api(self, mock_config, mock_post):
     mock_config.get.side_effect = mocking_config.config_side_effect({
         'submission.api_token':
         'api_token',
         'submission.cookie':
         None,
         'submission.endpoint':
         'http://test_endpoint/no_submission/'
     })
     endpoint_url = 'http://test_endpoint/no_submission/measurement-sets/'
     api_submitter._post_to_measurement_sets_api(
         measurement_set=self.measurement_set)
     mock_post.assert_called_with(url=endpoint_url,
                                  data=self.measurement_set.to_json(),
                                  headers=self.no_cookie_header)
Beispiel #7
0
    def test_process_provider_infer_performance_period(self, mock_config):
        """Test process_provider if infer_performance_period is True."""
        # FIXME: This test does not test infer_performance_period.
        self.processor.infer_performance_period = True
        claims_data = get_single_claim_with_quality_codes()

        mock_config.get.side_effect = mocking_config.config_side_effect(
            {'submission.filter_out_zero_reporting': False})

        measurement_set = self.processor.process_provider(
            tin='tax_num',
            npi='npi_num',
            claims_data=claims_data,
        )
        assert not measurement_set.is_empty()
Beispiel #8
0
    def test_process_provider_has_quality_codes_zero_reporting_filtered(
            self, mock_config):
        """Test process_provider, quaity codes but no reporting. Zero reporting filtered."""
        claims_data = get_single_claim_with_quality_codes()

        mock_config.get.side_effect = mocking_config.config_side_effect(
            {'submission.filter_out_zero_reporting': True})

        measurement_set = self.processor.process_provider(
            tin='tax_num',
            npi='npi_num',
            claims_data=claims_data,
        )

        assert measurement_set is not None
        assert measurement_set.is_empty()
Beispiel #9
0
    def test_query_hides_sensitive_information_fewer_than_fifty(
            self, mock_config, mock_query_claims_from_teradata_batch):
        """Test case when fewer than 50 claims and hide_sensitive_information is true."""
        mock_config.get.side_effect = mocking_config.config_side_effect(
            {'hide_sensitive_information': True})
        provider_identifier = ('tax_num', 'npi_num')
        sample_columns, sample_rows = row_handling.csv_to_query_output(
            TWO_CLAIMS_CSV_PATH)
        mock_query_claims_from_teradata_batch.return_value = (sample_columns,
                                                              sample_rows)

        reader = claim_reader.ClaimsDataReader()
        output = reader.load_batch_from_db(
            ['tax_num'], ['npi_num'], datetime.date.today(),
            datetime.date.today())[provider_identifier]

        assert output == []
Beispiel #10
0
    def test_two_claim_data_reader(self, mock_query_claims_from_teradata_batch,
                                   get):
        """Test the merging of claim lines into claims."""
        mock_query_claims_from_teradata_batch.return_value = row_handling.csv_to_query_output(
            TWO_CLAIMS_CSV_PATH)
        get.side_effect = mocking_config.config_side_effect(
            {'hide_sensitive_information': False})
        provider_identifier = ('tax_num', 'npi_num')

        reader = claim_reader.ClaimsDataReader()
        claims = reader.load_batch_from_db(
            provider_tin_list=['tax_num'],
            provider_npi_list=['npi_num'],
            start_date='start_date',
            end_date='end_date')[provider_identifier]

        assert len(claims) == 2
        for claim in claims:
            assert len(claim.claim_lines) == 2
Beispiel #11
0
    def test_safe_process_provider(self, mock_config,
                                   query_claims_from_teradata_batch_provider):
        """Test _safe_process_provider."""
        mock_config.get.side_effect = mocking_config.config_side_effect({
            'teradata.access_layer_name':
            'access_layer_name',
            'hide_sensitive_information':
            False
        })

        query_claims_from_teradata_batch_provider.return_value = row_handling.csv_to_query_output(
            'tests/assets/test_two_claims.csv')

        processor = self.processor
        initial_count = processor.count
        processor.remove_messages = True
        processor.claim_reader.hide_sensitive_information = False

        batch_claims_data = processor.claim_reader.load_batch_from_db(
            ['tax_num'], ['npi_num'], date.today(), date.today())

        mock_message = MockMessage(
            body='{{"tin": "{tin}", "npi": "{npi}"}}'.format(tin='tax_num',
                                                             npi='npi_num'))

        provider = {
            'tin': 'tax_num',
            'npi': 'npi_num',
            'message': mock_message
        }
        processed_provider = processor._safe_process_provider(
            batch_claims_data, provider)

        measurement_set = processed_provider.get('measurement_set', None)

        assert processed_provider.get('message', None) is not None
        assert measurement_set is not None
        assert not processed_provider['processing_error']
        assert processor.count == initial_count + 1
Beispiel #12
0
    def test_single_claim_data_reader(self,
                                      mock_query_claims_from_teradata_batch,
                                      get):
        """Test the parsing of a single claim into the Claim model object."""
        mock_query_claims_from_teradata_batch.return_value = row_handling.csv_to_query_output(
            SINGLE_CLAIM_CSV_PATH)
        get.side_effect = mocking_config.config_side_effect(
            {'hide_sensitive_information': False})
        provider_identifier = ('tax_num', 'npi_num')

        reader = claim_reader.ClaimsDataReader()
        claims = reader.load_batch_from_db(
            provider_tin_list=['tax_num'],
            provider_npi_list=['npi_num'],
            start_date='start_date',
            end_date='end_date')[provider_identifier]

        assert len(claims) == 1
        claim = claims[0]
        assert len(claim.claim_lines) == 2
        assert len(claim.dx_codes) == 12
        assert len(claim.claim_lines[0].mdfr_cds) == 5
Beispiel #13
0
    def test_query_hides_sensitive_information_more_than_fifty(
            self, mock_config, mock_query_claims_from_teradata_batch):
        """Test case when more than 50 claims and hide_sensitive_information is true."""
        mock_config.get.side_effect = mocking_config.config_side_effect(
            {'hide_sensitive_information': True})
        provider_identifier = ('tax_num', 'npi_num')
        sample_columns, sample_rows = row_handling.csv_to_query_output(
            TWO_CLAIMS_CSV_PATH)
        # Need > 50 rows for them to pass through anonymization.
        sample_rows = sample_rows * 50
        mock_query_claims_from_teradata_batch.return_value = (sample_columns,
                                                              sample_rows)

        reader = claim_reader.ClaimsDataReader()
        output = reader.load_batch_from_db(
            ['tax_num'], ['npi_num'], datetime.date.today(),
            datetime.date.today())[provider_identifier]

        # The same number of claims should be returned.
        assert len(output) == 2 * 50  # Two claims in initial csv.
        # The values of the fields in the returned rows should be different.
        assert output[0]['clm_ptnt_birth_dt'] != sample_rows[0][
            'clm_ptnt_birth_dt']
Beispiel #14
0
    def test_process_batch_messages(self, test_connection,
                                    query_claims_from_teradata_batch_provider,
                                    mock_config, safe_process_provider):
        """Test process_batch_messages."""
        test_connection.return_value = True

        query_claims_from_teradata_batch_provider.return_value = row_handling.csv_to_query_output(
            'tests/assets/test_single_claim.csv')

        mock_config.get.side_effect = mocking_config.config_side_effect({
            'teradata.access_layer_name':
            'access_layer_name',
            'hide_sensitive_information':
            False
        })

        processor = self.processor
        processor.claim_reader.hide_sensitive_information = False

        mock_message = MockMessage(
            body='{{"tin": "{tin}", "npi": "{npi}"}}'.format(tin='tax_num',
                                                             npi='npi_num'))

        processor.process_batch_messages([mock_message])

        expected_provider = {
            'tin': 'tax_num',
            'npi': 'npi_num',
            'message': mock_message
        }
        expected_batch_claims_data = {
            ('tax_num', 'npi_num'): get_single_claim_with_quality_codes()
        }

        safe_process_provider.assert_called_once_with(
            expected_batch_claims_data, expected_provider)
    def test_get_existing_submissions_does_not_exist(self, mock_config,
                                                     mock_get):
        mock_config.get.side_effect = mocking_config.config_side_effect({
            'submission.api_token':
            'api_token',
            'submission.cookie':
            None,
            'submission.endpoint':
            'http://test_endpoint/no_submission/'
        })
        endpoint_url = 'http://test_endpoint/no_submission/submissions'

        params = {
            'itemsPerPage':
            99999,
            'nationalProviderIdentifier':
            self.measurement_set.data['submission']
            ['nationalProviderIdentifier'],
            'performanceYear':
            str(self.measurement_set.data['submission']['performanceYear'])
        }

        headers = api_submitter.get_headers()
        headers.update({
            'qpp-taxpayer-identification-number':
            self.measurement_set.data['submission']
            ['taxpayerIdentificationNumber']
        })
        mock_get.side_effect = mocked_requests_get

        with pytest.raises(api_submitter.NoMatchingSubmissionsException):
            api_submitter.get_existing_submissions(self.measurement_set)

        mock_get.assert_called_with(endpoint_url,
                                    params=params,
                                    headers=headers)
    def test_get_existing_submissions_exists(self, mock_config, mock_get):
        mock_config.get.side_effect = mocking_config.config_side_effect({
            'submission.api_token':
            'api_token',
            'submission.cookie':
            'cookie',
            'submission.endpoint':
            'http://test_endpoint'
        })
        endpoint_url = 'http://test_endpoint/submissions'

        params = {
            'itemsPerPage':
            99999,
            'nationalProviderIdentifier':
            self.measurement_set.data['submission']
            ['nationalProviderIdentifier'],
            'performanceYear':
            str(self.measurement_set.data['submission']['performanceYear']),
        }

        headers = api_submitter.get_headers()
        headers.update({
            'qpp-taxpayer-identification-number':
            self.measurement_set.data['submission']
            ['taxpayerIdentificationNumber']
        })

        mock_get.side_effect = mocked_requests_get
        existing_submissions_in_same_year = api_submitter.get_existing_submissions(
            self.measurement_set)
        mock_get.assert_called_with(endpoint_url,
                                    params=params,
                                    headers=headers)

        assert existing_submissions_in_same_year == {'performanceYear': 2017}
Beispiel #17
0
    def test_process_batch_messages_error(
            self, test_connection, query_claims_from_teradata_batch_provider,
            mock_config, safe_process_provider):
        """Test process_batch_messages with error does not process provider."""
        test_connection.return_value = True
        query_claims_from_teradata_batch_provider.return_value = row_handling.csv_to_query_output(
            'tests/assets/test_single_claim.csv')

        mock_config.get.side_effect = mocking_config.config_side_effect({
            'teradata.access_layer_name':
            'access_layer_name',
            'hide_sensitive_information':
            False
        })

        processor = self.processor
        processor.remove_messages = True
        processor.claim_reader.hide_sensitive_information = False

        mock_message = MockMessage(body='{"unparsable":}')

        processor.process_batch_messages([mock_message])

        assert not safe_process_provider.called