diff --git a/R/data-load.R b/R/data-load.R index 80b57ee4..071a8195 100644 --- a/R/data-load.R +++ b/R/data-load.R @@ -178,6 +178,18 @@ load_difftime.sic_tbl <- function(x, rows, cols = colnames(x), load_eiau(x, {{ rows }}, cols, id_hint, time_vars, sec_as_mins) } +#' @rdname load_src +#' @export +# copy-pasted from mimic_tbl +load_difftime.picdb_tbl <- function(x, rows, cols = colnames(x), + id_hint = id_vars(x), + time_vars = ricu::time_vars(x), ...) { + + warn_dots(...) + + load_mihi(x, {{ rows }}, cols, id_hint, time_vars) +} + #' @rdname load_src #' @export load_difftime.character <- function(x, src, ...) { diff --git a/R/data-utils.R b/R/data-utils.R index 0d2b73cc..31fa02df 100644 --- a/R/data-utils.R +++ b/R/data-utils.R @@ -361,6 +361,35 @@ id_win_helper.miiv_env <- function(x) { order_rename(res, ids, sta, end) } +#' @rdname data_utils +#' @export +# copy-pasted from mimic +id_win_helper.picdb_env <- function(x) { + + merge_inter <- function(x, y) { + merge(x, y, by = intersect(colnames(x), colnames(y))) + } + + get_id_tbl <- function(tbl, id, start, end, aux) { + as_src_tbl(x, tbl)[, c(id, start, end, aux)] + } + + cfg <- sort(as_id_cfg(x), decreasing = TRUE) + + ids <- field(cfg, "id") + sta <- field(cfg, "start") + end <- field(cfg, "end") + + res <- Map(get_id_tbl, field(cfg, "table"), ids, sta, + end, c(as.list(ids[-1L]), list(NULL))) + res <- Reduce(merge_inter, res) + + res <- res[, c(sta, end) := lapply(.SD, as_dt_min, get(sta[1L])), + .SDcols = c(sta, end)] + + order_rename(res, ids, sta, end) +} + #' @export id_win_helper.default <- function(x) stop_generic(x, .Generic)