Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tests for all social care extracts #854

Merged
merged 16 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ export(process_tests_mental_health)
export(process_tests_nrs_deaths)
export(process_tests_outpatients)
export(process_tests_prescribing)
export(process_tests_sc_ch_episodes)
export(process_tests_sc_all_at_episodes)
export(process_tests_sc_all_ch_episodes)
export(process_tests_sc_all_hc_episodes)
export(process_tests_sc_all_sds_episodes)
export(process_tests_sc_client_lookup)
export(process_tests_sc_demographics)
export(process_tests_sds)
Expand Down
26 changes: 26 additions & 0 deletions R/process_tests_sc_all_at_episodes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Process Social Care Alarms Telecare all episodes tests
#'
#' @param data The processed Alarms Telecare all episode data produced by
#' [process_sc_all_alarms_telecare()].
#'
#' @description This script takes the processed all Alarms Telecare file and produces
#' a test comparison with the previous data.
#'
#' @return a [tibble][tibble::tibble-package] containing a test comparison.
#'
#' @export
process_tests_sc_all_at_episodes <- function(data) {
comparison <- produce_test_comparison(
old_data = produce_sc_all_episodes_tests(
read_file(get_sc_at_episodes_path(update = previous_update()))
),
new_data = produce_sc_all_episodes_tests(
data
)
)

comparison %>%
write_tests_xlsx(sheet_name = "all_at_episodes", workbook_name = "lookup")

return(comparison)
}
26 changes: 26 additions & 0 deletions R/process_tests_sc_all_ch_episodes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Process Social Care Care Home all episodes tests
#'
#' @param data The processed Care Home all episode data produced by
#' [process_extract_care_home()].
#'
#' @description This script takes the processed all Care Home file and produces
#' a test comparison with the previous data.
#'
#' @return a [tibble][tibble::tibble-package] containing a test comparison.
#'
#' @export
process_tests_sc_all_ch_episodes <- function(data) {
comparison <- produce_test_comparison(
old_data = produce_sc_all_episodes_tests(
read_file(get_sc_ch_episodes_path(update = previous_update()))
),
new_data = produce_sc_all_episodes_tests(
data
)
)

comparison %>%
write_tests_xlsx(sheet_name = "all_ch_episodes", workbook_name = "lookup")

return(comparison)
}
26 changes: 26 additions & 0 deletions R/process_tests_sc_all_hc_episodes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Process Social Care Home Care all episodes tests
#'
#' @param data The processed Home Care all episode data produced by
#' [process_sc_all_home_care()].
#'
#' @description This script takes the processed all Home Care file and produces
#' a test comparison with the previous data.
#'
#' @return a [tibble][tibble::tibble-package] containing a test comparison.
#'
#' @export
process_tests_sc_all_hc_episodes <- function(data) {
comparison <- produce_test_comparison(
old_data = produce_sc_all_episodes_tests(
read_file(get_sc_hc_episodes_path(update = previous_update()))
),
new_data = produce_sc_all_episodes_tests(
data
)
)

comparison %>%
write_tests_xlsx(sheet_name = "all_hc_episodes", workbook_name = "lookup")

return(comparison)
}
26 changes: 26 additions & 0 deletions R/process_tests_sc_all_sds_episodes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Process Social Care SDS all episodes tests
#'
#' @param data The processed SDS all episode data produced by
#' [process_sc_all_sds()].
#'
#' @description This script takes the processed all SDS file and produces
#' a test comparison with the previous data.
#'
#' @return a [tibble][tibble::tibble-package] containing a test comparison.
#'
#' @export
process_tests_sc_all_sds_episodes <- function(data) {
comparison <- produce_test_comparison(
old_data = produce_sc_all_episodes_tests(
read_file(get_sc_sds_episodes_path(update = previous_update()))
),
new_data = produce_sc_all_episodes_tests(
data
)
)

comparison %>%
write_tests_xlsx(sheet_name = "all_sds_episodes", workbook_name = "lookup")

return(comparison)
}
64 changes: 0 additions & 64 deletions R/process_tests_sc_ch_episodes.R

This file was deleted.

30 changes: 30 additions & 0 deletions R/produce_sc_all_episodes_tests.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' Social care All Episodes Tests
#'
#' @description Produce the test for the social care all episodes
#'
#' @param data new or old data for testing summary flags
#'
#' @return a dataframe with a count of each flag.
#'
#' @family social care test functions
produce_sc_all_episodes_tests <- function(data) {
data %>%
# create test flags
create_demog_test_flags() %>%
dplyr::mutate(
n_missing_sending_loc = dplyr::if_else(
is.na(.data$sending_location),
1L,
0L
),
n_missing_sc_id = dplyr::if_else(
is_missing(.data$social_care_id),
1L,
0L
)
) %>%
# keep variables for comparison
dplyr::select(c("valid_chi":dplyr::last_col())) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")
}
16 changes: 9 additions & 7 deletions R/write_tests_xlsx.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ write_tests_xlsx <- function(comparison_data,
workbook_name = c("ep_file", "indiv_file", "lookup", "extract")) {
# Set up the workbook ----

tests_workbook_name <- dplyr::case_when(
workbook_name == "ep_file" ~ stringr::str_glue(latest_update(), "_ep_file_tests"),
workbook_name == "indiv_file" ~ stringr::str_glue(latest_update(), "_indiv_file_tests"),
workbook_name == "lookup" ~ stringr::str_glue(latest_update(), "_lookups_tests"),
workbook_name == "extract" ~ stringr::str_glue(latest_update(), "_{year}_extract_tests")
)

if (missing(year) & workbook_name == "lookup") {
tests_workbook_name <- stringr::str_glue(latest_update(), "_lookups_tests")
} else {
tests_workbook_name <- dplyr::case_when(
workbook_name == "ep_file" ~ stringr::str_glue(latest_update(), "_ep_file_tests"),
workbook_name == "indiv_file" ~ stringr::str_glue(latest_update(), "_indiv_file_tests"),
workbook_name == "extract" ~ stringr::str_glue(latest_update(), "_{year}_extract_tests")
)
}

tests_workbook_path <- fs::path(
get_slf_dir(),
Expand Down
14 changes: 13 additions & 1 deletion _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ list(
),
priority = 0.5
),
tar_target(
tests_sc_all_at,
process_tests_sc_all_at_episodes(all_at)
),
tar_target(
all_home_care_extract,
read_sc_all_home_care(),
Expand All @@ -151,6 +155,10 @@ list(
),
priority = 0.5
),
tar_target(
tests_sc_all_home_care,
process_tests_sc_all_hc_episodes(all_home_care)
),
tar_target(
all_care_home_extract,
read_sc_all_care_home(),
Expand All @@ -173,7 +181,7 @@ list(
),
tar_target(
tests_all_care_home,
process_tests_sc_ch_episodes(all_care_home)
process_tests_sc_all_ch_episodes(all_care_home)
),
tar_target(
all_sds_extract,
Expand All @@ -192,6 +200,10 @@ list(
),
priority = 0.5
),
tar_target(
tests_sc_all_sds,
process_tests_sc_all_sds_episodes(all_sds)
),
tar_map(
list(year = years_to_run),
tar_rds(
Expand Down
19 changes: 19 additions & 0 deletions man/process_tests_sc_all_at_episodes.Rd

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

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

19 changes: 19 additions & 0 deletions man/process_tests_sc_all_hc_episodes.Rd

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

19 changes: 19 additions & 0 deletions man/process_tests_sc_all_sds_episodes.Rd

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

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

2 changes: 1 addition & 1 deletion man/produce_sc_demog_lookup_tests.Rd

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

Loading
Loading