Skip to content

Commit

Permalink
include information on mechanical ventilation patients; closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rekkasa committed Nov 6, 2024
1 parent 23d19d1 commit 9314395
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 89 deletions.
69 changes: 37 additions & 32 deletions code/load_tables.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
patients <- DBI::dbGetQuery(conn, "SELECT * FROM patients_patient")
centers <- DBI::dbGetQuery(conn, "SELECT * FROM centers_center")
gender <- DBI::dbGetQuery(conn, "SELECT * FROM patients_gender")
caregiver <- DBI::dbGetQuery(conn, "SELECT * FROM patients_caregiver")
condition <- DBI::dbGetQuery(conn, "SELECT * FROM patients_patientcondition")
profession <- DBI::dbGetQuery(conn, "SELECT * FROM patients_profession")
education <- DBI::dbGetQuery(conn, "SELECT * FROM patients_education")
visit <- DBI::dbGetQuery(conn, "SELECT * FROM patients_patientvisit") |>
dplyr::mutate(
visit_date = lubridate::as_date(visit_date)
)
bad_habit <- DBI::dbGetQuery(conn, "SELECT * FROM patients_badhabit")
underlying_disease <- DBI::dbGetQuery(conn, "SELECT * FROM patients_underlyingdisease")
cardiopathy <- DBI::dbGetQuery(conn, "SELECT * FROM patients_cardiopathy")
device_testing_info <- DBI::dbGetQuery(conn, "SELECT * FROM patients_devicetestinginfo")
mv_type <- DBI::dbGetQuery(conn, "SELECT * FROM patients_mvtype")
mask_type <- DBI::dbGetQuery(conn, "SELECT * FROM patients_masktype")
device_selection <- DBI::dbGetQuery(conn, "SELECT * FROM patients_deviceselection")
check_cause <- DBI::dbGetQuery(conn, "SELECT * FROM patients_checkcause")
checked_by <- DBI::dbGetQuery(conn, "SELECT * FROM patients_checkedby")
ventilation_type <- DBI::dbGetQuery(conn, "SELECT * FROM patients_ventilationtype")
breath_and_sleep_test <- DBI::dbGetQuery(conn, "SELECT * FROM patients_breathandsleeptest")
breath_and_sleep_test_clinical_symptoms <- DBI::dbGetQuery(conn, "SELECT * FROM patients_breathandsleeptest_clinical_symptoms")
clinical_symptom <- DBI::dbGetQuery(conn, "SELECT * FROM patients_clinicalsymptom")

characteristics <- DBI::dbGetQuery(
conn = conn,
statement = "SELECT * FROM patients_patientcharacteristics"
patients <- suppressWarnings(DBI::dbReadTable(conn, "patients_patient"))
centers <- suppressWarnings(DBI::dbReadTable(conn, "centers_center"))
gender <- suppressWarnings(DBI::dbReadTable(conn, "patients_gender"))
caregiver <- suppressWarnings(DBI::dbReadTable(conn, "patients_caregiver"))
condition <- suppressWarnings(DBI::dbReadTable(conn, "patients_patientcondition"))
profession <- suppressWarnings(DBI::dbReadTable(conn, "patients_profession"))
education <- suppressWarnings(DBI::dbReadTable(conn, "patients_education"))
visit <- suppressWarnings(
DBI::dbReadTable(conn, "patients_patientvisit") |>
dplyr::mutate(
visit_date = lubridate::as_date(visit_date)
)
)
bad_habit <- suppressWarnings(DBI::dbReadTable(conn, "patients_badhabit"))
underlying_disease <- suppressWarnings(DBI::dbReadTable(conn, "patients_underlyingdisease"))
cardiopathy <- suppressWarnings(DBI::dbGetQuery(conn, "SELECT * FROM patients_cardiopathy"))
device_testing_info <- suppressWarnings(DBI::dbReadTable(conn, "patients_devicetestinginfo"))
mv_type <- suppressWarnings(DBI::dbReadTable(conn, "patients_mvtype"))
mask_type <- suppressWarnings(DBI::dbReadTable(conn, "patients_masktype"))
device_selection <- suppressWarnings(DBI::dbReadTable(conn, "patients_deviceselection"))
check_cause <- suppressWarnings(DBI::dbReadTable(conn, "patients_checkcause"))
checked_by <- suppressWarnings(DBI::dbReadTable(conn, "patients_checkedby"))
ventilation_type <- suppressWarnings(DBI::dbReadTable(conn, "patients_ventilationtype"))
breath_and_sleep_test <- suppressWarnings(DBI::dbReadTable(conn, "patients_breathandsleeptest"))
breath_and_sleep_test_clinical_symptoms <- suppressWarnings(DBI::dbReadTable(conn, "patients_breathandsleeptest_clinical_symptoms"))
clinical_symptom <- suppressWarnings(DBI::dbReadTable(conn, "patients_clinicalsymptom"))
period_of_usage <- suppressWarnings(DBI::dbReadTable(conn, "patients_periodofusage"))
treatment_provider <- suppressWarnings(DBI::dbReadTable(conn, "patients_treatmentprovider"))
xoth <- suppressWarnings(DBI::dbReadTable(conn, "patients_xoth"))
ventilation_reason <- suppressWarnings(DBI::dbReadTable(conn, "patients_ventilationreason"))
ventilation_status <- suppressWarnings(DBI::dbReadTable(conn, "patients_ventilationstatus"))
ventilation_type <- suppressWarnings(DBI::dbReadTable(conn, "patients_ventilationtype"))
invasive_system_estimation <- suppressWarnings(DBI::dbReadTable(conn, "patients_invasivesystemestimation"))
tracheostomy_type <- DBI::dbReadTable(conn, "patients_tracheostomytype")

patient_ventilation <- DBI::dbGetQuery(
conn = conn,
statement = "SELECT * FROM patients_patientventilation"
)
characteristics <- suppressWarnings(DBI::dbReadTable(conn, "patients_patientcharacteristics"))
patient_ventilation <- suppressWarnings(DBI::dbReadTable(conn, "patients_patientventilation"))

message("Loaded all required tables from database...")
91 changes: 85 additions & 6 deletions code/prepare_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,61 @@ patient_ventilation_mv_first_visit <- patients_mv |>
dplyr::left_join(
characteristics_overall_first_visit |>
dplyr::select(pat_id_id, bmi),
by = c("id" = "pat_id_id"))
by = c("id" = "pat_id_id")) |>
dplyr::left_join(
period_of_usage,
by = c("period_of_usage_id" = "id")
) |>
dplyr::rename("period_of_usage" = "period") |>
dplyr::select(-period_of_usage_id) |>
dplyr::left_join(
treatment_provider,
by = c("treatment_provider_id" = "id")
) |>
dplyr::rename("treatment_provider" = "provider") |>
dplyr::select(-treatment_provider_id) |>
dplyr::left_join(
xoth,
by = c("xoth_id" = "id")
) |>
dplyr::select(-xoth_id) |>
dplyr::left_join(
ventilation_reason,
by = c("ventilation_reason_id" = "id")
) |>
dplyr::rename("ventilation_reason" = "reason") |>
dplyr::select(-ventilation_reason_id) |>
dplyr::left_join(
ventilation_status,
by = c("ventilation_status_id" = "id")
) |>
dplyr::rename("ventilation_status" = "status") |>
dplyr::select(-ventilation_status_id) |>
dplyr::left_join(
ventilation_type,
by = c("ventilation_type_id" = "id")
) |>
dplyr::select(-ventilation_type_id) |>
dplyr::left_join(
invasive_system_estimation,
by = c("invasive_ventilation_id" = "id")
) |>
dplyr::rename("invasive_ventilation" = "estimation") |>
dplyr::select(-invasive_ventilation_id) |>
dplyr::left_join(
tracheostomy_type,
by = c("tracheostomy_id" = "id")
) |>
dplyr::select(-tracheostomy_id)

device_testing_info_overall_first_visit<- device_testing_info |>
device_testing_info_overall_first_visit <- device_testing_info |>
dplyr::select(-id) |>
dplyr::left_join(visit, by = c("visit_id" = "id")) |>
dplyr::group_by(pat_id_id) |>
dplyr::arrange(visit_date) |>
dplyr::slice_head(n = 1)

device_testing_info_overall_first_visist_adult <- patients_sayy |>
device_testing_info_overall_sayy_first_visit_adult <- patients_sayy |>
dplyr::select(id, gender, age) |>
dplyr::filter(age >= 18) |>
dplyr::left_join(
Expand Down Expand Up @@ -149,6 +194,34 @@ device_testing_info_overall_first_visist_adult <- patients_sayy |>
)
)

device_testing_info_overall_mv_first_visit <- patients_mv |>
dplyr::select(id, gender, age) |>
dplyr::left_join(
device_testing_info_overall_first_visit,
by = c("id" = "pat_id_id")
) |>
dplyr::left_join(mask_type, by = c("mask_type_id" = "id")) |>
dplyr::rename("mask_type" = "type") |>
dplyr::left_join(mv_type, by = c("ma_type_id" = "id")) |>
dplyr::rename("ma_type" = "type") |>
dplyr::left_join(device_selection, by = c("dev_sel_id" = "id")) |>
dplyr::rename("dev_sel_type" = "type") |>
dplyr::left_join(check_cause, by = c("check_cause_id" = "id")) |>
dplyr::rename("check_cause" = "cause") |>
dplyr::left_join(checked_by, by = c("checked_by_id" = "id")) |>
dplyr::rename("checked_by" = "by") |>
dplyr::mutate(
mask_type = tidyr::replace_na(mask_type, "ΑΓΝΩΣΤΟ"),
ma_type = tidyr::replace_na(ma_type, "ΑΓΝΩΣΤΟ"),
dev_sel_type = tidyr::replace_na(dev_sel_type, "ΑΓΝΩΣΤΟ"),
checked_by = tidyr::replace_na(checked_by, "ΑΓΝΩΣΤΟ"),
check_cause = tidyr::replace_na(check_cause, "ΑΓΝΩΣΤΟ")
) |>
dplyr::select(
-c(
"mask_type_id", "ma_type_id", "dev_sel_id", "check_cause_id", "checked_by_id"
)
)

breath_and_sleep_test_overall_first_visit <- breath_and_sleep_test |>
dplyr::left_join(
Expand Down Expand Up @@ -227,10 +300,16 @@ readr::write_csv(
message("Wrote file: data/characteristics_sayy_first_visit_adult")

readr::write_csv(
device_testing_info_overall_first_visist_adult,
"data/device_testing_info_overall_first_visist_adult.csv"
device_testing_info_overall_sayy_first_visit_adult,
"data/device_testing_info_overall_sayy_first_visit_adult.csv"
)
message("Wrote file: data/device_testing_info_overall_sayy_first_visit_adult.csv")

readr::write_csv(
device_testing_info_overall_mv_first_visit,
"data/device_testing_info_overall_mv_first_visit.csv"
)
message("Wrote file: data/device_testing_info_overall_first_visist_adult.csv")
message("Wrote file: data/device_testing_info_overall_mv_first_visit.csv")

readr::write_csv(
breath_and_sleep_test_overall_first_visit_adult,
Expand Down
Loading

0 comments on commit 9314395

Please sign in to comment.