diff --git a/NAMESPACE b/NAMESPACE index d87bf9397..464cced34 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -115,6 +115,7 @@ export(process_tests_ae) export(process_tests_alarms_telecare) export(process_tests_care_home) export(process_tests_cmh) +export(process_tests_delayed_discharges) export(process_tests_district_nursing) export(process_tests_episode_file) export(process_tests_gp_ooh) diff --git a/R/process_tests_delayed_discharges.R b/R/process_tests_delayed_discharges.R new file mode 100644 index 000000000..b540d1f74 --- /dev/null +++ b/R/process_tests_delayed_discharges.R @@ -0,0 +1,50 @@ +#' Process Delayed Discharges tests +#' +#' @description Takes the processed Delayed Discharges extract and produces +#' a test comparison with the previous data. This is written to disk as a CSV. +#' +#' @param data a [tibble][tibble::tibble-package] of the processed data extract. +#' @param year the financial year of the extract in the format '1718'. +#' +#' @return a [tibble][tibble::tibble-package] containing a test comparison. +#' +#' @export +process_tests_delayed_discharges <- function(data, year) { + old_data <- get_existing_data_for_tests(data) + + comparison <- produce_test_comparison( + old_data = produce_source_dd_tests(old_data), + new_data = produce_source_dd_tests(data) + ) %>% + write_tests_xlsx(sheet_name = "DD", year) + + return(comparison) +} + +#' Delayed Discharges extract tests +#' +#' @description Produce tests for the delayed discharges extract. +#' +#' @param data new or old data for testing summary flags +#' (data is from [get_source_extract_path()]) +#' +#' @return a dataframe with a count of each flag +#' from [calculate_measures()] +#' +#' @family extract test functions +#' for creating test flags +#' @seealso calculate_measures +produce_source_dd_tests <- function(data) { + test_flags <- data %>% + dplyr::mutate( + n_delay_episodes = 1L, + code9_episodes = .data$primary_delay_reason == "9" + ) %>% + create_hb_test_flags(.data$hbtreatcode) %>% + # keep variables for comparison + dplyr::select(c("n_delay_episodes":dplyr::last_col())) %>% + # use function to sum new test flags + calculate_measures(measure = "sum") + + return(test_flags) +} diff --git a/_targets.R b/_targets.R index 0886466a8..f50045aed 100644 --- a/_targets.R +++ b/_targets.R @@ -310,12 +310,18 @@ list( year ) ), - # TODO add tests for the Delayed Discharges extract tar_target(source_dd_extract, process_extract_delayed_discharges( dd_data, year, write_to_disk = write_to_disk )), + tar_target( + tests_source_dd_extract, + process_tests_delayed_discharges( + source_dd_extract, + year + ) + ), tar_target(source_dn_extract, process_extract_district_nursing( dn_data, year, diff --git a/man/process_tests_delayed_discharges.Rd b/man/process_tests_delayed_discharges.Rd new file mode 100644 index 000000000..68e1b8f17 --- /dev/null +++ b/man/process_tests_delayed_discharges.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/process_tests_delayed_discharges.R +\name{process_tests_delayed_discharges} +\alias{process_tests_delayed_discharges} +\title{Process Delayed Discharges tests} +\usage{ +process_tests_delayed_discharges(data, year) +} +\arguments{ +\item{data}{a \link[tibble:tibble-package]{tibble} of the processed data extract.} + +\item{year}{the financial year of the extract in the format '1718'.} +} +\value{ +a \link[tibble:tibble-package]{tibble} containing a test comparison. +} +\description{ +Takes the processed Delayed Discharges extract and produces +a test comparison with the previous data. This is written to disk as a CSV. +} diff --git a/man/produce_source_dd_tests.Rd b/man/produce_source_dd_tests.Rd new file mode 100644 index 000000000..2eb9f6455 --- /dev/null +++ b/man/produce_source_dd_tests.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/process_tests_delayed_discharges.R +\name{produce_source_dd_tests} +\alias{produce_source_dd_tests} +\title{Delayed Discharges extract tests} +\usage{ +produce_source_dd_tests(data) +} +\arguments{ +\item{data}{new or old data for testing summary flags +(data is from \code{\link[=get_source_extract_path]{get_source_extract_path()}})} +} +\value{ +a dataframe with a count of each flag +from \code{\link[=calculate_measures]{calculate_measures()}} +} +\description{ +Produce tests for the delayed discharges extract. +} +\seealso{ +calculate_measures + +Other extract test functions +for creating test flags: +\code{\link{produce_source_pis_tests}()} +} +\concept{extract test functions +for creating test flags} diff --git a/man/produce_source_pis_tests.Rd b/man/produce_source_pis_tests.Rd index 070cc789d..487ad2fd7 100644 --- a/man/produce_source_pis_tests.Rd +++ b/man/produce_source_pis_tests.Rd @@ -24,6 +24,10 @@ episode date variables. } \seealso{ calculate_measures + +Other extract test functions +for creating test flags: +\code{\link{produce_source_dd_tests}()} } \concept{extract test functions for creating test flags}