-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for delayed discharges extract (#760)
* 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
1 parent
4eb6b93
commit 1efe25e
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
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,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) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.