Merged in bugfix/code-funcs (pull request #872)
Bugfix/code funcs * Try-except code extraction * Additional try-except for protection * Black format Approved-by: Praneel Panchigar
This commit is contained in:
+29
-14
@@ -116,8 +116,11 @@ def code_explicit(service, methodology, filename):
|
||||
instruction=prompt_templates.CODE_EXPLICIT_INSTRUCTION(),
|
||||
usage_label="CODE_EXPLICIT",
|
||||
)
|
||||
code_answer_dict = _parser(llm_answer_raw)
|
||||
return code_answer_dict
|
||||
try:
|
||||
code_answer_dict = _parser(llm_answer_raw)
|
||||
return code_answer_dict
|
||||
except:
|
||||
return {}
|
||||
|
||||
|
||||
def code_category(service, proc_category, hcpcs_level2_mapping, filename):
|
||||
@@ -151,7 +154,10 @@ def code_category(service, proc_category, hcpcs_level2_mapping, filename):
|
||||
cache=True,
|
||||
instruction=prompt_templates.CODE_CATEGORY_INSTRUCTION(),
|
||||
)
|
||||
llm_answer_final = _parser(llm_answer_raw) # Returns list
|
||||
try:
|
||||
llm_answer_final = _parser(llm_answer_raw) # Returns list
|
||||
except:
|
||||
{}
|
||||
|
||||
code_answer_dict = {"PROCEDURE_CD": [], "PROCEDURE_CD_DESC": []}
|
||||
for answer in llm_answer_final:
|
||||
@@ -179,16 +185,19 @@ def code_implicit_special(service, filename):
|
||||
Returns:
|
||||
dict: A dictionary containing the implicit codes found for the service. If no codes are found, returns an empty dictionary.
|
||||
"""
|
||||
prompt, _parser = prompt_templates.CODE_IMPLICIT_SPECIAL(service)
|
||||
|
||||
llm_answer_raw = llm_utils.invoke_claude(
|
||||
prompt,
|
||||
"sonnet_latest",
|
||||
filename,
|
||||
cache=True,
|
||||
instruction=prompt_templates.CODE_IMPLICIT_SPECIAL_INSTRUCTION(),
|
||||
)
|
||||
llm_answer_final = _parser(llm_answer_raw)
|
||||
prompt, _parser = prompt_templates.CODE_IMPLICIT_SPECIAL(service)
|
||||
try:
|
||||
llm_answer_raw = llm_utils.invoke_claude(
|
||||
prompt,
|
||||
"sonnet_latest",
|
||||
filename,
|
||||
cache=True,
|
||||
instruction=prompt_templates.CODE_IMPLICIT_SPECIAL_INSTRUCTION(),
|
||||
)
|
||||
llm_answer_final = _parser(llm_answer_raw)
|
||||
except:
|
||||
return {}
|
||||
|
||||
special_case_mapping = {
|
||||
"Drugs": ["J0000-J9999"],
|
||||
@@ -512,7 +521,10 @@ def fill_bill_type(
|
||||
cache=True,
|
||||
instruction=prompt_templates.FILL_BILL_TYPE_INSTRUCTION(),
|
||||
)
|
||||
llm_answer_final = _parser(llm_answer_raw)
|
||||
try:
|
||||
llm_answer_final = _parser(llm_answer_raw)
|
||||
except:
|
||||
return answer_dict
|
||||
|
||||
# Second attempt: Service term + reimbursement term + exhibit context (if first attempt failed and context available)
|
||||
if string_utils.is_empty(llm_answer_final) and exhibit_text:
|
||||
@@ -530,7 +542,10 @@ def fill_bill_type(
|
||||
cache=True,
|
||||
instruction=prompt_templates.FILL_BILL_TYPE_INSTRUCTION(),
|
||||
)
|
||||
llm_answer_final = _parser(llm_answer_raw)
|
||||
try:
|
||||
llm_answer_final = _parser(llm_answer_raw)
|
||||
except:
|
||||
return answer_dict
|
||||
|
||||
# Keep legacy behavior: return answer_dict unchanged if no result found
|
||||
if not llm_answer_final:
|
||||
|
||||
@@ -880,9 +880,7 @@ def fill_claim_type_from_title(df: pd.DataFrame) -> pd.DataFrame:
|
||||
file_rows = df.loc[file_mask, "AARETE_DERIVED_CLAIM_TYPE_CD"]
|
||||
|
||||
# Get non-empty values for this file
|
||||
non_empty_values = [
|
||||
v for v in file_rows if not string_utils.is_empty(v)
|
||||
]
|
||||
non_empty_values = [v for v in file_rows if not string_utils.is_empty(v)]
|
||||
|
||||
if non_empty_values:
|
||||
# Use mode (most common value) to fill empty rows in this file
|
||||
@@ -934,7 +932,7 @@ def fill_claim_type_from_title(df: pd.DataFrame) -> pd.DataFrame:
|
||||
"HOSPITAL",
|
||||
"INSTITUTIONAL",
|
||||
"FACILITY",
|
||||
"INPATIENT",
|
||||
"INPATIENT",
|
||||
]
|
||||
|
||||
def infer_from_title(row):
|
||||
|
||||
@@ -1246,7 +1246,7 @@ def CODE_IMPLICIT_SPECIAL(service) -> Tuple[str, Callable[[str], list]]:
|
||||
"""
|
||||
prompt = f"""[CONTEXT]
|
||||
Here is the Service to analyze:
|
||||
{service}"""
|
||||
SERVICE: {service}"""
|
||||
|
||||
return (prompt, _json_list_parser)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user