From 7393d38e30b24bfa87c2453d8d0cd6f13933f17c Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Fri, 26 Jul 2024 16:46:27 +0100 Subject: [PATCH 01/17] Update lookup to use anon-chi --- R/process_lookup_deaths.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index 9a5c21974..a4d8fd7ea 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -17,11 +17,12 @@ process_slf_deaths_lookup <- function( year, nrs_deaths_data = read_file( get_source_extract_path(year, "deaths"), - col_select = c("chi", "record_keydate1") + col_select = c("anon_chi", "record_keydate1") ), chi_deaths_data = read_file(get_slf_chi_deaths_path()), write_to_disk = TRUE) { slf_deaths_lookup <- nrs_deaths_data %>% + slfhelper::get_chi() %>% # Only modification over 'raw' NRS is to keep the earliest death date dplyr::select("chi", "record_keydate1") %>% dplyr::arrange(.data$record_keydate1) %>% From 4f5fd8b270c23087523eb89dab26279fcdfc7612 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Fri, 26 Jul 2024 16:47:46 +0100 Subject: [PATCH 02/17] Remove redundant code This uses the NRS Weekly dates and if this is blank use the chi death date. This methodology is wrong. We want to use the monthly nrs boxi date by default and chi date if there is an issue --- R/process_it_chi_deaths.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/R/process_it_chi_deaths.R b/R/process_it_chi_deaths.R index 85354880b..192d72043 100644 --- a/R/process_it_chi_deaths.R +++ b/R/process_it_chi_deaths.R @@ -17,10 +17,6 @@ process_it_chi_deaths <- function(data, write_to_disk = TRUE) { dplyr::desc(.data$death_date_chi) ) %>% dplyr::distinct(.data$chi, .keep_all = TRUE) %>% - # Use the NRS death_date unless it isn't there - dplyr::mutate( - death_date = dplyr::coalesce(.data$death_date_nrs, .data$death_date_chi) - ) %>% slfhelper::get_anon_chi() if (write_to_disk) { From 7e14e1c93541e7d34344647001b6b1bbbbf55075 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Fri, 26 Jul 2024 15:50:38 +0000 Subject: [PATCH 03/17] Update documentation --- man/process_slf_deaths_lookup.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/process_slf_deaths_lookup.Rd b/man/process_slf_deaths_lookup.Rd index 8ad103a2a..bf69d3952 100644 --- a/man/process_slf_deaths_lookup.Rd +++ b/man/process_slf_deaths_lookup.Rd @@ -7,7 +7,7 @@ process_slf_deaths_lookup( year, nrs_deaths_data = read_file(get_source_extract_path(year, "deaths"), col_select = - c("chi", "record_keydate1")), + c("anon_chi", "record_keydate1")), chi_deaths_data = read_file(get_slf_chi_deaths_path()), write_to_disk = TRUE ) From cbd504f8ee0f21fa03985597922eb88654d597ab Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 29 Jul 2024 12:12:15 +0100 Subject: [PATCH 04/17] remove weekly nrs date variable --- R/process_it_chi_deaths.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/process_it_chi_deaths.R b/R/process_it_chi_deaths.R index 192d72043..cfca32e0f 100644 --- a/R/process_it_chi_deaths.R +++ b/R/process_it_chi_deaths.R @@ -17,6 +17,9 @@ process_it_chi_deaths <- function(data, write_to_disk = TRUE) { dplyr::desc(.data$death_date_chi) ) %>% dplyr::distinct(.data$chi, .keep_all = TRUE) %>% + # remove death_date_nrs as this is the nrs weekly unvalidated data and we should not use this. + # the boxi nrs death date is more reliable as this is provided monthly and is validated. + dplyr::select(.data$chi, .data$death_date_chi) %>% slfhelper::get_anon_chi() if (write_to_disk) { From b5121f521dc8daf1f8e042ac4edbf7b5cb723a3b Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 29 Jul 2024 12:13:15 +0100 Subject: [PATCH 05/17] Use boxi nrs date or chi death date --- R/process_lookup_deaths.R | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index a4d8fd7ea..c33acf7d1 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -21,17 +21,27 @@ process_slf_deaths_lookup <- function( ), chi_deaths_data = read_file(get_slf_chi_deaths_path()), write_to_disk = TRUE) { - slf_deaths_lookup <- nrs_deaths_data %>% + boxi_nrs_data <- nrs_deaths_data %>% slfhelper::get_chi() %>% # Only modification over 'raw' NRS is to keep the earliest death date dplyr::select("chi", "record_keydate1") %>% dplyr::arrange(.data$record_keydate1) %>% - dplyr::distinct(.data$chi, .keep_all = TRUE) %>% + dplyr::distinct(.data$chi, .keep_all = TRUE) + + # create slf deaths lookup + slf_deaths_lookup <- chi_deaths %>% + # join boxi nrs data to chi deaths + dplyr::right_join(boxi_nrs_data, by = "chi") %>% + # If the BOXI NRS date does not match the chi death date, use the chi death date + # should now have one row per chi with deaths within the FY dplyr::mutate( - death_date = .data$record_keydate1, + death_date = dplyr::if_else(.data$record_keydate1 != .data$death_date_chi, + .data$death_date_chi, .data$record_keydate1 + ), deceased = TRUE, .keep = "unused" ) %>% + # save anon chi on disk slfhelper::get_anon_chi() if (write_to_disk) { From f9cb8c7804b23757d199b5e6ca4ac0aef8b4f8a3 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 29 Jul 2024 14:01:19 +0100 Subject: [PATCH 06/17] Use `get_combined_slf_deaths_path` --- R/add_activity_after_death_flag.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 39c894681..fdede9001 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -183,9 +183,7 @@ process_combined_deaths_lookup <- function(update = latest_update(), if (write_to_disk) { write_file( all_boxi_deaths, - fs::path(get_slf_dir(), "Deaths", - file_name = stringr::str_glue("anon-combined_slf_deaths_lookup_{update}.parquet") - ) + get_combined_slf_deaths_lookup_path() ) } From aa9d647823666cf0cb449b8c72cc2e89f4c577e9 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 29 Jul 2024 15:22:42 +0100 Subject: [PATCH 07/17] add catch for NAs --- R/process_lookup_deaths.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index c33acf7d1..9f070ca9b 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -38,6 +38,7 @@ process_slf_deaths_lookup <- function( death_date = dplyr::if_else(.data$record_keydate1 != .data$death_date_chi, .data$death_date_chi, .data$record_keydate1 ), + death_date = dplyr::if_else(is.na(.data$death_date_chi), .data$record_keydate1, .data$death_date), deceased = TRUE, .keep = "unused" ) %>% From eabd8e8d4f0c5433b8fd6f88cbebf989b57c7d15 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Mon, 29 Jul 2024 15:31:31 +0100 Subject: [PATCH 08/17] add notes --- R/process_lookup_deaths.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index 9f070ca9b..d50d64ca9 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -38,6 +38,7 @@ process_slf_deaths_lookup <- function( death_date = dplyr::if_else(.data$record_keydate1 != .data$death_date_chi, .data$death_date_chi, .data$record_keydate1 ), + # check in case boxi and chi dates do not match due to a NA value death_date = dplyr::if_else(is.na(.data$death_date_chi), .data$record_keydate1, .data$death_date), deceased = TRUE, .keep = "unused" From b4de3d871129230d48f5d45f160dc2d1f034ddb0 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 30 Jul 2024 09:29:04 +0100 Subject: [PATCH 09/17] Fix typo --- R/process_lookup_deaths.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index d50d64ca9..53dd6c819 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -29,7 +29,7 @@ process_slf_deaths_lookup <- function( dplyr::distinct(.data$chi, .keep_all = TRUE) # create slf deaths lookup - slf_deaths_lookup <- chi_deaths %>% + slf_deaths_lookup <- chi_deaths_data %>% # join boxi nrs data to chi deaths dplyr::right_join(boxi_nrs_data, by = "chi") %>% # If the BOXI NRS date does not match the chi death date, use the chi death date From 5925ebac81a955c9ff53a88c64bbb85a678a1835 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 30 Jul 2024 13:40:49 +0100 Subject: [PATCH 10/17] remove redundant code --- R/process_lookup_deaths.R | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index 53dd6c819..b478a55e7 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -30,16 +30,19 @@ process_slf_deaths_lookup <- function( # create slf deaths lookup slf_deaths_lookup <- chi_deaths_data %>% + slfhelper::get_chi() %>% + dplyr::mutate(fy = phsmethods::extract_fin_year(death_date_chi), + fy = as.character(paste0(substr(fy, 3, 4), substr(fy,6,7))) + ) %>% + # Filter the chi death dates to the FY as the lookup is by FY + dplyr::filter(fy == year) %>% # join boxi nrs data to chi deaths - dplyr::right_join(boxi_nrs_data, by = "chi") %>% - # If the BOXI NRS date does not match the chi death date, use the chi death date - # should now have one row per chi with deaths within the FY + dplyr::full_join(boxi_nrs_data, by = "chi") %>% + # use the BOXI NRS death date by default, but if it's missing, use the chi death date. dplyr::mutate( - death_date = dplyr::if_else(.data$record_keydate1 != .data$death_date_chi, + death_date = dplyr::if_else(is.na(.data$record_keydate1), .data$death_date_chi, .data$record_keydate1 ), - # check in case boxi and chi dates do not match due to a NA value - death_date = dplyr::if_else(is.na(.data$death_date_chi), .data$record_keydate1, .data$death_date), deceased = TRUE, .keep = "unused" ) %>% From 99f936002dd53e24b9e2daa2f8be0d73be030ad8 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Tue, 30 Jul 2024 12:42:32 +0000 Subject: [PATCH 11/17] Style code --- R/process_lookup_deaths.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index b478a55e7..40f316a4a 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -31,9 +31,10 @@ process_slf_deaths_lookup <- function( # create slf deaths lookup slf_deaths_lookup <- chi_deaths_data %>% slfhelper::get_chi() %>% - dplyr::mutate(fy = phsmethods::extract_fin_year(death_date_chi), - fy = as.character(paste0(substr(fy, 3, 4), substr(fy,6,7))) - ) %>% + dplyr::mutate( + fy = phsmethods::extract_fin_year(death_date_chi), + fy = as.character(paste0(substr(fy, 3, 4), substr(fy, 6, 7))) + ) %>% # Filter the chi death dates to the FY as the lookup is by FY dplyr::filter(fy == year) %>% # join boxi nrs data to chi deaths From 62c90ae1e0bcd6e62b73cff85601deffe3055149 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 2 Aug 2024 18:01:34 +0100 Subject: [PATCH 12/17] add a function of combine nrs and it_chi death --- R/00-update_refs.R | 17 +++++++ R/add_deceased_flag.R | 41 +++++++++++++++++ R/get_slf_lookup_paths.R | 8 +++- R/process_lookup_deaths.R | 32 ++----------- R/process_refined_death.R | 55 ++++++++++++++++++++++ R/process_sc_all_care_home.R | 8 ++-- R/process_slf_deaths_lookup.R | 61 +++++++++++++++++++++++++ Run_SLF_Files_targets/run_all_targets.R | 4 -- _targets.R | 53 +++++++++++++-------- 9 files changed, 224 insertions(+), 55 deletions(-) create mode 100644 R/add_deceased_flag.R create mode 100644 R/process_refined_death.R create mode 100644 R/process_slf_deaths_lookup.R diff --git a/R/00-update_refs.R b/R/00-update_refs.R index 6106f17cf..c22585aaf 100644 --- a/R/00-update_refs.R +++ b/R/00-update_refs.R @@ -76,3 +76,20 @@ get_dd_period <- function() { latest_cost_year <- function() { "2223" } + +#' The year list for slf to update +#' +#' @description Get the vector of years to update slf +#' +#' @return The vector of financial years +#' +#' @export +#' +#' @family initialisation +years_to_run <- function() { + fy_start_2digit <- 17 + fy_end_2digit <- 23 + years_to_run = paste0(fy_start_2digit:fy_end_2digit, + (fy_start_2digit + 1):(fy_end_2digit + 1)) + return(years_to_run) +} diff --git a/R/add_deceased_flag.R b/R/add_deceased_flag.R new file mode 100644 index 000000000..25010cba6 --- /dev/null +++ b/R/add_deceased_flag.R @@ -0,0 +1,41 @@ +#' Create the SLF Deaths lookup +#' +#' @description Currently this just uses the NRS death dates 'as is', with no +#' corrections or modifications, it is expected that this will be expanded to +#' use the CHI deaths extract from IT as well as taking into account data in +#' the episode file to assess the validity of a death date. +#' +#' @param year The year to process, in FY format. +#' @param nrs_deaths_data NRS deaths data. +#' @param chi_deaths_data IT CHI deaths data. +#' @param write_to_disk (optional) Should the data be written to disk default is +#' `TRUE` i.e. write the data to disk. +#' +#' @return a [tibble][tibble::tibble-package] containing the episode file +#' @export +add_deceased_flag <- function( + year, + refined_death = read_file(get_combined_slf_deaths_lookup_path()) %>% slfhelper::get_chi(), + write_to_disk = TRUE) { + + # create slf deaths lookup + + dplyr::mutate( + death_date = dplyr::if_else(is.na(.data$record_keydate1), + .data$death_date_chi, .data$record_keydate1 + ), + deceased = TRUE, + .keep = "unused" + ) %>% + # save anon chi on disk + slfhelper::get_anon_chi() + + if (write_to_disk) { + write_file( + slf_deaths_lookup, + get_slf_deaths_lookup_path(year, check_mode = "write") + ) + } + + return(slf_deaths_lookup) +} diff --git a/R/get_slf_lookup_paths.R b/R/get_slf_lookup_paths.R index 2455be768..e06627e54 100644 --- a/R/get_slf_lookup_paths.R +++ b/R/get_slf_lookup_paths.R @@ -73,6 +73,10 @@ get_slf_deaths_lookup_path <- function(year, ...) { #' SLF death dates File Path #' #' @description Get the full path to the BOXI NRS Deaths lookup file for all financial years +#' Note this name is very similar to the existing slf_deaths_lookup_path +#' which returns the path for the refined_death with deceased flag for each financial year. +#' This function will return the combined financial years lookup +#' i.e. all years put together. #' #' @param ... additional arguments passed to [get_file_path()] #' @param update the update month (defaults to use [latest_update()]) @@ -80,10 +84,10 @@ get_slf_deaths_lookup_path <- function(year, ...) { #' @export #' @family slf lookup file path #' @seealso [get_file_path()] for the generic function. - get_combined_slf_deaths_lookup_path <- function(update = latest_update(), ...) { # Note this name is very similar to the existing slf_deaths_lookup_path which returns the path for - # the processed BOXI extract for each financial year. This function will return the combined financial + # the refined_death with deceased flag for each financial year. + # This function will return the combined financial # years lookup i.e. all years put together. combined_slf_deaths_lookup_path <- get_file_path( directory = fs::path(get_slf_dir(), "Deaths"), diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index 40f316a4a..ca5c6fc67 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -1,9 +1,7 @@ #' Create the SLF Deaths lookup #' -#' @description Currently this just uses the NRS death dates 'as is', with no -#' corrections or modifications, it is expected that this will be expanded to -#' use the CHI deaths extract from IT as well as taking into account data in -#' the episode file to assess the validity of a death date. +#' @description Use all-year refined death data to produce year-specific +#' slf_deaths_lookup with deceased flag added. #' #' @param year The year to process, in FY format. #' @param nrs_deaths_data NRS deaths data. @@ -15,37 +13,17 @@ #' @export process_slf_deaths_lookup <- function( year, - nrs_deaths_data = read_file( - get_source_extract_path(year, "deaths"), - col_select = c("anon_chi", "record_keydate1") - ), - chi_deaths_data = read_file(get_slf_chi_deaths_path()), + refined_death = read_file(get_combined_slf_deaths_lookup_path()), write_to_disk = TRUE) { - boxi_nrs_data <- nrs_deaths_data %>% - slfhelper::get_chi() %>% - # Only modification over 'raw' NRS is to keep the earliest death date - dplyr::select("chi", "record_keydate1") %>% - dplyr::arrange(.data$record_keydate1) %>% - dplyr::distinct(.data$chi, .keep_all = TRUE) # create slf deaths lookup - slf_deaths_lookup <- chi_deaths_data %>% + slf_deaths_lookup <- refined_death %>% slfhelper::get_chi() %>% - dplyr::mutate( - fy = phsmethods::extract_fin_year(death_date_chi), - fy = as.character(paste0(substr(fy, 3, 4), substr(fy, 6, 7))) - ) %>% # Filter the chi death dates to the FY as the lookup is by FY dplyr::filter(fy == year) %>% - # join boxi nrs data to chi deaths - dplyr::full_join(boxi_nrs_data, by = "chi") %>% # use the BOXI NRS death date by default, but if it's missing, use the chi death date. dplyr::mutate( - death_date = dplyr::if_else(is.na(.data$record_keydate1), - .data$death_date_chi, .data$record_keydate1 - ), - deceased = TRUE, - .keep = "unused" + deceased = TRUE ) %>% # save anon chi on disk slfhelper::get_anon_chi() diff --git a/R/process_refined_death.R b/R/process_refined_death.R new file mode 100644 index 000000000..d7067e91e --- /dev/null +++ b/R/process_refined_death.R @@ -0,0 +1,55 @@ +#' Process the refined death data +#' +#' @description This will process +#' year-specific BOXI NRS death file (written to disk), and +#' combine them together to get all years NRS file (Not written to disk). +#' Then join all NRS deaths with IT CHI death data +#' to get an all-year refined death file (written to disk). +#' +#' @param it_chi_deaths it chi death data +#' @param write_to_disk write the result to disk or not. +#' +#' @return refined_death The processed lookup of deaths combining NRS and IT_CHI. +#' @export +#' @family process extracts +process_refined_death <- function( + it_chi_deaths = read_file(get_slf_chi_deaths_path()), + write_to_disk = TRUE) { + years_list = years_to_run() + + nrs_all_years <- lapply(years_list, (\(year) { + read_extract_nrs_deaths(year, + get_boxi_extract_path(year, type = "deaths")) %>% + process_extract_nrs_deaths(year, + write_to_disk = write_to_disk) + })) %>% + data.table::rbindlist() + + it_chi_deaths <- it_chi_deaths %>% + dplyr::select(c("anon_chi", + "death_date_chi")) %>% + dplyr::arrange(.data$anon_chi, .keep_all = TRUE) + + refined_death <- nrs_all_years %>% + dplyr::arrange(.data$anon_chi, .keep_all = TRUE) %>% + dplyr::full_join(it_chi_deaths, by = "anon_chi") %>% + # use the BOXI NRS death date by default, but if it's missing, use the chi death date. + dplyr::mutate(death_date = dplyr::if_else( + is.na(.data$record_keydate1), + .data$death_date_chi, + .data$record_keydate1 + )) %>% + dplyr::select(anon_chi, death_date) %>% + # add fy when death happened + dplyr::mutate( + fy = phsmethods::extract_fin_year(death_date), + fy = as.character(paste0(substr(fy, 3, 4), substr(fy, 6, 7))) + ) + + if (write_to_disk) { + write_file(refined_death, + get_combined_slf_deaths_lookup_path()) + } + + return(refined_death) +} diff --git a/R/process_sc_all_care_home.R b/R/process_sc_all_care_home.R index b7c29fbc7..7b87d68f0 100644 --- a/R/process_sc_all_care_home.R +++ b/R/process_sc_all_care_home.R @@ -7,8 +7,8 @@ #' @param data The extract to process #' @param sc_demog_lookup The Social Care Demographics lookup produced by #' [process_lookup_sc_demographics()]. -#' @param it_chi_deaths_data The processed lookup of deaths from IT produced -#' with [process_it_chi_deaths()]. +#' @param refined_death The processed lookup of deaths from IT produced +#' with [process_refined_death()]. #' @param ch_name_lookup_path Path to the Care Home name Lookup Excel workbook. #' @param spd_path (Optional) Path the Scottish Postcode Directory, default is #' to use [get_spd_path()]. @@ -23,7 +23,7 @@ process_sc_all_care_home <- function( data, sc_demog_lookup = read_file(get_sc_demog_lookup_path()) %>% slfhelper::get_chi(), - it_chi_deaths_data = read_file(get_slf_chi_deaths_path()), + refined_death = read_file(get_combined_slf_deaths_lookup_path()) %>% slfhelper::get_chi(), ch_name_lookup_path = read_file(get_slf_ch_name_lookup_path()), spd_path = read_file(get_spd_path()), write_to_disk = TRUE) { @@ -207,7 +207,7 @@ process_sc_all_care_home <- function( # Compare to Deaths Data # match ch_episode data with deaths data matched_deaths_data <- ch_episode %>% - dplyr::left_join(it_chi_deaths_data, + dplyr::left_join(refined_death, by = "chi" ) %>% # compare discharge date with NRS and CHI death date diff --git a/R/process_slf_deaths_lookup.R b/R/process_slf_deaths_lookup.R new file mode 100644 index 000000000..40f316a4a --- /dev/null +++ b/R/process_slf_deaths_lookup.R @@ -0,0 +1,61 @@ +#' Create the SLF Deaths lookup +#' +#' @description Currently this just uses the NRS death dates 'as is', with no +#' corrections or modifications, it is expected that this will be expanded to +#' use the CHI deaths extract from IT as well as taking into account data in +#' the episode file to assess the validity of a death date. +#' +#' @param year The year to process, in FY format. +#' @param nrs_deaths_data NRS deaths data. +#' @param chi_deaths_data IT CHI deaths data. +#' @param write_to_disk (optional) Should the data be written to disk default is +#' `TRUE` i.e. write the data to disk. +#' +#' @return a [tibble][tibble::tibble-package] containing the episode file +#' @export +process_slf_deaths_lookup <- function( + year, + nrs_deaths_data = read_file( + get_source_extract_path(year, "deaths"), + col_select = c("anon_chi", "record_keydate1") + ), + chi_deaths_data = read_file(get_slf_chi_deaths_path()), + write_to_disk = TRUE) { + boxi_nrs_data <- nrs_deaths_data %>% + slfhelper::get_chi() %>% + # Only modification over 'raw' NRS is to keep the earliest death date + dplyr::select("chi", "record_keydate1") %>% + dplyr::arrange(.data$record_keydate1) %>% + dplyr::distinct(.data$chi, .keep_all = TRUE) + + # create slf deaths lookup + slf_deaths_lookup <- chi_deaths_data %>% + slfhelper::get_chi() %>% + dplyr::mutate( + fy = phsmethods::extract_fin_year(death_date_chi), + fy = as.character(paste0(substr(fy, 3, 4), substr(fy, 6, 7))) + ) %>% + # Filter the chi death dates to the FY as the lookup is by FY + dplyr::filter(fy == year) %>% + # join boxi nrs data to chi deaths + dplyr::full_join(boxi_nrs_data, by = "chi") %>% + # use the BOXI NRS death date by default, but if it's missing, use the chi death date. + dplyr::mutate( + death_date = dplyr::if_else(is.na(.data$record_keydate1), + .data$death_date_chi, .data$record_keydate1 + ), + deceased = TRUE, + .keep = "unused" + ) %>% + # save anon chi on disk + slfhelper::get_anon_chi() + + if (write_to_disk) { + write_file( + slf_deaths_lookup, + get_slf_deaths_lookup_path(year, check_mode = "write") + ) + } + + return(slf_deaths_lookup) +} diff --git a/Run_SLF_Files_targets/run_all_targets.R b/Run_SLF_Files_targets/run_all_targets.R index 9ea6e9e6f..fb5b94fab 100644 --- a/Run_SLF_Files_targets/run_all_targets.R +++ b/Run_SLF_Files_targets/run_all_targets.R @@ -3,7 +3,3 @@ library(targets) # use tar_make_future() to run targets for all years # This will run everything needed for creating the episode file. tar_make_future() - -# Combine deaths lookup here rather than in targets to make sure that -# it is run after the death file for each year is produced. -createslf::process_combined_deaths_lookup() diff --git a/_targets.R b/_targets.R index 9ea0d9a38..66df85f63 100644 --- a/_targets.R +++ b/_targets.R @@ -172,7 +172,7 @@ list( process_sc_all_care_home( all_care_home_extract, sc_demog_lookup = sc_demog_lookup %>% slfhelper::get_chi(), - it_chi_deaths_data = it_chi_deaths_data %>% slfhelper::get_chi(), + refined_death = refined_death %>% slfhelper::get_chi(), ch_name_lookup_path = slf_ch_name_lookup_path, spd_path = spd_path, write_to_disk = write_to_disk @@ -204,6 +204,13 @@ list( tests_sc_all_sds, process_tests_sc_all_sds_episodes(all_sds) ), + tar_target( + refined_death, + process_refined_death(it_chi_deaths = it_chi_deaths_data, + write_to_disk = write_to_disk) + ), + + # Phase II tar_map( list(year = years_to_run), tar_rds( @@ -251,11 +258,11 @@ list( get_boxi_extract_path(year, type = "mh"), read_extract_mental_health(year, !!.x) ), - tar_file_read( - nrs_deaths_data, - get_boxi_extract_path(year, type = "deaths"), - read_extract_nrs_deaths(year, !!.x) - ), + # tar_file_read( + # nrs_deaths_data, + # get_boxi_extract_path(year, type = "deaths"), + # read_extract_nrs_deaths(year, !!.x) + # ), tar_file_read( outpatients_data, get_boxi_extract_path(year, type = "outpatient"), @@ -403,11 +410,13 @@ list( year ) ), - tar_target(source_mental_health_extract, process_extract_mental_health( - mental_health_data, - year, - write_to_disk = write_to_disk - )), + tar_target( + source_mental_health_extract, + process_extract_mental_health( + mental_health_data, + year, + write_to_disk = write_to_disk) + ), tar_target( tests_source_mental_health_extract, process_tests_mental_health( @@ -415,11 +424,20 @@ list( year ) ), - tar_target(source_nrs_deaths_extract, process_extract_nrs_deaths( - nrs_deaths_data, - year, - write_to_disk = write_to_disk - )), + # tar_target(source_nrs_deaths_extract, process_extract_nrs_deaths( + # nrs_deaths_data, + # year, + # write_to_disk = write_to_disk + # )), + tar_target( + source_nrs_deaths_extract, + # use this anomymous function with redundant but necessary refined_death + # to make sure reading year-specific nrs deaths extracts after it is produced + (\(year, refined_death) { + read_file(get_source_extract_path(year, "deaths")) %>% + as.data.frame() + })(year, refined_death) + ), tar_target( tests_source_nrs_deaths_extract, process_tests_nrs_deaths( @@ -549,8 +567,7 @@ list( slf_deaths_lookup, process_slf_deaths_lookup( year = year, - nrs_deaths_data = source_nrs_deaths_extract %>% slfhelper::get_chi(), - chi_deaths_data = it_chi_deaths_data %>% slfhelper::get_chi(), + refined_data = refined_data, write_to_disk = write_to_disk ) ), From 94c2251e83e6de8a0fe9b40902f9fd2a505daae7 Mon Sep 17 00:00:00 2001 From: lizihao-anu Date: Fri, 2 Aug 2024 17:06:53 +0000 Subject: [PATCH 13/17] Update documentation --- NAMESPACE | 3 ++ man/add_deceased_flag.Rd | 32 +++++++++++ man/create_homelessness_lookup.Rd | 1 + man/get_combined_slf_deaths_lookup_path.Rd | 4 ++ man/get_dd_period.Rd | 3 +- man/latest_cost_year.Rd | 3 +- man/latest_update.Rd | 3 +- man/previous_update.Rd | 3 +- man/process_extract_acute.Rd | 1 + man/process_extract_ae.Rd | 1 + man/process_extract_alarms_telecare.Rd | 1 + man/process_extract_care_home.Rd | 1 + man/process_extract_cmh.Rd | 1 + man/process_extract_delayed_discharges.Rd | 1 + man/process_extract_district_nursing.Rd | 1 + man/process_extract_gp_ooh.Rd | 1 + man/process_extract_home_care.Rd | 1 + man/process_extract_homelessness.Rd | 1 + man/process_extract_maternity.Rd | 1 + man/process_extract_mental_health.Rd | 1 + man/process_extract_nrs_deaths.Rd | 1 + man/process_extract_ooh_consultations.Rd | 1 + man/process_extract_ooh_diagnosis.Rd | 1 + man/process_extract_ooh_outcomes.Rd | 1 + man/process_extract_outpatients.Rd | 1 + man/process_extract_prescribing.Rd | 1 + man/process_extract_sds.Rd | 1 + man/process_it_chi_deaths.Rd | 1 + man/process_lookup_gpprac.Rd | 1 + man/process_lookup_postcode.Rd | 1 + man/process_lookup_sc_client.Rd | 1 + man/process_lookup_sc_demographics.Rd | 1 + man/process_refined_death.Rd | 62 ++++++++++++++++++++++ man/process_sc_all_alarms_telecare.Rd | 1 + man/process_sc_all_care_home.Rd | 8 +-- man/process_sc_all_home_care.Rd | 1 + man/process_sc_all_sds.Rd | 1 + man/process_slf_deaths_lookup.Rd | 16 +++++- man/read_extract_gp_ooh.Rd | 1 + man/read_it_chi_deaths.Rd | 1 + man/read_lookup_sc_client.Rd | 1 + man/years_to_run.Rd | 22 ++++++++ 42 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 man/add_deceased_flag.Rd create mode 100644 man/process_refined_death.Rd create mode 100644 man/years_to_run.Rd diff --git a/NAMESPACE b/NAMESPACE index b4314febd..6f1c88841 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export("%>%") +export(add_deceased_flag) export(add_homelessness_date_flags) export(add_homelessness_flag) export(add_hri_variables) @@ -115,6 +116,7 @@ export(process_lookup_ltc) export(process_lookup_postcode) export(process_lookup_sc_client) export(process_lookup_sc_demographics) +export(process_refined_death) export(process_sc_all_alarms_telecare) export(process_sc_all_care_home) export(process_sc_all_home_care) @@ -182,6 +184,7 @@ export(start_fy) export(start_fy_quarter) export(start_next_fy_quarter) export(write_file) +export(years_to_run) importFrom(data.table,.N) importFrom(data.table,.SD) importFrom(magrittr,"%>%") diff --git a/man/add_deceased_flag.Rd b/man/add_deceased_flag.Rd new file mode 100644 index 000000000..c84568522 --- /dev/null +++ b/man/add_deceased_flag.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/add_deceased_flag.R +\name{add_deceased_flag} +\alias{add_deceased_flag} +\title{Create the SLF Deaths lookup} +\usage{ +add_deceased_flag( + year, + refined_death = read_file(get_combined_slf_deaths_lookup_path()) \%>\% + slfhelper::get_chi(), + write_to_disk = TRUE +) +} +\arguments{ +\item{year}{The year to process, in FY format.} + +\item{write_to_disk}{(optional) Should the data be written to disk default is +\code{TRUE} i.e. write the data to disk.} + +\item{nrs_deaths_data}{NRS deaths data.} + +\item{chi_deaths_data}{IT CHI deaths data.} +} +\value{ +a \link[tibble:tibble-package]{tibble} containing the episode file +} +\description{ +Currently this just uses the NRS death dates 'as is', with no +corrections or modifications, it is expected that this will be expanded to +use the CHI deaths extract from IT as well as taking into account data in +the episode file to assess the validity of a death date. +} diff --git a/man/create_homelessness_lookup.Rd b/man/create_homelessness_lookup.Rd index d6a2f2bc8..9826f4ced 100644 --- a/man/create_homelessness_lookup.Rd +++ b/man/create_homelessness_lookup.Rd @@ -50,6 +50,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/get_combined_slf_deaths_lookup_path.Rd b/man/get_combined_slf_deaths_lookup_path.Rd index dd03a0541..709773d01 100644 --- a/man/get_combined_slf_deaths_lookup_path.Rd +++ b/man/get_combined_slf_deaths_lookup_path.Rd @@ -13,6 +13,10 @@ get_combined_slf_deaths_lookup_path(update = latest_update(), ...) } \description{ Get the full path to the BOXI NRS Deaths lookup file for all financial years +Note this name is very similar to the existing slf_deaths_lookup_path +which returns the path for the refined_death with deceased flag for each financial year. +This function will return the combined financial years lookup +i.e. all years put together. } \seealso{ \code{\link[=get_file_path]{get_file_path()}} for the generic function. diff --git a/man/get_dd_period.Rd b/man/get_dd_period.Rd index 29bd8baea..c478f401f 100644 --- a/man/get_dd_period.Rd +++ b/man/get_dd_period.Rd @@ -17,6 +17,7 @@ Get the period for Delayed Discharge Other initialisation: \code{\link{latest_cost_year}()}, \code{\link{latest_update}()}, -\code{\link{previous_update}()} +\code{\link{previous_update}()}, +\code{\link{years_to_run}()} } \concept{initialisation} diff --git a/man/latest_cost_year.Rd b/man/latest_cost_year.Rd index 0240c6ad0..0f50b3ac6 100644 --- a/man/latest_cost_year.Rd +++ b/man/latest_cost_year.Rd @@ -16,6 +16,7 @@ Get the latest year for cost uplift Other initialisation: \code{\link{get_dd_period}()}, \code{\link{latest_update}()}, -\code{\link{previous_update}()} +\code{\link{previous_update}()}, +\code{\link{years_to_run}()} } \concept{initialisation} diff --git a/man/latest_update.Rd b/man/latest_update.Rd index b3fbe765c..926e472e4 100644 --- a/man/latest_update.Rd +++ b/man/latest_update.Rd @@ -16,6 +16,7 @@ Get the date of the latest update, e.g 'Jun_2022' Other initialisation: \code{\link{get_dd_period}()}, \code{\link{latest_cost_year}()}, -\code{\link{previous_update}()} +\code{\link{previous_update}()}, +\code{\link{years_to_run}()} } \concept{initialisation} diff --git a/man/previous_update.Rd b/man/previous_update.Rd index f87b4656f..547138700 100644 --- a/man/previous_update.Rd +++ b/man/previous_update.Rd @@ -28,6 +28,7 @@ previous_update(override = "May_2023") # Specific Month Other initialisation: \code{\link{get_dd_period}()}, \code{\link{latest_cost_year}()}, -\code{\link{latest_update}()} +\code{\link{latest_update}()}, +\code{\link{years_to_run}()} } \concept{initialisation} diff --git a/man/process_extract_acute.Rd b/man/process_extract_acute.Rd index 22ff164c8..fae9c7bab 100644 --- a/man/process_extract_acute.Rd +++ b/man/process_extract_acute.Rd @@ -53,6 +53,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_ae.Rd b/man/process_extract_ae.Rd index 9eec39ba5..36d2bb4d3 100644 --- a/man/process_extract_ae.Rd +++ b/man/process_extract_ae.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_alarms_telecare.Rd b/man/process_extract_alarms_telecare.Rd index 76093be7d..016f5e2b6 100644 --- a/man/process_extract_alarms_telecare.Rd +++ b/man/process_extract_alarms_telecare.Rd @@ -49,6 +49,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_care_home.Rd b/man/process_extract_care_home.Rd index 269ae1e7d..a002d30ab 100644 --- a/man/process_extract_care_home.Rd +++ b/man/process_extract_care_home.Rd @@ -51,6 +51,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_cmh.Rd b/man/process_extract_cmh.Rd index 64e085dcf..799b6d717 100644 --- a/man/process_extract_cmh.Rd +++ b/man/process_extract_cmh.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_delayed_discharges.Rd b/man/process_extract_delayed_discharges.Rd index c6fd560a7..385bdff2a 100644 --- a/man/process_extract_delayed_discharges.Rd +++ b/man/process_extract_delayed_discharges.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_district_nursing.Rd b/man/process_extract_district_nursing.Rd index eb2814fbc..49284b70f 100644 --- a/man/process_extract_district_nursing.Rd +++ b/man/process_extract_district_nursing.Rd @@ -55,6 +55,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_gp_ooh.Rd b/man/process_extract_gp_ooh.Rd index b137f581c..5c68c35dd 100644 --- a/man/process_extract_gp_ooh.Rd +++ b/man/process_extract_gp_ooh.Rd @@ -53,6 +53,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_home_care.Rd b/man/process_extract_home_care.Rd index 4dd609770..98c45a8e2 100644 --- a/man/process_extract_home_care.Rd +++ b/man/process_extract_home_care.Rd @@ -49,6 +49,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_homelessness.Rd b/man/process_extract_homelessness.Rd index 405da34bb..59fe6f283 100644 --- a/man/process_extract_homelessness.Rd +++ b/man/process_extract_homelessness.Rd @@ -62,6 +62,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_maternity.Rd b/man/process_extract_maternity.Rd index 17dd1a64c..19142c4a8 100644 --- a/man/process_extract_maternity.Rd +++ b/man/process_extract_maternity.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_mental_health.Rd b/man/process_extract_mental_health.Rd index 5f1fc7330..bd91dc4ec 100644 --- a/man/process_extract_mental_health.Rd +++ b/man/process_extract_mental_health.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_nrs_deaths.Rd b/man/process_extract_nrs_deaths.Rd index 1938e15ec..71fab68e2 100644 --- a/man/process_extract_nrs_deaths.Rd +++ b/man/process_extract_nrs_deaths.Rd @@ -47,6 +47,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_ooh_consultations.Rd b/man/process_extract_ooh_consultations.Rd index e00155191..ae4265823 100644 --- a/man/process_extract_ooh_consultations.Rd +++ b/man/process_extract_ooh_consultations.Rd @@ -45,6 +45,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_ooh_diagnosis.Rd b/man/process_extract_ooh_diagnosis.Rd index 2dcbee647..78db15f0f 100644 --- a/man/process_extract_ooh_diagnosis.Rd +++ b/man/process_extract_ooh_diagnosis.Rd @@ -45,6 +45,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_ooh_outcomes.Rd b/man/process_extract_ooh_outcomes.Rd index 31ec64439..d59617e7b 100644 --- a/man/process_extract_ooh_outcomes.Rd +++ b/man/process_extract_ooh_outcomes.Rd @@ -45,6 +45,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_outpatients.Rd b/man/process_extract_outpatients.Rd index 3a46ad119..8af2c6ddf 100644 --- a/man/process_extract_outpatients.Rd +++ b/man/process_extract_outpatients.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_prescribing.Rd b/man/process_extract_prescribing.Rd index 195a60bfe..c959ce1e7 100644 --- a/man/process_extract_prescribing.Rd +++ b/man/process_extract_prescribing.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_extract_sds.Rd b/man/process_extract_sds.Rd index 03ee60362..b0cc8788a 100644 --- a/man/process_extract_sds.Rd +++ b/man/process_extract_sds.Rd @@ -49,6 +49,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_it_chi_deaths.Rd b/man/process_it_chi_deaths.Rd index 1d8e085ab..757f06aa7 100644 --- a/man/process_it_chi_deaths.Rd +++ b/man/process_it_chi_deaths.Rd @@ -45,6 +45,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_lookup_gpprac.Rd b/man/process_lookup_gpprac.Rd index 107af24c0..bfda08282 100644 --- a/man/process_lookup_gpprac.Rd +++ b/man/process_lookup_gpprac.Rd @@ -54,6 +54,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_lookup_postcode.Rd b/man/process_lookup_postcode.Rd index e556efd51..b8b1ebd4f 100644 --- a/man/process_lookup_postcode.Rd +++ b/man/process_lookup_postcode.Rd @@ -55,6 +55,7 @@ Other process extracts: \code{\link{process_lookup_gpprac}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_lookup_sc_client.Rd b/man/process_lookup_sc_client.Rd index 5ea50cea5..4b85a06b5 100644 --- a/man/process_lookup_sc_client.Rd +++ b/man/process_lookup_sc_client.Rd @@ -56,6 +56,7 @@ Other process extracts: \code{\link{process_lookup_gpprac}()}, \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_lookup_sc_demographics.Rd b/man/process_lookup_sc_demographics.Rd index a89933425..29215f657 100644 --- a/man/process_lookup_sc_demographics.Rd +++ b/man/process_lookup_sc_demographics.Rd @@ -52,6 +52,7 @@ Other process extracts: \code{\link{process_lookup_gpprac}()}, \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_refined_death.Rd b/man/process_refined_death.Rd new file mode 100644 index 000000000..fd5392eb2 --- /dev/null +++ b/man/process_refined_death.Rd @@ -0,0 +1,62 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/process_refined_death.R +\name{process_refined_death} +\alias{process_refined_death} +\title{Process the refined death data} +\usage{ +process_refined_death( + it_chi_deaths = read_file(get_slf_chi_deaths_path()), + write_to_disk = TRUE +) +} +\arguments{ +\item{it_chi_deaths}{it chi death data} + +\item{write_to_disk}{write the result to disk or not.} +} +\value{ +refined_death The processed lookup of deaths combining NRS and IT_CHI. +} +\description{ +This will process +year-specific BOXI NRS death file (written to disk), and +combine them together to get all years NRS file (Not written to disk). +Then join all NRS deaths with IT CHI death data +to get an all-year refined death file (written to disk). +} +\seealso{ +Other process extracts: +\code{\link{create_homelessness_lookup}()}, +\code{\link{process_extract_acute}()}, +\code{\link{process_extract_ae}()}, +\code{\link{process_extract_alarms_telecare}()}, +\code{\link{process_extract_care_home}()}, +\code{\link{process_extract_cmh}()}, +\code{\link{process_extract_delayed_discharges}()}, +\code{\link{process_extract_district_nursing}()}, +\code{\link{process_extract_gp_ooh}()}, +\code{\link{process_extract_home_care}()}, +\code{\link{process_extract_homelessness}()}, +\code{\link{process_extract_maternity}()}, +\code{\link{process_extract_mental_health}()}, +\code{\link{process_extract_nrs_deaths}()}, +\code{\link{process_extract_ooh_consultations}()}, +\code{\link{process_extract_ooh_diagnosis}()}, +\code{\link{process_extract_ooh_outcomes}()}, +\code{\link{process_extract_outpatients}()}, +\code{\link{process_extract_prescribing}()}, +\code{\link{process_extract_sds}()}, +\code{\link{process_it_chi_deaths}()}, +\code{\link{process_lookup_gpprac}()}, +\code{\link{process_lookup_postcode}()}, +\code{\link{process_lookup_sc_client}()}, +\code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_sc_all_alarms_telecare}()}, +\code{\link{process_sc_all_care_home}()}, +\code{\link{process_sc_all_home_care}()}, +\code{\link{process_sc_all_sds}()}, +\code{\link{read_extract_gp_ooh}()}, +\code{\link{read_it_chi_deaths}()}, +\code{\link{read_lookup_sc_client}()} +} +\concept{process extracts} diff --git a/man/process_sc_all_alarms_telecare.Rd b/man/process_sc_all_alarms_telecare.Rd index a2e319cbf..1f3eb30e0 100644 --- a/man/process_sc_all_alarms_telecare.Rd +++ b/man/process_sc_all_alarms_telecare.Rd @@ -54,6 +54,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, \code{\link{process_sc_all_sds}()}, diff --git a/man/process_sc_all_care_home.Rd b/man/process_sc_all_care_home.Rd index 792d2200d..7d4234b25 100644 --- a/man/process_sc_all_care_home.Rd +++ b/man/process_sc_all_care_home.Rd @@ -7,7 +7,8 @@ process_sc_all_care_home( data, sc_demog_lookup = read_file(get_sc_demog_lookup_path()) \%>\% slfhelper::get_chi(), - it_chi_deaths_data = read_file(get_slf_chi_deaths_path()), + refined_death = read_file(get_combined_slf_deaths_lookup_path()) \%>\% + slfhelper::get_chi(), ch_name_lookup_path = read_file(get_slf_ch_name_lookup_path()), spd_path = read_file(get_spd_path()), write_to_disk = TRUE @@ -19,8 +20,8 @@ process_sc_all_care_home( \item{sc_demog_lookup}{The Social Care Demographics lookup produced by \code{\link[=process_lookup_sc_demographics]{process_lookup_sc_demographics()}}.} -\item{it_chi_deaths_data}{The processed lookup of deaths from IT produced -with \code{\link[=process_it_chi_deaths]{process_it_chi_deaths()}}.} +\item{refined_death}{The processed lookup of deaths from IT produced +with \code{\link[=process_refined_death]{process_refined_death()}}.} \item{ch_name_lookup_path}{Path to the Care Home name Lookup Excel workbook.} @@ -65,6 +66,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_home_care}()}, \code{\link{process_sc_all_sds}()}, diff --git a/man/process_sc_all_home_care.Rd b/man/process_sc_all_home_care.Rd index c6777889f..1f64cad95 100644 --- a/man/process_sc_all_home_care.Rd +++ b/man/process_sc_all_home_care.Rd @@ -54,6 +54,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_sds}()}, diff --git a/man/process_sc_all_sds.Rd b/man/process_sc_all_sds.Rd index f91c9dfb9..43d18b29d 100644 --- a/man/process_sc_all_sds.Rd +++ b/man/process_sc_all_sds.Rd @@ -54,6 +54,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/process_slf_deaths_lookup.Rd b/man/process_slf_deaths_lookup.Rd index bf69d3952..9361bedbd 100644 --- a/man/process_slf_deaths_lookup.Rd +++ b/man/process_slf_deaths_lookup.Rd @@ -1,9 +1,18 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/process_lookup_deaths.R +% Please edit documentation in R/process_lookup_deaths.R, +% R/process_slf_deaths_lookup.R \name{process_slf_deaths_lookup} \alias{process_slf_deaths_lookup} \title{Create the SLF Deaths lookup} \usage{ +process_slf_deaths_lookup( + year, + nrs_deaths_data = read_file(get_source_extract_path(year, "deaths"), col_select = + c("anon_chi", "record_keydate1")), + chi_deaths_data = read_file(get_slf_chi_deaths_path()), + write_to_disk = TRUE +) + process_slf_deaths_lookup( year, nrs_deaths_data = read_file(get_source_extract_path(year, "deaths"), col_select = @@ -23,9 +32,14 @@ process_slf_deaths_lookup( \code{TRUE} i.e. write the data to disk.} } \value{ +a \link[tibble:tibble-package]{tibble} containing the episode file + a \link[tibble:tibble-package]{tibble} containing the episode file } \description{ +Use all-year refined death data to produce year-specific +slf_deaths_lookup with deceased flag added. + Currently this just uses the NRS death dates 'as is', with no corrections or modifications, it is expected that this will be expanded to use the CHI deaths extract from IT as well as taking into account data in diff --git a/man/read_extract_gp_ooh.Rd b/man/read_extract_gp_ooh.Rd index ba908127b..61eaf7d32 100644 --- a/man/read_extract_gp_ooh.Rd +++ b/man/read_extract_gp_ooh.Rd @@ -55,6 +55,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/read_it_chi_deaths.Rd b/man/read_it_chi_deaths.Rd index d1bfe5cf7..fe548d84b 100644 --- a/man/read_it_chi_deaths.Rd +++ b/man/read_it_chi_deaths.Rd @@ -42,6 +42,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/read_lookup_sc_client.Rd b/man/read_lookup_sc_client.Rd index 283bc6a9a..4cef9df29 100644 --- a/man/read_lookup_sc_client.Rd +++ b/man/read_lookup_sc_client.Rd @@ -48,6 +48,7 @@ Other process extracts: \code{\link{process_lookup_postcode}()}, \code{\link{process_lookup_sc_client}()}, \code{\link{process_lookup_sc_demographics}()}, +\code{\link{process_refined_death}()}, \code{\link{process_sc_all_alarms_telecare}()}, \code{\link{process_sc_all_care_home}()}, \code{\link{process_sc_all_home_care}()}, diff --git a/man/years_to_run.Rd b/man/years_to_run.Rd new file mode 100644 index 000000000..188ea7f5f --- /dev/null +++ b/man/years_to_run.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/00-update_refs.R +\name{years_to_run} +\alias{years_to_run} +\title{The year list for slf to update} +\usage{ +years_to_run() +} +\value{ +The vector of financial years +} +\description{ +Get the vector of years to update slf +} +\seealso{ +Other initialisation: +\code{\link{get_dd_period}()}, +\code{\link{latest_cost_year}()}, +\code{\link{latest_update}()}, +\code{\link{previous_update}()} +} +\concept{initialisation} From dd4ed04ee6c3253a26e4b429ba319b19de1b4433 Mon Sep 17 00:00:00 2001 From: lizihao-anu Date: Fri, 2 Aug 2024 17:06:58 +0000 Subject: [PATCH 14/17] Style code --- R/00-update_refs.R | 6 ++++-- R/add_deceased_flag.R | 15 +++++++-------- R/process_lookup_deaths.R | 1 - R/process_refined_death.R | 23 +++++++++++++++-------- _targets.R | 9 ++++++--- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/R/00-update_refs.R b/R/00-update_refs.R index c22585aaf..c45f10e9c 100644 --- a/R/00-update_refs.R +++ b/R/00-update_refs.R @@ -89,7 +89,9 @@ latest_cost_year <- function() { years_to_run <- function() { fy_start_2digit <- 17 fy_end_2digit <- 23 - years_to_run = paste0(fy_start_2digit:fy_end_2digit, - (fy_start_2digit + 1):(fy_end_2digit + 1)) + years_to_run <- paste0( + fy_start_2digit:fy_end_2digit, + (fy_start_2digit + 1):(fy_end_2digit + 1) + ) return(years_to_run) } diff --git a/R/add_deceased_flag.R b/R/add_deceased_flag.R index 25010cba6..f3be216cf 100644 --- a/R/add_deceased_flag.R +++ b/R/add_deceased_flag.R @@ -17,16 +17,15 @@ add_deceased_flag <- function( year, refined_death = read_file(get_combined_slf_deaths_lookup_path()) %>% slfhelper::get_chi(), write_to_disk = TRUE) { - # create slf deaths lookup - dplyr::mutate( - death_date = dplyr::if_else(is.na(.data$record_keydate1), - .data$death_date_chi, .data$record_keydate1 - ), - deceased = TRUE, - .keep = "unused" - ) %>% + dplyr::mutate( + death_date = dplyr::if_else(is.na(.data$record_keydate1), + .data$death_date_chi, .data$record_keydate1 + ), + deceased = TRUE, + .keep = "unused" + ) %>% # save anon chi on disk slfhelper::get_anon_chi() diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index ca5c6fc67..e1ba9edf3 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -15,7 +15,6 @@ process_slf_deaths_lookup <- function( year, refined_death = read_file(get_combined_slf_deaths_lookup_path()), write_to_disk = TRUE) { - # create slf deaths lookup slf_deaths_lookup <- refined_death %>% slfhelper::get_chi() %>% diff --git a/R/process_refined_death.R b/R/process_refined_death.R index d7067e91e..48f14fd43 100644 --- a/R/process_refined_death.R +++ b/R/process_refined_death.R @@ -15,19 +15,24 @@ process_refined_death <- function( it_chi_deaths = read_file(get_slf_chi_deaths_path()), write_to_disk = TRUE) { - years_list = years_to_run() + years_list <- years_to_run() nrs_all_years <- lapply(years_list, (\(year) { - read_extract_nrs_deaths(year, - get_boxi_extract_path(year, type = "deaths")) %>% + read_extract_nrs_deaths( + year, + get_boxi_extract_path(year, type = "deaths") + ) %>% process_extract_nrs_deaths(year, - write_to_disk = write_to_disk) + write_to_disk = write_to_disk + ) })) %>% data.table::rbindlist() it_chi_deaths <- it_chi_deaths %>% - dplyr::select(c("anon_chi", - "death_date_chi")) %>% + dplyr::select(c( + "anon_chi", + "death_date_chi" + )) %>% dplyr::arrange(.data$anon_chi, .keep_all = TRUE) refined_death <- nrs_all_years %>% @@ -47,8 +52,10 @@ process_refined_death <- function( ) if (write_to_disk) { - write_file(refined_death, - get_combined_slf_deaths_lookup_path()) + write_file( + refined_death, + get_combined_slf_deaths_lookup_path() + ) } return(refined_death) diff --git a/_targets.R b/_targets.R index 66df85f63..7b613fc4a 100644 --- a/_targets.R +++ b/_targets.R @@ -206,8 +206,10 @@ list( ), tar_target( refined_death, - process_refined_death(it_chi_deaths = it_chi_deaths_data, - write_to_disk = write_to_disk) + process_refined_death( + it_chi_deaths = it_chi_deaths_data, + write_to_disk = write_to_disk + ) ), # Phase II @@ -415,7 +417,8 @@ list( process_extract_mental_health( mental_health_data, year, - write_to_disk = write_to_disk) + write_to_disk = write_to_disk + ) ), tar_target( tests_source_mental_health_extract, From cf1ef7a15a91b757612fe858fc3a096565ab376e Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 2 Aug 2024 18:41:23 +0100 Subject: [PATCH 15/17] minor changes --- R/process_lookup_deaths.R | 3 +-- _targets.R | 22 +++++++++++----------- man/process_slf_deaths_lookup.Rd | 2 ++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index e1ba9edf3..d4e5d126c 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -4,8 +4,7 @@ #' slf_deaths_lookup with deceased flag added. #' #' @param year The year to process, in FY format. -#' @param nrs_deaths_data NRS deaths data. -#' @param chi_deaths_data IT CHI deaths data. +#' @param refined_death refined death date combining nrs and it_chi. #' @param write_to_disk (optional) Should the data be written to disk default is #' `TRUE` i.e. write the data to disk. #' diff --git a/_targets.R b/_targets.R index 7b613fc4a..0fea087ca 100644 --- a/_targets.R +++ b/_targets.R @@ -167,12 +167,19 @@ list( age = as.difftime(28.0, units = "days") ) ), + tar_target( + refined_death_data, + process_refined_death( + it_chi_deaths = it_chi_deaths_data, + write_to_disk = write_to_disk + ) + ), tar_target( all_care_home, process_sc_all_care_home( all_care_home_extract, sc_demog_lookup = sc_demog_lookup %>% slfhelper::get_chi(), - refined_death = refined_death %>% slfhelper::get_chi(), + refined_death = refined_death_data %>% slfhelper::get_chi(), ch_name_lookup_path = slf_ch_name_lookup_path, spd_path = spd_path, write_to_disk = write_to_disk @@ -204,13 +211,6 @@ list( tests_sc_all_sds, process_tests_sc_all_sds_episodes(all_sds) ), - tar_target( - refined_death, - process_refined_death( - it_chi_deaths = it_chi_deaths_data, - write_to_disk = write_to_disk - ) - ), # Phase II tar_map( @@ -436,10 +436,10 @@ list( source_nrs_deaths_extract, # use this anomymous function with redundant but necessary refined_death # to make sure reading year-specific nrs deaths extracts after it is produced - (\(year, refined_death) { + (\(year, refined_death_datas) { read_file(get_source_extract_path(year, "deaths")) %>% as.data.frame() - })(year, refined_death) + })(year, refined_death_data) ), tar_target( tests_source_nrs_deaths_extract, @@ -570,7 +570,7 @@ list( slf_deaths_lookup, process_slf_deaths_lookup( year = year, - refined_data = refined_data, + refined_death = refined_death_data, write_to_disk = write_to_disk ) ), diff --git a/man/process_slf_deaths_lookup.Rd b/man/process_slf_deaths_lookup.Rd index 9361bedbd..424e52073 100644 --- a/man/process_slf_deaths_lookup.Rd +++ b/man/process_slf_deaths_lookup.Rd @@ -30,6 +30,8 @@ process_slf_deaths_lookup( \item{write_to_disk}{(optional) Should the data be written to disk default is \code{TRUE} i.e. write the data to disk.} + +\item{refined_death}{refined death date combining nrs and it_chi.} } \value{ a \link[tibble:tibble-package]{tibble} containing the episode file From 90eb14d3a54f67939f8761eca072756a85319e46 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Mon, 5 Aug 2024 10:06:30 +0100 Subject: [PATCH 16/17] remove process_slf_deaths_lookup --- R/process_lookup_deaths.R | 2 +- R/process_slf_deaths_lookup.R | 61 ----------------------------------- 2 files changed, 1 insertion(+), 62 deletions(-) delete mode 100644 R/process_slf_deaths_lookup.R diff --git a/R/process_lookup_deaths.R b/R/process_lookup_deaths.R index d4e5d126c..edc083cd2 100644 --- a/R/process_lookup_deaths.R +++ b/R/process_lookup_deaths.R @@ -8,7 +8,7 @@ #' @param write_to_disk (optional) Should the data be written to disk default is #' `TRUE` i.e. write the data to disk. #' -#' @return a [tibble][tibble::tibble-package] containing the episode file +#' @return a [tibble][tibble::tibble-package] add deceased flag to deaths #' @export process_slf_deaths_lookup <- function( year, diff --git a/R/process_slf_deaths_lookup.R b/R/process_slf_deaths_lookup.R deleted file mode 100644 index 40f316a4a..000000000 --- a/R/process_slf_deaths_lookup.R +++ /dev/null @@ -1,61 +0,0 @@ -#' Create the SLF Deaths lookup -#' -#' @description Currently this just uses the NRS death dates 'as is', with no -#' corrections or modifications, it is expected that this will be expanded to -#' use the CHI deaths extract from IT as well as taking into account data in -#' the episode file to assess the validity of a death date. -#' -#' @param year The year to process, in FY format. -#' @param nrs_deaths_data NRS deaths data. -#' @param chi_deaths_data IT CHI deaths data. -#' @param write_to_disk (optional) Should the data be written to disk default is -#' `TRUE` i.e. write the data to disk. -#' -#' @return a [tibble][tibble::tibble-package] containing the episode file -#' @export -process_slf_deaths_lookup <- function( - year, - nrs_deaths_data = read_file( - get_source_extract_path(year, "deaths"), - col_select = c("anon_chi", "record_keydate1") - ), - chi_deaths_data = read_file(get_slf_chi_deaths_path()), - write_to_disk = TRUE) { - boxi_nrs_data <- nrs_deaths_data %>% - slfhelper::get_chi() %>% - # Only modification over 'raw' NRS is to keep the earliest death date - dplyr::select("chi", "record_keydate1") %>% - dplyr::arrange(.data$record_keydate1) %>% - dplyr::distinct(.data$chi, .keep_all = TRUE) - - # create slf deaths lookup - slf_deaths_lookup <- chi_deaths_data %>% - slfhelper::get_chi() %>% - dplyr::mutate( - fy = phsmethods::extract_fin_year(death_date_chi), - fy = as.character(paste0(substr(fy, 3, 4), substr(fy, 6, 7))) - ) %>% - # Filter the chi death dates to the FY as the lookup is by FY - dplyr::filter(fy == year) %>% - # join boxi nrs data to chi deaths - dplyr::full_join(boxi_nrs_data, by = "chi") %>% - # use the BOXI NRS death date by default, but if it's missing, use the chi death date. - dplyr::mutate( - death_date = dplyr::if_else(is.na(.data$record_keydate1), - .data$death_date_chi, .data$record_keydate1 - ), - deceased = TRUE, - .keep = "unused" - ) %>% - # save anon chi on disk - slfhelper::get_anon_chi() - - if (write_to_disk) { - write_file( - slf_deaths_lookup, - get_slf_deaths_lookup_path(year, check_mode = "write") - ) - } - - return(slf_deaths_lookup) -} From 6df708997958f7532568c7d4da19a282e35ad553 Mon Sep 17 00:00:00 2001 From: lizihao-anu Date: Mon, 5 Aug 2024 09:08:11 +0000 Subject: [PATCH 17/17] Update documentation --- man/process_slf_deaths_lookup.Rd | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/man/process_slf_deaths_lookup.Rd b/man/process_slf_deaths_lookup.Rd index 424e52073..80e7559e0 100644 --- a/man/process_slf_deaths_lookup.Rd +++ b/man/process_slf_deaths_lookup.Rd @@ -1,49 +1,27 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/process_lookup_deaths.R, -% R/process_slf_deaths_lookup.R +% Please edit documentation in R/process_lookup_deaths.R \name{process_slf_deaths_lookup} \alias{process_slf_deaths_lookup} \title{Create the SLF Deaths lookup} \usage{ process_slf_deaths_lookup( year, - nrs_deaths_data = read_file(get_source_extract_path(year, "deaths"), col_select = - c("anon_chi", "record_keydate1")), - chi_deaths_data = read_file(get_slf_chi_deaths_path()), - write_to_disk = TRUE -) - -process_slf_deaths_lookup( - year, - nrs_deaths_data = read_file(get_source_extract_path(year, "deaths"), col_select = - c("anon_chi", "record_keydate1")), - chi_deaths_data = read_file(get_slf_chi_deaths_path()), + refined_death = read_file(get_combined_slf_deaths_lookup_path()), write_to_disk = TRUE ) } \arguments{ \item{year}{The year to process, in FY format.} -\item{nrs_deaths_data}{NRS deaths data.} - -\item{chi_deaths_data}{IT CHI deaths data.} +\item{refined_death}{refined death date combining nrs and it_chi.} \item{write_to_disk}{(optional) Should the data be written to disk default is \code{TRUE} i.e. write the data to disk.} - -\item{refined_death}{refined death date combining nrs and it_chi.} } \value{ -a \link[tibble:tibble-package]{tibble} containing the episode file - -a \link[tibble:tibble-package]{tibble} containing the episode file +a \link[tibble:tibble-package]{tibble} add deceased flag to deaths } \description{ Use all-year refined death data to produce year-specific slf_deaths_lookup with deceased flag added. - -Currently this just uses the NRS death dates 'as is', with no -corrections or modifications, it is expected that this will be expanded to -use the CHI deaths extract from IT as well as taking into account data in -the episode file to assess the validity of a death date. }