Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

georgm8/fix emergency care features #43

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions avoidable_admissions/data/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ class Config:
],
),
"opertn_count": pa.Column(int, nullable=False, checks=[pa.Check.ge(0)]),
"opertn_cat": pa.Column(str, nullable=False, checks=[pa.Check.isin(['Yes', 'No', 'Missing'])]),

"comorb_count": pa.Column(int, nullable=False, checks=[pa.Check.ge(0)]),
"comorb_cat": pa.Column(str, nullable=False, checks=[pa.Check.isin(['Yes', 'No', 'Missing'])]),
}
)

Expand Down
19 changes: 19 additions & 0 deletions avoidable_admissions/features/admitted_care_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,27 @@ def _procedures(df: pd.DataFrame) -> pd.DataFrame:
.count(axis=1)
)

rules = {
'Yes': df['opertn_count'] > 0,
'No': df['opertn_count'] <= 0,
'Missing': df['opertn_count'].isna()
}

df['opertn_cat'] = np.select(
list(rules.values()), list(rules.keys()), default='Missing'
)

return df

def _comorbidities(df: pd.DataFrame) -> pd.DataFrame:
diag_cols = [f'diag_{i:02d}' for i in range(2, 21)]
df['comorb_count'] = df[diag_cols].count(axis=1)
df['comorb_cat'] = df['comorb_count'].apply(lambda x: 'Yes' if x > 0 else 'No')

return df



def build_all(df: pd.DataFrame) -> pd.DataFrame:

df = (
Expand All @@ -157,6 +175,7 @@ def build_all(df: pd.DataFrame) -> pd.DataFrame:
.pipe(_dismeth)
.pipe(_acsc_code)
.pipe(_procedures)
.pipe(_comorbidities)
)

return df
2 changes: 1 addition & 1 deletion avoidable_admissions/features/emergency_care_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _cc_code(df: pd.DataFrame) -> pd.DataFrame:

# TODO: This section needs manual review of a good sample size to ensure it works

cc_mapping = load_ed_cc_mapping()
cc_mapping = feature_maps.load_ed_cc_mapping()
df["edchiefcomplaint_cat"] = replace_values(df.edchiefcomplaint, cc_mapping)

return df
Expand Down