104 lines
3.0 KiB
Python
104 lines
3.0 KiB
Python
import pandas as pd
|
|
import re
|
|
|
|
import postprocess_funcs
|
|
import config
|
|
|
|
|
|
def postprocess_results(combined_df):
|
|
|
|
# Define valid values dictionary
|
|
valid_values_dict = {
|
|
"CONTRACT_LOB": config.VALID_LOBS,
|
|
"CONTRACT_PROGRAM": config.VALID_PROGRAMS,
|
|
"CONTRACT_NETWORK": config.VALID_NETWORKS,
|
|
}
|
|
|
|
# Sanitize the combined data
|
|
try:
|
|
df = postprocess_funcs.sanitize_combined(combined_df)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - santize_combined : {e}")
|
|
|
|
# Clean specific columns for exact matches
|
|
for field_list in [
|
|
["CONTRACT_LOB", "Corrected_LOB", config.VALID_LOBS],
|
|
["CONTRACT_PROGRAM", "Corrected_PROGRAM", config.VALID_PROGRAMS],
|
|
["CONTRACT_NETWORK", "Corrected_NETWORK", config.VALID_NETWORKS],
|
|
]:
|
|
try:
|
|
postprocess_funcs.clean_columns_combined(df, field_list[0], field_list[2], field_list[1])
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - clean_columns_combined : {e}")
|
|
|
|
try:
|
|
postprocess_funcs.clean_columns_combined_fuzzy(df, field_list[0], field_list[2], config.FUZZY_MATCH_THRESHOLD)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - clean_columns_combined_fuzzy : {e}")
|
|
|
|
# Correct misplaced values across columns
|
|
try:
|
|
df = postprocess_funcs.correct_misplaced_values(df, ['CONTRACT_LOB', 'CONTRACT_PROGRAM', 'CONTRACT_NETWORK'], valid_values_dict)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - correct_misplaced_values : {e}")
|
|
|
|
# Move percentages and large numbers to correct columns
|
|
try:
|
|
df = postprocess_funcs.move_percentage_to_rate(df)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - move_percentage_to_rate : {e}")
|
|
|
|
# Replace N/As in "Not Covered" with 0%
|
|
try:
|
|
df = postprocess_funcs.set_rate_to_zero_if_not_covered(df)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - set_rate_to_zero_if_not_covered : {e}")
|
|
|
|
# Adjust for adding or subtracting
|
|
try:
|
|
df = postprocess_funcs.adjust_reimbursement_rate(df)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - adjust_reimbursement_rate : {e}")
|
|
|
|
# -- Deprecated --
|
|
# Clean dates so that Termination and Effective aren't the same
|
|
# try:
|
|
# df = postprocessing_funcs.clean_dates(df)
|
|
# except Exception as e:
|
|
# print(f"Postprocessing Error - clean_dates : {e}")
|
|
|
|
# Re order columns
|
|
column_order = [col for col in config.VALID_COLUMNS if col in df.columns] + [
|
|
col for col in df.columns if col not in config.VALID_COLUMNS
|
|
]
|
|
df = df[column_order]
|
|
|
|
return df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Order columns
|
|
cols = [col for col in config.VALID_COLUMNS if col in combined_df.columns] + [col for col in combined_df.columns if col not in config.VALID_COLUMNS]
|
|
#combined_df = combined_df.loc[:, cols]
|
|
combined_df = combined_df[cols]
|
|
return combined_df
|