From dc4759f128383809f0350a89b4306f45ad92d8d4 Mon Sep 17 00:00:00 2001 From: svittoz Date: Thu, 18 Apr 2024 14:36:19 +0000 Subject: [PATCH] precommit --- eds_scikit/io/omop_explorer_default_config.py | 27 ++++++++-------- eds_scikit/plot/omop_explorer.py | 32 +++++++++++++------ eds_scikit/plot/table_viz.py | 2 +- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/eds_scikit/io/omop_explorer_default_config.py b/eds_scikit/io/omop_explorer_default_config.py index 93f759d7..0ba020f7 100644 --- a/eds_scikit/io/omop_explorer_default_config.py +++ b/eds_scikit/io/omop_explorer_default_config.py @@ -45,7 +45,7 @@ "mapper": { "visit_occurrence_id": {"not NaN": ".*"}, "condition_source_value": {"not NaN": ".*"}, - }, + }, }, "note": { "category_columns": [ @@ -59,7 +59,7 @@ "mapper": { "note_class_source_value": {"CR": r"^CR", "CRH": r"^CRH", "LT": r"^LT"}, "visit_occurrence_id": {"not NaN": ".*"}, - }, + }, }, "drug_exposure_prescription": { "category_columns": [ @@ -72,7 +72,7 @@ "dose_unit_source_value", "drug_ucd_source_value", "prescription_type_source_value", - "cdm_source" + "cdm_source", ], "date_column": "drug_exposure_start_datetime", "mapper": { @@ -80,11 +80,11 @@ "drug_type_source_value": {"not NaN": ".*"}, "drug_source_value": {"not NaN": ".*"}, "drug_class_source_value": {"not NaN": ".*"}, - "drug_ucd_source_value" : {"not NaN": ".*"}, - "route_source_value" : {"not NaN": ".*"}, - "dose_unit_source_value" : {"not NaN": ".*"}, - "prescription_type_source_value" : {"not NaN": ".*"}, - }, + "drug_ucd_source_value": {"not NaN": ".*"}, + "route_source_value": {"not NaN": ".*"}, + "dose_unit_source_value": {"not NaN": ".*"}, + "prescription_type_source_value": {"not NaN": ".*"}, + }, }, "drug_exposure_administration": { "category_columns": [ @@ -96,7 +96,7 @@ "route_source_value", "dose_unit_source_value", "drug_ucd_source_value", - "cdm_source" + "cdm_source", ], "date_column": "drug_exposure_start_datetime", "mapper": { @@ -104,10 +104,9 @@ "drug_type_source_value": {"not NaN": ".*"}, "drug_source_value": {"not NaN": ".*"}, "drug_class_source_value": {"not NaN": ".*"}, - "drug_ucd_source_value" : {"not NaN": ".*"}, - "route_source_value" : {"not NaN": ".*"}, - "dose_unit_source_value" : {"not NaN": ".*"}, - }, + "drug_ucd_source_value": {"not NaN": ".*"}, + "route_source_value": {"not NaN": ".*"}, + "dose_unit_source_value": {"not NaN": ".*"}, + }, }, - } diff --git a/eds_scikit/plot/omop_explorer.py b/eds_scikit/plot/omop_explorer.py index ad7a3392..62f09141 100644 --- a/eds_scikit/plot/omop_explorer.py +++ b/eds_scikit/plot/omop_explorer.py @@ -1,3 +1,5 @@ +import os + from loguru import logger from eds_scikit.io import HiveData @@ -24,7 +26,7 @@ def generate_omop_explorer( output_dir : str, optional Output directory path, by default "omop_explorer" """ - + if not os.path.exists(f"{output_dir}/"): os.makedirs(f"{output_dir}/") @@ -146,15 +148,19 @@ def generate_omop_explorer( chart.save(f"{output_dir}/note_chart.html") logger.info("notes processing done.") - + # Drug Exposure Prescription logger.info("Starting drug exposure prescription processing.") drg_exposure = data.drug_exposure_prescription config = explorer_config["drug_exposure_prescription"] - drg_exposure = drg_exposure.merge(visit_occurrence, on="visit_occurrence_id", how="left") - drg_exposure["visit_occurrence_id"] = drg_exposure["visit_occurrence_id"].astype(str) + drg_exposure = drg_exposure.merge( + visit_occurrence, on="visit_occurrence_id", how="left" + ) + drg_exposure["visit_occurrence_id"] = drg_exposure["visit_occurrence_id"].astype( + str + ) drg_exposure_count = reduce_table( drg_exposure, @@ -165,19 +171,25 @@ def generate_omop_explorer( mapper=config["mapper"], ) drg_exposure_count = drg_exposure_count[~(drg_exposure_count == 0).any(axis=1)] - chart = visualize_table(drg_exposure_count, title="drug exposure prescription table dashboard") + chart = visualize_table( + drg_exposure_count, title="drug exposure prescription table dashboard" + ) chart.save(f"{output_dir}/drug_exposure_prescription.html") logger.info("drug exposure prescription processing done.") - + # Drug Exposure Administration logger.info("Starting drug exposure administration processing.") drg_exposure = data.drug_exposure_administration config = explorer_config["drug_exposure_administration"] - drg_exposure = drg_exposure.merge(visit_occurrence, on="visit_occurrence_id", how="left") - drg_exposure["visit_occurrence_id"] = drg_exposure["visit_occurrence_id"].astype(str) + drg_exposure = drg_exposure.merge( + visit_occurrence, on="visit_occurrence_id", how="left" + ) + drg_exposure["visit_occurrence_id"] = drg_exposure["visit_occurrence_id"].astype( + str + ) drg_exposure_count = reduce_table( drg_exposure, @@ -188,7 +200,9 @@ def generate_omop_explorer( mapper=config["mapper"], ) drg_exposure_count = drg_exposure_count[~(drg_exposure_count == 0).any(axis=1)] - chart = visualize_table(drg_exposure_count, title="drug exposure administration table dashboard") + chart = visualize_table( + drg_exposure_count, title="drug exposure administration table dashboard" + ) chart.save(f"{output_dir}/drug_exposure_administration.html") logger.info("drug exposure administration processing done.") diff --git a/eds_scikit/plot/table_viz.py b/eds_scikit/plot/table_viz.py index 9bb3e1ec..f15805ce 100644 --- a/eds_scikit/plot/table_viz.py +++ b/eds_scikit/plot/table_viz.py @@ -3,8 +3,8 @@ import altair as alt import pandas as pd -from eds_scikit.plot.altair_utils import generate_color_map +from eds_scikit.plot.altair_utils import generate_color_map from eds_scikit.utils.checks import check_columns from eds_scikit.utils.framework import get_framework, to