From d09efcd7e736d14937ee7bdf1ab13b4c3caadbd6 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Tue, 18 Jul 2023 08:15:11 +0100 Subject: [PATCH] Make episode file output with `anon_chi` (#747) I've added this as a parameter so you can output CHI if desired, but the default is for anon_chi. For the tests, it swaps back to CHI as there are some tests which specifically us the CHI number. Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/process_tests_episode_file.R | 5 +++-- R/run_episode_file.R | 16 +++++++++++++++- man/run_episode_file.Rd | 10 +++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/R/process_tests_episode_file.R b/R/process_tests_episode_file.R index b595d1d54..46e9e7171 100644 --- a/R/process_tests_episode_file.R +++ b/R/process_tests_episode_file.R @@ -10,7 +10,7 @@ process_tests_episode_file <- function(data, year) { data <- data %>% dplyr::select( "year", - "chi", + "anon_chi", "gender", "postcode", "hbtreatcode", @@ -20,7 +20,8 @@ process_tests_episode_file <- function(data, year) { "record_keydate1", "record_keydate2", dplyr::contains(c("beddays", "cost", "cij")) - ) + ) %>% + slfhelper::get_chi() old_data <- get_existing_data_for_tests(data) diff --git a/R/run_episode_file.R b/R/run_episode_file.R index 45a4e6ed5..1f2bb33ed 100644 --- a/R/run_episode_file.R +++ b/R/run_episode_file.R @@ -4,11 +4,17 @@ #' @param year The year to process, in FY format. #' @param write_to_disk (optional) Should the data be written to disk default is #' `TRUE` i.e. write the data to disk. +#' @param anon_chi_out (Default:TRUE) Should `anon_chi` be used in the output +#' (instead of chi) #' #' @return a [tibble][tibble::tibble-package] containing the episode file #' @export #' -run_episode_file <- function(processed_data_list, year, write_to_disk = TRUE) { +run_episode_file <- function( + processed_data_list, + year, + write_to_disk = TRUE, + anon_chi_out = TRUE) { episode_file <- dplyr::bind_rows(processed_data_list) %>% create_cost_inc_dna() %>% apply_cost_uplift() %>% @@ -103,6 +109,14 @@ run_episode_file <- function(processed_data_list, year, write_to_disk = TRUE) { join_deaths_data(year) %>% load_ep_file_vars(year) + if (anon_chi_out) { + episode_file <- slfhelper::get_anon_chi( + episode_file, + chi_var = "chi", + drop = TRUE + ) + } + if (write_to_disk) { slf_path <- get_file_path( get_year_dir(year), diff --git a/man/run_episode_file.Rd b/man/run_episode_file.Rd index e85621b59..59d5fea1d 100644 --- a/man/run_episode_file.Rd +++ b/man/run_episode_file.Rd @@ -4,7 +4,12 @@ \alias{run_episode_file} \title{Produce the Source Episode file} \usage{ -run_episode_file(processed_data_list, year, write_to_disk = TRUE) +run_episode_file( + processed_data_list, + year, + write_to_disk = TRUE, + anon_chi_out = TRUE +) } \arguments{ \item{processed_data_list}{containing data from processed extracts.} @@ -13,6 +18,9 @@ run_episode_file(processed_data_list, year, write_to_disk = TRUE) \item{write_to_disk}{(optional) Should the data be written to disk default is \code{TRUE} i.e. write the data to disk.} + +\item{anon_chi_out}{(Default:TRUE) Should \code{anon_chi} be used in the output +(instead of chi)} } \value{ a \link[tibble:tibble-package]{tibble} containing the episode file