93 lines
2.8 KiB
Python
93 lines
2.8 KiB
Python
import pandas as pd
|
|
import re
|
|
|
|
import postprocessingfuncs
|
|
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 = postprocessingfuncs.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:
|
|
postprocessingfuncs.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:
|
|
postprocessingfuncs.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 = postprocessingfuncs.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 = postprocessingfuncs.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 = postprocessingfuncs.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 = postprocessingfuncs.adjust_reimbursement_rate(df)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - adjust_reimbursement_rate : {e}")
|
|
|
|
# Clean dates so that Termination and Effective aren't the same
|
|
try:
|
|
df = postprocessingfuncs.clean_dates(df)
|
|
except Exception as e:
|
|
print(f"Postprocessing Error - clean_dates : {e}")
|
|
|
|
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
|