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

Finish PICdb integration #16

Merged
merged 8 commits into from
Apr 8, 2024
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
27 changes: 27 additions & 0 deletions R/callback-icu-mortality.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,30 @@ miiv_death_icu <- function(x, env, ...){
mi_death_icu(x, transfers, icu_wards, ...)
}

picdb_death_icu <- function(x, env, ...){
#' Extract in-ICU mortality from PICdb
#'
#' We rely on a concept-dict config, which passes rows for each `icustay_id`
#' separately (e.g. the `icustays` table). As this table does not contain mortality
#' information we rely on a auxiliary column defined for all patients in PICdb in
#' the chosen table (e.g. `los`).
#' We extract the last ICU stay for each `hadm_id`. We reset the `los` column to be
#' FALSE for each `icustay_id` and set it to TRUE for the `icustay_id` of the last
#' ICU stay of each `hadm_id`, which is marked as deceased.

icu_stays <- load_ts(env[["icustays"]], id_var = "hadm_id", index_var = "intime", interval = mins(1L))
admissions <- load_id(env[["admissions"]], id_var = "hadm_id", cols = c("hospital_expire_flag"))

# For each "hadm_id" we find the "icustay_id" of the last ICU stay based on the "intime"
last_icu_stay <- icu_stays[, .(icustay_id = icustay_id[.N]), by = hadm_id]
deceased_hadm_id <- admissions[ricu:::is_true(hospital_expire_flag), .(hadm_id)]$hadm_id
deceased_icustay_id <- icu_stays[hadm_id %in% deceased_hadm_id, .(icustay_id)]$icustay_id

# For all `icustay_id` not in last_icu_stay, we set the value of the `hospital_expire_flag` variable to FALSE
# Patients only die in the last ICU stay
# `los` should be configured to be the target extraction column as a dummy column
# to put the value of the `hospital_expire_flag` variable
x[, los := FALSE]
x[icustay_id %in% deceased_icustay_id, los := TRUE]
x[!icustay_id %in% last_icu_stay$icustay_id, los := FALSE]
}
109 changes: 57 additions & 52 deletions inst/extdata/config/concept-dict/hematology.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@
"picdb": [
{
"table": "labevents",
"ids": [
5492
],
"ids": 5492,
"sub_var": "itemid"
},
{
"table": "labevents",
"ids": 5493,
"sub_var": "itemid",
"callback": "blood_cell_ratio"
}
]
}
Expand Down Expand Up @@ -139,8 +143,7 @@
"table": "labevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
},
"eos": {
Expand Down Expand Up @@ -217,9 +220,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
5002
],
"ids": 5002,
"sub_var": "itemid"
}
]
Expand Down Expand Up @@ -274,8 +275,7 @@
"table": "labevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
},
"fgn": {
Expand Down Expand Up @@ -350,7 +350,14 @@
"class": "sic_itm"
}
],
"picdb": []
"picdb": [
{
"table": "labevents",
"ids": 5164,
"sub_var": "itemid",
"callback": "convert_unit(binary_op(`*`, 100), 'mg/dL', 'g/L')"
}
]
}
},
"hba1c": {
Expand Down Expand Up @@ -398,7 +405,13 @@
"class": "sic_itm"
}
],
"picdb": []
"picdb": [
{
"table": "labevents",
"ids": [5628, 6070],
"sub_var": "itemid"
}
]
}
},
"hct": {
Expand Down Expand Up @@ -567,7 +580,8 @@
5099,
5257
],
"sub_var": "itemid"
"sub_var": "itemid",
"callback": "convert_unit(binary_op(`*`, 0.1), 'g/dL', 'g/L')"
}
]
}
Expand Down Expand Up @@ -626,8 +640,7 @@
"table": "labevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
},
"lymph": {
Expand Down Expand Up @@ -710,7 +723,19 @@
"class": "sic_itm"
}
],
"picdb": []
"picdb": [
{
"table": "labevents",
"ids": [5006, 5503, 5111, 5503],
"sub_var": "itemid"
},
{
"table": "labevents",
"ids": 5110,
"sub_var": "itemid",
"callback": "blood_cell_ratio"
}
]
}
},
"mch": {
Expand Down Expand Up @@ -782,9 +807,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
5113
],
"ids": 5113,
"sub_var": "itemid"
}
]
Expand Down Expand Up @@ -862,10 +885,9 @@
"picdb": [
{
"table": "labevents",
"ids": [
5114
],
"sub_var": "itemid"
"ids": 5114,
"sub_var": "itemid",
"callback": "convert_unit(binary_op(`*`, 0.1), '%')"
}
]
}
Expand Down Expand Up @@ -939,9 +961,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
5115
],
"ids": 5115,
"sub_var": "itemid"
}
]
Expand Down Expand Up @@ -1033,9 +1053,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
5094
],
"ids": [5005, 5094, 5095, 5511],
"sub_var": "itemid"
}
]
Expand Down Expand Up @@ -1118,9 +1136,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
5129
],
"ids": 5129,
"sub_var": "itemid"
}
]
Expand Down Expand Up @@ -1186,11 +1202,9 @@
"picdb": [
{
"table": "labevents",
"ids": [
5186,
6890
],
"sub_var": "itemid"
"ids": [5186, 6890],
"sub_var": "itemid",
"callback": "convert_unit(identity_callback, 'sec')"
}
]
}
Expand Down Expand Up @@ -1263,10 +1277,9 @@
"picdb": [
{
"table": "labevents",
"ids": [
5161
],
"sub_var": "itemid"
"ids": 5161,
"sub_var": "itemid",
"callback": "convert_unit(identity_callback, 'sec')"
}
]
}
Expand Down Expand Up @@ -1336,11 +1349,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
5379,
5381,
6515
],
"ids": 5132,
"sub_var": "itemid"
}
]
Expand Down Expand Up @@ -1399,9 +1408,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
5136
],
"ids": 5136,
"sub_var": "itemid"
}
]
Expand Down Expand Up @@ -1481,9 +1488,7 @@
"picdb": [
{
"table": "labevents",
"ids": [
6516
],
"ids": 5141,
"sub_var": "itemid"
}
]
Expand Down
15 changes: 5 additions & 10 deletions inst/extdata/config/concept-dict/neurological.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
"table": "chartevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
},
"gcs": {
Expand Down Expand Up @@ -170,8 +169,7 @@
"table": "chartevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
},
"rass": {
Expand Down Expand Up @@ -232,8 +230,7 @@
"table": "chartevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
},
"tgcs": {
Expand Down Expand Up @@ -270,8 +267,7 @@
"table": "chartevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
},
"vgcs": {
Expand Down Expand Up @@ -343,8 +339,7 @@
"table": "chartevents",
"sub_var": "itemid"
}
],
"picdb": []
]
}
}
}
34 changes: 32 additions & 2 deletions inst/extdata/config/concept-dict/outcome.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@
"callback": "transform_fun(comp_na(`==`, 1L))",
"class": "col_itm"
}
],
"picdb": [
{
"table": "admissions",
"index_var": "deathtime",
"val_var": "hospital_expire_flag",
"callback": "transform_fun(comp_na(`==`, 1L))",
"class": "col_itm"
}
]
}
},
Expand Down Expand Up @@ -222,6 +231,15 @@
"callback": "sic_death",
"class": "col_itm"
}
],
"picdb": [
{
"table": "icustays",
"index_var": "intime",
"val_var": "los",
"callback": "picdb_death_icu",
"class": "col_itm"
}
]
}
},
Expand Down Expand Up @@ -297,7 +315,13 @@
"class": "fun_itm"
}
],
"picdb": []
"picdb": [
{
"callback": "los_callback",
"win_type": "hadm",
"class": "fun_itm"
}
]
}
},
"los_icu": {
Expand Down Expand Up @@ -364,7 +388,13 @@
"class": "col_itm"
}
],
"picdb": []
"picdb": [
{
"table": "icustays",
"val_var": "los",
"class": "col_itm"
}
]
}
},
"mews": {
Expand Down
Loading
Loading