Skip to content

Commit

Permalink
load_difftime and id_win_helper for picdb.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlondschien committed Mar 5, 2024
1 parent 660dae7 commit a349f19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions R/data-load.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
29 changes: 29 additions & 0 deletions R/data-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a349f19

Please sign in to comment.