|
1 | | -#' Create ASU patient trajectory |
| 1 | +#' Create acute stroke unit (ASU) patient trajectory. |
2 | 2 | #' |
| 3 | +#' Represents patient stay in the ASU - samples their (1) destination after |
| 4 | +#' the ASU, and (2) length of stay (LOS) on the ASU. |
| 5 | +#' |
| 6 | +#' @param env Simmer environment object. The simulation environment where |
| 7 | +#' generators will be added. |
3 | 8 | #' @param patient_type Character string specifying patient category. Must be |
4 | 9 | #' one of: "stroke", "tia", "neuro", or "other". Determines which arrival rate |
5 | 10 | #' parameter is used. |
6 | 11 | #' @param param Nested list containing simulation parameters. Must have |
7 | | -#' structure `param$asu_routing$<patient_type>` containing the probability of |
8 | | -#' routing to each destination (e.g.`param$asu_routing$stroke$rehab = 0.24`). |
| 12 | +#' structure \code{param$asu_routing$<patient_type>} containing the probability |
| 13 | +#' of routing to each destination (e.g. |
| 14 | +#' \code{param$asu_routing$stroke$rehab = 0.24}). |
9 | 15 | #' |
10 | 16 | #' @importFrom simmer trajectory |
| 17 | +#' @importFrom stats rlnorm |
11 | 18 | #' |
12 | 19 | #' @return Simmer trajectory object. Defines patient journey logic through the |
13 | 20 | #' healthcare system. |
14 | 21 | #' @export |
15 | 22 |
|
16 | | -create_asu_trajectory <- function(patient_type, param) { |
| 23 | +create_asu_trajectory <- function(env, patient_type, param) { |
| 24 | + |
| 25 | + # Set up simmer trajectory object... |
17 | 26 | trajectory(paste0("ASU_", patient_type, "_path")) |> |
18 | | - set_attribute("post_asu_destination", function(env) { |
| 27 | + |
| 28 | + # Sample destination after ASU (we do this immediately on arrival in the |
| 29 | + # ASU, as the destination influences the length of stay) |
| 30 | + set_attribute("post_asu_destination", function() { |
19 | 31 | sample_routing(prob_list = param[["asu_routing"]][[patient_type]]) |
20 | 32 | }) |> |
21 | | - timeout(1L) |
| 33 | + |
| 34 | + timeout(function() { |
| 35 | + |
| 36 | + # Retrieve attribute, and use to get post-ASU destination as a string |
| 37 | + dest_index <- get_attribute(env, "post_asu_destination") |
| 38 | + dest_names <- names(param[["asu_routing"]][[patient_type]]) |
| 39 | + dest <- dest_names[dest_index] |
| 40 | + |
| 41 | + # Determine which LOS distribution to use |
| 42 | + if (patient_type == "stroke") { |
| 43 | + los_params <- switch( |
| 44 | + dest, |
| 45 | + "esd" = param[["asu_los_lnorm"]][["stroke_esd"]], |
| 46 | + "rehab" = param[["asu_los_lnorm"]][["stroke_noesd"]], |
| 47 | + param[["asu_los_lnorm"]][["stroke_mortality"]] # Default case |
| 48 | + ) |
| 49 | + } else { |
| 50 | + los_params <- param[["asu_los_lnorm"]][[patient_type]] |
| 51 | + } |
| 52 | + |
| 53 | + # Sample LOS from lognormal |
| 54 | + rlnorm( |
| 55 | + n = 1L, |
| 56 | + meanlog = los_params[["meanlog"]], |
| 57 | + sdlog = los_params[["sdlog"]] |
| 58 | + ) |
| 59 | + }) |
22 | 60 | } |
0 commit comments