diff --git a/fieldExtraction/constants/constants.py b/fieldExtraction/constants/constants.py index 14b96c5..d695a7f 100644 --- a/fieldExtraction/constants/constants.py +++ b/fieldExtraction/constants/constants.py @@ -124,6 +124,16 @@ class Constants: .from_excel("constants/mapping_csvs/rev_cd/rev.csv", "Code", "Description") .mapping ) + self.GROUPER_APR_DRG_MAPPING = ( + CrosswalkBuilder() + .from_excel("constants/mapping_csvs/grouper_cd/drg_mapping_apr-drg.csv", "Code", "Description") + .mapping + ) + self.GROUPER_MS_DRG_MAPPING = ( + CrosswalkBuilder() + .from_excel("constants/mapping_csvs/grouper_cd/drg_mapping_ms-drg.csv", "Code", "Description") + .mapping + ) self.BILL_TYPE_MAPPING = ( CrosswalkBuilder() diff --git a/fieldExtraction/src/codes/code_funcs.py b/fieldExtraction/src/codes/code_funcs.py index 7ef69e2..fcaec9a 100644 --- a/fieldExtraction/src/codes/code_funcs.py +++ b/fieldExtraction/src/codes/code_funcs.py @@ -426,6 +426,40 @@ def fill_bill_type(service, answer_dict, BILL_TYPE_MAPPING, BILL_TYPE_REVERSE_MA return answer_dict +def fill_grouper_cd_desc(answer_dict, constants: Constants): + """ + Fills the GROUPER_CD_DESC field in the answer dictionary based on the GROUPER_CD. + + Args: + answer_dict (dict): The answer dictionary to update. + + Returns: + dict: The updated answer dictionary. + """ + + grouper_cd = answer_dict.get("GROUPER_CD") + if string_utils.is_empty(grouper_cd): + return answer_dict + grouper_type = answer_dict.get("GROUPER_TYPE") + if string_utils.is_empty(grouper_type): + return answer_dict + + grouper_descs = [] + grouper_cd = eval(grouper_cd) if "[" in grouper_cd else grouper_cd + + for code in grouper_cd: + code_without_severity = int(code.split("-")[0]) # Remove severity level if present + if grouper_type == "APR-DRG" and (code_without_severity in constants.GROUPER_APR_DRG_MAPPING): + grouper_descs.append(constants.GROUPER_APR_DRG_MAPPING[code_without_severity]) + elif grouper_type == "MS-DRG" and (code_without_severity in constants.GROUPER_MS_DRG_MAPPING): + grouper_descs.append(constants.GROUPER_MS_DRG_MAPPING[code_without_severity]) + + if grouper_descs: + answer_dict["GROUPER_CD_DESC"] = "|".join(list(set(grouper_descs))) + + return answer_dict + + def get_implicit_runs(answer_dict): """ Determines which code runs should be executed implicitly based on the Claim Type and Bill Type @@ -620,6 +654,11 @@ def code_breakout(merged_results: pd.DataFrame, constants: Constants): answer_dict.update(code_answer_dict) answer_dicts_with_code.append(answer_dict) + # Fill in GROUPER_CD_DESC based on GROUPER_TYPE and GROUPER_CD + answer_dicts_with_code = [ + fill_grouper_cd_desc(answer_dict, constants) for answer_dict in answer_dicts_with_code + ] + return pd.DataFrame(answer_dicts_with_code)