-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from nhs-r-community/new_main
New main for meeting
- Loading branch information
Showing
78 changed files
with
701 additions
and
394 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#' @title Calculate Column Indices | ||
#' | ||
#' @description Internal Helper function to get column indicies for referrals, | ||
#' removals, and withdrawals | ||
#' | ||
#' @param waiting_list a dataframe containing the waitinglist | ||
#' @param colname string giving the column name | ||
#' @param type if colname, write referral, withdrawal, removal to guess the index | ||
#' | ||
#' @return index | ||
#' | ||
|
||
calc_index <- function(waiting_list, | ||
colname = NULL, | ||
type = NULL){ | ||
Check warning on line 15 in R/calc_index.R
|
||
|
||
# get column index if name given | ||
if( !is.null(colname) ){ | ||
Check warning on line 18 in R/calc_index.R
|
||
index <- which(colnames(waiting_list)==colname) | ||
return(index) | ||
} else { | ||
|
||
# if name not give guess the name or index based on type | ||
if (is.null(type)) { | ||
index <- 1 | ||
return(index) | ||
} else if ( type == "referral") { | ||
guesses <- c("referral","Referral",1) | ||
} else if ( type == "removal" ) { | ||
guesses <- c("removal","Removal",2) | ||
} else if ( type == "withdrawal") { | ||
guesses <- c("withdrawal","Withdrawal",3) | ||
} else if ( type == "target") { | ||
guesses <- c("target","Target_wait",NULL) | ||
} else { | ||
warning("Waiting list index not found") | ||
index <- 1 | ||
return(index) | ||
} | ||
|
||
# implement guess and return index given | ||
for ( guess in guesses ) { | ||
if ( is.character(guess) ){ | ||
index <- which(colnames(waiting_list)==guess) | ||
} else { | ||
index <- guess | ||
} | ||
if (!identical(index,integer(0)) ){ | ||
break | ||
} | ||
} | ||
return(index) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#' @title Calculates target days from priority code | ||
#' | ||
#' @description Internal Helper function number of days from prioirty code | ||
#' | ||
#' @param priority number 1,2,3 or 4 | ||
#' | ||
#' @return number of days | ||
#' | ||
#' @export | ||
#' | ||
|
||
calc_priority_to_target <- function(priority){ | ||
if (priority == 1){ | ||
return(7) | ||
} else if (priority == 2) { | ||
return(28) | ||
} else if (priority == 3) { | ||
return(84) | ||
} else { | ||
return(365) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
R/target_queue_size.R → R/calc_target_queue_size.R
100644 → 100755
File renamed without changes.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#' OPCS4 data | ||
#' | ||
#' @docType data | ||
#' | ||
#' @usage data(OPCS4) | ||
#' | ||
#' @format | ||
#' | ||
#' @keywords datasets | ||
#' | ||
#' @references | ||
#' | ||
#' @source https://biobank.ndph.ox.ac.uk/ukb/coding.cgi?id=240 | ||
#' | ||
#' @examples | ||
#' \dontrun{data(OPCS4)} | ||
"OPCS4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#' demographic data | ||
#' | ||
#' @docType data | ||
#' | ||
#' @usage data(demographic_data) | ||
#' | ||
#' @format | ||
#' | ||
#' @keywords datasets | ||
#' | ||
#' @references | ||
#' | ||
#' | ||
#' @examples | ||
#' \dontrun{data(demographic_data)} | ||
"demographic_data" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#' @title Generator of NHS patients | ||
#' | ||
#' @description Generates simulated NHS patients | ||
#' | ||
#' @param n_rows Number of rows/patients to generate | ||
#' @param start_date Start date (needed to generate patient ages) | ||
#' | ||
#' @return dataframe. Empty waiting list. | ||
#' @export sim_patients | ||
#' @import randomNames | ||
#' @examples | ||
#' | ||
|
||
|
||
|
||
|
||
sim_patients <- function( | ||
n_rows = 10, | ||
start_date = NULL | ||
) { | ||
|
||
if ( is.null(start_date) ){ | ||
start_date = Sys.Date() | ||
} | ||
if (!exists("OPCS4")){ | ||
load(file='./data/OPCS4.rda') | ||
} | ||
|
||
# get proceedures | ||
OPS <- OPCS4[(OPCS4$selectable=="Y") & (!is.na(OPCS4$name_4digit)),] | ||
ran <- OPS[sample(nrow(OPS),n_rows,replace=TRUE),] | ||
proceedures <- ran[c("code_1digit","name_1digit","code_4digit","name_4digit")] | ||
|
||
# get names consultants and NHS numbers (length actually too short) | ||
names <- randomNames::randomNames(n_rows) | ||
consultant <- randomNames::randomNames(n_rows) | ||
NHS_number <- sample.int(1e+8,n_rows, replace=TRUE) | ||
|
||
# get semi-realistic ages (from gov.uk) | ||
ages_rounded <-c(0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85) | ||
probs <- c( | ||
5.4,5.9,6.0,3.4,8.3,6.5,7.0,6.7,6.3,6.4,6.9,6.8,5.8,4.9,5.0,3.6,2.5,2.4 | ||
) | ||
years <- 365*(sample(ages_rounded,size=n_rows,replace=TRUE,prob=probs) + | ||
sample.int(4,n_rows, replace = TRUE) -1) | ||
days <- sample.int(365,n_rows, replace = TRUE) -1 | ||
dobs <- as.Date(as.numeric(start_date)-years-days) | ||
priority <- sample(c(1,2,3,4),size=n_rows,replace=TRUE,prob=c(0.05,0.2,0.25,0.5)) | ||
target_wait <- sapply(priority, calc_priority_to_target) | ||
|
||
# referral, removal, withdrawal columns | ||
referral <- c(rep(NA,n_rows)) | ||
removal <- as.Date(c(rep(NA,n_rows))) | ||
withdrawal <- c(rep(NA,n_rows)) | ||
|
||
waiting_list <- data.frame( | ||
Referral = referral, | ||
Removal = removal, | ||
Withdrawal = withdrawal, | ||
Priority = priority, | ||
Target_wait = target_wait, | ||
Name = names, | ||
Birth_Date = dobs, | ||
NHS_number = NHS_number, | ||
Specialty_code = proceedures$code_1digit, | ||
Specialty = proceedures$name_1digit, | ||
OPCS = proceedures$code_4digit, | ||
Proceedure = proceedures$name_4digit, | ||
Consultant = consultant | ||
) | ||
|
||
return(waiting_list) | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' @title Generator a list of dates to schedule | ||
#' | ||
#' @description Generates a list if dates in a given range | ||
#' | ||
#' @param n_rows Number of rows/patients to generate | ||
#' @param start_date Start date (needed to generate patient ages) | ||
#' @param daily_capacity Number of paitents per day | ||
#' | ||
#' @return dataframe. Empty waiting list. | ||
#' @export sim_schedule | ||
#' | ||
|
||
sim_schedule <- function( | ||
n_rows = 10, | ||
start_date = NULL, | ||
daily_capacity = 1) { | ||
|
||
if (is.null(start_date)){ | ||
start_date = Sys.Date() | ||
} | ||
|
||
schedule <- | ||
as.Date( | ||
as.numeric(start_date) + | ||
ceiling(seq(0, n_rows - 1, 1 / daily_capacity)), | ||
origin = "1970-01-01") | ||
|
||
return(schedule) | ||
|
||
} | ||
|
||
|
Empty file.
Oops, something went wrong.