From 7824352f5c0a87e622102fcaf392ca6e3fe3c5c6 Mon Sep 17 00:00:00 2001 From: Malte Londschien <61679398+mlondschien@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:43:29 +0100 Subject: [PATCH] Add variables to PICDS (#8) * Add picdb ca and cai. * Add sbp and dbp. * Add tco2 * Add 1002 - 'pulse' to HR. * fio2 * Add ph. * po2 * Add sex. * age. * death * height: get rid of biopsy variable. * weight: get rid of labevents entry * alb * alt * ast * bili and bilidir. * ck * ckmb and cl * fix conversion ckmb * Add conversion to crea. * glu add conversion. * mg * na * phos * tnt * Fix outcome json. * samp * Add working `picdb_sampling` * Fix unit conversion on `alb` --------- Co-authored-by: Manuel Burger --- R/callback-itm.R | 19 +++ .../config/concept-dict/blood_gas.json | 33 +++-- .../config/concept-dict/chemistry.json | 123 +++++++++++++++--- .../config/concept-dict/demographics.json | 36 ++--- .../config/concept-dict/microbiology.json | 10 +- inst/extdata/config/concept-dict/outcome.json | 10 +- inst/extdata/config/concept-dict/vitals.json | 16 ++- 7 files changed, 201 insertions(+), 46 deletions(-) diff --git a/R/callback-itm.R b/R/callback-itm.R index 89bd1abe..77917c22 100644 --- a/R/callback-itm.R +++ b/R/callback-itm.R @@ -43,6 +43,25 @@ mimic_sampling <- function(x, val_var, aux_time, ...) { set(x, j = val_var, value = !is.na(x[[val_var]])) } +picdb_sampling <- function(x, val_var, aux_time, ...) { + x <- combine_date_time(x, aux_time, hours(12L)) + + # These identifiers indicate that the culture showed no growth + # of the respective organism + no_growth_identifiers <- c('MIC1008', 'MIC2123', 'MIC2287', 'MIC2291', 'MIC2293', + 'MIC2370', 'MIC2408', 'MIC2421', 'MIC575', + 'MIC585', 'MIC593', 'MIC629', 'MIC631', + 'MIC635', 'MIC637', 'MIC645', 'MIC648', + 'MIC874', 'MIC941', 'MIC979' + ) + + # Assign: + # - 0 if NA or in no_growth_identifiers + # - 1 otherwise, indicating growth + bool_value <- !is.na(x[[val_var]]) & !(x[[val_var]] %in% no_growth_identifiers) + set(x, j = val_var, value = bool_value) +} + #' Item callback utilities #' #' For concept loading, item callback functions are used in order to handle diff --git a/inst/extdata/config/concept-dict/blood_gas.json b/inst/extdata/config/concept-dict/blood_gas.json index 04b7854d..ca11b887 100644 --- a/inst/extdata/config/concept-dict/blood_gas.json +++ b/inst/extdata/config/concept-dict/blood_gas.json @@ -155,7 +155,13 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "ids": 5215, + "table": "labevents", + "sub_var": "itemid" + } + ] } }, "fio2": { @@ -258,7 +264,14 @@ "sub_var": "DataID" } ], - "picdb": [] + "picdb": [ + { + "ids": 5222, + "table": "labevents", + "sub_var": "itemid" + } + + ] } }, "hbco": { @@ -614,10 +627,7 @@ "table": "labevents", "ids": [ 5237, - 5238, - 5373, - 5374, - 5386 + 5238 ], "sub_var": "itemid" } @@ -704,7 +714,8 @@ "table": "labevents", "ids": [ 5239, - 5244 + 5244, + 5242 ], "sub_var": "itemid" } @@ -756,7 +767,13 @@ "sub_var": "itemid" } ], - "picdb": [] + "picdb": [ + { + "ids": 5256, + "table": "labevents", + "sub_var": "itemid" + } + ] } } } \ No newline at end of file diff --git a/inst/extdata/config/concept-dict/chemistry.json b/inst/extdata/config/concept-dict/chemistry.json index bae0b17c..2d40e68c 100644 --- a/inst/extdata/config/concept-dict/chemistry.json +++ b/inst/extdata/config/concept-dict/chemistry.json @@ -73,9 +73,11 @@ { "table": "labevents", "ids": [ - 5024 + 5024, + 6465 ], - "sub_var": "itemid" + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 0.1), 'g/dL')" } ] } @@ -231,7 +233,13 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "ids": [5026, 5195], + "table": "labevents", + "sub_var": "itemid" + } + ] } }, "ast": { @@ -304,7 +312,15 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "table": "labevents", + "ids": [ + 5031 + ], + "sub_var": "itemid" + } + ] } }, "bicar": { @@ -459,7 +475,16 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "table": "labevents", + "ids": [ + 5075 + ], + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 0.058467), 'mg/dL')" + } + ] } }, "bili_dir": { @@ -529,7 +554,16 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "table": "labevents", + "ids": [ + 5042 + ], + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 0.058467), 'mg/dL')" + } + ] } }, "bun": { @@ -603,7 +637,16 @@ "callback": "transform_fun(binary_op(`*`, 2.14))" } ], - "picdb": [] + "picdb": [ + { + "table": "labevents", + "ids": [ + 5224 + ], + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 2.8), 'mg/dL')" + } + ] } }, "ca": { @@ -679,7 +722,14 @@ "callback": "transform_fun(binary_op(`*`, 4.008))" } ], - "picdb": [] + "picdb": [ + { + "ids": 5034, + "table": "labevents", + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 4), 'mg/dL', 'mmol/L')" + } + ] } }, "ck": { @@ -752,7 +802,15 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "table": "labevents", + "ids": [ + 5038 + ], + "sub_var": "itemid" + } + ] } }, "ckmb": { @@ -819,7 +877,16 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "table": "labevents", + "ids": [ + 5039 + ], + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 0.1893), 'ng/mL', 'U/L')" + } + ] } }, "cl": { @@ -896,7 +963,15 @@ "sub_var": "LaboratoryID" } ], - "picdb": [] + "picdb": [ + { + "table": "labevents", + "ids": [ + 5218 + ], + "sub_var": "itemid" + } + ] } }, "crea": { @@ -978,7 +1053,8 @@ 5041, 6954 ], - "sub_var": "itemid" + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 0.011312), 'mg/dL')" } ] } @@ -1164,7 +1240,8 @@ 5047, 5223 ], - "sub_var": "itemid" + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 18.016), 'mg/dL')" } ] } @@ -1340,7 +1417,8 @@ "ids": [ 5059 ], - "sub_var": "itemid" + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 2.431), 'mg/dL')" } ] } @@ -1431,7 +1509,7 @@ { "table": "labevents", "ids": [ - 5062 + 5230 ], "sub_var": "itemid" } @@ -1515,7 +1593,8 @@ "ids": [ 5072 ], - "sub_var": "itemid" + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`*`, 3.097521), 'mg/dL')" } ] } @@ -1592,7 +1671,17 @@ "ids": [ 6525 ], - "sub_var": "itemid" + "sub_var": "itemid", + "callback": "convert_unit(binary_op(`/`, 1000), 'ng/mL', 'pg/m')" + }, + { + "table": "labevents", + "ids": [ + 6525 + ], + "sub_var": "itemid", + "val_var": "value", + "callback": "apply_map(c(`<0.003` = 0.003))" } ] } diff --git a/inst/extdata/config/concept-dict/demographics.json b/inst/extdata/config/concept-dict/demographics.json index 6f156f78..b88cba79 100644 --- a/inst/extdata/config/concept-dict/demographics.json +++ b/inst/extdata/config/concept-dict/demographics.json @@ -131,7 +131,14 @@ "class": "col_itm" } ], - "picdb": [] + "picdb": [ + { + "table": "patients", + "val_var": "dob", + "callback": "transform_fun(mimic_age)", + "class": "col_itm" + } + ] } }, "bmi": { @@ -236,14 +243,7 @@ { "table": "chartevents", "ids": [ - "1013" - ], - "sub_var": "itemid" - }, - { - "table": "labevents", - "ids": [ - 6322 + 1013 ], "sub_var": "itemid" } @@ -323,7 +323,14 @@ "class": "col_itm" } ], - "picdb": [] + "picdb": [ + { + "table": "patients", + "val_var": "gender", + "class": "col_itm", + "callback": "apply_map(c(M = 'Male', F = 'Female'))" + } + ] } }, "weight": { @@ -406,14 +413,7 @@ { "table": "chartevents", "ids": [ - "1014" - ], - "sub_var": "itemid" - }, - { - "table": "labevents", - "ids": [ - 6323 + 1014 ], "sub_var": "itemid" } diff --git a/inst/extdata/config/concept-dict/microbiology.json b/inst/extdata/config/concept-dict/microbiology.json index d3313efb..7a380e64 100644 --- a/inst/extdata/config/concept-dict/microbiology.json +++ b/inst/extdata/config/concept-dict/microbiology.json @@ -77,7 +77,15 @@ "class": "col_itm" } ], - "picdb": [] + "picdb": [ + { + "table": "microbiologyevents", + "val_var": "org_itemid", + "callback": "picdb_sampling", + "aux_time": "charttime", + "class": "col_itm" + } + ] } } } \ No newline at end of file diff --git a/inst/extdata/config/concept-dict/outcome.json b/inst/extdata/config/concept-dict/outcome.json index fef255ff..0d08a873 100644 --- a/inst/extdata/config/concept-dict/outcome.json +++ b/inst/extdata/config/concept-dict/outcome.json @@ -71,7 +71,15 @@ "class": "col_itm" } ], - "picdb": [] + "picdb": [ + { + "table": "admissions", + "index_var": "deathtime", + "val_var": "hospital_expire_flag", + "callback": "transform_fun(comp_na(`==`, 1L))", + "class": "col_itm" + } + ] } }, "dopa60": { diff --git a/inst/extdata/config/concept-dict/vitals.json b/inst/extdata/config/concept-dict/vitals.json index 91dfcc08..4cb3571d 100644 --- a/inst/extdata/config/concept-dict/vitals.json +++ b/inst/extdata/config/concept-dict/vitals.json @@ -86,6 +86,13 @@ } ], "picdb": [ + { + "table": "chartevents", + "ids": [ + 1015 + ], + "sub_var": "itemid" + } ] } }, @@ -236,7 +243,7 @@ { "table": "chartevents", "ids": [ - "1003" + 1003, 1002 ], "sub_var": "itemid" } @@ -438,6 +445,13 @@ } ], "picdb": [ + { + "table": "chartevents", + "ids": [ + 1016 + ], + "sub_var": "itemid" + } ] } },