diff --git a/R/add_activity_after_death_flag.R b/R/add_activity_after_death_flag.R index 0842b47ec..78131d941 100644 --- a/R/add_activity_after_death_flag.R +++ b/R/add_activity_after_death_flag.R @@ -13,6 +13,8 @@ add_activity_after_death_flag <- function( year, deaths_data = read_file(get_all_slf_deaths_lookup_path()) %>% slfhelper::get_chi()) { + cli::cli_alert_info("Add activity after death flag function started at {Sys.time()}") + # to skip warnings no visible binding for global variable ‘.’ . <- NULL @@ -85,7 +87,7 @@ add_activity_after_death_flag <- function( flag_data <- flag_data %>% 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(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$activity_after_death) %>% + dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$activity_after_death, .data$death_date_boxi) %>% dplyr::distinct() # Match activity after death flag back to episode file @@ -94,7 +96,12 @@ add_activity_after_death_flag <- function( flag_data, by = c("year", "chi", "record_keydate1", "record_keydate2"), na_matches = "never" - ) + ) %>% + dplyr::mutate(death_date = lubridate::as_date(ifelse(is.na(death_date) & !(is.na(death_date_boxi)), + death_date_boxi, death_date + ))) %>% + dplyr::select(-death_date_boxi) + return(final_data) diff --git a/R/add_nsu_cohort.R b/R/add_nsu_cohort.R index 15d5d4e01..bf6216e57 100644 --- a/R/add_nsu_cohort.R +++ b/R/add_nsu_cohort.R @@ -13,6 +13,8 @@ add_nsu_cohort <- function( data, year, nsu_cohort = read_file(get_nsu_path(year)) %>% slfhelper::get_chi()) { + cli::cli_alert_info("Add NSU cohort function started at {Sys.time()}") + year_param <- year if (!check_year_valid(year, "nsu")) { diff --git a/R/add_ppa_flag.R b/R/add_ppa_flag.R index bb99f0543..1d5f9739d 100644 --- a/R/add_ppa_flag.R +++ b/R/add_ppa_flag.R @@ -8,6 +8,8 @@ #' @return A data frame to use as a lookup of PPAs #' @family episode_file add_ppa_flag <- function(data) { + cli::cli_alert_info("Add PPA flag function started at {Sys.time()}") + check_variables_exist( data, variables = c( diff --git a/R/correct_demographics.R b/R/correct_demographics.R index d7ef6f469..d221c25ab 100644 --- a/R/correct_demographics.R +++ b/R/correct_demographics.R @@ -7,6 +7,8 @@ #' #' @return episode files with updated date of birth and ages correct_demographics <- function(data, year) { + cli::cli_alert_info("Correct demographics function started at {Sys.time()}") + # keep episodes with missing chi data_no_chi <- data %>% dplyr::filter(is_missing(.data$chi)) diff --git a/R/cost_uplift.R b/R/cost_uplift.R index e554c2505..f14600da6 100644 --- a/R/cost_uplift.R +++ b/R/cost_uplift.R @@ -5,6 +5,8 @@ #' @return episode data with uplifted costs #' @family episode_file apply_cost_uplift <- function(data) { + cli::cli_alert_info("Apply cost uplift function started at {Sys.time()}") + data <- data %>% # attach a uplift scale as the last column lookup_uplift() %>% diff --git a/R/create_episode_file.R b/R/create_episode_file.R index 0bb804c7d..34d2ddf9e 100644 --- a/R/create_episode_file.R +++ b/R/create_episode_file.R @@ -199,6 +199,8 @@ create_episode_file <- function( #' #' @return `data` with only the `vars_to_keep` kept store_ep_file_vars <- function(data, year, vars_to_keep) { + cli::cli_alert_info("Store episode file variables function started at {Sys.time()}") + tempfile_path <- get_file_path( directory = get_year_dir(year), file_name = stringr::str_glue("temp_ep_file_variable_store_{year}.parquet"), @@ -236,6 +238,8 @@ store_ep_file_vars <- function(data, year, vars_to_keep) { #' #' @return The full SLF data. load_ep_file_vars <- function(data, year) { + cli::cli_alert_info("Load episode file variable function started at {Sys.time()}") + tempfile_path <- get_file_path( directory = get_year_dir(year), file_name = stringr::str_glue("temp_ep_file_variable_store_{year}.parquet"), @@ -263,6 +267,8 @@ load_ep_file_vars <- function(data, year) { #' #' @return A data frame with CIJ markers filled in for those missing. fill_missing_cij_markers <- function(data) { + cli::cli_alert_info("Fill missing cij markers function started at {Sys.time()}") + fixable_data <- data %>% dplyr::filter( .data[["recid"]] %in% c("01B", "04B", "GLS", "02B", "DD") & !is.na(.data[["chi"]]) @@ -317,6 +323,8 @@ fill_missing_cij_markers <- function(data) { #' #' @return The data with CIJ variables corrected. correct_cij_vars <- function(data) { + cli::cli_alert_info("Correct cij variables function started at {Sys.time()}") + check_variables_exist( data, c("chi", "recid", "cij_admtype", "cij_pattype_code") @@ -358,6 +366,8 @@ correct_cij_vars <- function(data) { #' #' @return The data with cost including dna. create_cost_inc_dna <- function(data) { + cli::cli_alert_info("Create cost inc dna function started at {Sys.time()}") + check_variables_exist(data, c("cost_total_net", "attendance_status")) # Create cost including DNAs and modify costs @@ -382,6 +392,8 @@ create_cost_inc_dna <- function(data) { #' #' @return The data unchanged (the cohorts are written to disk) create_cohort_lookups <- function(data, year, update = latest_update()) { + cli::cli_alert_info("Create cohort lookups function started at {Sys.time()}") + create_demographic_cohorts( data, year, @@ -421,6 +433,8 @@ join_cohort_lookups <- function( col_select = c("anon_chi", "service_use_cohort") ) %>% slfhelper::get_chi()) { + cli::cli_alert_info("Join cohort lookups function started at {Sys.time()}") + join_cohort_lookups <- data %>% dplyr::left_join( demographic_cohort, @@ -447,6 +461,8 @@ join_sc_client <- function(data, year, sc_client = read_file(get_sc_client_lookup_path(year)) %>% slfhelper::get_chi(), file_type = c("episode", "individual")) { + cli::cli_alert_info("Join social care client function started at {Sys.time()}") + if (file_type == "episode") { # Match on client variables by chi data_file <- data %>% diff --git a/R/create_individual_file.R b/R/create_individual_file.R index c98531310..dc15fcb0e 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -260,6 +260,8 @@ add_all_columns <- function(episode_file, year) { #' @param condition Condition to create new columns based on #' @family individual_file add_acute_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add acute columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>% @@ -271,6 +273,8 @@ add_acute_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_mat_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add maternity columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>% @@ -282,6 +286,8 @@ add_mat_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_mh_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add mental health columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>% @@ -293,6 +299,8 @@ add_mh_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_gls_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add geriatric long stay columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>% @@ -304,6 +312,8 @@ add_gls_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_op_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add outpatient columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file <- episode_file %>% add_standard_cols(prefix, condition) @@ -327,6 +337,8 @@ add_op_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_ae_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add A&E columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition, cost = TRUE) %>% @@ -338,6 +350,8 @@ add_ae_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_pis_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add prescribing columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition, cost = TRUE) %>% @@ -349,6 +363,8 @@ add_pis_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_ooh_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add out of hours columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file <- episode_file %>% add_standard_cols(prefix, condition, cost = TRUE) %>% @@ -384,6 +400,8 @@ add_ooh_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_dn_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add district nursing columns function started at {Sys.time()}") + condition <- substitute(condition) if ("total_no_dn_contacts" %in% names(episode_file)) { episode_file %>% @@ -407,6 +425,8 @@ add_dn_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_cmh_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add communicty mental health columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition) %>% @@ -418,6 +438,8 @@ add_cmh_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_dd_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add delayed discharges columns function started at {Sys.time()}") + condition <- substitute(condition) condition_delay <- substitute(condition & primary_delay_reason != "9") episode_file <- episode_file %>% @@ -439,6 +461,8 @@ add_dd_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_nsu_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add non service users columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition) %>% @@ -450,6 +474,8 @@ add_nsu_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_nrs_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add nrs columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition) %>% @@ -461,6 +487,8 @@ add_nrs_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_hl1_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add homelessness columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition) @@ -471,6 +499,8 @@ add_hl1_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_ch_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add care home columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition) %>% @@ -501,6 +531,8 @@ add_ch_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_hc_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add home care columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file <- episode_file %>% @@ -545,6 +577,8 @@ add_hc_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_at_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add alarms telecare columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition) %>% @@ -559,6 +593,8 @@ add_at_columns <- function(episode_file, prefix, condition) { #' @inheritParams add_acute_columns #' @family individual_file add_sds_columns <- function(episode_file, prefix, condition) { + cli::cli_alert_info("Add SDS columns function started at {Sys.time()}") + condition <- substitute(condition) episode_file %>% add_standard_cols(prefix, condition) %>% @@ -581,6 +617,8 @@ add_sds_columns <- function(episode_file, prefix, condition) { #' cij_pattype (lgl) #' @family individual_file add_ipdc_cols <- function(episode_file, prefix, condition, ipdc_d = TRUE, elective = TRUE) { + cli::cli_alert_info("Add ipdc columns function started at {Sys.time()}") + condition_i <- substitute(eval(condition) & ipdc == "I") episode_file <- episode_file %>% dplyr::mutate( @@ -625,6 +663,8 @@ add_ipdc_cols <- function(episode_file, prefix, condition, ipdc_d = TRUE, electi #' @param cost Whether to create prefix_cost col, e.g. "Acute_cost" #' @family individual_file add_standard_cols <- function(episode_file, prefix, condition, episode = FALSE, cost = FALSE) { + cli::cli_alert_info("Add standard columns function started at {Sys.time()}") + if (episode) { episode_file <- dplyr::mutate(episode_file, "{prefix}_episodes" := dplyr::if_else(eval(condition), 1L, NA_integer_)) } @@ -703,6 +743,8 @@ recode_gender <- function(episode_file) { #' "dementia" and "dementia_date" #' @family individual_file condition_cols <- function() { + cli::cli_alert_info("Return condition columns function started at {Sys.time()}") + conditions <- slfhelper::ltc_vars date_cols <- paste0(conditions, "_date") all_cols <- c(conditions, date_cols) @@ -759,6 +801,8 @@ clean_individual_file <- function(individual_file, year) { #' #' @inheritParams clean_individual_file clean_up_gender <- function(individual_file) { + cli::cli_alert_info("Clean up gender column function started at {Sys.time()}") + individual_file %>% dplyr::mutate( gender = dplyr::case_when( @@ -785,6 +829,8 @@ join_slf_lookup_vars <- function(individual_file, col_select = c("gpprac", "cluster", "hbpraccode") ), hbrescode_var = "hb2018") { + cli::cli_alert_info("Join slf lookup variables function started at {Sys.time()}") + individual_file <- individual_file %>% dplyr::left_join( slf_postcode_lookup, diff --git a/R/fill_geographies.R b/R/fill_geographies.R index c9aee6355..5638c8758 100644 --- a/R/fill_geographies.R +++ b/R/fill_geographies.R @@ -16,6 +16,8 @@ fill_geographies <- function( get_slf_gpprac_path(), col_select = c("gpprac", "cluster", "hbpraccode") )) { + cli::cli_alert_info("Fill geographies function started at {Sys.time()}") + check_variables_exist(data, c( "chi", "postcode", diff --git a/R/join_deaths_data.R b/R/join_deaths_data.R index 7fbf203d0..d2fc51b91 100644 --- a/R/join_deaths_data.R +++ b/R/join_deaths_data.R @@ -10,6 +10,8 @@ join_deaths_data <- function( data, year, slf_deaths_lookup = read_file(get_slf_deaths_lookup_path(year)) %>% slfhelper::get_chi()) { + cli::cli_alert_info("Join deaths data function started at {Sys.time()}") + return( data %>% dplyr::left_join( diff --git a/R/join_sparra_hhg.R b/R/join_sparra_hhg.R index dafaca867..c22e1a9c3 100644 --- a/R/join_sparra_hhg.R +++ b/R/join_sparra_hhg.R @@ -5,6 +5,8 @@ #' @return The data including the SPARRA and HHG variables matched #' on to the episode file. join_sparra_hhg <- function(data, year) { + cli::cli_alert_info("Join SPARRA and HHG function started at {Sys.time()}") + if (check_year_valid(year, "sparra")) { data <- dplyr::left_join( data, diff --git a/R/link_delayed_discharge_eps.R b/R/link_delayed_discharge_eps.R index ef4aa4754..a28ee3b0f 100644 --- a/R/link_delayed_discharge_eps.R +++ b/R/link_delayed_discharge_eps.R @@ -12,6 +12,8 @@ link_delayed_discharge_eps <- function( episode_file, year, dd_data = read_file(get_source_extract_path(year, "dd")) %>% slfhelper::get_chi()) { + cli::cli_alert_info("Link delayed discharge to episode file function started at {Sys.time()}") + episode_file <- episode_file %>% dplyr::mutate( # remember to revoke the cij_end_date with dummy_cij_end diff --git a/R/match_on_ltcs.R b/R/match_on_ltcs.R index 3ed052be8..f0522c00d 100644 --- a/R/match_on_ltcs.R +++ b/R/match_on_ltcs.R @@ -12,6 +12,8 @@ match_on_ltcs <- function( data, year, ltc_data = read_file(get_ltcs_path(year)) %>% slfhelper::get_chi()) { + cli::cli_alert_info("Match on LTCs function started at {Sys.time()}") + # Match on LTC lookup matched <- dplyr::left_join( data, diff --git a/R/process_lookup_homelessness.R b/R/process_lookup_homelessness.R index b0dc30d51..5341cf2b6 100644 --- a/R/process_lookup_homelessness.R +++ b/R/process_lookup_homelessness.R @@ -13,6 +13,8 @@ create_homelessness_lookup <- function( year, homelessness_data = read_file(get_source_extract_path(year, "homelessness")) %>% slfhelper::get_chi()) { + cli::cli_alert_info("Create homelessness lookup function started at {Sys.time()}") + homelessness_lookup <- homelessness_data %>% dplyr::distinct(.data$chi, .data$record_keydate1, .data$record_keydate2) %>% tidyr::drop_na(.data$chi) %>% @@ -35,6 +37,8 @@ create_homelessness_lookup <- function( #' @export add_homelessness_flag <- function(data, year, lookup = create_homelessness_lookup(year)) { + cli::cli_alert_info("Add homelessness flag function started at {Sys.time()}") + data <- data %>% dplyr::left_join( lookup %>% @@ -59,6 +63,8 @@ add_homelessness_flag <- function(data, year, #' @return the final data as a [tibble][tibble::tibble-package]. #' @export add_homelessness_date_flags <- function(data, year, lookup = create_homelessness_lookup(year)) { + cli::cli_alert_info("Add homelessness date flags function started at {Sys.time()}") + lookup <- lookup %>% dplyr::filter(!(is.na(.data$record_keydate2))) %>% dplyr::rename(