Skip to content

Commit

Permalink
Merge branch 'september-2024' into care_home_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 authored Jul 5, 2024
2 parents b78abfe + 4e761ec commit a5fbbb8
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/add_activity_after_death_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions R/add_nsu_cohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
2 changes: 2 additions & 0 deletions R/add_ppa_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @return A data frame to use as a lookup of PPAs

Check failure on line 8 in R/add_ppa_flag.R

View workflow job for this annotation

GitHub Actions / Check Spelling

`PPAs` is not a recognized word. (unrecognized-spelling)
#' @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(
Expand Down
2 changes: 2 additions & 0 deletions R/correct_demographics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions R/cost_uplift.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() %>%
Expand Down
16 changes: 16 additions & 0 deletions R/create_episode_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"]])
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 %>%
Expand Down
46 changes: 46 additions & 0 deletions R/create_individual_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>%
Expand All @@ -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) %>%
Expand All @@ -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) %>%
Expand All @@ -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) %>%
Expand All @@ -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)
Expand All @@ -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) %>%
Expand All @@ -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) %>%
Expand All @@ -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) %>%
Expand Down Expand Up @@ -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 %>%
Expand All @@ -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) %>%
Expand All @@ -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 %>%
Expand All @@ -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) %>%
Expand All @@ -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) %>%
Expand All @@ -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)
Expand All @@ -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) %>%
Expand Down Expand Up @@ -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 %>%
Expand Down Expand Up @@ -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) %>%
Expand All @@ -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) %>%
Expand All @@ -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(
Expand Down Expand Up @@ -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_))
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions R/fill_geographies.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions R/join_deaths_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions R/join_sparra_hhg.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions R/link_delayed_discharge_eps.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions R/match_on_ltcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit a5fbbb8

Please sign in to comment.