Skip to content

Commit

Permalink
feature: implement calculated baseline method
Browse files Browse the repository at this point in the history
  • Loading branch information
aegis301 committed Nov 21, 2023
1 parent efa3f4a commit cc6226b
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions pyAKI/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,17 @@ def __init__(
self,
column: str = "creat",
baseline_timeframe: str = "7d",
baseline_constants: None | pd.Series = None,
expected_clearance: float = 72,
method: CreatinineBaselineMethod = CreatinineBaselineMethod.FIXED,
baseline_constant: None | pd.Series = None,
) -> None:
super().__init__()

self._column: str = column
self._baseline_timeframe: str = baseline_timeframe
self._method: CreatinineBaselineMethod = method
self._baseline_constant: None | pd.Series = baseline_constant
self._baseline_constants: None | pd.Series = baseline_constants
self._expected_clearance: float = expected_clearance

def creatinine_baseline(self, df: pd.DataFrame) -> pd.Series:
"""
Expand Down Expand Up @@ -281,12 +283,36 @@ def creatinine_baseline(self, df: pd.DataFrame) -> pd.Series:
return values

if self._method == CreatinineBaselineMethod.CONSTANT:
if self._baseline_constant is None:
if self._baseline_constants is None:
raise ValueError(
"Baseline constant method requires baseline constant values. Please provide a pd.Series containing baseline values for creatinine."
)
else:
return self._baseline_constant
return self._baseline_constants
if self._method == CreatinineBaselineMethod.CALCULATED:
if self._patient[weight_col] == None:
raise ValueError(
"Calculated baseline method requires patient weight. Please provide a pd.Series containing patient weight."
)
if self._patient[age_col] == None:
raise ValueError(
"Calculated baseline method requires patient age. Please provide a pd.Series containing patient age."
)
if self._patient[height_col] == None:
raise ValueError(
"Calculated baseline method requires patient height. Please provide a pd.Series containing patient height."
)
if self._patient[gender_col]] == None:
raise ValueError(
"Calculated baseline method requires patient gender. Please provide a pd.Series containing patient gender."
)
else:
a = (140 - self._patient[age_col]) * self._patient[weight_col]
if self._patient[gender_col] == "F":
a = a * 0.85
b = 72 * self._expected_clearance
return a/b



class AbsoluteCreatinineProbe(AbstractCreatinineProbe):
Expand All @@ -308,7 +334,9 @@ class AbsoluteCreatinineProbe(AbstractCreatinineProbe):

@dataset_as_df(df=DatasetType.CREATININE)
@df_to_dataset(DatasetType.CREATININE)
def probe(self, df: pd.DataFrame, **kwargs) -> pd.DataFrame:
def probe(
self, df: pd.DataFrame, **kwargs
) -> pd.DataFrame:
"""
Perform KDIGO stage calculation based on absolute creatinine elevations on the provided DataFrame.
Expand All @@ -322,7 +350,7 @@ def probe(self, df: pd.DataFrame, **kwargs) -> pd.DataFrame:
Returns:
pd.DataFrame: The modified DataFrame with the absolute creatinine stage column added.
"""
baseline_values: pd.Series = self.creatinine_baseline(df)
baseline_values: pd.Series = self.creatinine_baseline(df, patient)

df.loc[:, self.RESNAME] = 0
df.loc[approx_gte((df[self._column] - baseline_values), 0.3), self.RESNAME] = 1
Expand Down

0 comments on commit cc6226b

Please sign in to comment.