From 7d05ce9c8f5f678abd147c8325cb9c64b221b03c Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 16 Jan 2024 15:39:38 +0000 Subject: [PATCH 01/54] Remove redundant code --- R/process_tests_district_nursing.R | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/R/process_tests_district_nursing.R b/R/process_tests_district_nursing.R index d3d55a15a..df3c876f0 100644 --- a/R/process_tests_district_nursing.R +++ b/R/process_tests_district_nursing.R @@ -13,14 +13,7 @@ process_tests_district_nursing <- function(data, year) { return(data) } - old_data <- get_existing_data_for_tests(data) %>% - # TODO: remove this bit after SPSS stopped - # replace NA by 0 in monthly costs - dplyr::mutate(dplyr::across( - dplyr::ends_with("_cost"), - ~ tidyr::replace_na(.x, 0.0) - )) - + old_data <- get_existing_data_for_tests(data) data <- rename_hscp(data) comparison <- produce_test_comparison( From d1718f0a2a630b854cd9fd2add7912cd984e5514 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Tue, 16 Jan 2024 15:41:28 +0000 Subject: [PATCH 02/54] Update documentation --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5123289dd..4bb0c6f18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 From 6aec7b1ce6ca0be3d1902240fa6ae371ef82bb3b Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Tue, 16 Jan 2024 15:44:11 +0000 Subject: [PATCH 03/54] Style code --- R/create_individual_file.R | 3 ++- R/get_fy_quarter_dates.R | 8 ++++---- Run_SLF_Files_manually/run_episode_file_1718.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1819.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1920.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2021.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2122.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2223.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2324.R | 3 ++- 9 files changed, 20 insertions(+), 12 deletions(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index d9316b41b..4ca2f96d7 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -483,7 +483,8 @@ add_ch_columns <- function(episode_file, prefix, condition) { ch_ep_end = dplyr::if_else( eval(condition), .data$record_keydate2, - lubridate::NA_Date_ ), + lubridate::NA_Date_ + ), # If end date is missing use the first day of next FY quarter ch_ep_end = dplyr::if_else( eval(condition) & is.na(.data$ch_ep_end), diff --git a/R/get_fy_quarter_dates.R b/R/get_fy_quarter_dates.R index cd4c3492c..a772099b8 100644 --- a/R/get_fy_quarter_dates.R +++ b/R/get_fy_quarter_dates.R @@ -15,7 +15,7 @@ start_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -47,7 +47,7 @@ start_fy_quarter <- function(quarter) { end_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -80,7 +80,7 @@ end_fy_quarter <- function(quarter) { start_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -112,7 +112,7 @@ start_next_fy_quarter <- function(quarter) { end_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) diff --git a/Run_SLF_Files_manually/run_episode_file_1718.R b/Run_SLF_Files_manually/run_episode_file_1718.R index 9be2eb9c6..ab75b94d7 100644 --- a/Run_SLF_Files_manually/run_episode_file_1718.R +++ b/Run_SLF_Files_manually/run_episode_file_1718.R @@ -4,7 +4,8 @@ library(createslf) year <- "1718" processed_data_list <- targets::tar_read("processed_data_list_1718", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1819.R b/Run_SLF_Files_manually/run_episode_file_1819.R index 7dec9e5c1..cd5a7435f 100644 --- a/Run_SLF_Files_manually/run_episode_file_1819.R +++ b/Run_SLF_Files_manually/run_episode_file_1819.R @@ -4,7 +4,8 @@ library(createslf) year <- "1819" processed_data_list <- targets::tar_read("processed_data_list_1819", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1920.R b/Run_SLF_Files_manually/run_episode_file_1920.R index 066bd27b7..a9dc591b1 100644 --- a/Run_SLF_Files_manually/run_episode_file_1920.R +++ b/Run_SLF_Files_manually/run_episode_file_1920.R @@ -4,7 +4,8 @@ library(createslf) year <- "1920" processed_data_list <- targets::tar_read("processed_data_list_1920", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2021.R b/Run_SLF_Files_manually/run_episode_file_2021.R index 8354f49ae..37708ee8b 100644 --- a/Run_SLF_Files_manually/run_episode_file_2021.R +++ b/Run_SLF_Files_manually/run_episode_file_2021.R @@ -4,7 +4,8 @@ library(createslf) year <- "2021" processed_data_list <- targets::tar_read("processed_data_list_2021", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2122.R b/Run_SLF_Files_manually/run_episode_file_2122.R index 4057770d1..47400e2d1 100644 --- a/Run_SLF_Files_manually/run_episode_file_2122.R +++ b/Run_SLF_Files_manually/run_episode_file_2122.R @@ -4,7 +4,8 @@ library(createslf) year <- "2122" processed_data_list <- targets::tar_read("processed_data_list_2122", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2223.R b/Run_SLF_Files_manually/run_episode_file_2223.R index 5df7b5db6..e64a57f32 100644 --- a/Run_SLF_Files_manually/run_episode_file_2223.R +++ b/Run_SLF_Files_manually/run_episode_file_2223.R @@ -4,7 +4,8 @@ library(createslf) year <- "2223" processed_data_list <- targets::tar_read("processed_data_list_2223", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2324.R b/Run_SLF_Files_manually/run_episode_file_2324.R index af9a3efe5..4a7f0ad29 100644 --- a/Run_SLF_Files_manually/run_episode_file_2324.R +++ b/Run_SLF_Files_manually/run_episode_file_2324.R @@ -4,7 +4,8 @@ library(createslf) year <- "2324" processed_data_list <- targets::tar_read("processed_data_list_2324", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% From 65e8caa56008ec4eccac7f828e329064de9219e0 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 10:14:00 +0000 Subject: [PATCH 04/54] Reorder when we match on client variables This was causing NSUs to show a social care id. This now resolves this. --- R/create_episode_file.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/create_episode_file.R b/R/create_episode_file.R index 3de9223dd..493d71bd3 100644 --- a/R/create_episode_file.R +++ b/R/create_episode_file.R @@ -103,6 +103,8 @@ create_episode_file <- function( "mar_beddays" ) ) %>% + # match on sc client variables + join_sc_client(year, sc_client = sc_client, file_type = "episode") %>% # Check chi is valid using phsmethods function # If the CHI is invalid for whatever reason, set the CHI to NA dplyr::mutate( @@ -135,7 +137,6 @@ create_episode_file <- function( year, slf_deaths_lookup ) %>% - join_sc_client(year, sc_client = sc_client, file_type = "episode") %>% load_ep_file_vars(year) if (!check_year_valid(year, type = c("ch", "hc", "at", "sds"))) { From 35bcddcbfc18a3d034dc7ae1ba1cd2ecdfdec437 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Mon, 22 Jan 2024 10:16:22 +0000 Subject: [PATCH 05/54] Update documentation --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5123289dd..4bb0c6f18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 From 800083a72d212e82d08898effc8f602a290922e2 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Mon, 22 Jan 2024 10:23:44 +0000 Subject: [PATCH 06/54] Style code --- R/create_individual_file.R | 3 ++- R/get_fy_quarter_dates.R | 8 ++++---- Run_SLF_Files_manually/run_episode_file_1718.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1819.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1920.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2021.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2122.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2223.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2324.R | 3 ++- 9 files changed, 20 insertions(+), 12 deletions(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index d9316b41b..4ca2f96d7 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -483,7 +483,8 @@ add_ch_columns <- function(episode_file, prefix, condition) { ch_ep_end = dplyr::if_else( eval(condition), .data$record_keydate2, - lubridate::NA_Date_ ), + lubridate::NA_Date_ + ), # If end date is missing use the first day of next FY quarter ch_ep_end = dplyr::if_else( eval(condition) & is.na(.data$ch_ep_end), diff --git a/R/get_fy_quarter_dates.R b/R/get_fy_quarter_dates.R index cd4c3492c..a772099b8 100644 --- a/R/get_fy_quarter_dates.R +++ b/R/get_fy_quarter_dates.R @@ -15,7 +15,7 @@ start_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -47,7 +47,7 @@ start_fy_quarter <- function(quarter) { end_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -80,7 +80,7 @@ end_fy_quarter <- function(quarter) { start_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -112,7 +112,7 @@ start_next_fy_quarter <- function(quarter) { end_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) diff --git a/Run_SLF_Files_manually/run_episode_file_1718.R b/Run_SLF_Files_manually/run_episode_file_1718.R index 9be2eb9c6..ab75b94d7 100644 --- a/Run_SLF_Files_manually/run_episode_file_1718.R +++ b/Run_SLF_Files_manually/run_episode_file_1718.R @@ -4,7 +4,8 @@ library(createslf) year <- "1718" processed_data_list <- targets::tar_read("processed_data_list_1718", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1819.R b/Run_SLF_Files_manually/run_episode_file_1819.R index 7dec9e5c1..cd5a7435f 100644 --- a/Run_SLF_Files_manually/run_episode_file_1819.R +++ b/Run_SLF_Files_manually/run_episode_file_1819.R @@ -4,7 +4,8 @@ library(createslf) year <- "1819" processed_data_list <- targets::tar_read("processed_data_list_1819", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1920.R b/Run_SLF_Files_manually/run_episode_file_1920.R index 066bd27b7..a9dc591b1 100644 --- a/Run_SLF_Files_manually/run_episode_file_1920.R +++ b/Run_SLF_Files_manually/run_episode_file_1920.R @@ -4,7 +4,8 @@ library(createslf) year <- "1920" processed_data_list <- targets::tar_read("processed_data_list_1920", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2021.R b/Run_SLF_Files_manually/run_episode_file_2021.R index 8354f49ae..37708ee8b 100644 --- a/Run_SLF_Files_manually/run_episode_file_2021.R +++ b/Run_SLF_Files_manually/run_episode_file_2021.R @@ -4,7 +4,8 @@ library(createslf) year <- "2021" processed_data_list <- targets::tar_read("processed_data_list_2021", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2122.R b/Run_SLF_Files_manually/run_episode_file_2122.R index 4057770d1..47400e2d1 100644 --- a/Run_SLF_Files_manually/run_episode_file_2122.R +++ b/Run_SLF_Files_manually/run_episode_file_2122.R @@ -4,7 +4,8 @@ library(createslf) year <- "2122" processed_data_list <- targets::tar_read("processed_data_list_2122", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2223.R b/Run_SLF_Files_manually/run_episode_file_2223.R index 5df7b5db6..e64a57f32 100644 --- a/Run_SLF_Files_manually/run_episode_file_2223.R +++ b/Run_SLF_Files_manually/run_episode_file_2223.R @@ -4,7 +4,8 @@ library(createslf) year <- "2223" processed_data_list <- targets::tar_read("processed_data_list_2223", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2324.R b/Run_SLF_Files_manually/run_episode_file_2324.R index af9a3efe5..4a7f0ad29 100644 --- a/Run_SLF_Files_manually/run_episode_file_2324.R +++ b/Run_SLF_Files_manually/run_episode_file_2324.R @@ -4,7 +4,8 @@ library(createslf) year <- "2324" processed_data_list <- targets::tar_read("processed_data_list_2324", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% From 996db4cf576834dfc4549b07288d5990aef68748 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 12:16:46 +0000 Subject: [PATCH 07/54] Revert "Update logic to use end of Quarter" This reverts commit 004e831449f56f898bb48596c491c2acc954acc9. --- R/create_individual_file.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index d9316b41b..4ca2f96d7 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -483,7 +483,8 @@ add_ch_columns <- function(episode_file, prefix, condition) { ch_ep_end = dplyr::if_else( eval(condition), .data$record_keydate2, - lubridate::NA_Date_ ), + lubridate::NA_Date_ + ), # If end date is missing use the first day of next FY quarter ch_ep_end = dplyr::if_else( eval(condition) & is.na(.data$ch_ep_end), From d10376ddc84871b82b8a8844d527739f5fb6f789 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Mon, 22 Jan 2024 12:18:30 +0000 Subject: [PATCH 08/54] Style code --- R/get_fy_quarter_dates.R | 8 ++++---- Run_SLF_Files_manually/run_episode_file_1718.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1819.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1920.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2021.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2122.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2223.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2324.R | 3 ++- 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/R/get_fy_quarter_dates.R b/R/get_fy_quarter_dates.R index cd4c3492c..a772099b8 100644 --- a/R/get_fy_quarter_dates.R +++ b/R/get_fy_quarter_dates.R @@ -15,7 +15,7 @@ start_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -47,7 +47,7 @@ start_fy_quarter <- function(quarter) { end_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -80,7 +80,7 @@ end_fy_quarter <- function(quarter) { start_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -112,7 +112,7 @@ start_next_fy_quarter <- function(quarter) { end_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) diff --git a/Run_SLF_Files_manually/run_episode_file_1718.R b/Run_SLF_Files_manually/run_episode_file_1718.R index 9be2eb9c6..ab75b94d7 100644 --- a/Run_SLF_Files_manually/run_episode_file_1718.R +++ b/Run_SLF_Files_manually/run_episode_file_1718.R @@ -4,7 +4,8 @@ library(createslf) year <- "1718" processed_data_list <- targets::tar_read("processed_data_list_1718", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1819.R b/Run_SLF_Files_manually/run_episode_file_1819.R index 7dec9e5c1..cd5a7435f 100644 --- a/Run_SLF_Files_manually/run_episode_file_1819.R +++ b/Run_SLF_Files_manually/run_episode_file_1819.R @@ -4,7 +4,8 @@ library(createslf) year <- "1819" processed_data_list <- targets::tar_read("processed_data_list_1819", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1920.R b/Run_SLF_Files_manually/run_episode_file_1920.R index 066bd27b7..a9dc591b1 100644 --- a/Run_SLF_Files_manually/run_episode_file_1920.R +++ b/Run_SLF_Files_manually/run_episode_file_1920.R @@ -4,7 +4,8 @@ library(createslf) year <- "1920" processed_data_list <- targets::tar_read("processed_data_list_1920", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2021.R b/Run_SLF_Files_manually/run_episode_file_2021.R index 8354f49ae..37708ee8b 100644 --- a/Run_SLF_Files_manually/run_episode_file_2021.R +++ b/Run_SLF_Files_manually/run_episode_file_2021.R @@ -4,7 +4,8 @@ library(createslf) year <- "2021" processed_data_list <- targets::tar_read("processed_data_list_2021", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2122.R b/Run_SLF_Files_manually/run_episode_file_2122.R index 4057770d1..47400e2d1 100644 --- a/Run_SLF_Files_manually/run_episode_file_2122.R +++ b/Run_SLF_Files_manually/run_episode_file_2122.R @@ -4,7 +4,8 @@ library(createslf) year <- "2122" processed_data_list <- targets::tar_read("processed_data_list_2122", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2223.R b/Run_SLF_Files_manually/run_episode_file_2223.R index 5df7b5db6..e64a57f32 100644 --- a/Run_SLF_Files_manually/run_episode_file_2223.R +++ b/Run_SLF_Files_manually/run_episode_file_2223.R @@ -4,7 +4,8 @@ library(createslf) year <- "2223" processed_data_list <- targets::tar_read("processed_data_list_2223", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2324.R b/Run_SLF_Files_manually/run_episode_file_2324.R index af9a3efe5..4a7f0ad29 100644 --- a/Run_SLF_Files_manually/run_episode_file_2324.R +++ b/Run_SLF_Files_manually/run_episode_file_2324.R @@ -4,7 +4,8 @@ library(createslf) year <- "2324" processed_data_list <- targets::tar_read("processed_data_list_2324", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% From b8e1dd250095eb92a1273aeb0abd45b4c9f2bdda Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Mon, 22 Jan 2024 12:21:31 +0000 Subject: [PATCH 09/54] Update documentation --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5123289dd..4bb0c6f18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 From 3591aca7a3e77b39fd8405b2da23cfd39028c783 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 12:23:48 +0000 Subject: [PATCH 10/54] add check comment (TO DO for this PR) --- R/calculate_stay.R | 1 + R/create_individual_file.R | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/R/calculate_stay.R b/R/calculate_stay.R index ae80b33c1..ad4f5f53c 100644 --- a/R/calculate_stay.R +++ b/R/calculate_stay.R @@ -51,6 +51,7 @@ calculate_stay <- function(year, start_date, end_date, sc_qtr = NULL) { lubridate::period(1L, "days") ) + # check logic here for care home methodology dummy_end_date <- dplyr::case_when( # If end_date is not missing use the end date !is.na(end_date) ~ end_date, diff --git a/R/create_individual_file.R b/R/create_individual_file.R index 4ca2f96d7..70066b42d 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -485,7 +485,8 @@ add_ch_columns <- function(episode_file, prefix, condition) { .data$record_keydate2, lubridate::NA_Date_ ), - # If end date is missing use the first day of next FY quarter + # check logic here for care home methodology + # If end date is missing use the end of the FY quarter ch_ep_end = dplyr::if_else( eval(condition) & is.na(.data$ch_ep_end), start_next_fy_quarter(.data$sc_latest_submission), From 47769e31f78eaf507eeb594975184f004bc47ccc Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 12:32:52 +0000 Subject: [PATCH 11/54] Remove `check_quarter_format` function --- R/get_fy_quarter_dates.R | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/R/get_fy_quarter_dates.R b/R/get_fy_quarter_dates.R index a772099b8..86e9ed95f 100644 --- a/R/get_fy_quarter_dates.R +++ b/R/get_fy_quarter_dates.R @@ -128,28 +128,3 @@ end_next_fy_quarter <- function(quarter) { return(end_next_fy_quarter) } - -#' Check quarter format -#' -#' @inheritParams start_fy_quarter -#' -#' @return `quarter` invisibly if no issues were found -#' -#' @family date functions -# check_quarter_format <- function(quarter) { -# stopifnot(typeof(quarter) == "character") -# -# if (any( -# stringr::str_detect(quarter, "^\\d{4}Q[1-4]$", negate = TRUE), -# na.rm = TRUE -# )) { -# cli::cli_abort( -# c("{.var quarter} must be in the format {.val YYYYQx} -# where {.val x} is the quarter number.", -# "v" = "For example {.val 2019Q1}." -# ) -# ) -# } -# -# return(invisible(quarter)) -# } From 85c22ad7f1f64321f03a24bf17c0c01e9ec9e179 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 12:35:40 +0000 Subject: [PATCH 12/54] Remove `check_quarter_format` --- R/calculate_stay.R | 3 --- R/get_fy_quarter_dates.R | 8 -------- 2 files changed, 11 deletions(-) diff --git a/R/calculate_stay.R b/R/calculate_stay.R index ad4f5f53c..d1748a470 100644 --- a/R/calculate_stay.R +++ b/R/calculate_stay.R @@ -37,9 +37,6 @@ calculate_stay <- function(year, start_date, end_date, sc_qtr = NULL) { if (anyNA(sc_qtr)) { cli::cli_abort("Some of the submitted quarters are missing") } - # else { - # sc_qtr <- check_quarter_format(sc_qtr) - # } # Set Quarters qtr_end <- lubridate::add_with_rollback( diff --git a/R/get_fy_quarter_dates.R b/R/get_fy_quarter_dates.R index 86e9ed95f..68ac3266e 100644 --- a/R/get_fy_quarter_dates.R +++ b/R/get_fy_quarter_dates.R @@ -15,8 +15,6 @@ start_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - # check_quarter_format(quarter) - cal_quarter_date_unique <- lubridate::yq(quarter_unique) fy_quarter_date_unique <- lubridate::add_with_rollback( @@ -47,8 +45,6 @@ start_fy_quarter <- function(quarter) { end_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - # check_quarter_format(quarter) - cal_quarter_date_unique <- lubridate::yq(quarter_unique) fy_quarter_date_unique <- lubridate::add_with_rollback( @@ -80,8 +76,6 @@ end_fy_quarter <- function(quarter) { start_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - # check_quarter_format(quarter) - cal_quarter_date_unique <- lubridate::yq(quarter_unique) fy_quarter_date_unique <- lubridate::add_with_rollback( @@ -112,8 +106,6 @@ start_next_fy_quarter <- function(quarter) { end_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - # check_quarter_format(quarter) - cal_quarter_date_unique <- lubridate::yq(quarter_unique) fy_quarter_date_unique <- lubridate::add_with_rollback( From e4d91284ecfbc82700c4b36d5d668b6d82ebb15f Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 12:59:08 +0000 Subject: [PATCH 13/54] Add chi parameter to `create_demog_test_flags` --- DESCRIPTION | 2 +- R/create_demog_test_flags.R | 10 +++++----- man/create_demog_test_flags.Rd | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5123289dd..4bb0c6f18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 diff --git a/R/create_demog_test_flags.R b/R/create_demog_test_flags.R index 3023292ce..b909679d9 100644 --- a/R/create_demog_test_flags.R +++ b/R/create_demog_test_flags.R @@ -3,19 +3,19 @@ #' @description Create the demographic flags for testing #' #' @param data a dataframe containing demographic variables e.g. chi +#' @param chi Specify chi or anon_chi. #' #' @return a dataframe with flag (1 or 0) for each demographic variable. #' Missing value flag from [is_missing()] #' #' @family flag functions -create_demog_test_flags <- function(data) { +create_demog_test_flags <- function(data, chi = c(chi, anon_chi)) { data %>% - dplyr::arrange(.data$chi) %>% + dplyr::arrange({{ chi }}) %>% # create test flags dplyr::mutate( - valid_chi = phsmethods::chi_check(.data$chi) == "Valid CHI", - unique_chi = dplyr::lag(.data$chi) != .data$chi, - n_missing_chi = is_missing(.data$chi), + unique_chi = dplyr::lag({{ chi }}) != {{ chi }}, + n_missing_chi = is_missing({{ chi }}), n_males = .data$gender == 1L, n_females = .data$gender == 2L, n_postcode = !is.na(.data$postcode) | !.data$postcode == "", diff --git a/man/create_demog_test_flags.Rd b/man/create_demog_test_flags.Rd index 589877738..fbc0fadcc 100644 --- a/man/create_demog_test_flags.Rd +++ b/man/create_demog_test_flags.Rd @@ -4,10 +4,12 @@ \alias{create_demog_test_flags} \title{Create demographic test flags} \usage{ -create_demog_test_flags(data) +create_demog_test_flags(data, chi = c(chi, anon_chi)) } \arguments{ \item{data}{a dataframe containing demographic variables e.g. chi} + +\item{chi}{Specify chi or anon_chi.} } \value{ a dataframe with flag (1 or 0) for each demographic variable. From daa9ee7a87ba8e5daa4c42fca7c9256a32f84246 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Mon, 22 Jan 2024 13:02:10 +0000 Subject: [PATCH 14/54] Style code --- R/create_individual_file.R | 3 ++- R/get_fy_quarter_dates.R | 8 ++++---- Run_SLF_Files_manually/run_episode_file_1718.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1819.R | 3 ++- Run_SLF_Files_manually/run_episode_file_1920.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2021.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2122.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2223.R | 3 ++- Run_SLF_Files_manually/run_episode_file_2324.R | 3 ++- 9 files changed, 20 insertions(+), 12 deletions(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index d9316b41b..4ca2f96d7 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -483,7 +483,8 @@ add_ch_columns <- function(episode_file, prefix, condition) { ch_ep_end = dplyr::if_else( eval(condition), .data$record_keydate2, - lubridate::NA_Date_ ), + lubridate::NA_Date_ + ), # If end date is missing use the first day of next FY quarter ch_ep_end = dplyr::if_else( eval(condition) & is.na(.data$ch_ep_end), diff --git a/R/get_fy_quarter_dates.R b/R/get_fy_quarter_dates.R index cd4c3492c..a772099b8 100644 --- a/R/get_fy_quarter_dates.R +++ b/R/get_fy_quarter_dates.R @@ -15,7 +15,7 @@ start_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -47,7 +47,7 @@ start_fy_quarter <- function(quarter) { end_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -80,7 +80,7 @@ end_fy_quarter <- function(quarter) { start_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) @@ -112,7 +112,7 @@ start_next_fy_quarter <- function(quarter) { end_next_fy_quarter <- function(quarter) { quarter_unique <- unique(quarter) - #check_quarter_format(quarter) + # check_quarter_format(quarter) cal_quarter_date_unique <- lubridate::yq(quarter_unique) diff --git a/Run_SLF_Files_manually/run_episode_file_1718.R b/Run_SLF_Files_manually/run_episode_file_1718.R index 9be2eb9c6..ab75b94d7 100644 --- a/Run_SLF_Files_manually/run_episode_file_1718.R +++ b/Run_SLF_Files_manually/run_episode_file_1718.R @@ -4,7 +4,8 @@ library(createslf) year <- "1718" processed_data_list <- targets::tar_read("processed_data_list_1718", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1819.R b/Run_SLF_Files_manually/run_episode_file_1819.R index 7dec9e5c1..cd5a7435f 100644 --- a/Run_SLF_Files_manually/run_episode_file_1819.R +++ b/Run_SLF_Files_manually/run_episode_file_1819.R @@ -4,7 +4,8 @@ library(createslf) year <- "1819" processed_data_list <- targets::tar_read("processed_data_list_1819", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_1920.R b/Run_SLF_Files_manually/run_episode_file_1920.R index 066bd27b7..a9dc591b1 100644 --- a/Run_SLF_Files_manually/run_episode_file_1920.R +++ b/Run_SLF_Files_manually/run_episode_file_1920.R @@ -4,7 +4,8 @@ library(createslf) year <- "1920" processed_data_list <- targets::tar_read("processed_data_list_1920", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2021.R b/Run_SLF_Files_manually/run_episode_file_2021.R index 8354f49ae..37708ee8b 100644 --- a/Run_SLF_Files_manually/run_episode_file_2021.R +++ b/Run_SLF_Files_manually/run_episode_file_2021.R @@ -4,7 +4,8 @@ library(createslf) year <- "2021" processed_data_list <- targets::tar_read("processed_data_list_2021", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2122.R b/Run_SLF_Files_manually/run_episode_file_2122.R index 4057770d1..47400e2d1 100644 --- a/Run_SLF_Files_manually/run_episode_file_2122.R +++ b/Run_SLF_Files_manually/run_episode_file_2122.R @@ -4,7 +4,8 @@ library(createslf) year <- "2122" processed_data_list <- targets::tar_read("processed_data_list_2122", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2223.R b/Run_SLF_Files_manually/run_episode_file_2223.R index 5df7b5db6..e64a57f32 100644 --- a/Run_SLF_Files_manually/run_episode_file_2223.R +++ b/Run_SLF_Files_manually/run_episode_file_2223.R @@ -4,7 +4,8 @@ library(createslf) year <- "2223" processed_data_list <- targets::tar_read("processed_data_list_2223", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% diff --git a/Run_SLF_Files_manually/run_episode_file_2324.R b/Run_SLF_Files_manually/run_episode_file_2324.R index af9a3efe5..4a7f0ad29 100644 --- a/Run_SLF_Files_manually/run_episode_file_2324.R +++ b/Run_SLF_Files_manually/run_episode_file_2324.R @@ -4,7 +4,8 @@ library(createslf) year <- "2324" processed_data_list <- targets::tar_read("processed_data_list_2324", - store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")) + store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets") +) # Run episode file create_episode_file(processed_data_list, year = year) %>% From 702225fd6d31ca64d30067bc1b42c2c0dab4313f Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 14:40:00 +0000 Subject: [PATCH 15/54] Use CHI parameter for ep/indiv tests --- R/process_tests_episode_file.R | 12 ++---------- R/process_tests_individual_file.R | 12 ++---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/R/process_tests_episode_file.R b/R/process_tests_episode_file.R index eaa946e3e..6b66cd655 100644 --- a/R/process_tests_episode_file.R +++ b/R/process_tests_episode_file.R @@ -73,15 +73,7 @@ produce_episode_file_tests <- function( test_flags <- data %>% dplyr::group_by(.data$recid) %>% # use functions to create HB and partnership flags - dplyr::mutate( - unique_anon_chi = dplyr::lag(.data$anon_chi) != .data$anon_chi, - n_missing_anon_chi = is_missing(.data$anon_chi), - n_males = .data$gender == 1L, - n_females = .data$gender == 2L, - n_postcode = !is.na(.data$postcode) | !.data$postcode == "", - n_missing_postcode = is_missing(.data$postcode), - missing_dob = is.na(.data$dob) - ) %>% + create_demog_test_flags(chi = anon_chi) %>% create_hb_test_flags(.data$hbtreatcode) %>% create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net) %>% create_hscp_test_flags(.data$hscp2018) %>% @@ -111,7 +103,7 @@ produce_episode_file_tests <- function( test_flags <- test_flags %>% # keep variables for comparison - dplyr::select("unique_anon_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum", group_by = "recid") diff --git a/R/process_tests_individual_file.R b/R/process_tests_individual_file.R index bbd13948c..35ad7443a 100644 --- a/R/process_tests_individual_file.R +++ b/R/process_tests_individual_file.R @@ -60,19 +60,11 @@ produce_individual_file_tests <- function(data) { test_flags <- data %>% # use functions to create HB and partnership flags - dplyr::mutate( - unique_anon_chi = dplyr::lag(.data$anon_chi) != .data$anon_chi, - n_missing_anon_chi = is_missing(.data$anon_chi), - n_males = .data$gender == 1L, - n_females = .data$gender == 2L, - n_postcode = !is.na(.data$postcode) | !.data$postcode == "", - n_missing_postcode = is_missing(.data$postcode), - missing_dob = is.na(.data$dob) - ) %>% + create_demog_test_flags(chi = anon_chi) %>% create_hb_test_flags(.data$hbrescode) %>% create_hb_cost_test_flags(.data$hbrescode, .data$health_net_cost) %>% # keep variables for comparison - dplyr::select(c("unique_anon_chi":dplyr::last_col())) %>% + dplyr::select(c("unique_chi":dplyr::last_col())) %>% # use function to sum new test flags calculate_measures(measure = "sum") From d0fb3cdcb8b4120244d748544c70f910fe35ec31 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 22 Jan 2024 14:48:35 +0000 Subject: [PATCH 16/54] Use CHI parameter for extract tests (chi) --- R/process_tests_alarms_telecare.R | 4 ++-- R/process_tests_care_home.R | 4 ++-- R/process_tests_cmh.R | 4 ++-- R/process_tests_district_nursing.R | 4 ++-- R/process_tests_home_care.R | 4 ++-- R/process_tests_homelessness.R | 4 ++-- R/process_tests_nrs_deaths.R | 4 ++-- R/process_tests_prescribing.R | 4 ++-- R/process_tests_sc_demographics.R | 2 +- R/process_tests_sds.R | 4 ++-- R/produce_sc_all_episodes_tests.R | 4 ++-- R/produce_source_extract_tests.R | 4 ++-- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/R/process_tests_alarms_telecare.R b/R/process_tests_alarms_telecare.R index d7f9fa699..3c70c8cab 100644 --- a/R/process_tests_alarms_telecare.R +++ b/R/process_tests_alarms_telecare.R @@ -37,14 +37,14 @@ produce_source_at_tests <- function(data, max_min_vars = c("record_keydate1", "record_keydate2")) { test_flags <- data %>% # create test flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% dplyr::mutate( n_at_alarms = .data$smrtype == "AT-Alarm", n_at_telecare = .data$smrtype == "AT-Tele" ) %>% create_lca_test_flags(.data$sc_send_lca) %>% # remove variables that won't be summed - dplyr::select(.data$valid_chi:.data$West_Lothian) %>% + dplyr::select(.data$unique_chi:.data$West_Lothian) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_care_home.R b/R/process_tests_care_home.R index 2032c2473..a46071c22 100644 --- a/R/process_tests_care_home.R +++ b/R/process_tests_care_home.R @@ -47,7 +47,7 @@ produce_source_ch_tests <- function(data, )) { test_flags <- data %>% # use functions to create HB and partnership flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% dplyr::mutate( n_episodes = 1L, ch_name_missing = is.na(.data$ch_name), @@ -60,7 +60,7 @@ produce_source_ch_tests <- function(data, ) %>% create_lca_test_flags(.data$sc_send_lca) %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_cmh.R b/R/process_tests_cmh.R index 09a17bdbb..4a34c08f9 100644 --- a/R/process_tests_cmh.R +++ b/R/process_tests_cmh.R @@ -43,11 +43,11 @@ process_tests_cmh <- function(data, year) { produce_source_cmh_tests <- function(data) { test_flags <- data %>% # create test flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% create_hb_test_flags(hb_var = .data$hbrescode) %>% dplyr::mutate(n_episodes = 1L) %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_district_nursing.R b/R/process_tests_district_nursing.R index d3d55a15a..8f428b954 100644 --- a/R/process_tests_district_nursing.R +++ b/R/process_tests_district_nursing.R @@ -65,11 +65,11 @@ produce_source_dn_tests <- function(data, )) { test_flags <- data %>% # use functions to create HB and partnership flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% create_hb_test_flags(.data$hbtreatcode) %>% create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net) %>% # keep variables for comparison - dplyr::select(.data$valid_chi:.data$NHS_Lanarkshire_cost) %>% + dplyr::select(.data$unique_chi:.data$NHS_Lanarkshire_cost) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_home_care.R b/R/process_tests_home_care.R index c1af63e97..a8ee76672 100644 --- a/R/process_tests_home_care.R +++ b/R/process_tests_home_care.R @@ -49,7 +49,7 @@ produce_source_hc_tests <- function(data, )) { test_flags <- data %>% # use functions to create HB and partnership flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% dplyr::mutate( n_episodes = 1L, hc_per = dplyr::if_else(.data$smrtype == "HC-Per", 1L, 0L), @@ -61,7 +61,7 @@ produce_source_hc_tests <- function(data, ) %>% create_lca_test_flags(.data$sc_send_lca) %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_homelessness.R b/R/process_tests_homelessness.R index 4d49f1aa4..0b2c33880 100644 --- a/R/process_tests_homelessness.R +++ b/R/process_tests_homelessness.R @@ -38,10 +38,10 @@ produce_slf_homelessness_tests <- function(data, test_flags <- data %>% dplyr::arrange(.data$chi) %>% # create test flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% create_lca_test_flags(.data$hl1_sending_lca) %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_nrs_deaths.R b/R/process_tests_nrs_deaths.R index c1a963dcf..3796476c5 100644 --- a/R/process_tests_nrs_deaths.R +++ b/R/process_tests_nrs_deaths.R @@ -38,10 +38,10 @@ process_tests_nrs_deaths <- function(data, year) { produce_source_nrs_tests <- function(data) { test_flags <- data %>% # create test flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% dplyr::mutate(n_deaths = 1L) %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_prescribing.R b/R/process_tests_prescribing.R index bac0e3c52..8a7b0e73f 100644 --- a/R/process_tests_prescribing.R +++ b/R/process_tests_prescribing.R @@ -41,10 +41,10 @@ process_tests_prescribing <- function(data, year) { produce_source_pis_tests <- function(data) { test_flags <- data %>% # use functions to create HB and partnership flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% dplyr::mutate(n_episodes = 1L) %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/process_tests_sc_demographics.R b/R/process_tests_sc_demographics.R index dfb110aa9..b503969ef 100644 --- a/R/process_tests_sc_demographics.R +++ b/R/process_tests_sc_demographics.R @@ -36,7 +36,7 @@ process_tests_sc_demographics <- function(data) { produce_sc_demog_lookup_tests <- function(data) { data %>% # create test flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% dplyr::mutate( n_missing_sending_loc = is.na(.data$sending_location), n_missing_sc_id = is.na(.data$social_care_id) diff --git a/R/process_tests_sds.R b/R/process_tests_sds.R index f624f504b..ce6de656b 100644 --- a/R/process_tests_sds.R +++ b/R/process_tests_sds.R @@ -35,10 +35,10 @@ produce_source_sds_tests <- function(data, max_min_vars = c("record_keydate1", "record_keydate2")) { test_flags <- data %>% # create test flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% create_lca_test_flags(.data$sc_send_lca) %>% # remove variables that won't be summed - dplyr::select("valid_chi":"West_Lothian") %>% + dplyr::select("unique_chi":"West_Lothian") %>% # use function to sum new test flags calculate_measures(measure = "sum") diff --git a/R/produce_sc_all_episodes_tests.R b/R/produce_sc_all_episodes_tests.R index efe980cd4..4c5f736bb 100644 --- a/R/produce_sc_all_episodes_tests.R +++ b/R/produce_sc_all_episodes_tests.R @@ -10,7 +10,7 @@ produce_sc_all_episodes_tests <- function(data) { data %>% # create test flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% dplyr::mutate( n_missing_sending_loc = dplyr::if_else( is.na(.data$sending_location), @@ -24,7 +24,7 @@ produce_sc_all_episodes_tests <- function(data) { ) ) %>% # keep variables for comparison - dplyr::select(c("valid_chi":dplyr::last_col())) %>% + dplyr::select(c("unique_chi":dplyr::last_col())) %>% # use function to sum new test flags calculate_measures(measure = "sum") } diff --git a/R/produce_source_extract_tests.R b/R/produce_source_extract_tests.R index d9a07c893..13b33d549 100644 --- a/R/produce_source_extract_tests.R +++ b/R/produce_source_extract_tests.R @@ -33,7 +33,7 @@ produce_source_extract_tests <- function(data, add_hscp_count = TRUE) { test_flags <- data %>% # use functions to create HB and partnership flags - create_demog_test_flags() %>% + create_demog_test_flags(chi = chi) %>% create_hb_test_flags(.data$hbtreatcode) %>% create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net) @@ -43,7 +43,7 @@ produce_source_extract_tests <- function(data, test_flags <- test_flags %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select("unique_chi":dplyr::last_col()) %>% # use function to sum new test flags calculate_measures(measure = "sum") From bbf28dd6ad0f535800e17bc16d5abd8ea08f4811 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 23 Jan 2024 11:09:42 +0000 Subject: [PATCH 17/54] Change test sheet names to lowercase --- R/process_tests_acute.R | 2 +- R/process_tests_ae.R | 2 +- R/process_tests_alarms_telecare.R | 2 +- R/process_tests_care_home.R | 2 +- R/process_tests_cmh.R | 2 +- R/process_tests_delayed_discharges.R | 2 +- R/process_tests_gp_ooh.R | 2 +- R/process_tests_home_care.R | 2 +- R/process_tests_homelessness.R | 2 +- R/process_tests_maternity.R | 2 +- R/process_tests_mental_health.R | 2 +- R/process_tests_nrs_deaths.R | 2 +- R/process_tests_outpatients.R | 2 +- R/process_tests_prescribing.R | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/R/process_tests_acute.R b/R/process_tests_acute.R index 759d866b7..8a974e442 100644 --- a/R/process_tests_acute.R +++ b/R/process_tests_acute.R @@ -18,7 +18,7 @@ process_tests_acute <- function(data, year) { old_data = produce_source_extract_tests(old_data), new_data = produce_source_extract_tests(data) ) %>% - write_tests_xlsx(sheet_name = "01B", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "01b", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_ae.R b/R/process_tests_ae.R index 5bcd6a3c9..2ec97b8d0 100644 --- a/R/process_tests_ae.R +++ b/R/process_tests_ae.R @@ -21,7 +21,7 @@ process_tests_ae <- function(data, year) { max_min_vars = c("record_keydate1", "record_keydate2", "cost_total_net") ) ) %>% - write_tests_xlsx(sheet_name = "AE2", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "ae2", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_alarms_telecare.R b/R/process_tests_alarms_telecare.R index d7f9fa699..c99aaa857 100644 --- a/R/process_tests_alarms_telecare.R +++ b/R/process_tests_alarms_telecare.R @@ -18,7 +18,7 @@ process_tests_alarms_telecare <- function(data, year) { ) comparison %>% - write_tests_xlsx(sheet_name = "AT", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "at", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_care_home.R b/R/process_tests_care_home.R index 2032c2473..dd54bd98b 100644 --- a/R/process_tests_care_home.R +++ b/R/process_tests_care_home.R @@ -15,7 +15,7 @@ process_tests_care_home <- function(data, year) { old_data = produce_source_ch_tests(old_data), new_data = produce_source_ch_tests(data) ) %>% - write_tests_xlsx(sheet_name = "CH", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "ch", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_cmh.R b/R/process_tests_cmh.R index 09a17bdbb..7ddec1657 100644 --- a/R/process_tests_cmh.R +++ b/R/process_tests_cmh.R @@ -20,7 +20,7 @@ process_tests_cmh <- function(data, year) { old_data = produce_source_cmh_tests(old_data), new_data = produce_source_cmh_tests(data) ) %>% - write_tests_xlsx(sheet_name = "CMH", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "cmh", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_delayed_discharges.R b/R/process_tests_delayed_discharges.R index c2370eb76..86a60968d 100644 --- a/R/process_tests_delayed_discharges.R +++ b/R/process_tests_delayed_discharges.R @@ -18,7 +18,7 @@ process_tests_delayed_discharges <- function(data, year) { old_data = produce_source_dd_tests(old_data), new_data = produce_source_dd_tests(data) ) %>% - write_tests_xlsx(sheet_name = "DD", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "dd", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_gp_ooh.R b/R/process_tests_gp_ooh.R index fd3ec5f59..6ce3ab5e5 100644 --- a/R/process_tests_gp_ooh.R +++ b/R/process_tests_gp_ooh.R @@ -19,7 +19,7 @@ process_tests_gp_ooh <- function(data, year) { sum_mean_vars = "cost" ) ) %>% - write_tests_xlsx(sheet_name = "GPOoH", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "gpooh", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_home_care.R b/R/process_tests_home_care.R index c1af63e97..f39cf8f5d 100644 --- a/R/process_tests_home_care.R +++ b/R/process_tests_home_care.R @@ -17,7 +17,7 @@ process_tests_home_care <- function(data, year) { ) comparison %>% - write_tests_xlsx(sheet_name = "home_care", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "hc", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_homelessness.R b/R/process_tests_homelessness.R index 4d49f1aa4..9c70161e1 100644 --- a/R/process_tests_homelessness.R +++ b/R/process_tests_homelessness.R @@ -16,7 +16,7 @@ process_tests_homelessness <- function(data, year) { old_data = produce_slf_homelessness_tests(old_data), new_data = produce_slf_homelessness_tests(data) ) %>% - write_tests_xlsx(sheet_name = "HL1", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "hl1", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_maternity.R b/R/process_tests_maternity.R index 90f0ec449..39d7c8aa1 100644 --- a/R/process_tests_maternity.R +++ b/R/process_tests_maternity.R @@ -15,7 +15,7 @@ process_tests_maternity <- function(data, year) { old_data = produce_source_extract_tests(old_data), new_data = produce_source_extract_tests(data) ) %>% - write_tests_xlsx(sheet_name = "02B", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "02b", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_mental_health.R b/R/process_tests_mental_health.R index 96283d47b..5b5cb9001 100644 --- a/R/process_tests_mental_health.R +++ b/R/process_tests_mental_health.R @@ -15,7 +15,7 @@ process_tests_mental_health <- function(data, year) { old_data = produce_source_extract_tests(old_data), new_data = produce_source_extract_tests(data) ) %>% - write_tests_xlsx(sheet_name = "04B", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "04b", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_nrs_deaths.R b/R/process_tests_nrs_deaths.R index c1a963dcf..cbfff2d54 100644 --- a/R/process_tests_nrs_deaths.R +++ b/R/process_tests_nrs_deaths.R @@ -15,7 +15,7 @@ process_tests_nrs_deaths <- function(data, year) { old_data = produce_source_nrs_tests(old_data), new_data = produce_source_nrs_tests(data) ) %>% - write_tests_xlsx(sheet_name = "NRS", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "nrs", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_outpatients.R b/R/process_tests_outpatients.R index 5787e6884..6a377fcf2 100644 --- a/R/process_tests_outpatients.R +++ b/R/process_tests_outpatients.R @@ -23,7 +23,7 @@ process_tests_outpatients <- function(data, year) { add_hscp_count = FALSE ) ) %>% - write_tests_xlsx(sheet_name = "00B", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "00b", year, workbook_name = "extract") return(comparison) } diff --git a/R/process_tests_prescribing.R b/R/process_tests_prescribing.R index bac0e3c52..003f00091 100644 --- a/R/process_tests_prescribing.R +++ b/R/process_tests_prescribing.R @@ -15,7 +15,7 @@ process_tests_prescribing <- function(data, year) { old_data = produce_source_pis_tests(old_data), new_data = produce_source_pis_tests(data) ) %>% - write_tests_xlsx(sheet_name = "PIS", year, workbook_name = "extract") + write_tests_xlsx(sheet_name = "pis", year, workbook_name = "extract") return(comparison) } From b3d826bb1ff034b1ba5573299490a0ee1f5b6071 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 23 Jan 2024 11:10:37 +0000 Subject: [PATCH 18/54] Change date to lowercase --- R/write_tests_xlsx.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/write_tests_xlsx.R b/R/write_tests_xlsx.R index c6a962857..f05f20025 100644 --- a/R/write_tests_xlsx.R +++ b/R/write_tests_xlsx.R @@ -89,6 +89,9 @@ write_tests_xlsx <- function(comparison_data, # add a new sheet for tests date_today <- format(Sys.Date(), "%d_%b") + + date_today<- stringr::str_to_lower(date_today) + sheet_name_dated <- ifelse( is.null(year), stringr::str_glue("{sheet_name}_{date_today}"), From 4ca03b7f738056c618a8a18adb11d5db7c483d1c Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Tue, 23 Jan 2024 11:12:23 +0000 Subject: [PATCH 19/54] Update documentation --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5123289dd..4bb0c6f18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 From 0e69e503643c08ee33a559ac8e7010c118c164f8 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Wed, 24 Jan 2024 13:24:51 +0000 Subject: [PATCH 20/54] Update documentation --- DESCRIPTION | 2 +- man/calculate_stay.Rd | 4 ++-- man/compute_mid_year_age.Rd | 4 ++-- man/convert_date_to_numeric.Rd | 4 ++-- man/convert_numeric_to_date.Rd | 4 ++-- man/end_fy.Rd | 2 +- man/end_fy_quarter.Rd | 2 +- man/end_next_fy_quarter.Rd | 4 ++-- man/fy_interval.Rd | 4 ++-- man/is_date_in_fyyear.Rd | 4 ++-- man/last_date_month.Rd | 4 ++-- man/midpoint_fy.Rd | 4 ++-- man/next_fy.Rd | 4 ++-- man/start_fy.Rd | 2 +- man/start_fy_quarter.Rd | 2 +- man/start_next_fy_quarter.Rd | 6 +++--- 16 files changed, 28 insertions(+), 28 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4bb0c6f18..3a75852e2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 diff --git a/man/calculate_stay.Rd b/man/calculate_stay.Rd index 43b7bd166..5e9266b10 100644 --- a/man/calculate_stay.Rd +++ b/man/calculate_stay.Rd @@ -34,16 +34,16 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/compute_mid_year_age.Rd b/man/compute_mid_year_age.Rd index 142fa4aab..5a50370e0 100644 --- a/man/compute_mid_year_age.Rd +++ b/man/compute_mid_year_age.Rd @@ -31,16 +31,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/convert_date_to_numeric.Rd b/man/convert_date_to_numeric.Rd index 5511fec84..b67eaa778 100644 --- a/man/convert_date_to_numeric.Rd +++ b/man/convert_date_to_numeric.Rd @@ -24,16 +24,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{compute_mid_year_age}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/convert_numeric_to_date.Rd b/man/convert_numeric_to_date.Rd index f786e0319..a09b7b9b9 100644 --- a/man/convert_numeric_to_date.Rd +++ b/man/convert_numeric_to_date.Rd @@ -24,16 +24,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_fy.Rd b/man/end_fy.Rd index 2925ffe60..6220f5f32 100644 --- a/man/end_fy.Rd +++ b/man/end_fy.Rd @@ -34,8 +34,8 @@ Other date functions: \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_fy_quarter.Rd b/man/end_fy_quarter.Rd index 0efe9624a..26c439a04 100644 --- a/man/end_fy_quarter.Rd +++ b/man/end_fy_quarter.Rd @@ -33,8 +33,8 @@ Other date functions: \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_next_fy_quarter.Rd b/man/end_next_fy_quarter.Rd index f9cc1720a..702446e82 100644 --- a/man/end_next_fy_quarter.Rd +++ b/man/end_next_fy_quarter.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/fy_interval.Rd b/man/fy_interval.Rd index 12d1d36bb..00b9ea52c 100644 --- a/man/fy_interval.Rd +++ b/man/fy_interval.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/is_date_in_fyyear.Rd b/man/is_date_in_fyyear.Rd index 97a0f3639..e74bd5734 100644 --- a/man/is_date_in_fyyear.Rd +++ b/man/is_date_in_fyyear.Rd @@ -41,15 +41,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/last_date_month.Rd b/man/last_date_month.Rd index f52305356..3d3b9544e 100644 --- a/man/last_date_month.Rd +++ b/man/last_date_month.Rd @@ -25,15 +25,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/midpoint_fy.Rd b/man/midpoint_fy.Rd index 7bac9b6b3..2363df773 100644 --- a/man/midpoint_fy.Rd +++ b/man/midpoint_fy.Rd @@ -27,15 +27,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/next_fy.Rd b/man/next_fy.Rd index 19e1193f4..7524c5f11 100644 --- a/man/next_fy.Rd +++ b/man/next_fy.Rd @@ -27,15 +27,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/start_fy.Rd b/man/start_fy.Rd index 4996bfb72..9951af2ec 100644 --- a/man/start_fy.Rd +++ b/man/start_fy.Rd @@ -27,8 +27,8 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, diff --git a/man/start_fy_quarter.Rd b/man/start_fy_quarter.Rd index f5729dcb0..9936736a8 100644 --- a/man/start_fy_quarter.Rd +++ b/man/start_fy_quarter.Rd @@ -26,8 +26,8 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, diff --git a/man/start_next_fy_quarter.Rd b/man/start_next_fy_quarter.Rd index 098f0bf73..fdac297a7 100644 --- a/man/start_next_fy_quarter.Rd +++ b/man/start_next_fy_quarter.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, -\code{\link{start_fy}()} +\code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()} } \concept{date functions} From cbf5ae4cd6f6d6f12ee0de18a01313abd3aaa3df Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Wed, 24 Jan 2024 13:58:36 +0000 Subject: [PATCH 21/54] Update documentation --- DESCRIPTION | 2 +- man/calculate_stay.Rd | 4 ++-- man/compute_mid_year_age.Rd | 4 ++-- man/convert_date_to_numeric.Rd | 4 ++-- man/convert_numeric_to_date.Rd | 4 ++-- man/end_fy.Rd | 2 +- man/end_fy_quarter.Rd | 2 +- man/end_next_fy_quarter.Rd | 4 ++-- man/fy_interval.Rd | 4 ++-- man/is_date_in_fyyear.Rd | 4 ++-- man/last_date_month.Rd | 4 ++-- man/midpoint_fy.Rd | 4 ++-- man/next_fy.Rd | 4 ++-- man/start_fy.Rd | 2 +- man/start_fy_quarter.Rd | 2 +- man/start_next_fy_quarter.Rd | 6 +++--- 16 files changed, 28 insertions(+), 28 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4bb0c6f18..3a75852e2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 diff --git a/man/calculate_stay.Rd b/man/calculate_stay.Rd index 43b7bd166..5e9266b10 100644 --- a/man/calculate_stay.Rd +++ b/man/calculate_stay.Rd @@ -34,16 +34,16 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/compute_mid_year_age.Rd b/man/compute_mid_year_age.Rd index 142fa4aab..5a50370e0 100644 --- a/man/compute_mid_year_age.Rd +++ b/man/compute_mid_year_age.Rd @@ -31,16 +31,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/convert_date_to_numeric.Rd b/man/convert_date_to_numeric.Rd index 5511fec84..b67eaa778 100644 --- a/man/convert_date_to_numeric.Rd +++ b/man/convert_date_to_numeric.Rd @@ -24,16 +24,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{compute_mid_year_age}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/convert_numeric_to_date.Rd b/man/convert_numeric_to_date.Rd index f786e0319..a09b7b9b9 100644 --- a/man/convert_numeric_to_date.Rd +++ b/man/convert_numeric_to_date.Rd @@ -24,16 +24,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_fy.Rd b/man/end_fy.Rd index 2925ffe60..6220f5f32 100644 --- a/man/end_fy.Rd +++ b/man/end_fy.Rd @@ -34,8 +34,8 @@ Other date functions: \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_fy_quarter.Rd b/man/end_fy_quarter.Rd index 0efe9624a..26c439a04 100644 --- a/man/end_fy_quarter.Rd +++ b/man/end_fy_quarter.Rd @@ -33,8 +33,8 @@ Other date functions: \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_next_fy_quarter.Rd b/man/end_next_fy_quarter.Rd index f9cc1720a..702446e82 100644 --- a/man/end_next_fy_quarter.Rd +++ b/man/end_next_fy_quarter.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/fy_interval.Rd b/man/fy_interval.Rd index 12d1d36bb..00b9ea52c 100644 --- a/man/fy_interval.Rd +++ b/man/fy_interval.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/is_date_in_fyyear.Rd b/man/is_date_in_fyyear.Rd index 97a0f3639..e74bd5734 100644 --- a/man/is_date_in_fyyear.Rd +++ b/man/is_date_in_fyyear.Rd @@ -41,15 +41,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/last_date_month.Rd b/man/last_date_month.Rd index f52305356..3d3b9544e 100644 --- a/man/last_date_month.Rd +++ b/man/last_date_month.Rd @@ -25,15 +25,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/midpoint_fy.Rd b/man/midpoint_fy.Rd index 7bac9b6b3..2363df773 100644 --- a/man/midpoint_fy.Rd +++ b/man/midpoint_fy.Rd @@ -27,15 +27,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/next_fy.Rd b/man/next_fy.Rd index 19e1193f4..7524c5f11 100644 --- a/man/next_fy.Rd +++ b/man/next_fy.Rd @@ -27,15 +27,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/start_fy.Rd b/man/start_fy.Rd index 4996bfb72..9951af2ec 100644 --- a/man/start_fy.Rd +++ b/man/start_fy.Rd @@ -27,8 +27,8 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, diff --git a/man/start_fy_quarter.Rd b/man/start_fy_quarter.Rd index f5729dcb0..9936736a8 100644 --- a/man/start_fy_quarter.Rd +++ b/man/start_fy_quarter.Rd @@ -26,8 +26,8 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, diff --git a/man/start_next_fy_quarter.Rd b/man/start_next_fy_quarter.Rd index 098f0bf73..fdac297a7 100644 --- a/man/start_next_fy_quarter.Rd +++ b/man/start_next_fy_quarter.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, -\code{\link{start_fy}()} +\code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()} } \concept{date functions} From 3055d54f80f75b3b8c29306116a0ad83837d8645 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Mon, 29 Jan 2024 09:56:34 +0000 Subject: [PATCH 22/54] Style code --- R/write_tests_xlsx.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/write_tests_xlsx.R b/R/write_tests_xlsx.R index f05f20025..ffe86f48f 100644 --- a/R/write_tests_xlsx.R +++ b/R/write_tests_xlsx.R @@ -90,7 +90,7 @@ write_tests_xlsx <- function(comparison_data, # add a new sheet for tests date_today <- format(Sys.Date(), "%d_%b") - date_today<- stringr::str_to_lower(date_today) + date_today <- stringr::str_to_lower(date_today) sheet_name_dated <- ifelse( is.null(year), From 30cb567fe1df6cfab6e0818017a0e6aef5014c51 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 5 Feb 2024 13:41:25 +0000 Subject: [PATCH 23/54] Fix pick variables This was not taking the correct variables, leading to NSUs being assigned psychiatry --- R/create_service_use_lookup.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/create_service_use_lookup.R b/R/create_service_use_lookup.R index 4acbfc507..242e0b351 100644 --- a/R/create_service_use_lookup.R +++ b/R/create_service_use_lookup.R @@ -908,7 +908,13 @@ assign_cohort_names <- function(data) { # Situation where no cost is greater than another, # so the maximum is the same as the mean .data$cost_max == rowSums( - dplyr::pick("psychiatry_cost":"residential_care_cost") + dplyr::pick(c( + "psychiatry_cost", "maternity_cost", "geriatric_cost", + "elective_inpatient_cost", "limited_daycases_cost", + "routine_daycase_cost", "single_emergency_cost", + "multiple_emergency_cost", "prescribing_cost", + "outpatient_cost", "ae2_cost", "residential_care_cost" + )) ) / 12.0 ~ "Unassigned", .data$cost_max == .data$psychiatry_cost ~ "Psychiatry", .data$cost_max == .data$maternity_cost ~ "Maternity", From 744bbc024b5cba09ebe9514cd36ad794b1e24fff Mon Sep 17 00:00:00 2001 From: Megan McNicol <43570769+SwiftySalmon@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:28:21 +0000 Subject: [PATCH 24/54] SC Demographics and SDS (#900) * Style code * # read in sc demographics different variables - removed extract date as not accurate, using chi over upi after discussion with social care data management. Added in date of death just for fun. * social care demographics first draft removed a lot of the submitted variables and instead using chi variables from chi seeding. Other changes: - Fill in missing values, - create flag for latest social care id (one from database is not accurate), this makes sure that each chi only has ONE sc id as the latest to stop it creating duplicates - change postcode to choose chi over submitted * Style code * had a github error? Not sure what happened but commiting first draft of sc demographics * Style code * first draft sds. No major changes - only how demographics is matched on and how latest social care id is selected * Update documentation * demographics - add sending location to group by * Style code * Update documentation * Added ungroup() * Remove comments * Remove comments * Style code --------- Co-authored-by: SwiftySalmon Co-authored-by: marjom02 Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> Co-authored-by: Jennit07 Co-authored-by: Zihao Li --- R/fix_sc_dates.R | 8 +-- R/process_lookup_sc_demographics.R | 97 +++++++++++++++++++----------- R/process_sc_all_sds.R | 19 ++++-- R/read_lookup_sc_demographics.R | 15 +++-- R/read_sc_all_sds.R | 8 +-- R/replace_sc_id_with_latest.R | 25 +++----- man/fix_sc_end_dates.Rd | 2 +- 7 files changed, 98 insertions(+), 76 deletions(-) diff --git a/R/fix_sc_dates.R b/R/fix_sc_dates.R index c636980a6..117acbaab 100644 --- a/R/fix_sc_dates.R +++ b/R/fix_sc_dates.R @@ -9,7 +9,7 @@ #' @return A date vector with replaced end dates fix_sc_start_dates <- function(start_date, period_start) { # Fix sds_start_date is missing by setting start_date to be the start of - # financial year + # financial period start_date <- dplyr::if_else( is.na(start_date), period_start, @@ -30,12 +30,12 @@ fix_sc_start_dates <- function(start_date, period_start) { #' @param period Social care latest submission period. #' #' @return A date vector with replaced end dates -fix_sc_end_dates <- function(start_date, end_date, period) { +fix_sc_end_dates <- function(start_date, end_date, period_end_date) { # Fix sds_end_date is earlier than sds_start_date by setting end_date to be # the end of financial year end_date <- dplyr::if_else( start_date > end_date, - end_fy(year = stringr::str_sub(period, 1L, 4L), "alternate"), + period_end_date, end_date ) @@ -57,7 +57,7 @@ fix_sc_end_dates <- function(start_date, end_date, period) { #' @return A date vector with replaced end dates fix_sc_missing_end_dates <- function(end_date, period_end) { # Fix sds_end_date is earlier than sds_start_date by setting end_date to be - # the end of financial year + # the end of financial period end_date <- dplyr::if_else( is.na(end_date), period_end, diff --git a/R/process_lookup_sc_demographics.R b/R/process_lookup_sc_demographics.R index 8c363f547..96adc985e 100644 --- a/R/process_lookup_sc_demographics.R +++ b/R/process_lookup_sc_demographics.R @@ -28,30 +28,46 @@ process_lookup_sc_demographics <- function( dplyr::pull(.data$pc7) - # Data Cleaning --------------------------------------- - + # Fill in missing data and flag latest cases to keep --------------------------------------- sc_demog <- data %>% - dplyr::mutate( - # use chi if upi is NA - upi = dplyr::coalesce(.data$upi, .data$chi_upi), - # check gender code - replace code 99 with 9 - submitted_gender = replace(.data$submitted_gender, .data$submitted_gender == 99L, 9L) + dplyr::rename( + chi = chi_upi, + gender = chi_gender_code, + dob = chi_date_of_birth ) %>% + # fill in missing demographic details + dplyr::arrange(period, social_care_id) %>% + dplyr::group_by(social_care_id, sending_location) %>% + tidyr::fill(chi, .direction = ("updown")) %>% + tidyr::fill(dob, .direction = ("updown")) %>% + tidyr::fill(date_of_death, .direction = ("updown")) %>% + tidyr::fill(gender, .direction = ("updown")) %>% + tidyr::fill(chi_postcode, .direction = ("updown")) %>% + tidyr::fill(submitted_postcode, .direction = ("updown")) %>% + dplyr::ungroup() %>% + # format postcodes using `phsmethods` + dplyr::mutate(dplyr::across(tidyselect::contains("postcode"), ~ phsmethods::format_postcode(.x, format = "pc7"))) # are sc postcodes even used anywhere? + + + # flag unique cases of chi and sc_id, and flag the latest record (sc_demographics latest flag is not accurate) + sc_demog <- sc_demog %>% + dplyr::group_by(chi, sending_location) %>% + dplyr::mutate(latest = dplyr::last(period)) %>% # flag latest period for chi + dplyr::group_by(chi, social_care_id, sending_location) %>% + dplyr::mutate(latest_sc_id = dplyr::last(period)) %>% # flag latest period for social care + dplyr::group_by(chi, sending_location) %>% + dplyr::mutate(last_sc_id = dplyr::last(social_care_id)) %>% dplyr::mutate( - # use CHI sex if available - gender = dplyr::if_else( - is.na(.data$chi_gender_code) | .data$chi_gender_code == 9L, - .data$submitted_gender, - .data$chi_gender_code - ), - # Use CHI DoB if available - dob = dplyr::coalesce(.data$chi_date_of_birth, .data$submitted_date_of_birth) + latest_flag = ifelse((latest == period & last_sc_id == social_care_id) | is.na(chi), 1, 0), + keep = ifelse(latest_sc_id == period, 1, 0) ) %>% - # format postcodes using `phsmethods` - dplyr::mutate(dplyr::across( - tidyselect::contains("postcode"), - ~ phsmethods::format_postcode(.x, format = "pc7") - )) + dplyr::ungroup() + + sc_demog <- sc_demog %>% + dplyr::select(-period, -latest_record_flag, -latest, -last_sc_id, -latest_sc_id) %>% + dplyr::distinct() + + # postcodes --------------------------------------------------------------- # count number of na postcodes na_postcodes <- sc_demog %>% @@ -69,29 +85,32 @@ process_lookup_sc_demographics <- function( ~ dplyr::if_else(stringr::str_detect(.x, uk_pc_regexp), .x, NA) )) %>% dplyr::select( - "latest_record_flag", - "extract_date", "sending_location", "social_care_id", - "upi", + "chi", "gender", "dob", + "date_of_death", "submitted_postcode", - "chi_postcode" + "chi_postcode", + "keep", + "latest_flag" ) %>% # check if submitted_postcode matches with postcode lookup dplyr::mutate( - valid_pc = .data$submitted_postcode %in% valid_spd_postcodes + valid_pc_submitted = .data$submitted_postcode %in% valid_spd_postcodes, + valid_pc_chi = .data$chi_postcode %in% valid_spd_postcodes ) %>% # use submitted_postcode if valid, otherwise use chi_postcode dplyr::mutate(postcode = dplyr::case_when( - (!is.na(.data$submitted_postcode) & .data$valid_pc) ~ .data$submitted_postcode, - (is.na(.data$submitted_postcode) & !.data$valid_pc) ~ .data$chi_postcode + (!is.na(.data$chi_postcode) & .data$valid_pc_chi) ~ .data$chi_postcode, + ((is.na(.data$chi_postcode) | !(.data$valid_pc_chi)) & !(is.na(.data$submitted_postcode)) & .data$valid_pc_submitted) ~ .data$submitted_postcode, + (is.na(.data$submitted_postcode) & !.data$valid_pc_submitted) ~ .data$chi_postcode )) %>% dplyr::mutate(postcode_type = dplyr::case_when( - (!is.na(.data$submitted_postcode) & .data$valid_pc) ~ "submitted", - (is.na(.data$submitted_postcode) & !.data$valid_pc) ~ "chi", - (is.na(.data$submitted_postcode) & is.na(.data$chi_postcode)) ~ "missing" + (postcode == chi_postcode) ~ "chi", + (postcode == submitted_postcode) ~ "submitted", + (is.na(.data$submitted_postcode) & is.na(.data$chi_postcode) | is.na(.data$postcode)) ~ "missing" )) # Check where the postcodes are coming from @@ -102,26 +121,32 @@ process_lookup_sc_demographics <- function( na_replaced_postcodes <- sc_demog %>% dplyr::count(dplyr::across(tidyselect::ends_with("_postcode"), ~ is.na(.x))) - sc_demog_lookup <- sc_demog %>% + dplyr::filter(keep == 1) %>% # filter to only keep latest record for sc id and chi + dplyr::select(-postcode_type, -valid_pc_submitted, -valid_pc_chi, -submitted_postcode, -chi_postcode) %>% + dplyr::distinct() %>% # group by sending location and ID - dplyr::group_by(.data$sending_location, .data$social_care_id) %>% + dplyr::group_by(.data$sending_location, .data$chi, .data$social_care_id, .data$latest_flag) %>% # arrange so latest submissions are last dplyr::arrange( .data$sending_location, .data$social_care_id, - .data$latest_record_flag, - .data$extract_date + .data$latest_flag ) %>% # summarise to select the last (non NA) submission dplyr::summarise( - chi = dplyr::last(.data$upi), gender = dplyr::last(.data$gender), dob = dplyr::last(.data$dob), - postcode = dplyr::last(.data$postcode) + postcode = dplyr::last(.data$postcode), + date_of_death = dplyr::last(.data$date_of_death) ) %>% dplyr::ungroup() + # check to make sure all cases of chi are still there + dplyr::n_distinct(sc_demog_lookup$chi) # 524810 + dplyr::n_distinct(sc_demog_lookup$social_care_id) # 636404 + + if (write_to_disk) { write_file( sc_demog_lookup, diff --git a/R/process_sc_all_sds.R b/R/process_sc_all_sds.R index f9ca52f24..453db3e40 100644 --- a/R/process_sc_all_sds.R +++ b/R/process_sc_all_sds.R @@ -15,14 +15,17 @@ process_sc_all_sds <- function( sc_demog_lookup, write_to_disk = TRUE) { # Match on demographics data (chi, gender, dob and postcode) - matched_sds_data <- data %>% - dplyr::left_join( + matched_sds_data <- data %>% # + dplyr::filter(.data$sds_start_date_after_period_end_date != 1) %>% + dplyr::right_join( sc_demog_lookup, by = c("sending_location", "social_care_id") ) %>% # when multiple social_care_id from sending_location for single CHI # replace social_care_id with latest - replace_sc_id_with_latest() + replace_sc_id_with_latest() %>% + dplyr::select(-latest_sc_id, -latest_flag, -sds_start_date_after_period_end_date) %>% + dplyr::distinct() # Data Cleaning --------------------------------------- sds_full_clean <- matched_sds_data %>% @@ -50,7 +53,7 @@ process_sc_all_sds <- function( .data$sds_start_date, .data$sds_period_start_date ), - # If SDS end date is missing, assign end of FY + # If SDS end date is missing, assign end of financial period sds_end_date = fix_sc_missing_end_dates( .data$sds_end_date, .data$sds_period_end_date @@ -59,14 +62,19 @@ process_sc_all_sds <- function( sds_end_date = fix_sc_end_dates( .data$sds_start_date, .data$sds_end_date, - .data$period + .data$sds_period_end_date ) ) %>% + dplyr::select( + -sds_period_start_date, -sds_period_end_date, + -sds_start_date_after_end_date + ) %>% # rename for matching source variables dplyr::rename( record_keydate1 = .data$sds_start_date, record_keydate2 = .data$sds_end_date ) %>% + dplyr::distinct() %>% # Pivot longer on sds option variables tidyr::pivot_longer( cols = tidyselect::contains("sds_option_"), @@ -103,6 +111,7 @@ process_sc_all_sds <- function( ) %>% dplyr::arrange(.data$period, .data$record_keydate1, + .data$record_keydate2, .by_group = TRUE ) %>% # Create a flag for episodes that are going to be merged diff --git a/R/read_lookup_sc_demographics.R b/R/read_lookup_sc_demographics.R index fcdde5417..fe9a5e71f 100644 --- a/R/read_lookup_sc_demographics.R +++ b/R/read_lookup_sc_demographics.R @@ -12,16 +12,15 @@ read_lookup_sc_demographics <- function(sc_connection = phs_db_connection(dsn = ) %>% dplyr::select( "latest_record_flag", - "extract_date", + "period", "sending_location", + "sending_location_name", "social_care_id", - "upi", "chi_upi", - "submitted_postcode", - "chi_postcode", - "submitted_date_of_birth", "chi_date_of_birth", - "submitted_gender", + "date_of_death", + "chi_postcode", + "submitted_postcode", "chi_gender_code" ) %>% dplyr::collect() %>% @@ -29,10 +28,10 @@ read_lookup_sc_demographics <- function(sc_connection = phs_db_connection(dsn = dplyr::across(c( "latest_record_flag", "sending_location", - "submitted_gender", "chi_gender_code" ), as.integer) - ) + ) %>% + dplyr::distinct() return(sc_demog) } diff --git a/R/read_sc_all_sds.R b/R/read_sc_all_sds.R index 18c5b52ec..ab9bb20e1 100644 --- a/R/read_sc_all_sds.R +++ b/R/read_sc_all_sds.R @@ -22,9 +22,8 @@ read_sc_all_sds <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPR "sds_option_1", "sds_option_2", "sds_option_3", - "sds_start_date_after_end_date", - "sds_start_date_after_period_end_date", - "sds_end_date_not_within_period" + "sds_start_date_after_end_date", # get fixed + "sds_start_date_after_period_end_date" # get removed ) %>% dplyr::collect() %>% dplyr::distinct() %>% @@ -33,8 +32,7 @@ read_sc_all_sds <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPR "sds_option_1", "sds_option_2", "sds_option_3" - ), as.integer)) %>% - dplyr::filter(.data$sds_start_date_after_period_end_date != 1) + ), as.integer)) return(sds_full_data) } diff --git a/R/replace_sc_id_with_latest.R b/R/replace_sc_id_with_latest.R index 73c1a3706..2c32bbb93 100644 --- a/R/replace_sc_id_with_latest.R +++ b/R/replace_sc_id_with_latest.R @@ -7,33 +7,23 @@ replace_sc_id_with_latest <- function(data) { # Check for required variables check_variables_exist( data, - c("sending_location", "social_care_id", "chi", "period") + c("sending_location", "social_care_id", "chi", "latest_flag") ) # select variables we need filter_data <- data %>% dplyr::select( - "sending_location", "social_care_id", "chi", "period" + "sending_location", "social_care_id", "chi", "latest_flag" ) %>% - dplyr::filter(!(is.na(.data$chi))) + dplyr::filter(!(is.na(.data$chi))) %>% + dplyr::distinct() change_sc_id <- filter_data %>% - # Sort (by sending_location, chi and period) for unique chi/sending location - dplyr::arrange( - .data$sending_location, - .data$chi, - dplyr::desc(.data$period) - ) %>% - # Find the latest sc_id for each chi/sending location by keeping latest period - dplyr::distinct( - .data$sending_location, - .data$chi, - .keep_all = TRUE - ) %>% + dplyr::filter(latest_flag == 1) %>% # Rename for latest sc id dplyr::rename(latest_sc_id = "social_care_id") %>% - # drop period for matching - dplyr::select(-"period") + # drop latest_flag for matching + dplyr::select(-"latest_flag") return_data <- change_sc_id %>% # Match back onto data @@ -41,6 +31,7 @@ replace_sc_id_with_latest <- function(data) { by = c("sending_location", "chi"), multiple = "all" ) %>% + dplyr::filter(!(is.na(period))) %>% # Overwrite sc id with the latest dplyr::mutate( social_care_id = dplyr::if_else( diff --git a/man/fix_sc_end_dates.Rd b/man/fix_sc_end_dates.Rd index 1bf808bea..041751319 100644 --- a/man/fix_sc_end_dates.Rd +++ b/man/fix_sc_end_dates.Rd @@ -4,7 +4,7 @@ \alias{fix_sc_end_dates} \title{Fix sc end dates} \usage{ -fix_sc_end_dates(start_date, end_date, period) +fix_sc_end_dates(start_date, end_date, period_end_date) } \arguments{ \item{start_date}{A vector containing dates.} From cd8b35948abf588a8eea7fa0474be8e8cd8c03a0 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Wed, 7 Feb 2024 15:32:47 +0000 Subject: [PATCH 25/54] Sc all at speedup (#904) * speed up process_sc_all_alarms_telecare function with data.table package * Update documentation --------- Co-authored-by: lizihao-anu Co-authored-by: Megan McNicol <43570769+SwiftySalmon@users.noreply.github.com> Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/process_sc_all_alarms_telecare.R | 181 +++++++++++++++++------------ 1 file changed, 104 insertions(+), 77 deletions(-) diff --git a/R/process_sc_all_alarms_telecare.R b/R/process_sc_all_alarms_telecare.R index 988d1f3e7..bc417a8cd 100644 --- a/R/process_sc_all_alarms_telecare.R +++ b/R/process_sc_all_alarms_telecare.R @@ -17,58 +17,85 @@ process_sc_all_alarms_telecare <- function( write_to_disk = TRUE) { # Data Cleaning----------------------------------------------------- - replaced_dates <- data %>% - # If the end date is missing, set this to the end of the period - dplyr::mutate( - service_end_date = fix_sc_missing_end_dates( - .data$service_end_date, - .data$period_end_date - ), - # If the start_date is missing, set this to the start of the period - service_start_date = fix_sc_start_dates( - .data$service_start_date, - .data$period_start_date - ), - # Fix service_end_date if earlier than service_start_date by setting end_date to the end of fy - service_end_date = fix_sc_end_dates( - .data$service_start_date, - .data$service_end_date, - .data$period - ) + # Convert to data.table + data.table::setDT(data) + data.table::setDT(sc_demog_lookup) + + # Fix dates and create new variables + data[ + , + service_end_date := fix_sc_missing_end_dates( + service_end_date, + period_end_date ) + ] + data[ + , + service_start_date := fix_sc_start_dates( + service_start_date, + period_start_date + ) + ] + data[ + , + service_end_date := fix_sc_end_dates( + service_start_date, + service_end_date, + period + ) + ] - at_full_clean <- replaced_dates %>% - # rename for matching source variables - dplyr::rename( - record_keydate1 = "service_start_date", - record_keydate2 = "service_end_date" - ) %>% - # Include source variables - dplyr::mutate( - recid = "AT", - smrtype = dplyr::case_when( - .data$service_type == 1L ~ "AT-Alarm", - .data$service_type == 2L ~ "AT-Tele" + # Rename columns + data.table::setnames( + data, + old = c("service_start_date", "service_end_date"), + new = c("record_keydate1", "record_keydate2") + ) + + # Additional mutations + data[ + , + c( + "recid", + "smrtype", + "sc_send_lca" + ) := list( + "AT", + data.table::fcase( + service_type == 1L, + "AT-Alarm", + service_type == 2L, + "AT-Tele", + default, + NA_character_ ), - # Create person id variable - person_id = stringr::str_glue("{sending_location}-{social_care_id}"), - # Use function for creating sc send lca variables - sc_send_lca = convert_sc_sending_location_to_lca(.data$sending_location) - ) %>% - # Match on demographics data (chi, gender, dob and postcode) - dplyr::left_join( - sc_demog_lookup, - by = c("sending_location", "social_care_id") - ) %>% - # when multiple social_care_id from sending_location for single CHI - # replace social_care_id with latest - replace_sc_id_with_latest() + convert_sc_sending_location_to_lca(sending_location) + ) + ] + data$person_id <- paste0( + data$sending_location, + "-", + data$social_care_id + ) + + # Join with sc_demog_lookup + data <- sc_demog_lookup[data, on = .(sending_location, social_care_id)] - # Deal with episodes which have a package across quarters. - qtr_merge <- at_full_clean %>% - # use as.data.table to change the data format to data.table to accelerate - data.table::as.data.table() %>% + # Replace social_care_id with latest if needed (assuming replace_sc_id_with_latest is a custom function) + data <- replace_sc_id_with_latest(data) + + # Deal with episodes that have a package across quarters + data[, pkg_count := seq_len(.N), by = .( + sending_location, + social_care_id, + record_keydate1, + smrtype, + period + )] + + # Order data before summarizing + data <- data %>% dplyr::group_by( .data$sending_location, .data$social_care_id, @@ -76,38 +103,38 @@ process_sc_all_alarms_telecare <- function( .data$smrtype, .data$period ) %>% - # Create a count for the package number across episodes - dplyr::mutate(pkg_count = dplyr::row_number()) %>% # Sort prior to merging dplyr::arrange(.by_group = TRUE) %>% - # group for merging episodes - dplyr::group_by( - .data$sending_location, - .data$social_care_id, - .data$record_keydate1, - .data$smrtype, - .data$pkg_count - ) %>% - # merge episodes with packages across quarters - # drop variables not needed - dplyr::summarise( - sending_location = dplyr::last(.data$sending_location), - social_care_id = dplyr::last(.data$social_care_id), - sc_latest_submission = dplyr::last(.data$period), - record_keydate1 = dplyr::last(.data$record_keydate1), - record_keydate2 = dplyr::last(.data$record_keydate2), - smrtype = dplyr::last(.data$smrtype), - pkg_count = dplyr::last(.data$pkg_count), - chi = dplyr::last(.data$chi), - gender = dplyr::last(.data$gender), - dob = dplyr::last(.data$dob), - postcode = dplyr::last(.data$postcode), - recid = dplyr::last(.data$recid), - person_id = dplyr::last(.data$person_id), - sc_send_lca = dplyr::last(.data$sc_send_lca) - ) %>% - # change the data format from data.table to data.frame - tibble::as_tibble() + dplyr::ungroup() %>% + data.table::as.data.table() + + # Summarize to merge episodes + qtr_merge <- data[, .( + sending_location = data.table::last(sending_location), + social_care_id = data.table::last(social_care_id), + sc_latest_submission = data.table::last(period), + record_keydate1 = data.table::last(record_keydate1), + record_keydate2 = data.table::last(record_keydate2), + smrtype = data.table::last(smrtype), + pkg_count = data.table::last(pkg_count), + chi = data.table::last(chi), + gender = data.table::last(gender), + dob = data.table::last(dob), + postcode = data.table::last(postcode), + recid = data.table::last(recid), + person_id = data.table::last(person_id), + sc_send_lca = data.table::last(sc_send_lca) + ), by = .( + sending_location, + social_care_id, + record_keydate1, + smrtype, + pkg_count + )] + + # Convert back to data.frame if necessary + qtr_merge <- as.data.frame(qtr_merge) + if (write_to_disk) { write_file( From b1a9523623b740144098418d59891228a005e74e Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Wed, 7 Feb 2024 16:40:51 +0000 Subject: [PATCH 26/54] Add case_when statement for `high_cc` cohort --- R/create_demographic_lookup.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/create_demographic_lookup.R b/R/create_demographic_lookup.R index 2b252a151..d0e0c9988 100644 --- a/R/create_demographic_lookup.R +++ b/R/create_demographic_lookup.R @@ -344,18 +344,21 @@ assign_d_cohort_high_cc <- function(dementia, liver, cancer, spec) { - high_cc <- + high_cc <- dplyr::case_when( + spec == "G5" ~ TRUE, # FOR FUTURE: PhysicalandSensoryDisabilityClientGroup or LearningDisabilityClientGroup = "Y", # then high_cc_cohort = TRUE # FOR FUTURE: Care home removed, here's the code: .data$recid = "CH" & age < 65 - rowSums(dplyr::pick(c( + (rowSums(dplyr::pick(c( "dementia", "hefailure", "refailure", "liver", "cancer" - )), na.rm = TRUE) >= 1L | - spec == "G5" + )), na.rm = TRUE) >= 1L) ~ TRUE, + .default = FALSE + ) + return(high_cc) } From 6829c1acb55586050a786edc478c11281e675eb6 Mon Sep 17 00:00:00 2001 From: Jennit07 <67372904+Jennit07@users.noreply.github.com> Date: Mon, 12 Feb 2024 12:04:34 +0000 Subject: [PATCH 27/54] Bug - `high_cc` in demographic cohort showing `NAs` instead of `TRUE/FALSE` (#911) Add case_when statement for `high_cc` cohort --- R/create_demographic_lookup.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/create_demographic_lookup.R b/R/create_demographic_lookup.R index 2b252a151..d0e0c9988 100644 --- a/R/create_demographic_lookup.R +++ b/R/create_demographic_lookup.R @@ -344,18 +344,21 @@ assign_d_cohort_high_cc <- function(dementia, liver, cancer, spec) { - high_cc <- + high_cc <- dplyr::case_when( + spec == "G5" ~ TRUE, # FOR FUTURE: PhysicalandSensoryDisabilityClientGroup or LearningDisabilityClientGroup = "Y", # then high_cc_cohort = TRUE # FOR FUTURE: Care home removed, here's the code: .data$recid = "CH" & age < 65 - rowSums(dplyr::pick(c( + (rowSums(dplyr::pick(c( "dementia", "hefailure", "refailure", "liver", "cancer" - )), na.rm = TRUE) >= 1L | - spec == "G5" + )), na.rm = TRUE) >= 1L) ~ TRUE, + .default = FALSE + ) + return(high_cc) } From c7a140068bc1376cd8ae3951e96a1aca74bcd7fd Mon Sep 17 00:00:00 2001 From: marjom02 Date: Tue, 13 Feb 2024 11:55:27 +0000 Subject: [PATCH 28/54] added a casewhen to update property type description for homelessness --- R/process_extract_homelessness.R | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/R/process_extract_homelessness.R b/R/process_extract_homelessness.R index 3211f0fb7..3b9756183 100644 --- a/R/process_extract_homelessness.R +++ b/R/process_extract_homelessness.R @@ -100,6 +100,36 @@ process_extract_homelessness <- function( ) ) ) %>% + dplyr::mutate(property_type_code = as.character(property_type_code)) %>% + dplyr::mutate( + property_type_code = dplyr::case_when( + property_type_code == "1" ~ "1 - Own Property - LA Tenancy", + property_type_code == "2" ~ "2 - Own Property - RSL Tenancy", + property_type_code == "3" ~ "3 - Own Property - private rented tenancy", + property_type_code == "4" ~ "4 - Own Property - tenancy secured through employment/tied house", + property_type_code == "5" ~ "5 - Own Property - owning/buying", + property_type_code == "6" ~ "6 - Parental / family home / relatives", + property_type_code == "7" ~ " 7 - Friends / partners", + property_type_code == "8" ~ "8 - Armed Services Accommodation", + property_type_code == "9" ~ "9 - Prison", + property_type_code == "10" ~ "10 - Hospital", + property_type_code == "11" ~ "11 - Children's residential accommodation (looked after by the local authority)", + property_type_code == "12" ~ "12 - Supported accommodation", + property_type_code == "13" ~ "13 - Hostel (unsupported)", + property_type_code == "14" ~ "14 - Bed & Breakfast", + property_type_code == "15" ~ "15 - Caravan / mobile home", + property_type_code == "16" ~ "16 - Long-term roofless", + property_type_code == "17" ~ "17 - Long-term sofa surfing", + property_type_code == "18" ~ "18 - Other", + property_type_code == "19" ~ "19 - Not known / refused", + property_type_code == "20" ~ "20 - Own property - Shared ownership/Shared equity/ LCHO", + property_type_code == "21" ~ "21 - Lodger", + property_type_code == "22" ~ "22 - Shared Property - Private Rented Sector", + property_type_code == "23" ~ "23 - Shared Property - Local Authority", + property_type_code == "24" ~ "24 - Shared Property - RSL", + TRUE ~ property_type_code + ) + ) %>% dplyr::left_join( la_code_lookup, by = dplyr::join_by("sending_local_authority_code_9" == "CA") @@ -117,7 +147,7 @@ process_extract_homelessness <- function( if (!is.null(completeness_data)) { filtered_data <- data %>% dplyr::left_join(completeness_data, - by = c("year", "sending_local_authority_name") + by = c("year", "sending_local_authority_name") ) %>% dplyr::filter( dplyr::between(.data[["pct_complete_all"]], 0.90, 1.05) | From ea192202d8b57c2182ac0d01c2761c14745abc0a Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Tue, 13 Feb 2024 11:58:45 +0000 Subject: [PATCH 29/54] Update documentation --- DESCRIPTION | 2 +- man/calculate_stay.Rd | 4 ++-- man/compute_mid_year_age.Rd | 4 ++-- man/convert_date_to_numeric.Rd | 4 ++-- man/convert_numeric_to_date.Rd | 4 ++-- man/end_fy.Rd | 2 +- man/end_fy_quarter.Rd | 2 +- man/end_next_fy_quarter.Rd | 4 ++-- man/fy_interval.Rd | 4 ++-- man/is_date_in_fyyear.Rd | 4 ++-- man/last_date_month.Rd | 4 ++-- man/midpoint_fy.Rd | 4 ++-- man/next_fy.Rd | 4 ++-- man/start_fy.Rd | 2 +- man/start_fy_quarter.Rd | 2 +- man/start_next_fy_quarter.Rd | 6 +++--- 16 files changed, 28 insertions(+), 28 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5123289dd..3a75852e2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -73,4 +73,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/man/calculate_stay.Rd b/man/calculate_stay.Rd index 43b7bd166..5e9266b10 100644 --- a/man/calculate_stay.Rd +++ b/man/calculate_stay.Rd @@ -34,16 +34,16 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/compute_mid_year_age.Rd b/man/compute_mid_year_age.Rd index 142fa4aab..5a50370e0 100644 --- a/man/compute_mid_year_age.Rd +++ b/man/compute_mid_year_age.Rd @@ -31,16 +31,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/convert_date_to_numeric.Rd b/man/convert_date_to_numeric.Rd index 5511fec84..b67eaa778 100644 --- a/man/convert_date_to_numeric.Rd +++ b/man/convert_date_to_numeric.Rd @@ -24,16 +24,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{compute_mid_year_age}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/convert_numeric_to_date.Rd b/man/convert_numeric_to_date.Rd index f786e0319..a09b7b9b9 100644 --- a/man/convert_numeric_to_date.Rd +++ b/man/convert_numeric_to_date.Rd @@ -24,16 +24,16 @@ Other date functions: \code{\link{calculate_stay}()}, \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_fy.Rd b/man/end_fy.Rd index 2925ffe60..6220f5f32 100644 --- a/man/end_fy.Rd +++ b/man/end_fy.Rd @@ -34,8 +34,8 @@ Other date functions: \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_fy_quarter.Rd b/man/end_fy_quarter.Rd index 0efe9624a..26c439a04 100644 --- a/man/end_fy_quarter.Rd +++ b/man/end_fy_quarter.Rd @@ -33,8 +33,8 @@ Other date functions: \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/end_next_fy_quarter.Rd b/man/end_next_fy_quarter.Rd index f9cc1720a..702446e82 100644 --- a/man/end_next_fy_quarter.Rd +++ b/man/end_next_fy_quarter.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/fy_interval.Rd b/man/fy_interval.Rd index 12d1d36bb..00b9ea52c 100644 --- a/man/fy_interval.Rd +++ b/man/fy_interval.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/is_date_in_fyyear.Rd b/man/is_date_in_fyyear.Rd index 97a0f3639..e74bd5734 100644 --- a/man/is_date_in_fyyear.Rd +++ b/man/is_date_in_fyyear.Rd @@ -41,15 +41,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/last_date_month.Rd b/man/last_date_month.Rd index f52305356..3d3b9544e 100644 --- a/man/last_date_month.Rd +++ b/man/last_date_month.Rd @@ -25,15 +25,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/midpoint_fy.Rd b/man/midpoint_fy.Rd index 7bac9b6b3..2363df773 100644 --- a/man/midpoint_fy.Rd +++ b/man/midpoint_fy.Rd @@ -27,15 +27,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/next_fy.Rd b/man/next_fy.Rd index 19e1193f4..7524c5f11 100644 --- a/man/next_fy.Rd +++ b/man/next_fy.Rd @@ -27,15 +27,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, -\code{\link{start_fy_quarter}()}, \code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()}, \code{\link{start_next_fy_quarter}()} } \concept{date functions} diff --git a/man/start_fy.Rd b/man/start_fy.Rd index 4996bfb72..9951af2ec 100644 --- a/man/start_fy.Rd +++ b/man/start_fy.Rd @@ -27,8 +27,8 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, diff --git a/man/start_fy_quarter.Rd b/man/start_fy_quarter.Rd index f5729dcb0..9936736a8 100644 --- a/man/start_fy_quarter.Rd +++ b/man/start_fy_quarter.Rd @@ -26,8 +26,8 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, diff --git a/man/start_next_fy_quarter.Rd b/man/start_next_fy_quarter.Rd index 098f0bf73..fdac297a7 100644 --- a/man/start_next_fy_quarter.Rd +++ b/man/start_next_fy_quarter.Rd @@ -26,15 +26,15 @@ Other date functions: \code{\link{compute_mid_year_age}()}, \code{\link{convert_date_to_numeric}()}, \code{\link{convert_numeric_to_date}()}, -\code{\link{end_fy_quarter}()}, \code{\link{end_fy}()}, +\code{\link{end_fy_quarter}()}, \code{\link{end_next_fy_quarter}()}, \code{\link{fy_interval}()}, \code{\link{is_date_in_fyyear}()}, \code{\link{last_date_month}()}, \code{\link{midpoint_fy}()}, \code{\link{next_fy}()}, -\code{\link{start_fy_quarter}()}, -\code{\link{start_fy}()} +\code{\link{start_fy}()}, +\code{\link{start_fy_quarter}()} } \concept{date functions} From a634ea74a511d4cee207bcc256fb5b7078c094d1 Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Tue, 13 Feb 2024 11:59:37 +0000 Subject: [PATCH 30/54] Style code --- R/process_extract_homelessness.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/process_extract_homelessness.R b/R/process_extract_homelessness.R index 3b9756183..04d7082e7 100644 --- a/R/process_extract_homelessness.R +++ b/R/process_extract_homelessness.R @@ -147,7 +147,7 @@ process_extract_homelessness <- function( if (!is.null(completeness_data)) { filtered_data <- data %>% dplyr::left_join(completeness_data, - by = c("year", "sending_local_authority_name") + by = c("year", "sending_local_authority_name") ) %>% dplyr::filter( dplyr::between(.data[["pct_complete_all"]], 0.90, 1.05) | From 14cde166bffd7d1d9ac77c8732407fe17b5268d0 Mon Sep 17 00:00:00 2001 From: Jennit07 <67372904+Jennit07@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:06:50 +0000 Subject: [PATCH 31/54] Bug - deal with missing variables (#914) * Add missing sc variables for no sc data * Fix code for including `_inc_dna` variables * Remove commented line --- R/add_hri_variables.R | 2 +- R/aggregate_by_chi.R | 4 ++-- R/create_episode_file.R | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/R/add_hri_variables.R b/R/add_hri_variables.R index 710324646..519ce3694 100644 --- a/R/add_hri_variables.R +++ b/R/add_hri_variables.R @@ -82,7 +82,7 @@ add_hri_variables <- function( "mh_episodes", "gls_episodes", "op_newcons_attendances", - # op_newcons_dnas, + "op_newcons_dnas", "ae_attendances", "pis_paid_items", "ooh_cases" diff --git a/R/aggregate_by_chi.R b/R/aggregate_by_chi.R index 8d9dff96d..6f5032242 100644 --- a/R/aggregate_by_chi.R +++ b/R/aggregate_by_chi.R @@ -89,6 +89,7 @@ aggregate_by_chi <- function(episode_file, exclude_sc_var = FALSE) { "episodes", "beddays", "cost", + "_dnas", "attendances", "attend", "contacts", @@ -109,8 +110,7 @@ aggregate_by_chi <- function(episode_file, exclude_sc_var = FALSE) { vars_start_with( episode_file, "sds_option" - ), - "health_net_cost_inc_dnas" + ) ) cols4 <- cols4[!(cols4 %in% "ch_cis_episodes")] if (exclude_sc_var) { diff --git a/R/create_episode_file.R b/R/create_episode_file.R index 493d71bd3..a9503e83c 100644 --- a/R/create_episode_file.R +++ b/R/create_episode_file.R @@ -143,8 +143,9 @@ create_episode_file <- function( episode_file <- episode_file %>% dplyr::mutate( ch_chi_cis = NA, - sc_id_cis = NA, + ch_sc_id_cis = NA, ch_name = NA, + ch_postcode = NA, ch_adm_reason = NA, ch_provider = NA, ch_nursing = NA, @@ -159,7 +160,9 @@ create_episode_file <- function( hc_cost_q4 = NA, hc_provider = NA, hc_reablement = NA, - sds_option_4 = NA, + person_id = NA, + sc_latest_submission = NA, + sc_send_lca = NA, sc_living_alone = NA, sc_support_from_unpaid_carer = NA, sc_social_worker = NA, From 625402b52f717b1f6b35344f7fb1ebaf4a9cecff Mon Sep 17 00:00:00 2001 From: Jennit07 <67372904+Jennit07@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:07:48 +0000 Subject: [PATCH 32/54] Bug - Fix get pop path failing and preventing the indiv file from running. (#913) Fix bug - pop file paths breaking indiv file --- R/add_keep_population_flag.R | 2 +- R/get_lookup_paths.R | 2 +- Rmarkdown/costs_district_nursing.Rmd | 2 +- tests/testthat/test-get_lookup_paths.R | 8 +++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/R/add_keep_population_flag.R b/R/add_keep_population_flag.R index 6050b278f..d418ac18c 100644 --- a/R/add_keep_population_flag.R +++ b/R/add_keep_population_flag.R @@ -15,7 +15,7 @@ add_keep_population_flag <- function(individual_file, year) { } else { ## Obtain the population estimates for Locality AgeGroup and Gender. pop_estimates <- - readr::read_rds(get_datazone_pop_path("DataZone2011_pop_est_2011_2021.rds")) %>% + readr::read_rds(get_pop_path(type = "datazone")) %>% dplyr::select(year, datazone2011, sex, age0:age90plus) # Step 1: Obtain the population estimates for Locality, AgeGroup, and Gender diff --git a/R/get_lookup_paths.R b/R/get_lookup_paths.R index fe35a7d2f..7df5c52e2 100644 --- a/R/get_lookup_paths.R +++ b/R/get_lookup_paths.R @@ -126,7 +126,7 @@ get_pop_path <- function(file_name = NULL, "intzone" ~ stringr::str_glue("IntZone_pop_est_2011_\\d+?\\.{ext}") ) - datazone_pop_path <- get_file_path( + pop_path <- get_file_path( directory = pop_dir, file_name = file_name, ext = ext, diff --git a/Rmarkdown/costs_district_nursing.Rmd b/Rmarkdown/costs_district_nursing.Rmd index e3c9bba13..fb198bccb 100644 --- a/Rmarkdown/costs_district_nursing.Rmd +++ b/Rmarkdown/costs_district_nursing.Rmd @@ -75,7 +75,7 @@ dn_raw_costs_contacts <- left_join(dn_raw_contacts, # Of the two HSCPs, Argyll and Bute provides the # District Nursing data which is 27% of the population. -population_lookup <- read_file(get_datazone_pop_path("HSCP2019_pop_est_1981_2021.rds")) %>% +population_lookup <- read_file(get_pop_path(type = "datazone")) %>% # Select only the HSCPs for NHS Highland & years since 2015 filter( hscp2019 %in% c("S37000004", "S37000016"), diff --git a/tests/testthat/test-get_lookup_paths.R b/tests/testthat/test-get_lookup_paths.R index c56752b03..29d538cc1 100644 --- a/tests/testthat/test-get_lookup_paths.R +++ b/tests/testthat/test-get_lookup_paths.R @@ -48,13 +48,11 @@ test_that("SIMD file path returns as expected", { test_that("population estimates file path returns as expected", { suppressMessages({ - expect_s3_class(get_datazone_pop_path(), "fs_path") + expect_s3_class(get_pop_path(type = "datazone"), "fs_path") - expect_equal(fs::path_ext(get_datazone_pop_path()), "rds") + expect_equal(fs::path_ext(get_pop_path(type = "datazone")), "rds") - expect_match(get_datazone_pop_path(), "DataZone2011_pop_est_2001_\\d+?") - - expect_true(fs::file_exists(get_datazone_pop_path())) + expect_true(fs::file_exists(get_pop_path(type = "datazone"))) }) }) From 36c5e74ed28444a7f44eff390bd96009bb0f0b51 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Fri, 16 Feb 2024 09:21:13 +0000 Subject: [PATCH 33/54] correct file hscp file path --- Rmarkdown/costs_district_nursing.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rmarkdown/costs_district_nursing.Rmd b/Rmarkdown/costs_district_nursing.Rmd index fb198bccb..59b8353f8 100644 --- a/Rmarkdown/costs_district_nursing.Rmd +++ b/Rmarkdown/costs_district_nursing.Rmd @@ -75,7 +75,7 @@ dn_raw_costs_contacts <- left_join(dn_raw_contacts, # Of the two HSCPs, Argyll and Bute provides the # District Nursing data which is 27% of the population. -population_lookup <- read_file(get_pop_path(type = "datazone")) %>% +population_lookup <- read_file(get_pop_path(type = "hscp")) %>% # Select only the HSCPs for NHS Highland & years since 2015 filter( hscp2019 %in% c("S37000004", "S37000016"), From ad629b27676d6b24b1d0f4552a6ce78c50e3996d Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Mon, 26 Feb 2024 10:48:28 +0000 Subject: [PATCH 34/54] Update process_sc_all_home_care.R A small issue was identified when running targets. Linked with changes to the function `fix_sc_end_dates()` --- R/process_sc_all_home_care.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/process_sc_all_home_care.R b/R/process_sc_all_home_care.R index bc3d3bdfc..0083bedaa 100644 --- a/R/process_sc_all_home_care.R +++ b/R/process_sc_all_home_care.R @@ -28,7 +28,7 @@ process_sc_all_home_care <- function( hc_service_end_date = fix_sc_end_dates( .data$hc_service_start_date, .data$hc_service_end_date, - .data$period + .data$hc_period_end_date ) ) From 640548bfc6a1ef5a6f6435c4fbbc3f2207f2d5bf Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Mon, 26 Feb 2024 11:06:19 +0000 Subject: [PATCH 35/54] Update process_sc_all_alarms_telecare.R --- R/process_sc_all_alarms_telecare.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/process_sc_all_alarms_telecare.R b/R/process_sc_all_alarms_telecare.R index bc417a8cd..e40e93241 100644 --- a/R/process_sc_all_alarms_telecare.R +++ b/R/process_sc_all_alarms_telecare.R @@ -41,7 +41,7 @@ process_sc_all_alarms_telecare <- function( service_end_date := fix_sc_end_dates( service_start_date, service_end_date, - period + period_end_date ) ] From e0da70ca8b66b5485be3fad9c1d97dcda5c948e9 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Mon, 26 Feb 2024 13:08:29 +0000 Subject: [PATCH 36/54] remove duplicate columns --- R/process_sc_all_alarms_telecare.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/process_sc_all_alarms_telecare.R b/R/process_sc_all_alarms_telecare.R index e40e93241..08cb9faa7 100644 --- a/R/process_sc_all_alarms_telecare.R +++ b/R/process_sc_all_alarms_telecare.R @@ -113,7 +113,6 @@ process_sc_all_alarms_telecare <- function( sending_location = data.table::last(sending_location), social_care_id = data.table::last(social_care_id), sc_latest_submission = data.table::last(period), - record_keydate1 = data.table::last(record_keydate1), record_keydate2 = data.table::last(record_keydate2), smrtype = data.table::last(smrtype), pkg_count = data.table::last(pkg_count), From 9699394500d1d11bd27c425ad6482732d9e502ee Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Tue, 27 Feb 2024 08:56:36 +0000 Subject: [PATCH 37/54] Fix targets (#892) * fix sc_client_lookup sc_send_lca * fix an issue of get_pop_path * Style code * fix the rest of get_pop_path from get_datazone_pop_path * Update documentation * fix sc_send_lca * add missing year column * explicitly specify the argument year to avoid corruption of targets * Update documentation * new data pipeline with targets remove create_individual_files from targets and append it to run_targets script * minor changes * Style code * undo sc_send_lca bit * Update targets scripts * Remove top level targets scripts --------- Co-authored-by: lizihao-anu Co-authored-by: Megan McNicol <43570769+SwiftySalmon@users.noreply.github.com> Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> Co-authored-by: Jennifer Thom --- R/aggregate_by_chi.R | 3 ++- R/create_individual_file.R | 6 ++--- Run_SLF_Files_targets/run_targets_1718.R | 14 +++++++++++ Run_SLF_Files_targets/run_targets_1819.R | 14 +++++++++++ Run_SLF_Files_targets/run_targets_1920.R | 14 +++++++++++ Run_SLF_Files_targets/run_targets_2021.R | 14 +++++++++++ Run_SLF_Files_targets/run_targets_2122.R | 14 +++++++++++ Run_SLF_Files_targets/run_targets_2223.R | 14 +++++++++++ Run_SLF_Files_targets/run_targets_2324.R | 14 +++++++++++ _targets.R | 32 ++++++++++++------------ man/add_all_columns.Rd | 4 ++- man/aggregate_by_chi.Rd | 4 ++- 12 files changed, 125 insertions(+), 22 deletions(-) diff --git a/R/aggregate_by_chi.R b/R/aggregate_by_chi.R index 6f5032242..d207b221a 100644 --- a/R/aggregate_by_chi.R +++ b/R/aggregate_by_chi.R @@ -7,7 +7,7 @@ #' @importFrom data.table .SD #' #' @inheritParams create_individual_file -aggregate_by_chi <- function(episode_file, exclude_sc_var = FALSE) { +aggregate_by_chi <- function(episode_file, year, exclude_sc_var = FALSE) { cli::cli_alert_info("Aggregate by CHI function started at {Sys.time()}") # Convert to data.table @@ -187,6 +187,7 @@ aggregate_by_chi <- function(episode_file, exclude_sc_var = FALSE) { individual_file_cols5[, chi := NULL], individual_file_cols6[, chi := NULL] ) + individual_file <- individual_file[, year := year] # convert back to tibble return(dplyr::as_tibble(individual_file)) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index 70066b42d..e5b0fd2fd 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -73,7 +73,7 @@ create_individual_file <- function( ))) %>% remove_blank_chi() %>% add_cij_columns() %>% - add_all_columns() + add_all_columns(year = year) if (!check_year_valid(year, type = c("ch", "hc", "at", "sds"))) { individual_file <- individual_file %>% @@ -82,7 +82,7 @@ create_individual_file <- function( individual_file <- individual_file %>% aggregate_ch_episodes() %>% clean_up_ch(year) %>% - aggregate_by_chi(exclude_sc_var = FALSE) + aggregate_by_chi(year = year, exclude_sc_var = FALSE) } individual_file <- individual_file %>% @@ -202,7 +202,7 @@ add_cij_columns <- function(episode_file) { #' of prefixed column names created based on some condition. #' @family individual_file #' @inheritParams create_individual_file -add_all_columns <- function(episode_file) { +add_all_columns <- function(episode_file, year) { cli::cli_alert_info("Add all columns function started at {Sys.time()}") episode_file <- episode_file %>% diff --git a/Run_SLF_Files_targets/run_targets_1718.R b/Run_SLF_Files_targets/run_targets_1718.R index ebc58895f..ac03edd3f 100644 --- a/Run_SLF_Files_targets/run_targets_1718.R +++ b/Run_SLF_Files_targets/run_targets_1718.R @@ -1,4 +1,18 @@ library(targets) + +year <- "1718" + +# use targets for the process until testing episode files tar_make_future( + # it does not recognise `contains(year)` names = (targets::contains("1718")) ) + +# use targets to create individual files due to RAM limit +library(createslf) + +episode_file <- arrow::read_parquet(get_slf_episode_path(year)) + +# Run individual file +create_individual_file(episode_file, year = year) %>% + process_tests_individual_file(year = year) diff --git a/Run_SLF_Files_targets/run_targets_1819.R b/Run_SLF_Files_targets/run_targets_1819.R index 83bbcedef..b60728359 100644 --- a/Run_SLF_Files_targets/run_targets_1819.R +++ b/Run_SLF_Files_targets/run_targets_1819.R @@ -1,4 +1,18 @@ library(targets) + +year <- "1819" + +# use targets for the process until testing episode files tar_make_future( + # it does not recognise `contains(year)` names = (targets::contains("1819")) ) + +# use targets to create individual files due to RAM limit +library(createslf) + +episode_file <- arrow::read_parquet(get_slf_episode_path(year)) + +# Run individual file +create_individual_file(episode_file, year = year) %>% + process_tests_individual_file(year = year) diff --git a/Run_SLF_Files_targets/run_targets_1920.R b/Run_SLF_Files_targets/run_targets_1920.R index 1640d1900..897ee0b7a 100644 --- a/Run_SLF_Files_targets/run_targets_1920.R +++ b/Run_SLF_Files_targets/run_targets_1920.R @@ -1,4 +1,18 @@ library(targets) + +year <- "1920" + +# use targets for the process until testing episode files tar_make_future( + # it does not recognise `contains(year)` names = (targets::contains("1920")) ) + +# use targets to create individual files due to RAM limit +library(createslf) + +episode_file <- arrow::read_parquet(get_slf_episode_path(year)) + +# Run individual file +create_individual_file(episode_file, year = year) %>% + process_tests_individual_file(year = year) diff --git a/Run_SLF_Files_targets/run_targets_2021.R b/Run_SLF_Files_targets/run_targets_2021.R index 80749e81a..53333c014 100644 --- a/Run_SLF_Files_targets/run_targets_2021.R +++ b/Run_SLF_Files_targets/run_targets_2021.R @@ -1,4 +1,18 @@ library(targets) + +year <- "2021" + +# use targets for the process until testing episode files tar_make_future( + # it does not recognise `contains(year)` names = (targets::contains("2021")) ) + +# use targets to create individual files due to RAM limit +library(createslf) + +episode_file <- arrow::read_parquet(get_slf_episode_path(year)) + +# Run individual file +create_individual_file(episode_file, year = year) %>% + process_tests_individual_file(year = year) diff --git a/Run_SLF_Files_targets/run_targets_2122.R b/Run_SLF_Files_targets/run_targets_2122.R index aa95d7b24..457fe33e7 100644 --- a/Run_SLF_Files_targets/run_targets_2122.R +++ b/Run_SLF_Files_targets/run_targets_2122.R @@ -1,4 +1,18 @@ library(targets) + +year <- "2122" + +# use targets for the process until testing episode files tar_make_future( + # it does not recognise `contains(year)` names = (targets::contains("2122")) ) + +# use targets to create individual files due to RAM limit +library(createslf) + +episode_file <- arrow::read_parquet(get_slf_episode_path(year)) + +# Run individual file +create_individual_file(episode_file, year = year) %>% + process_tests_individual_file(year = year) diff --git a/Run_SLF_Files_targets/run_targets_2223.R b/Run_SLF_Files_targets/run_targets_2223.R index 2ded7d5fd..fc851f3f7 100644 --- a/Run_SLF_Files_targets/run_targets_2223.R +++ b/Run_SLF_Files_targets/run_targets_2223.R @@ -1,4 +1,18 @@ library(targets) + +year <- "2223" + +# use targets for the process until testing episode files tar_make_future( + # it does not recognise `contains(year)` names = (targets::contains("2223")) ) + +# use targets to create individual files due to RAM limit +library(createslf) + +episode_file <- arrow::read_parquet(get_slf_episode_path(year)) + +# Run individual file +create_individual_file(episode_file, year = year) %>% + process_tests_individual_file(year = year) diff --git a/Run_SLF_Files_targets/run_targets_2324.R b/Run_SLF_Files_targets/run_targets_2324.R index b875984f4..3b4c9b240 100644 --- a/Run_SLF_Files_targets/run_targets_2324.R +++ b/Run_SLF_Files_targets/run_targets_2324.R @@ -1,4 +1,18 @@ library(targets) + +year <- "2324" + +# use targets for the process until testing episode files tar_make_future( + # it does not recognise `contains(year)` names = (targets::contains("2324")) ) + +# use targets to create individual files due to RAM limit +library(createslf) + +episode_file <- arrow::read_parquet(get_slf_episode_path(year)) + +# Run individual file +create_individual_file(episode_file, year = year) %>% + process_tests_individual_file(year = year) diff --git a/_targets.R b/_targets.R index 81adbf7c2..15d2584bb 100644 --- a/_targets.R +++ b/_targets.R @@ -591,24 +591,24 @@ list( data = episode_file, year = year ) - ), - tar_target( - individual_file, - create_individual_file( - episode_file = episode_file, - year = year, - homelessness_lookup = homelessness_lookup, - write_to_disk = write_to_disk - ) - ), - tar_target( - individual_file_tests, - process_tests_individual_file( - data = individual_file, - year = year - ) ) # , # tar_target( + # individual_file, + # create_individual_file( + # episode_file = episode_file, + # year = year, + # homelessness_lookup = homelessness_lookup, + # write_to_disk = write_to_disk + # ) + # ), + # tar_target( + # individual_file_tests, + # process_tests_individual_file( + # data = individual_file, + # year = year + # ) + # ) # , + # tar_target( # episode_file_dataset, # arrow::write_dataset( # dataset = episode_file, diff --git a/man/add_all_columns.Rd b/man/add_all_columns.Rd index 345a59e01..deb1594b3 100644 --- a/man/add_all_columns.Rd +++ b/man/add_all_columns.Rd @@ -4,10 +4,12 @@ \alias{add_all_columns} \title{Add all columns} \usage{ -add_all_columns(episode_file) +add_all_columns(episode_file, year) } \arguments{ \item{episode_file}{Tibble containing episodic data.} + +\item{year}{The year to process, in FY format.} } \description{ Add new columns based on SMRType and recid which follow a pattern diff --git a/man/aggregate_by_chi.Rd b/man/aggregate_by_chi.Rd index 84c9c0ad3..16bf7d792 100644 --- a/man/aggregate_by_chi.Rd +++ b/man/aggregate_by_chi.Rd @@ -4,10 +4,12 @@ \alias{aggregate_by_chi} \title{Aggregate by CHI} \usage{ -aggregate_by_chi(episode_file, exclude_sc_var = FALSE) +aggregate_by_chi(episode_file, year, exclude_sc_var = FALSE) } \arguments{ \item{episode_file}{Tibble containing episodic data.} + +\item{year}{The year to process, in FY format.} } \description{ Aggregate episode file by CHI to convert into From f5c744875f0620f11677d93d1117aebc46207288 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Tue, 27 Feb 2024 11:34:28 +0000 Subject: [PATCH 38/54] remove cases that start date is later than end date --- R/process_sc_all_home_care.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/process_sc_all_home_care.R b/R/process_sc_all_home_care.R index 0083bedaa..3ada9a2da 100644 --- a/R/process_sc_all_home_care.R +++ b/R/process_sc_all_home_care.R @@ -16,6 +16,7 @@ process_sc_all_home_care <- function( sc_demog_lookup, write_to_disk = TRUE) { replaced_dates <- data %>% + dplyr::filter(.data$hc_start_date_after_period_end_date != 1) %>% dplyr::mutate( hc_service_end_date = fix_sc_missing_end_dates( .data$hc_service_end_date, From b7e713834f8f09f762ce197c2ede78ddee436a9c Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 27 Feb 2024 15:35:13 +0000 Subject: [PATCH 39/54] Update Refs for March24 SLF update --- R/00-update_refs.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/00-update_refs.R b/R/00-update_refs.R index 9d119e74e..2052b938f 100644 --- a/R/00-update_refs.R +++ b/R/00-update_refs.R @@ -7,7 +7,7 @@ #' #' @family initialisation latest_update <- function() { - "Dec_2023" + "Mar_2024" } #' Previous update @@ -61,7 +61,7 @@ previous_update <- function(months_ago = 3L, override = NULL) { #' #' @family initialisation get_dd_period <- function() { - "Jul16_Sep23" + "Jul16_Dec23" } #' The latest financial year for Cost uplift setting From 6c2b6d5b49eabfcfe2326d9d4053e9803b3a1da6 Mon Sep 17 00:00:00 2001 From: rachev04 Date: Fri, 17 May 2024 14:56:51 +0100 Subject: [PATCH 40/54] Added function for get_all_slf_deaths_lookup_path --- R/get_slf_lookup_paths.R | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/R/get_slf_lookup_paths.R b/R/get_slf_lookup_paths.R index 1be1c9781..d96087347 100644 --- a/R/get_slf_lookup_paths.R +++ b/R/get_slf_lookup_paths.R @@ -49,6 +49,7 @@ get_slf_gpprac_path <- function(update = latest_update(), ...) { #' @family slf lookup file path #' @seealso [get_file_path()] for the generic function. get_slf_deaths_lookup_path <- function(year, ...) { + # Review the naming convention of this path and file slf_deaths_lookup_path <- get_file_path( directory = fs::path(get_slf_dir(), "Deaths"), file_name = stringr::str_glue("slf_deaths_lookup_{year}.parquet"), @@ -58,6 +59,31 @@ get_slf_deaths_lookup_path <- function(year, ...) { return(slf_deaths_lookup_path) } +#' SLF death dates File Path +#' +#' @description Get the full path to the BOXI NRS Deaths lookup file for all financial years +#' +#' @inheritParams get_boxi_extract_path +#' @param ... additional arguments passed to [get_file_path()] +#' @param year financial year e.g. "1920" +#' +#' @export +#' @family slf lookup file path +#' @seealso [get_file_path()] for the generic function. + +get_all_slf_deaths_lookup_path <- function(update = latest_update()) { + # Note this name is very similar to the existing slf_deaths_lookup_path which returnsthe path for + # the processed BOXI extract for each financial year. This function will return the combined financial + # years lookup i.e. all years put together. + all_slf_deaths_lookup_path <- get_file_path( + directory = fs::path(get_slf_dir(), "Deaths", + file_name = stringr::str_glue("all_slf_deaths_lookup_{update}.parquet")) + ) + + return(all_slf_deaths_lookup_path) + +} + #' SLF CHI Deaths File Path #' #' @description Get the full path to the CHI deaths file From d47c0a19b4d37670f2037fbf903f2d7c83ba1a19 Mon Sep 17 00:00:00 2001 From: rchlv Date: Fri, 17 May 2024 13:58:49 +0000 Subject: [PATCH 41/54] Update documentation --- NAMESPACE | 1 + man/get_all_slf_deaths_lookup_path.Rd | 27 +++++++++++++++++++++++++++ man/get_slf_ch_name_lookup_path.Rd | 1 + man/get_slf_chi_deaths_path.Rd | 1 + man/get_slf_deaths_lookup_path.Rd | 1 + man/get_slf_gpprac_path.Rd | 1 + man/get_slf_postcode_path.Rd | 1 + 7 files changed, 33 insertions(+) create mode 100644 man/get_all_slf_deaths_lookup_path.Rd diff --git a/NAMESPACE b/NAMESPACE index 4606cf3f2..1c13740ef 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,7 @@ export(end_fy_quarter) export(end_next_fy_quarter) export(find_latest_file) export(fy_interval) +export(get_all_slf_deaths_lookup_path) export(get_boxi_extract_path) export(get_ch_costs_path) export(get_dd_path) diff --git a/man/get_all_slf_deaths_lookup_path.Rd b/man/get_all_slf_deaths_lookup_path.Rd new file mode 100644 index 000000000..93c8a2840 --- /dev/null +++ b/man/get_all_slf_deaths_lookup_path.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_slf_lookup_paths.R +\name{get_all_slf_deaths_lookup_path} +\alias{get_all_slf_deaths_lookup_path} +\title{SLF death dates File Path} +\usage{ +get_all_slf_deaths_lookup_path(update = latest_update()) +} +\arguments{ +\item{...}{additional arguments passed to \code{\link[=get_file_path]{get_file_path()}}} + +\item{year}{financial year e.g. "1920"} +} +\description{ +Get the full path to the BOXI NRS Deaths lookup file for all financial years +} +\seealso{ +\code{\link[=get_file_path]{get_file_path()}} for the generic function. + +Other slf lookup file path: +\code{\link{get_slf_ch_name_lookup_path}()}, +\code{\link{get_slf_chi_deaths_path}()}, +\code{\link{get_slf_deaths_lookup_path}()}, +\code{\link{get_slf_gpprac_path}()}, +\code{\link{get_slf_postcode_path}()} +} +\concept{slf lookup file path} diff --git a/man/get_slf_ch_name_lookup_path.Rd b/man/get_slf_ch_name_lookup_path.Rd index 1f687308a..2660bbeab 100644 --- a/man/get_slf_ch_name_lookup_path.Rd +++ b/man/get_slf_ch_name_lookup_path.Rd @@ -22,6 +22,7 @@ has official Care Home names and addresses provided by the Care Inspectorate. \code{\link[=get_file_path]{get_file_path()}} for the generic function. Other slf lookup file path: +\code{\link{get_all_slf_deaths_lookup_path}()}, \code{\link{get_slf_chi_deaths_path}()}, \code{\link{get_slf_deaths_lookup_path}()}, \code{\link{get_slf_gpprac_path}()}, diff --git a/man/get_slf_chi_deaths_path.Rd b/man/get_slf_chi_deaths_path.Rd index c598a3c24..0db72d9d3 100644 --- a/man/get_slf_chi_deaths_path.Rd +++ b/man/get_slf_chi_deaths_path.Rd @@ -22,6 +22,7 @@ Get the full path to the CHI deaths file \code{\link[=get_file_path]{get_file_path()}} for the generic function. Other slf lookup file path: +\code{\link{get_all_slf_deaths_lookup_path}()}, \code{\link{get_slf_ch_name_lookup_path}()}, \code{\link{get_slf_deaths_lookup_path}()}, \code{\link{get_slf_gpprac_path}()}, diff --git a/man/get_slf_deaths_lookup_path.Rd b/man/get_slf_deaths_lookup_path.Rd index 5b1306c91..307c38ad3 100644 --- a/man/get_slf_deaths_lookup_path.Rd +++ b/man/get_slf_deaths_lookup_path.Rd @@ -21,6 +21,7 @@ Get the full path to the SLF deaths lookup file \code{\link[=get_file_path]{get_file_path()}} for the generic function. Other slf lookup file path: +\code{\link{get_all_slf_deaths_lookup_path}()}, \code{\link{get_slf_ch_name_lookup_path}()}, \code{\link{get_slf_chi_deaths_path}()}, \code{\link{get_slf_gpprac_path}()}, diff --git a/man/get_slf_gpprac_path.Rd b/man/get_slf_gpprac_path.Rd index c17403f7d..1fb23116f 100644 --- a/man/get_slf_gpprac_path.Rd +++ b/man/get_slf_gpprac_path.Rd @@ -21,6 +21,7 @@ Get the full path to the SLF GP practice lookup \code{\link[=get_file_path]{get_file_path()}} for the generic function. Other slf lookup file path: +\code{\link{get_all_slf_deaths_lookup_path}()}, \code{\link{get_slf_ch_name_lookup_path}()}, \code{\link{get_slf_chi_deaths_path}()}, \code{\link{get_slf_deaths_lookup_path}()}, diff --git a/man/get_slf_postcode_path.Rd b/man/get_slf_postcode_path.Rd index ed007c7c5..f37678695 100644 --- a/man/get_slf_postcode_path.Rd +++ b/man/get_slf_postcode_path.Rd @@ -21,6 +21,7 @@ Get the full path to the SLF Postcode lookup \code{\link[=get_file_path]{get_file_path()}} for the generic function. Other slf lookup file path: +\code{\link{get_all_slf_deaths_lookup_path}()}, \code{\link{get_slf_ch_name_lookup_path}()}, \code{\link{get_slf_chi_deaths_path}()}, \code{\link{get_slf_deaths_lookup_path}()}, From ec0c5ef84b443972f081d7adee032da59874e85f Mon Sep 17 00:00:00 2001 From: rchlv Date: Fri, 17 May 2024 14:03:59 +0000 Subject: [PATCH 42/54] Style code --- R/get_slf_lookup_paths.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/get_slf_lookup_paths.R b/R/get_slf_lookup_paths.R index d96087347..898fe4c74 100644 --- a/R/get_slf_lookup_paths.R +++ b/R/get_slf_lookup_paths.R @@ -77,11 +77,11 @@ get_all_slf_deaths_lookup_path <- function(update = latest_update()) { # years lookup i.e. all years put together. all_slf_deaths_lookup_path <- get_file_path( directory = fs::path(get_slf_dir(), "Deaths", - file_name = stringr::str_glue("all_slf_deaths_lookup_{update}.parquet")) + file_name = stringr::str_glue("all_slf_deaths_lookup_{update}.parquet") + ) ) return(all_slf_deaths_lookup_path) - } #' SLF CHI Deaths File Path From 8a704e01d71d1a7acf7d43fe7bfce66b7faf04c8 Mon Sep 17 00:00:00 2001 From: rachev04 Date: Mon, 20 May 2024 16:08:40 +0100 Subject: [PATCH 43/54] Add vars for activity after death flag --- R/create_episode_file.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/create_episode_file.R b/R/create_episode_file.R index f6443291f..53238eac5 100644 --- a/R/create_episode_file.R +++ b/R/create_episode_file.R @@ -79,6 +79,8 @@ create_episode_file <- function( "hscp", "datazone2011", "attendance_status", + "death_date", + "deceased", "deathdiag1", "deathdiag2", "deathdiag3", @@ -139,6 +141,7 @@ create_episode_file <- function( year, slf_deaths_lookup ) %>% + add_activity_after_death_flag(year, deaths_data = read_file(all_slf_deaths_lookup_path())) %>% load_ep_file_vars(year) if (!check_year_valid(year, type = c("ch", "hc", "at", "sds"))) { From 746d65d0314c2f728044e674c739a86b035bfdf3 Mon Sep 17 00:00:00 2001 From: rachev04 Date: Mon, 20 May 2024 16:11:00 +0100 Subject: [PATCH 44/54] Add activity after death flag --- R/add_activity_after_death_flag.R | 166 ++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 R/add_activity_after_death_flag.R diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R new file mode 100644 index 000000000..c82c177e0 --- /dev/null +++ b/R/add_activity_after_death_flag.R @@ -0,0 +1,166 @@ +#' Match on BOXI NRS death dates to process activity after death flag +#' +#' @description Match on CHI number where available in the episode file, and add date of death from the BOXI NRS lookup. +#' Create new activity after death flag +#' +#' @param data episode files +#' @param year financial year, e.g. '1920' +#' @param deaths_data The death data for the year +#' +#' @return data flagged if activity after death +add_activity_after_death_flag <- function( + data, + year, + deaths_data = read_file(all_slf_deaths_lookup_path())) { + # Match on BOXI NRS deaths lookup for records without chi + data <- data %>% + dplyr::filter(!is.na(chi) | chi != "") %>% + dplyr::left_join( + deaths_data, + by = "chi", + suffix = c("", "_boxi") + ) + + + # Check and print error message for records which already have a death_date in the episode file, but this doesn't match the BOXI death date + check_death_date_match <- data %>% + dplyr::filter(death_date != death_date_boxi) + + if (nrow(check_death_date_match) != 0) { + warning("There were records in the episode file which already have a death_date, but does not match the BOXI NRS death date.") + } + + + # Check and print error message for records which have a record_keydate1 after their BOXI death date + check_keydate1_death_date <- data %>% + dplyr::filter(record_keydate1 > death_date_boxi) + + if (nrow(check_death_date_match) != 0) { + warning("There were records in the episode file which have a record_keydate1 after the BOXI NRS death date.") + } + + + flag_data <- data %>% + dplyr::mutate( + flag_keydate1 = if_else(record_keydate1 > death_date_boxi, 1, 0), + flag_keydate2 = if_else(record_keydate2 > death_date_boxi, 1, 0), + + # Next flag records with 'ongoing' activity after date of death (available from BOXI) if keydate2 is missing and the death date occurs in + # in the current or a previous financial year. + flag_keydate2_missing = if_else(((is.na(record_keydate2) | record_keydate2 == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0), + + # Also flag records without a death_date in the episode file, but the BOXI death date occurs in the current or a previous financial year. + flag_deathdate_missing = if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0)) %>% + # These should be flagged by one of the two lines of code above, but in these cases, we will also fill in the blank death date if appropriate + + # Search all variables beginning with "flag_" for value "1" and create new variable to flag cases where 1 is present + # Multiplying by 1 changes flag from true/false to 1/0 + dplyr::mutate(activity_after_death = purrr::pmap_dbl(select(., contains("flag_")), + ~any(grepl("^1$", c(...)), + na.rm = TRUE) *1)) + + + # Check and print error message for records which already are TRUE for the deceased variable in the episode file, but this doesn't match the + # BOXI deceased variable + check_deceased_match <- flag_data %>% + dplyr::filter(deceased != deceased_boxi) + + if (nrow(check_deceased_match) != 0) { + warning("There were records in the episode file which have a deceased variable which does not match the BOXI NRS deceased variable") + } + + + # Fill in date of death if missing in the episode file but available in BOXI lookup, due to historic dates of death not being carried + # over from previous financial years + flag_data <- flag_data %>% + dplyr::mutate(death_date = if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 1, 2), "-03-31"))), death_date_boxi, death_date)) %>% + dplyr::mutate(deceased = if_else(((is.na(deceased) | deceased == "") & (deceased_boxi == TRUE)), deceased_boxi, deceased)) %>% + + # Remove temporary flag variables used to create activity after death flag and fill in missing death_date + dplyr::select(-c(death_date_boxi, deceased_boxi, flag_keydate1, flag_keydate2, flag_keydate2_missing, flag_deathdate_missing)) + + + return(flag_data) + +} + + +#' Create and read SLF Deaths lookup from processed BOXI NRS deaths extracts +#' +#' #' @description The BOXI NRS deaths extract lookup should be created after the extract files for all years have been processed, +# but before an episode file has been produced. Therefore, all BOXI NRS years should be run before running episode files. +#' +#' @param file_path Path to the BOXI NRS file for each financial year - may not use this +#' @param year The year to process, in FY format - may not use this +#' +#' @param write_to_disk (optional) Should the data be written to disk default is +#' `TRUE` i.e. write the data to disk. +#' +#' @return the final data as a [tibble][tibble::tibble-package]. +#' @export +#' +#' +#' +# Read data------------------------------------------------ +process_deaths_lookup <- function(update = latest_update(), ...) { + all_boxi_deaths <- read_file(get_slf_deaths_lookup_path("1415")) %>% + rbind(read_file(get_slf_deaths_lookup_path("1516"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("1617"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("1718"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("1819"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("1920"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("2021"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("2122"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("2223"))) %>% + rbind(read_file(get_slf_deaths_lookup_path("2324"))) %>% + # Can this be automated to pick up files starting with name "get_slf_deaths_lookup_path"? + + # Remove rows with missing or blank CHI number - could also use na.omit? + #na.omit(all_boxi_deaths) + dplyr::filter(!is.na(chi) | chi != "") + + # Check all CHI numbers are valid + chi_check <- all_boxi_deaths %>% + dplyr::pull(.data$chi) %>% + phsmethods::chi_check() + + if (!all(chi_check %in% c("Valid CHI", "Missing (Blank)", "Missing (NA)"))) { + # There are some Missing (NA) values in the extracts, but I have excluded them above as they cannot be matched to episode file + stop("There were bad CHI numbers in the BOXI NRS file") + } + + # Check and print error message for chi numbers with more than one death date + duplicates <- all_boxi_deaths %>% + janitor::get_dupes(.data$chi) + + if (nrow(duplicates) != 0) { + # There are some Missing (NA) values in the extracts, but I have excluded them above as they cannot be matched to episode file + warning("There were duplicate death dates in the BOXI NRS file.") + } + + + # We decided to include duplicates as unable to determine which is correct date (unless IT can tell us, however, they don't seem to know + # the process well enough), and overall impact will be negligible + # Get anon_chi and use this to match onto episode file later + all_boxi_deaths <- all_boxi_deaths %>% + slfhelper::get_anon_chi() + + # Save out duplicates for further investigation if needed (as anon_chi) + if (!missing(duplicates)) { + write_file( + duplicates, + fs::path(get_slf_dir(), "Deaths", + file_name = stringr::str_glue("slf_deaths_duplicates_{update}.parquet")) + ) + } + + # Maybe save as its own function + # Write the all BOXI NRS deaths lookup file to disk, so this can be used to populate activity after death flag in each episode file + if (write_to_disk) { + all_boxi_deaths %>% + write_file(get_all_slf_deaths_lookup_path()) + } + + return(all_boxi_deaths) + +} From 861bb2b03643ce5feee867d887b9581d7e6c95d6 Mon Sep 17 00:00:00 2001 From: rachev04 Date: Mon, 20 May 2024 16:19:29 +0100 Subject: [PATCH 45/54] Join data back to episode file --- R/add_activity_after_death_flag.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index c82c177e0..64930b3d3 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -79,8 +79,17 @@ add_activity_after_death_flag <- function( # Remove temporary flag variables used to create activity after death flag and fill in missing death_date dplyr::select(-c(death_date_boxi, deceased_boxi, flag_keydate1, flag_keydate2, flag_keydate2_missing, flag_deathdate_missing)) + # Match activity after death flag back to episode file + final_data <- data %>% + dplyr::left_join( + flag_data, + by = "chi", + na_matches = "never", + relationship = "many-to-one" + ) + - return(flag_data) + return(final_data) } From 8ea7941cf3259b43c1d4a2e8b11c33a74ee11011 Mon Sep 17 00:00:00 2001 From: rchlv Date: Mon, 20 May 2024 15:24:20 +0000 Subject: [PATCH 46/54] Style code --- R/add_activity_after_death_flag.R | 36 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 64930b3d3..55777859d 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -16,9 +16,9 @@ add_activity_after_death_flag <- function( data <- data %>% dplyr::filter(!is.na(chi) | chi != "") %>% dplyr::left_join( - deaths_data, - by = "chi", - suffix = c("", "_boxi") + deaths_data, + by = "chi", + suffix = c("", "_boxi") ) @@ -26,7 +26,7 @@ add_activity_after_death_flag <- function( check_death_date_match <- data %>% dplyr::filter(death_date != death_date_boxi) - if (nrow(check_death_date_match) != 0) { + if (nrow(check_death_date_match) != 0) { warning("There were records in the episode file which already have a death_date, but does not match the BOXI NRS death date.") } @@ -35,7 +35,7 @@ add_activity_after_death_flag <- function( check_keydate1_death_date <- data %>% dplyr::filter(record_keydate1 > death_date_boxi) - if (nrow(check_death_date_match) != 0) { + if (nrow(check_death_date_match) != 0) { warning("There were records in the episode file which have a record_keydate1 after the BOXI NRS death date.") } @@ -50,14 +50,18 @@ add_activity_after_death_flag <- function( flag_keydate2_missing = if_else(((is.na(record_keydate2) | record_keydate2 == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0), # Also flag records without a death_date in the episode file, but the BOXI death date occurs in the current or a previous financial year. - flag_deathdate_missing = if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0)) %>% - # These should be flagged by one of the two lines of code above, but in these cases, we will also fill in the blank death date if appropriate + flag_deathdate_missing = if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0) + ) %>% + # These should be flagged by one of the two lines of code above, but in these cases, we will also fill in the blank death date if appropriate # Search all variables beginning with "flag_" for value "1" and create new variable to flag cases where 1 is present # Multiplying by 1 changes flag from true/false to 1/0 - dplyr::mutate(activity_after_death = purrr::pmap_dbl(select(., contains("flag_")), - ~any(grepl("^1$", c(...)), - na.rm = TRUE) *1)) + dplyr::mutate(activity_after_death = purrr::pmap_dbl( + select(., contains("flag_")), + ~ any(grepl("^1$", c(...)), + na.rm = TRUE + ) * 1 + )) # Check and print error message for records which already are TRUE for the deceased variable in the episode file, but this doesn't match the @@ -65,7 +69,7 @@ add_activity_after_death_flag <- function( check_deceased_match <- flag_data %>% dplyr::filter(deceased != deceased_boxi) - if (nrow(check_deceased_match) != 0) { + if (nrow(check_deceased_match) != 0) { warning("There were records in the episode file which have a deceased variable which does not match the BOXI NRS deceased variable") } @@ -75,8 +79,7 @@ add_activity_after_death_flag <- function( flag_data <- flag_data %>% dplyr::mutate(death_date = if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 1, 2), "-03-31"))), death_date_boxi, death_date)) %>% dplyr::mutate(deceased = if_else(((is.na(deceased) | deceased == "") & (deceased_boxi == TRUE)), deceased_boxi, deceased)) %>% - - # Remove temporary flag variables used to create activity after death flag and fill in missing death_date + # Remove temporary flag variables used to create activity after death flag and fill in missing death_date dplyr::select(-c(death_date_boxi, deceased_boxi, flag_keydate1, flag_keydate2, flag_keydate2_missing, flag_deathdate_missing)) # Match activity after death flag back to episode file @@ -90,7 +93,6 @@ add_activity_after_death_flag <- function( return(final_data) - } @@ -125,7 +127,7 @@ process_deaths_lookup <- function(update = latest_update(), ...) { # Can this be automated to pick up files starting with name "get_slf_deaths_lookup_path"? # Remove rows with missing or blank CHI number - could also use na.omit? - #na.omit(all_boxi_deaths) + # na.omit(all_boxi_deaths) dplyr::filter(!is.na(chi) | chi != "") # Check all CHI numbers are valid @@ -159,7 +161,8 @@ process_deaths_lookup <- function(update = latest_update(), ...) { write_file( duplicates, fs::path(get_slf_dir(), "Deaths", - file_name = stringr::str_glue("slf_deaths_duplicates_{update}.parquet")) + file_name = stringr::str_glue("slf_deaths_duplicates_{update}.parquet") + ) ) } @@ -171,5 +174,4 @@ process_deaths_lookup <- function(update = latest_update(), ...) { } return(all_boxi_deaths) - } From b8589ad83aa81f5cf7e178a328cff357240094c4 Mon Sep 17 00:00:00 2001 From: rchlv Date: Mon, 20 May 2024 15:24:37 +0000 Subject: [PATCH 47/54] Update documentation --- NAMESPACE | 1 + man/add_activity_after_death_flag.Rd | 26 ++++++++++++++++++++++++++ man/process_deaths_lookup.Rd | 22 ++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 man/add_activity_after_death_flag.Rd create mode 100644 man/process_deaths_lookup.Rd diff --git a/NAMESPACE b/NAMESPACE index 1c13740ef..691a056db 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -92,6 +92,7 @@ export(process_costs_ch_rmd) export(process_costs_dn_rmd) export(process_costs_gp_ooh_rmd) export(process_costs_hc_rmd) +export(process_deaths_lookup) export(process_extract_acute) export(process_extract_ae) export(process_extract_alarms_telecare) diff --git a/man/add_activity_after_death_flag.Rd b/man/add_activity_after_death_flag.Rd new file mode 100644 index 000000000..f13a47ddf --- /dev/null +++ b/man/add_activity_after_death_flag.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/add_activity_after_death_flag.R +\name{add_activity_after_death_flag} +\alias{add_activity_after_death_flag} +\title{Match on BOXI NRS death dates to process activity after death flag} +\usage{ +add_activity_after_death_flag( + data, + year, + deaths_data = read_file(all_slf_deaths_lookup_path()) +) +} +\arguments{ +\item{data}{episode files} + +\item{year}{financial year, e.g. '1920'} + +\item{deaths_data}{The death data for the year} +} +\value{ +data flagged if activity after death +} +\description{ +Match on CHI number where available in the episode file, and add date of death from the BOXI NRS lookup. +Create new activity after death flag +} diff --git a/man/process_deaths_lookup.Rd b/man/process_deaths_lookup.Rd new file mode 100644 index 000000000..3780e48a7 --- /dev/null +++ b/man/process_deaths_lookup.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/add_activity_after_death_flag.R +\name{process_deaths_lookup} +\alias{process_deaths_lookup} +\title{Create and read SLF Deaths lookup from processed BOXI NRS deaths extracts} +\usage{ +process_deaths_lookup(update = latest_update(), ...) +} +\arguments{ +\item{file_path}{Path to the BOXI NRS file for each financial year - may not use this} + +\item{year}{The year to process, in FY format - may not use this} + +\item{write_to_disk}{(optional) Should the data be written to disk default is +\code{TRUE} i.e. write the data to disk.} +} +\value{ +the final data as a \link[tibble:tibble-package]{tibble}. +} +\description{ +#' @description The BOXI NRS deaths extract lookup should be created after the extract files for all years have been processed, +} From e3a646f2f8a47db94c44462a48e6d9bbbf094642 Mon Sep 17 00:00:00 2001 From: marjom02 Date: Mon, 27 May 2024 11:45:06 +0100 Subject: [PATCH 48/54] changes to activity after death flag --- R/add_activity_after_death_flag.R | 53 +++++++++++++++++-------------- R/get_slf_lookup_paths.R | 13 ++++---- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 55777859d..6be5c5f73 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -11,19 +11,22 @@ add_activity_after_death_flag <- function( data, year, - deaths_data = read_file(all_slf_deaths_lookup_path())) { - # Match on BOXI NRS deaths lookup for records without chi - data <- data %>% + deaths_data = read_file(get_all_slf_deaths_lookup_path())) { + death_joined <- data %>% + dplyr::select(year, chi, record_keydate1, record_keydate2, death_date, deceased) %>% dplyr::filter(!is.na(chi) | chi != "") %>% dplyr::left_join( - deaths_data, + deaths_data %>% + slfhelper::get_chi(), by = "chi", suffix = c("", "_boxi") - ) + ) %>% + dplyr::filter(deceased == TRUE | deceased_boxi == TRUE) %>% + dplyr::distinct() # Check and print error message for records which already have a death_date in the episode file, but this doesn't match the BOXI death date - check_death_date_match <- data %>% + check_death_date_match <- death_joined %>% dplyr::filter(death_date != death_date_boxi) if (nrow(check_death_date_match) != 0) { @@ -32,7 +35,7 @@ add_activity_after_death_flag <- function( # Check and print error message for records which have a record_keydate1 after their BOXI death date - check_keydate1_death_date <- data %>% + check_keydate1_death_date <- death_joined %>% dplyr::filter(record_keydate1 > death_date_boxi) if (nrow(check_death_date_match) != 0) { @@ -40,24 +43,24 @@ add_activity_after_death_flag <- function( } - flag_data <- data %>% + flag_data <- death_joined %>% dplyr::mutate( - flag_keydate1 = if_else(record_keydate1 > death_date_boxi, 1, 0), - flag_keydate2 = if_else(record_keydate2 > death_date_boxi, 1, 0), + flag_keydate1 = dplyr::if_else(record_keydate1 > death_date_boxi, 1, 0), + flag_keydate2 = dplyr::if_else(record_keydate2 > death_date_boxi, 1, 0), # Next flag records with 'ongoing' activity after date of death (available from BOXI) if keydate2 is missing and the death date occurs in # in the current or a previous financial year. - flag_keydate2_missing = if_else(((is.na(record_keydate2) | record_keydate2 == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0), + flag_keydate2_missing = dplyr::if_else(((is.na(record_keydate2) | record_keydate2 == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0), # Also flag records without a death_date in the episode file, but the BOXI death date occurs in the current or a previous financial year. - flag_deathdate_missing = if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0) + flag_deathdate_missing = dplyr::if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0) ) %>% # These should be flagged by one of the two lines of code above, but in these cases, we will also fill in the blank death date if appropriate # Search all variables beginning with "flag_" for value "1" and create new variable to flag cases where 1 is present # Multiplying by 1 changes flag from true/false to 1/0 dplyr::mutate(activity_after_death = purrr::pmap_dbl( - select(., contains("flag_")), + dplyr::select(., contains("flag_")), ~ any(grepl("^1$", c(...)), na.rm = TRUE ) * 1 @@ -77,18 +80,17 @@ add_activity_after_death_flag <- function( # Fill in date of death if missing in the episode file but available in BOXI lookup, due to historic dates of death not being carried # over from previous financial years flag_data <- flag_data %>% - dplyr::mutate(death_date = if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 1, 2), "-03-31"))), death_date_boxi, death_date)) %>% - dplyr::mutate(deceased = if_else(((is.na(deceased) | deceased == "") & (deceased_boxi == TRUE)), deceased_boxi, deceased)) %>% + dplyr::filter(activity_after_death == 1) %>% # Remove temporary flag variables used to create activity after death flag and fill in missing death_date - dplyr::select(-c(death_date_boxi, deceased_boxi, flag_keydate1, flag_keydate2, flag_keydate2_missing, flag_deathdate_missing)) + dplyr::select(year, chi, record_keydate1, record_keydate2, activity_after_death) %>% + dplyr::distinct() # Match activity after death flag back to episode file final_data <- data %>% dplyr::left_join( flag_data, - by = "chi", - na_matches = "never", - relationship = "many-to-one" + by = c("year", "chi", "record_keydate1", "record_keydate2"), + na_matches = "never" ) @@ -113,7 +115,8 @@ add_activity_after_death_flag <- function( #' #' # Read data------------------------------------------------ -process_deaths_lookup <- function(update = latest_update(), ...) { +process_deaths_lookup <- function(update = latest_update(), + write_to_disk = TRUE, ...) { all_boxi_deaths <- read_file(get_slf_deaths_lookup_path("1415")) %>% rbind(read_file(get_slf_deaths_lookup_path("1516"))) %>% rbind(read_file(get_slf_deaths_lookup_path("1617"))) %>% @@ -125,7 +128,7 @@ process_deaths_lookup <- function(update = latest_update(), ...) { rbind(read_file(get_slf_deaths_lookup_path("2223"))) %>% rbind(read_file(get_slf_deaths_lookup_path("2324"))) %>% # Can this be automated to pick up files starting with name "get_slf_deaths_lookup_path"? - + slfhelper::get_chi() %>% # Remove rows with missing or blank CHI number - could also use na.omit? # na.omit(all_boxi_deaths) dplyr::filter(!is.na(chi) | chi != "") @@ -169,8 +172,12 @@ process_deaths_lookup <- function(update = latest_update(), ...) { # Maybe save as its own function # Write the all BOXI NRS deaths lookup file to disk, so this can be used to populate activity after death flag in each episode file if (write_to_disk) { - all_boxi_deaths %>% - write_file(get_all_slf_deaths_lookup_path()) + write_file( + all_boxi_deaths, + fs::path(get_slf_dir(), "Deaths", + file_name = stringr::str_glue("anon-all_slf_deaths_lookup_{update}.parquet") + ) + ) } return(all_boxi_deaths) diff --git a/R/get_slf_lookup_paths.R b/R/get_slf_lookup_paths.R index d7e68c494..3a1b932be 100644 --- a/R/get_slf_lookup_paths.R +++ b/R/get_slf_lookup_paths.R @@ -63,7 +63,7 @@ get_slf_deaths_lookup_path <- function(year, ...) { # Review the naming convention of this path and file slf_deaths_lookup_path <- get_file_path( directory = fs::path(get_slf_dir(), "Deaths"), - file_name = stringr::str_glue("slf_deaths_lookup_{year}.parquet"), + file_name = stringr::str_glue("anon-slf_deaths_lookup_{year}.parquet"), ... ) @@ -82,19 +82,20 @@ get_slf_deaths_lookup_path <- function(year, ...) { #' @family slf lookup file path #' @seealso [get_file_path()] for the generic function. -get_all_slf_deaths_lookup_path <- function(update = latest_update()) { +get_all_slf_deaths_lookup_path <- function(update = latest_update(), ...) { # Note this name is very similar to the existing slf_deaths_lookup_path which returnsthe path for # the processed BOXI extract for each financial year. This function will return the combined financial # years lookup i.e. all years put together. all_slf_deaths_lookup_path <- get_file_path( - directory = fs::path(get_slf_dir(), "Deaths", - file_name = stringr::str_glue("all_slf_deaths_lookup_{update}.parquet") - ) + directory = fs::path(get_slf_dir(), "Deaths"), + file_name = stringr::str_glue("anon-all_slf_deaths_lookup_{update}.parquet"), + ... ) - return(all_slf_deaths_lookup_path) } + + #' SLF CHI Deaths File Path #' #' @description Get the full path to the CHI deaths file From 5e5c71a290e42cdc9a038b52c9ed2e1f3ff14781 Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Mon, 27 May 2024 10:46:49 +0000 Subject: [PATCH 49/54] Update documentation --- man/add_activity_after_death_flag.Rd | 2 +- man/get_all_slf_deaths_lookup_path.Rd | 2 +- man/process_deaths_lookup.Rd | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/man/add_activity_after_death_flag.Rd b/man/add_activity_after_death_flag.Rd index f13a47ddf..67d3cb1ad 100644 --- a/man/add_activity_after_death_flag.Rd +++ b/man/add_activity_after_death_flag.Rd @@ -7,7 +7,7 @@ add_activity_after_death_flag( data, year, - deaths_data = read_file(all_slf_deaths_lookup_path()) + deaths_data = read_file(get_all_slf_deaths_lookup_path()) ) } \arguments{ diff --git a/man/get_all_slf_deaths_lookup_path.Rd b/man/get_all_slf_deaths_lookup_path.Rd index 93c8a2840..dd5291c2d 100644 --- a/man/get_all_slf_deaths_lookup_path.Rd +++ b/man/get_all_slf_deaths_lookup_path.Rd @@ -4,7 +4,7 @@ \alias{get_all_slf_deaths_lookup_path} \title{SLF death dates File Path} \usage{ -get_all_slf_deaths_lookup_path(update = latest_update()) +get_all_slf_deaths_lookup_path(update = latest_update(), ...) } \arguments{ \item{...}{additional arguments passed to \code{\link[=get_file_path]{get_file_path()}}} diff --git a/man/process_deaths_lookup.Rd b/man/process_deaths_lookup.Rd index 3780e48a7..8e9ec1199 100644 --- a/man/process_deaths_lookup.Rd +++ b/man/process_deaths_lookup.Rd @@ -4,15 +4,15 @@ \alias{process_deaths_lookup} \title{Create and read SLF Deaths lookup from processed BOXI NRS deaths extracts} \usage{ -process_deaths_lookup(update = latest_update(), ...) +process_deaths_lookup(update = latest_update(), write_to_disk = TRUE, ...) } \arguments{ +\item{write_to_disk}{(optional) Should the data be written to disk default is +\code{TRUE} i.e. write the data to disk.} + \item{file_path}{Path to the BOXI NRS file for each financial year - may not use this} \item{year}{The year to process, in FY format - may not use this} - -\item{write_to_disk}{(optional) Should the data be written to disk default is -\code{TRUE} i.e. write the data to disk.} } \value{ the final data as a \link[tibble:tibble-package]{tibble}. From 5ed7cf35269703b466d2af720aec4f9a85b862f9 Mon Sep 17 00:00:00 2001 From: Megan McNicol <43570769+SwiftySalmon@users.noreply.github.com> Date: Mon, 27 May 2024 15:07:08 +0100 Subject: [PATCH 50/54] Update R/add_activity_after_death_flag.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/add_activity_after_death_flag.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 6be5c5f73..e7910b8f1 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -60,7 +60,7 @@ add_activity_after_death_flag <- function( # Search all variables beginning with "flag_" for value "1" and create new variable to flag cases where 1 is present # Multiplying by 1 changes flag from true/false to 1/0 dplyr::mutate(activity_after_death = purrr::pmap_dbl( - dplyr::select(., contains("flag_")), + dplyr::select(., tidyselect::contains("flag_")), ~ any(grepl("^1$", c(...)), na.rm = TRUE ) * 1 From 8faac6e22ecd291b4af505eaa5308fdfe55d2efd Mon Sep 17 00:00:00 2001 From: Megan McNicol <43570769+SwiftySalmon@users.noreply.github.com> Date: Mon, 27 May 2024 15:07:30 +0100 Subject: [PATCH 51/54] Update R/add_activity_after_death_flag.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/add_activity_after_death_flag.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index e7910b8f1..43ac1bd73 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -13,7 +13,7 @@ add_activity_after_death_flag <- function( year, deaths_data = read_file(get_all_slf_deaths_lookup_path())) { death_joined <- data %>% - dplyr::select(year, chi, record_keydate1, record_keydate2, death_date, deceased) %>% + dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$death_date, .data$deceased) %>% dplyr::filter(!is.na(chi) | chi != "") %>% dplyr::left_join( deaths_data %>% From 1406ff02a80b1145484ba4634ca4dbf209251e50 Mon Sep 17 00:00:00 2001 From: marjom02 Date: Mon, 27 May 2024 15:30:04 +0100 Subject: [PATCH 52/54] added .data$ to variables --- R/add_activity_after_death_flag.R | 33 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 43ac1bd73..2acad3bbe 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -11,23 +11,26 @@ add_activity_after_death_flag <- function( data, year, - deaths_data = read_file(get_all_slf_deaths_lookup_path())) { + deaths_data = read_file(get_all_slf_deaths_lookup_path()) %>% + slfhelper::get_chi() + + ) { + death_joined <- data %>% dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$death_date, .data$deceased) %>% - dplyr::filter(!is.na(chi) | chi != "") %>% + dplyr::filter(!is.na(.data$chi) | .data$chi != "") %>% dplyr::left_join( - deaths_data %>% - slfhelper::get_chi(), + deaths_data, by = "chi", suffix = c("", "_boxi") ) %>% - dplyr::filter(deceased == TRUE | deceased_boxi == TRUE) %>% + dplyr::filter(.data$deceased == TRUE | .data$deceased_boxi == TRUE) %>% dplyr::distinct() # Check and print error message for records which already have a death_date in the episode file, but this doesn't match the BOXI death date check_death_date_match <- death_joined %>% - dplyr::filter(death_date != death_date_boxi) + dplyr::filter(.data$death_date != .data$death_date_boxi) if (nrow(check_death_date_match) != 0) { warning("There were records in the episode file which already have a death_date, but does not match the BOXI NRS death date.") @@ -36,7 +39,7 @@ add_activity_after_death_flag <- function( # Check and print error message for records which have a record_keydate1 after their BOXI death date check_keydate1_death_date <- death_joined %>% - dplyr::filter(record_keydate1 > death_date_boxi) + dplyr::filter(.data$record_keydate1 > .data$death_date_boxi) if (nrow(check_death_date_match) != 0) { warning("There were records in the episode file which have a record_keydate1 after the BOXI NRS death date.") @@ -45,15 +48,15 @@ add_activity_after_death_flag <- function( flag_data <- death_joined %>% dplyr::mutate( - flag_keydate1 = dplyr::if_else(record_keydate1 > death_date_boxi, 1, 0), - flag_keydate2 = dplyr::if_else(record_keydate2 > death_date_boxi, 1, 0), + flag_keydate1 = dplyr::if_else(.data$record_keydate1 > .data$death_date_boxi, 1, 0), + flag_keydate2 = dplyr::if_else(.data$record_keydate2 > .data$death_date_boxi, 1, 0), # Next flag records with 'ongoing' activity after date of death (available from BOXI) if keydate2 is missing and the death date occurs in # in the current or a previous financial year. - flag_keydate2_missing = dplyr::if_else(((is.na(record_keydate2) | record_keydate2 == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0), + flag_keydate2_missing = dplyr::if_else(((is.na(.data$record_keydate2) | .data$record_keydate2 == "") & (.data$death_date_boxi <= paste0("20", substr(.data$year, 3, 4), "-03-31"))), 1, 0), # Also flag records without a death_date in the episode file, but the BOXI death date occurs in the current or a previous financial year. - flag_deathdate_missing = dplyr::if_else(((is.na(death_date) | death_date == "") & (death_date_boxi <= paste0("20", substr(year, 3, 4), "-03-31"))), 1, 0) + flag_deathdate_missing = dplyr::if_else(((is.na(.data$death_date) | .data$death_date == "") & (.data$death_date_boxi <= paste0("20", substr(.data$year, 3, 4), "-03-31"))), 1, 0) ) %>% # These should be flagged by one of the two lines of code above, but in these cases, we will also fill in the blank death date if appropriate @@ -70,7 +73,7 @@ add_activity_after_death_flag <- function( # Check and print error message for records which already are TRUE for the deceased variable in the episode file, but this doesn't match the # BOXI deceased variable check_deceased_match <- flag_data %>% - dplyr::filter(deceased != deceased_boxi) + dplyr::filter(.data$deceased != .data$deceased_boxi) if (nrow(check_deceased_match) != 0) { warning("There were records in the episode file which have a deceased variable which does not match the BOXI NRS deceased variable") @@ -80,9 +83,9 @@ add_activity_after_death_flag <- function( # Fill in date of death if missing in the episode file but available in BOXI lookup, due to historic dates of death not being carried # over from previous financial years flag_data <- flag_data %>% - dplyr::filter(activity_after_death == 1) %>% + dplyr::filter(.data$activity_after_death == 1) %>% # Remove temporary flag variables used to create activity after death flag and fill in missing death_date - dplyr::select(year, chi, record_keydate1, record_keydate2, activity_after_death) %>% + dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$activity_after_death) %>% dplyr::distinct() # Match activity after death flag back to episode file @@ -131,7 +134,7 @@ process_deaths_lookup <- function(update = latest_update(), slfhelper::get_chi() %>% # Remove rows with missing or blank CHI number - could also use na.omit? # na.omit(all_boxi_deaths) - dplyr::filter(!is.na(chi) | chi != "") + dplyr::filter(!is.na(.data$chi) | chi != "") # Check all CHI numbers are valid chi_check <- all_boxi_deaths %>% From c535165231f5cea2757a0988d8e84ff9cbcda090 Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Mon, 27 May 2024 14:33:29 +0000 Subject: [PATCH 53/54] Update documentation --- man/add_activity_after_death_flag.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/add_activity_after_death_flag.Rd b/man/add_activity_after_death_flag.Rd index 67d3cb1ad..36eafe7bd 100644 --- a/man/add_activity_after_death_flag.Rd +++ b/man/add_activity_after_death_flag.Rd @@ -7,7 +7,7 @@ add_activity_after_death_flag( data, year, - deaths_data = read_file(get_all_slf_deaths_lookup_path()) + deaths_data = read_file(get_all_slf_deaths_lookup_path()) \%>\% slfhelper::get_chi() ) } \arguments{ From edb4782badd22438f56cb0389ae72140b20fa883 Mon Sep 17 00:00:00 2001 From: SwiftySalmon Date: Mon, 27 May 2024 14:33:44 +0000 Subject: [PATCH 54/54] Style code --- R/add_activity_after_death_flag.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 2acad3bbe..f68c7c9f4 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -12,10 +12,7 @@ add_activity_after_death_flag <- function( data, year, deaths_data = read_file(get_all_slf_deaths_lookup_path()) %>% - slfhelper::get_chi() - - ) { - + slfhelper::get_chi()) { death_joined <- data %>% dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$death_date, .data$deceased) %>% dplyr::filter(!is.na(.data$chi) | .data$chi != "") %>%