Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into text-feature-describer
Browse files Browse the repository at this point in the history
  • Loading branch information
sarakolding authored Apr 24, 2023
2 parents cf57273 + ab3f0c6 commit ec54222
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ requires-python = ">=3.9"
dependencies = [
"wasabi>=0.9.1,<1.1.2",
"scikit-learn>=1.1.2,<1.2.3",
"wandb>=0.12.0,<0.14.3",
"wandb>=0.12.0,<0.15.1",
"deepchecks>=0.8.0,<0.12.0",
"dill>=0.3.0,<0.3.7",
"srsly>=2.4.4,<2.4.6",
"SQLAlchemy>=1.4.41, <2.0.10",
"SQLAlchemy>=1.4.41, <2.0.11",
"pyodbc>=4.0.34, <4.0.40",
"dask>=2022.9.0,<2023.5.0",
"pydantic>=1.9.0, <1.11.0",
"psutil>=5.9.1, <6.0.0",
"pandas>=1.4.0,<2.1.0",
"catalogue>=2.0.0, <2.1.0",
"numpy>=1.23.3,<1.24.2",
"numpy>=1.23.3,<1.24.4",
"transformers>=4.22.2, <5.0.0",
"pyarrow>=9.0.0,<11.1.0",
"psycopmlutils>=0.2.4,<0.12.0",
Expand All @@ -47,7 +47,7 @@ dev = [
"pylint",
"ruff",
"black>=22.8.0,<23.1.1",
"docformatter>=1.5.0, <1.6.1",
"docformatter>=1.5.0, <1.6.4",
"pre-commit==3.2.2",
"mypy==1.2.0",
"pydantic"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Example of loading lab results."""

import psycop_feature_generation.loaders.raw.load_lab_results as lb

if __name__ == "__main__":
df = lb.cancelled_standard_lab_results(n_rows=5000)
45 changes: 44 additions & 1 deletion src/psycop_feature_generation/loaders/raw/load_lab_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def load_cancelled(
else:
npu_where = f"npukode = '{blood_sample_id}'"

sql = f"SELECT {cols} FROM [fct].{view} {npu_where} AND datotid_sidstesvar IS NOT NULL AND Svar == 'Aflyst' AND (left(Svar,1) == '>' OR left(Svar, 1) == '<')"
sql = f"SELECT {cols} FROM [fct].{view} WHERE {npu_where} AND datotid_sidstesvar IS NOT NULL AND Svar = 'Aflyst'"

df = sql_load(
sql,
Expand Down Expand Up @@ -753,3 +753,46 @@ def p_ethanol(
n_rows=n_rows,
values_to_load=values_to_load,
)


@data_loaders.register("cancelled_standard_lab_results")
def cancelled_standard_lab_results(
n_rows: int | None = None,
values_to_load: str = "cancelled",
) -> pd.DataFrame:
"""Cancelled lab results for some standard lab results: HbA1c, triglycerides, HDL, LDL, ALAT, ASAT,
lymphocytes, leukocytes, crp, creatinine, egfr, albumine-creatinine-ratio, haemoglobin, natrium, kalium,
calcium, trombocytes, d-vitamin, tsh, b12-vitamin"""
return blood_sample(
blood_sample_id=[
"NPU27300", # hba1c
"AAB00093", # hba1c
"NPU04094", # triglycerides
"NPU01567", # hdl
"NPU01568", # ldl
"AAB00101", # ldl
"NPU19651", # alat
"NPU19654", # asat
"NPU02636", # lymphocytes
"NPU02593", # leukocytes
"NPU19748", # crp
"NPU18016", # creatinine
"ASS00355", # creatinine
"ASS00354", # creatinine
"DNK35302", # egfr
"DNK35131", # egfr
"AAB00345", # egfr
"AAB00343", # egfr
"NPU19661", # albumine_creatinine_ratio
"NPU02319", # haemoglobin
"NPU03429", # natrium
"NPU03230", # kalium
"NPU01443", # calcium
"NPU03568", # trombocytes
"NPU10267", # d-vitamin
"NPU03577", # tsh
"NPU01700", # b12-vitamin
],
n_rows=n_rows,
values_to_load=values_to_load,
)
2 changes: 1 addition & 1 deletion src/psycop_feature_generation/loaders/raw/load_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def load_text_sfis(

df = pd.concat(dfs)
df = df.rename(
{"datotid_senest_aendret_i_sfien": "timestamp", "fritekst": "text"},
{"datotid_senest_aendret_i_sfien": "timestamp", "fritekst": "value"},
axis=1,
)
return df
Expand Down

0 comments on commit ec54222

Please sign in to comment.