Title: | R-package to implement a waiting list management approach |
---|---|
Description: | R-package to implement the waiting list management approach described in this paper by Fong et al 2022. |
Authors: | Neil Walton [cre, aut] |
Maintainer: | Tom Smith <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9001 |
Built: | 2025-02-24 05:49:54 UTC |
Source: | https://github.com/nhs-r-community/NHSRwaitinglist |
Internal Helper function to get column indicies for referrals, removals, and withdrawals
calc_index(waiting_list, colname = NULL, type = NULL)
calc_index(waiting_list, colname = NULL, type = NULL)
waiting_list |
a dataframe containing the waitinglist |
colname |
string giving the column name |
type |
if colname, write referral, withdrawal, removal to guess the index |
index
Internal Helper function number of days from prioirty code
calc_priority_to_target(priority)
calc_priority_to_target(priority)
priority |
number 1,2,3 or 4 |
number of days
Calculates the queue load. The queue load is the number of arrivals that occur for every patient leaving the queue (given that the waiting list did not empty). It could also be described as the rate of service at the queue. The queue load is calculated by dividing the demand by the capacity: queue_load = demand / capacity.
calc_queue_load(demand, capacity)
calc_queue_load(demand, capacity)
demand |
Numeric value of rate of demand in same units as target wait - e.g. if target wait is weeks, then demand in units of patients/week. |
capacity |
Numeric value of the number of patients that can be served (removals) from the waiting list each week. |
Numeric value of load which is the ratio between demand and capacity.
# If 30 patients are added to the waiting list each week (demand) and 27 # removed (capacity) this results in a queue load of 1.11 (30/27). calc_queue_load(30, 27)
# If 30 patients are added to the waiting list each week (demand) and 27 # removed (capacity) this results in a queue load of 1.11 (30/27). calc_queue_load(30, 27)
Calculates required relief capacity to achieve target queue size in a given period of time as a function of demand, queue size, target queue size and time period. Relief Capacity is required if Queue Size > 2 * Target Queue Size.
Relief Capacity = Current Demand + (Queue Size - Target Queue Size)/Time Steps
WARNING!: make sure units match. I.e. if demand is measured per week then time_to_target should be weeks or if demand is per day then time_to_target is per day
calc_relief_capacity( demand, queue_size, target_queue_size, time_to_target = 26, num_referrals = 0, cv_demand = 0 )
calc_relief_capacity( demand, queue_size, target_queue_size, time_to_target = 26, num_referrals = 0, cv_demand = 0 )
demand |
Numeric value of rate of demand in same units as target wait e.g. if target wait is weeks, then demand in units of patients/week. |
queue_size |
Numeric value of current number of patients in queue. |
target_queue_size |
Numeric value of desired number of patients in queue. |
time_to_target |
Numeric value of desired number of time-steps to reach the target queue size by. |
A numeric value of the required rate of capacity to achieve a target queue size in a given period of time.
# If demand is 30 patients per week, the current queue size is 1200 and the # target is to achieve a queue size of 390 in 26 weeks, then # Relief Capacity = 30 + (1200 - 390)/26 = 61.15 patients per week. calc_relief_capacity(30, 1200, 390, 26)
# If demand is 30 patients per week, the current queue size is 1200 and the # target is to achieve a queue size of 390 in 26 weeks, then # Relief Capacity = 30 + (1200 - 390)/26 = 61.15 patients per week. calc_relief_capacity(30, 1200, 390, 26)
Applies Kingman/Marchal's Formula :
capacity = demand + (cvd**2 + cvc**2) / waiting_time
where cvd = coefficent of variation of time between arrivals cvd = coefficient of variation of sevice times waiting_time = target_wait / factor
calc_target_capacity( demand, target_wait, factor = 4, cv_demand = 1, cv_capacity = 1 )
calc_target_capacity( demand, target_wait, factor = 4, cv_demand = 1, cv_capacity = 1 )
demand |
Numeric value of rate of demand in same units as target wait e.g. if target wait is weeks, then demand in units of patients/week. |
target_wait |
Numeric value of number of weeks that has been set as the target within which the patient should be seen. |
factor |
the amount we divide the target by in the waiting list e.g. if target is 52 weeks the mean wait should be 13 for a factor of 4 |
cv_demand |
coefficient of variation of time between arrivals |
cv_capacity |
coefficient of variation between removals due to operations completed |
numeric. The capacity required to achieve a target waiting time.
demand <- 4 # weeks target_wait <- 52 # weeks # number of operations per week to have mean wait of 52/4 calc_target_capacity(demand, target_wait)
demand <- 4 # weeks target_wait <- 52 # weeks # number of operations per week to have mean wait of 52/4 calc_target_capacity(demand, target_wait)
This calculates the target mean wait given the two inputs of target_wait and a numerical value for factor. The average wait is actually the target mean wait and is calculated as follows: target_wait / factor. If we want to have a chance between 1.8%-0.2% of making a waiting time target, then the average patient should have a waiting time between a quarter and a sixth of the target. Therefore: The mean wait should sit somewhere between target_wait/factor=6 < Average Waiting Time < target_wait/factor=4.
calc_target_mean_wait(target_wait, factor = 4)
calc_target_mean_wait(target_wait, factor = 4)
target_wait |
Numeric value of the number of weeks that has been set as the target within which the patient should be seen. |
factor |
Numeric factor used in average wait calculation - to get a quarter of the target use factor=4 and one sixth of the target use factor = 6 etc. Defaults to 4. |
Numeric value of target mean waiting time to achieve a given target wait.
# If the target wait is 52 weeks then the target mean wait with a factor of 4 # would be 13 weeks and with a factor of 6 it would be 8.67 weeks. calc_target_mean_wait(52, 4)
# If the target wait is 52 weeks then the target mean wait with a factor of 4 # would be 13 weeks and with a factor of 6 it would be 8.67 weeks. calc_target_mean_wait(52, 4)
Uses Little's Law to calculate the target queue size to achieve a target waiting time as a function of observed demand, target wait and a variability factor used in the target mean waiting time calculation.
Target Queue Size = Demand * Target Wait / 4.
The average wait should sit somewhere between target_wait/factor=6 < Average Waiting Time < target_wait/factor=4 The factor defaults to 4.
Only applicable when Capacity > Demand.
calc_target_queue_size(demand, target_wait, factor = 4)
calc_target_queue_size(demand, target_wait, factor = 4)
demand |
Numeric value of rate of demand in same units as target wait e.g. if target wait is weeks, then demand in units of patients/week. |
target_wait |
Numeric value of number of weeks that has been set as the target within which the patient should be seen. |
factor |
Numeric factor used in average wait calculation
|
Numeric target queue length.
# If demand is 30 patients per week and the target wait is 52 weeks, then the # Target queue size = 30 * 52/4 = 390 patients. calc_target_queue_size(30, 52, 4)
# If demand is 30 patients per week and the target wait is 52 weeks, then the # Target queue size = 30 * 52/4 = 390 patients. calc_target_queue_size(30, 52, 4)
For a waiting list with target waiting time, the pressure on the waiting list is twice the mean delay divided by the waiting list target. The pressure of any given waiting list should be less than 1. If the pressure is greater than 1 then the waiting list is most likely going to miss its target. The waiting list pressure is calculated as follows: pressure = 2 * mean_wait / target_wait.
calc_waiting_list_pressure(mean_wait, target_wait)
calc_waiting_list_pressure(mean_wait, target_wait)
mean_wait |
Numeric value of target mean waiting time to achieve a given target wait. |
target_wait |
Numeric value of the number of weeks that has been set as the target within which the patient should be seen. |
Numeric value of wait_pressure which is the waiting list pressure.
calc_waiting_list_pressure(63, 52)
calc_waiting_list_pressure(63, 52)
Creates a waiting list using the parameters specified
create_waiting_list( n, mean_arrival_rate, mean_wait, start_date = Sys.Date(), limit_removals = TRUE, sd = 0, rott = 0, ... )
create_waiting_list( n, mean_arrival_rate, mean_wait, start_date = Sys.Date(), limit_removals = TRUE, sd = 0, rott = 0, ... )
n |
Numeric value of rate of demand in same units as target wait
|
mean_arrival_rate |
Numeric value of mean daily arrival rate. |
mean_wait |
Numeric value of mean wait time for treatment/on waiting list. |
start_date |
Character value of date from which to start generated waiting list. |
limit_removals |
Defaults to TRUE |
sd |
Numeric value, standard deviation. Defaults to 0. |
rott |
Numeric value, proportion of referrals to be randomly flagged as ROTT. Defaults to 0. |
... |
Container for the list |
A tibble of a random generated list of patients with addition_date, removal_date, wait_length and rott status for each patient
create_waiting_list(366,50,21,"2024-01-01",10,0.1)
create_waiting_list(366,50,21,"2024-01-01",10,0.1)
demographic data
data(demographic_data)
data(demographic_data)
An object of class data.frame
with 5 rows and 9 columns.
## Not run: data(demographic_data)
## Not run: data(demographic_data)
OPCS4 data
data(OPCS4)
data(OPCS4)
An object of class data.frame
with 12279 rows and 9 columns.
https://biobank.ndph.ox.ac.uk/ukb/coding.cgi?id=240
## Not run: data(OPCS4)
## Not run: data(OPCS4)
Generates simulated NHS patients
sim_patients(n_rows = 10, start_date = NULL)
sim_patients(n_rows = 10, start_date = NULL)
n_rows |
Number of rows/patients to generate |
start_date |
Start date (needed to generate patient ages) |
dataframe. Empty waiting list.
Generates a list if dates in a given range
sim_schedule(n_rows = 10, start_date = NULL, daily_capacity = 1)
sim_schedule(n_rows = 10, start_date = NULL, daily_capacity = 1)
n_rows |
Number of rows/patients to generate |
start_date |
Start date (needed to generate patient ages) |
daily_capacity |
Number of paitents per day |
dataframe. Empty waiting list.
adds new referrals (removal date is set as NA)
wl_insert(waiting_list, additions, referral_index = 1)
wl_insert(waiting_list, additions, referral_index = 1)
waiting_list |
dataframe. A df of referral dates and removals |
additions |
character vector. A list of referral dates to add to the waiting list |
referral_index |
integer. The column number in the waiting_list which contains the referral dates |
dataframe. A df of the updated waiting list
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) additions <- c.Date("2024-01-03", "2024-01-05", "2024-01-18") longer_waiting_list <- wl_insert(waiting_list, additions)
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) additions <- c.Date("2024-01-03", "2024-01-05", "2024-01-18") longer_waiting_list <- wl_insert(waiting_list, additions)
Take two waiting list and sorting in date order
wl_join(wl_1, wl_2, referral_index = 1)
wl_join(wl_1, wl_2, referral_index = 1)
wl_1 |
a waiting list: dataframe consisting addition and removal dates |
wl_2 |
a waiting list: dataframe consisting addition and removal dates |
referral_index |
the column index where referrals are listed |
updated_list a new waiting list
# referrals <- c.Date("2024-01-01","2024-01-04","2024-01-10","2024-01-16") # removals <- c.Date("2024-01-08",NA,NA,NA) # wl_1 <- data.frame("referral" = referrals ,"removal" = removals ) # referrals <- c.Date("2024-01-04","2024-01-05","2024-01-16","2024-01-25") # removals <- c.Date("2024-01-09",NA,"2024-01-19",NA) # wl_2 <- data.frame("referral" = referrals ,"removal" = removals ) # wl_join(wl_1,wl_2)
# referrals <- c.Date("2024-01-01","2024-01-04","2024-01-10","2024-01-16") # removals <- c.Date("2024-01-08",NA,NA,NA) # wl_1 <- data.frame("referral" = referrals ,"removal" = removals ) # referrals <- c.Date("2024-01-04","2024-01-05","2024-01-16","2024-01-25") # removals <- c.Date("2024-01-09",NA,"2024-01-19",NA) # wl_2 <- data.frame("referral" = referrals ,"removal" = removals ) # wl_join(wl_1,wl_2)
Calculates queue sizes from a waiting list
wl_queue_size( waiting_list, start_date = NULL, end_date = NULL, referral_index = 1, removal_index = 2 )
wl_queue_size( waiting_list, start_date = NULL, end_date = NULL, referral_index = 1, removal_index = 2 )
waiting_list |
dataframe consisting addition and removal dates |
start_date |
start of calculation period |
end_date |
end of calculation period |
a list of dates and queue sizes
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) wl_queue_size(waiting_list)
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) wl_queue_size(waiting_list)
Calculate some stats about referrals
wl_referral_stats( waiting_list, start_date = NULL, end_date = NULL, referral_index = 1 )
wl_referral_stats( waiting_list, start_date = NULL, end_date = NULL, referral_index = 1 )
waiting_list |
dataframe. A df of referral dates and removals |
start_date |
date. The start date to calculate from |
end_date |
date. The end date to calculate to |
referral_index |
the column index of referrals |
dataframe. A df containing number of referrals, mean demand, and the coefficient of variation of referrals
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) referral_stats <- wl_referral_stats(waiting_list)
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) referral_stats <- wl_referral_stats(waiting_list)
Calculate some stats about removals
wl_removal_stats( waiting_list, start_date = NULL, end_date = NULL, referral_index = 1, removal_index = 2 )
wl_removal_stats( waiting_list, start_date = NULL, end_date = NULL, referral_index = 1, removal_index = 2 )
waiting_list |
dataframe. A df of referral dates and removals |
start_date |
date. The start date to calculate from |
end_date |
date. The end date to calculate to |
dataframe. A df containing number of removals, mean capacity, and the coefficient of variation of removals
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) removal_stats <- wl_removal_stats(waiting_list)
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) removal_stats <- wl_removal_stats(waiting_list)
Takes a list of dates and schedules them to a waiting list, by adding a removal date to the dataframe. This is done in referral date order, I.e. earlier referrals are scheduled first (FIFO).
wl_schedule( waiting_list, schedule, referral_index = 1, removal_index = 2, unscheduled = FALSE )
wl_schedule( waiting_list, schedule, referral_index = 1, removal_index = 2, unscheduled = FALSE )
waiting_list |
dataframe. A df of referral dates and removals |
schedule |
vector of dates. The dates to schedule open referrals into (ie. dates of unbooked future capacity) |
referral_index |
integer. The column number in the waiting_list which contains the referral dates |
removal_index |
integer. The column number in the waiting_list which contains the removal dates |
dataframe. A df of the updated waiting list with removal dates added according to the schedule
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) schedule <- c.Date("2024-01-03", "2024-01-05", "2024-01-18") updated_waiting_list <- wl_schedule(waiting_list, schedule)
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) schedule <- c.Date("2024-01-03", "2024-01-05", "2024-01-18") updated_waiting_list <- wl_schedule(waiting_list, schedule)
Creates a simulated waiting list comprising referral dates, and removal dates
wl_simulator( start_date = NULL, end_date = NULL, demand = 10, capacity = 11, waiting_list = NULL, withdrawal_prob = NA, detailed_sim = FALSE )
wl_simulator( start_date = NULL, end_date = NULL, demand = 10, capacity = 11, waiting_list = NULL, withdrawal_prob = NA, detailed_sim = FALSE )
start_date |
date. The start date for the simulation |
end_date |
date. The end date for the simulation |
demand |
numeric. Weekly demand (ie. typical referrals per week) |
capacity |
numeric. Weekly capacity (ie. typical removals per week) |
waiting_list |
integer. The number of patients on the waiting list contains the referral dates |
dataframe. A df of simulated referrals and removals
over_capacity_simulation <- wl_simulator("2024-01-01", "2024-03-31", 100, 110) under_capacity_simulation <- wl_simulator("2024-01-01", "2024-03-31", 100, 90)
over_capacity_simulation <- wl_simulator("2024-01-01", "2024-03-31", 100, 110) under_capacity_simulation <- wl_simulator("2024-01-01", "2024-03-31", 100, 90)
A summary of all the key stats associated with a waiting list
wl_stats( waiting_list, target_wait = 4, categories = NULL, start_date = NULL, end_date = NULL, target_index = NULL )
wl_stats( waiting_list, target_wait = 4, categories = NULL, start_date = NULL, end_date = NULL, target_index = NULL )
waiting_list |
dataframe. A df of referral dates and removals |
target_wait |
numeric. The required waiting time |
start_date |
date. The start date to calculate from |
end_date |
date. The end date to calculate to |
dataframe. A df of important waiting list statistics
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) waiting_list_stats <- wl_stats(waiting_list)
referrals <- c.Date("2024-01-01", "2024-01-04", "2024-01-10", "2024-01-16") removals <- c.Date("2024-01-08", NA, NA, NA) waiting_list <- data.frame("referral" = referrals, "removal" = removals) waiting_list_stats <- wl_stats(waiting_list)