@@ -32,44 +32,30 @@ create_asu_trajectory <- function(env, patient_type, param) {
3232
3333 # Sample destination after ASU (as destination influences length of stay)
3434 set_attribute(" post_asu_destination" , function () {
35- sample_routing( prob_list = param [[" asu_routing " ]][[patient_type ]])
35+ param [[" dist " ]][[" routing " ]][[ " asu " ]][[ patient_type ]]( )
3636 }) | >
3737
3838 log_(function () {
39- # Retrieve attribute, and use to get post-ASU destination as a string
40- dest_index <- get_attribute(env , " post_asu_destination" )
41- dest_names <- names(param [[" asu_routing" ]][[patient_type ]])
42- dest <- dest_names [dest_index ]
43- # Create log message
44- paste0(" \U 0001F3AF Planned ASU -> " , dest_index , " (" , dest , " )" )
39+ dest <- get_attribute(env , " post_asu_destination" )
40+ paste0(" \U 0001F3AF Planned ASU -> " , dest )
4541 }, level = 1L ) | >
4642
43+ # Sample ASU LOS. For stroke patients, LOS distribution is based on
44+ # the planned destination after the ASU.
4745 set_attribute(" asu_los" , function () {
48- # Retrieve attribute, and use to get post-ASU destination as a string
49- dest_index <- get_attribute(env , " post_asu_destination" )
50- dest_names <- names(param [[" asu_routing" ]][[patient_type ]])
51- dest <- dest_names [dest_index ]
52-
53- # Determine which LOS distribution to use
46+ dest <- get_attribute(env , " post_asu_destination" )
5447 if (patient_type == " stroke" ) {
55- los_params <- switch (
48+ switch (
5649 dest ,
57- esd = param [[" asu_los_lnorm " ]][[" stroke_esd" ]],
58- rehab = param [[" asu_los_lnorm " ]][[" stroke_no_esd" ]],
59- other = param [[" asu_los_lnorm " ]][[" stroke_mortality" ]],
50+ esd = param [[" dest " ]][[ " los " ]][[ " asu " ]][[" stroke_esd" ]],
51+ rehab = param [[" dest " ]][[ " los " ]][[ " asu " ]][[" stroke_no_esd" ]],
52+ other = param [[" dest " ]][[ " los " ]][[ " asu " ]][[" stroke_mortality" ]],
6053 stop(" Stroke post-asu destination '" , dest , " ' invalid" ,
6154 call. = FALSE )
6255 )
6356 } else {
64- los_params <- param [[" asu_los_lnorm " ]][[patient_type ]]
57+ param [[" dest " ]][[" los " ]][[ " asu " ]][[ patient_type ]]()
6558 }
66-
67- # Sample LOS from lognormal
68- rlnorm(
69- n = 1L ,
70- meanlog = los_params [[" meanlog" ]],
71- sdlog = los_params [[" sdlog" ]]
72- )
7359 }) | >
7460
7561 log_(function () {
@@ -86,12 +72,7 @@ create_asu_trajectory <- function(env, patient_type, param) {
8672 # If that patient's destination is rehab, then start on that trajectory
8773 branch(
8874 option = function () {
89- # Retrieve attribute, and use to get post-ASU destination as a string
90- dest_index <- get_attribute(env , " post_asu_destination" )
91- dest_names <- names(param [[" asu_routing" ]][[patient_type ]])
92- dest <- dest_names [dest_index ]
93- # Return 1 for rehab and 0 otherwise
94- if (dest == " rehab" ) 1L else 0L
75+ if (get_attribute(env , " post_asu_destination" ) == " rehab" ) 1L else 0L
9576 },
9677 continue = FALSE , # Do not continue main trajectory after branch
9778 create_rehab_trajectory(env , patient_type , param )
0 commit comments