Merged in bugfix/uom (pull request #661)
Bugfix/uom * Add "Per Procedure" to valid unit of measure list * Enhance unit of measure prompt for clarity and specificity in reimbursement methodologies * Refine unit of measure prompt to ensure defaulting to 'Per Unit' regardless of procedure codes for flat rate methodologies * Merge remote-tracking branch 'origin/main' into bugfix/uom * Merged main into bugfix/uom * Enhance logic for setting UNIT_OF_MEASURE to 'Per Unit' for Flat Rate reimbursement, handling all edge cases including NaN and empty strings. * Enhance is_empty function to handle additional empty value cases for pd.Series and strings * Enhance test cases for is_empty function to cover additional whitespace and null-like values * Merge branch 'bugfix/uom' of https://bitbucket.org/aarete/doczy.ai into bugfix/uom * Enhance type checking for is_empty function with overloads for str, list, and pd.Series * Overload fix * Merged main into bugfix/uom Approved-by: Katon Minhas
This commit is contained in:
@@ -7,6 +7,8 @@ from datetime import datetime
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from typing import overload, Literal
|
||||
|
||||
from constants.delimiters import Delimiter
|
||||
from constants.regex_patterns import (
|
||||
BACKTICK_PATTERN,
|
||||
@@ -295,6 +297,23 @@ def count_reimbursements_in_exhibit(exhibit_text: str) -> int: # JUST by regex
|
||||
return len(re.findall(reimb_regex, exhibit_text))
|
||||
|
||||
|
||||
# Overloads for type checking
|
||||
@overload
|
||||
def is_empty(value: str, pd_mask: bool = True) -> bool: ...
|
||||
|
||||
|
||||
@overload
|
||||
def is_empty(value: list, pd_mask: bool = True) -> bool: ...
|
||||
|
||||
|
||||
@overload
|
||||
def is_empty(value: pd.Series, pd_mask: Literal[True] = True) -> pd.Series: ...
|
||||
|
||||
|
||||
@overload
|
||||
def is_empty(value: pd.Series, pd_mask: Literal[False]) -> bool: ...
|
||||
|
||||
|
||||
def is_empty(value: str | list | pd.Series, pd_mask: bool = True) -> bool | pd.Series:
|
||||
"""
|
||||
Checks if a value is considered empty or invalid.
|
||||
@@ -321,14 +340,32 @@ def is_empty(value: str | list | pd.Series, pd_mask: bool = True) -> bool | pd.S
|
||||
|
||||
# if it's a pd.Series, return the mask (True for empty values)
|
||||
if isinstance(value, pd.Series):
|
||||
return (
|
||||
value.isna() | (value.isin(empty_values)) if pd_mask else value.isna().all()
|
||||
)
|
||||
if pd_mask:
|
||||
return (
|
||||
value.isna()
|
||||
| (value.isin(empty_values))
|
||||
| (value.astype(str).str.strip() == "")
|
||||
| (
|
||||
value.astype(str)
|
||||
.str.lower()
|
||||
.str.strip()
|
||||
.isin(["n/a", "na", "null", "none", "nan"])
|
||||
)
|
||||
)
|
||||
else:
|
||||
return value.isna().all()
|
||||
|
||||
if pd.isna(value):
|
||||
return True
|
||||
else:
|
||||
return value in empty_values
|
||||
|
||||
if isinstance(value, str):
|
||||
if not value or value.isspace():
|
||||
return True
|
||||
lower_stripped = value.lower().strip()
|
||||
if lower_stripped in ["n/a", "na", "null", "none", "nan"]:
|
||||
return True
|
||||
|
||||
return value in empty_values
|
||||
|
||||
|
||||
def datetime_str():
|
||||
|
||||
Reference in New Issue
Block a user