rrp_refresh_products: Refresh an RRP project's analytical product CSVs

View source: R/product-refresh.R

rrp_refresh_productsR Documentation

Refresh an RRP project's analytical product CSVs

Description

Derive the current clinically eligible risk pool, observed accepted-risk trajectories, and operational scope from retained assessment history. The selected completed run has the greatest analytical as_of_time; execution created_at and then run_id break ties. A later-executed historical backfill does not replace a newer analytical snapshot.

Usage

rrp_refresh_products(path)

Arguments

path

Path to an existing RRP project with initialized analytical state and at least one completed assessment run.

Details

Files are written under ⁠state/products/⁠ as current-remaining-risk.csv, remaining-risk-trajectory.csv, and operational-scope-summary.csv. The current-risk file includes clinically eligible provider-failure episodes with a missing probability, never zero or an earlier estimate. Refresh reads history only: it does not run the source mapper or provider, add a run, change retained history, or edit the project-owned app. All files are staged and checked before replacement. Replacement of the three files is not fully atomic if a filesystem error occurs during the final replacement sequence. Call rrp_run() to retain an assessment first; rrp_inspect_history() reads its stored rows.

Value

Invisibly, a list with selected_run_id, UTC as_of_time, and a named character vector files of generated CSV paths. Its keys are current_risk (current-remaining-risk.csv), trajectory (remaining-risk-trajectory.csv), and scope (operational-scope-summary.csv); the paths identify files, not their in-memory contents.

Examples

project <- tempfile("rrp-products-")
rrp_project_init(project, "example-rrp")
time <- as.POSIXct("2026-01-10 12:00:00", tz = "UTC")
episode <- data.frame(
  episode_id = "episode-1", patient_id = "patient-1",
  index_encounter_id = "encounter-1",
  admission_time = time - 2 * 86400, discharge_time = time - 86400
)
events <- data.frame(
  terminal_event_id = character(), episode_id = character(),
  event_type = character(), occurred_at = time[FALSE],
  available_at = time[FALSE]
)
saveRDS(list(discharge_episode = episode, terminal_event = events),
        file.path(project, "canonical.rds"))
# Replace both generated stubs; this constant risk is illustrative only.
writeLines(
  c("rrp_produce_canonical <- function(project_root, as_of_time) {",
    "  readRDS(file.path(project_root, 'canonical.rds'))", "}"),
  file.path(project, "R", "produce-canonical.R")
)
writeLines(
  "rrp_calculate_risk <- function(project_root, request) list(probability = 0.2)",
  file.path(project, "R", "calculate-risk.R")
)
rrp_state_init(project)
rrp_run(project, time)
products <- rrp_refresh_products(project)
names(products$files)
file.exists(products$files)
unlink(project, recursive = TRUE)

readmit documentation built on Nov. 4, 2026, 1:15 a.m.