Skip to content

Commit

Permalink
Add tests for delayed discharges extract (#760)
Browse files Browse the repository at this point in the history
* Add tests for delayed discharges extract

* Style code

* Change calculation to TRUE/FALSE

Co-authored-by: James McMahon <[email protected]>

* Remove TODO and add DD tests to targets pipeline

---------

Co-authored-by: Jennit07 <[email protected]>
Co-authored-by: James McMahon <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2023
1 parent 4eb6b93 commit 1efe25e
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions R/process_tests_delayed_discharges.R
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 7 additions & 1 deletion _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions man/process_tests_delayed_discharges.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions man/produce_source_dd_tests.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/produce_source_pis_tests.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1efe25e

Please sign in to comment.