diff --git a/pyproject.toml b/pyproject.toml index f206751d..5c0986f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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" diff --git a/src/psycop_feature_generation/loaders/example/load_lab_results.py b/src/psycop_feature_generation/loaders/example/load_lab_results.py new file mode 100644 index 00000000..3007a601 --- /dev/null +++ b/src/psycop_feature_generation/loaders/example/load_lab_results.py @@ -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) diff --git a/src/psycop_feature_generation/loaders/raw/load_lab_results.py b/src/psycop_feature_generation/loaders/raw/load_lab_results.py index 413121b3..7f4add77 100644 --- a/src/psycop_feature_generation/loaders/raw/load_lab_results.py +++ b/src/psycop_feature_generation/loaders/raw/load_lab_results.py @@ -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, @@ -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, + ) diff --git a/src/psycop_feature_generation/loaders/raw/load_text.py b/src/psycop_feature_generation/loaders/raw/load_text.py index a545b4e2..ab6d19e6 100644 --- a/src/psycop_feature_generation/loaders/raw/load_text.py +++ b/src/psycop_feature_generation/loaders/raw/load_text.py @@ -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