Files
doczyai-pipelines/fieldExtraction/tests/cnc_hotfix_test.py
T
Alex Galarce 56e3fdd1f8 Merged in bugfix/all_cnc_hotfixes (pull request #302)
DRAFT: Bugfix/all cnc hotfixes

* Pipeline fix - health plan state

* Update for prompt vs non-prompt fixes

* Revert utils.find_regex_matches()

* Remove prints

* Non-prompt run

* Health Plan State, IRS, NPI, LOB, Lesser, Prov 2, Default, Rate Standard, Contract Effective Date, Term Group

* Merged in bugfix/agreement_name (pull request #294)

contract title fixed

* contract title fixed

* Merged bugfix/all_cnc_hotfixes into bugfix/agreement_name


Approved-by: Katon Minhas

* All hotfixes added

* Fixed utils

* fix for clean_contract_effective_date
* Merged in default-fix (pull request #296)

moved default funcs to the top, dropped intermediate columns

* moved default funcs to the top, dropped intermediate columns


Approved-by: Katon Minhas

* quick fix to dropping extra columns

* Merged in bugfix/effective_date_meridian (pull request #297)

fixed effective date for meridian contracts

* fixed effective date for meridian contracts


Approved-by: Katon Minhas

* Default rate and Lesser fix

* Merged in hotfix/irs_npi_updated (pull request #298)

updated irs and npi hotfix funcs

* updated irs and npi hotfix funcs

* Merged bugfix/all_cnc_hotfixes into hotfix/irs_npi_updated


Approved-by: Katon Minhas

* non-functional commit - default only

* debug commit - premerge

* Batch 1 Dup File Reconciliation

* Default rate fix

* Full CNC 1A Run Config

* Standard column refactor

* Working stitching for 1A

* Merged in Alex-Galarce/cnc_hotfix_effective_date_utilspy-edited-1732659983687 (pull request #301)

Remove "license" from effective date smart chunking

* Remove "license" from effective date smart chunking
* Merged bugfix/all_cnc_hotfixes into Alex-Galarce/cnc_hotfix_effective_date_utilspy-edited-1732659983687


Approved-by: Katon Minhas

* Merged in hotfix/irs_batch2_feedback (pull request #300)

IRS fix for feedback on batch2

* IRS fix for feedback on batch2

* Merged bugfix/all_cnc_hotfixes into hotfix/irs_batch2_feedback


Approved-by: Katon Minhas

* Merged main into bugfix/all_cnc_hotfixes


Approved-by: Katon Minhas
2024-11-27 15:08:04 +00:00

206 lines
8.6 KiB
Python

import pytest
import math
import pandas as pd
from pandas.testing import assert_frame_equal
from hotfix_helper_funcs import state_check
# class TestStateCheck:
# @pytest.mark.parametrize("input_state,expected_df_output,expected_non_df_output", [
# ("Multiple", "N/A",["N/A"]),
# ("Peach State", "N/A",["N/A"]),
# ("Statewide", "N/A",["N/A"]),
# ("Sunshine State Health Plan Suggests This Is For Florida, But Since The State Is Not Explicitly Specified, The Most Appropriate Answer Is:\n\nN/A", "N/A", ["N/A"]),
# ("The Contract Text Indicates This Health Plan Is For The Sunshine State, Which Is Florida. Therefore, The Answer Is:\n\nFlorida->N/A", "N/A", ["N/A"]),
# ("Sunshine State", "N/A", ["N/A"]),
# ("The Health Plan Is For The Sunshine State, Which Refers To Florida. However, Since The State Is Not Explicitly Specified, The Most Accurate Answer Based Solely On The Information Provided Is:\n\nN/A", "N/A", ["N/A"]),
# ])
# def test_invalid_state_names(self, input_state, expected_df_output, expected_non_df_output):
# """Test invalid inputs"""
# assert state_check(input_state,is_dataframe=True) == expected_df_output
# assert state_check(input_state,is_dataframe=False) == expected_non_df_output
# def test_hlorida_correction(self):
# """Test fix - Hlorida -> Florida"""
# assert state_check("Hlorida",is_dataframe=False) == ["Florida"]
# @pytest.mark.parametrize("input_state,expected_df_output,expected_non_df_output", [
# ("AL", "Alabama",["Alabama"]),
# ("Florida", "Florida",["Florida"]),
# ("FLORIDA", "Florida",["Florida"]),
# ("florida", "Florida",["Florida"]),
# ])
# def test_valid_states(self, input_state, expected_df_output, expected_non_df_output):
# """Test valid inputs"""
# assert state_check(input_state,is_dataframe=True) == expected_df_output
# assert state_check(input_state,is_dataframe=False) == expected_non_df_output
# def test_list_inputs(self):
# """Test a list of input"""
# input_states = ["AL", "Florida", "Hlorida", "Multiple"]
# expected_df_output = "Alabama, Florida, Florida, N/A"
# expected_non_df_output = ["Alabama", "Florida", "Florida", "N/A"]
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# @pytest.mark.parametrize("invalid_input", [
# 123,
# {"state": "Florida"},
# True
# ])
# def test_invalid_input_types(self, invalid_input):
# """Test invalid input types"""
# with pytest.raises(TypeError):
# state_check(invalid_input)
# @pytest.mark.parametrize("empty_input,expected_df_output,expected_non_df_output", [
# ("", "N/A",["N/A"]),
# ([], "",[]),
# ([" "], "N/A",["N/A"])
# ])
# def test_empty_inputs(self, empty_input, expected_df_output, expected_non_df_output):
# """Test empty inputs"""
# assert state_check(empty_input,is_dataframe=True) == expected_df_output
# assert state_check(empty_input,is_dataframe=False) == expected_non_df_output
# def test_multiple_invalid_states(self):
# """Test multiple invalid inputs"""
# input_states = [
# "Multiple",
# "Peach State",
# "The Health Plan Is For The Sunshine State, Which Refers To Florida. So The Answer Is:\n\nFlorida->N/A",
# "The Health Plan Is For The Florida State, Which Refers To Florida",
# "Sunshine State Health Plan Suggests This Is For Florida, But Since The State Is Not Explicitly Specified, The Most Appropriate Answer Is:\n\nN/A->N/A",
# "Sunshine State Health Plan->N/A",
# "Sunshine State->N/A",
# "The Contract Text Indicates This Health Plan Is For Florida, As It Mentions Sunshine State Health Plan, Inc. Which Operates In Florida. However, To Strictly Follow The Instructions, I Will Provide The Answer:\n\nN/A->N/A"
# ]
# expected_df_output = ", ".join(["N/A"]*8)
# expected_non_df_output = ["N/A"]*8
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# def test_mixed_states(self):
# """Test mixed input"""
# input_states = ["AL", "Multiple", "Florida", "Hlorida", "Florida State Health Plan"]
# expected_df_output = "Alabama, N/A, Florida, Florida, N/A"
# expected_non_df_output = ["Alabama", "N/A", "Florida", "Florida", "N/A"]
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# def concatenated_string_states(self):
# """Test concatentated input"""
# input_states = ["Arizona, Louisiana","NY, NJ, Connecticut"]
# expected_df_output = "Arizona, Louisiana, New York, New Jersey"
# expected_non_df_output = ["Arizona", "Louisiana", "New York", "New Jersey"]
# assert state_check(input_states,is_dataframe=True) == expected_df_output
# assert state_check(input_states,is_dataframe=False) == expected_non_df_output
# class TestApplyStateCheckToDataFrame:
# def test_basic_state_processing(self):
# """Test basic state code to full name conversion"""
# df = pd.DataFrame({
# 'Health Plan State': ['NY', 'CA', 'TX', ['CO','CT'], 'NJ, AR']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': ['NY', 'CA', 'TX', ['CO','CT'], 'NJ, AR'],
# 'Health Plan State_corrected': ['New York', 'California', 'Texas', 'Colorado, Connecticut', 'New Jersey, Arkansas']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_mixed_case_states(self):
# """Test handling of mixed case input"""
# df = pd.DataFrame({
# 'Health Plan State': ['ny', 'Ca', 'TeXaS']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': ['ny', 'Ca', 'TeXaS'],
# 'Health Plan State_corrected': ['New York', 'California', 'Texas']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_invalid_states(self):
# """Test handling of invalid state codes"""
# df = pd.DataFrame({
# 'Health Plan State': [['SH', 'IO'], 'LM', 'XY']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': [['SH', 'IO'], 'LM', 'XY'],
# 'Health Plan State_corrected': ['N/A, N/A', 'N/A', 'N/A']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_already_full_state_names(self):
# """Test handling of already expanded state names"""
# df = pd.DataFrame({
# 'Health Plan State': ['Vermont', 'Tennessee', 'Mississippi']
# })
# expected_df = pd.DataFrame({
# 'Health Plan State': ['Vermont', 'Tennessee', 'Mississippi'],
# 'Health Plan State_corrected': ['Vermont', 'Tennessee', 'Mississippi']
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_empty_dataframe(self):
# """Test handling of empty DataFrame"""
# df = pd.DataFrame({'Health Plan State': []})
# expected_df = pd.DataFrame({
# 'Health Plan State': [],
# 'Health Plan State_corrected': []
# })
# result_df = apply_state_check_to_df(df,is_dataframe=True)
# assert_frame_equal(result_df, expected_df)
# def test_wrong_column_name(self):
# """Test error handling for non-existent column"""
# df = pd.DataFrame({
# 'Heaalth Plans state': ['NY', 'CA'],
# })
# with pytest.raises(KeyError) as exc_info:
# apply_state_check_to_df(df,is_dataframe=True)
# def test_is_dataframe_parameter_false(self):
# """Test 'is_dataframe' parameter as false"""
# df = pd.DataFrame({'Health Plan State': ['NY', 'CA']})
# with pytest.raises(ValueError):
# apply_state_check_to_df(df,is_dataframe=False)