diff --git a/R/create_individual_file.R b/R/create_individual_file.R index 84dbd28ee..f0e6bcdfc 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -61,7 +61,7 @@ create_individual_file <- function( remove_blank_chi() %>% add_cij_columns() %>% add_all_columns() %>% - aggregate_ch_episodes_zihao() %>% + aggregate_ch_episodes() %>% clean_up_ch(year) %>% recode_gender() %>% aggregate_by_chi() %>% @@ -741,13 +741,25 @@ join_sc_client <- function( sc_demographics %>% dplyr::select("sending_location", "social_care_id", "chi"), by = c("sending_location", "social_care_id") - ) + ) %>% + dplyr::mutate(count_not_known = rowSums(dplyr::select(., all_of( + c( + "sc_living_alone", + "sc_support_from_unpaid_carer", + "sc_social_worker", + "sc_meals", + "sc_day_care" + ) + )) == "Not Known")) %>% + dplyr::arrange(chi, count_not_known) %>% + dplyr::distinct(chi, .keep_all = TRUE) # Match on client variables by chi individual_file <- individual_file %>% dplyr::left_join( join_client_demog, - by = "chi" + by = "chi", + relationship = "one-to-one" ) %>% dplyr::select(!c("sending_location", "social_care_id", "sc_latest_submission")) diff --git a/R/process_tests_individual_file.R b/R/process_tests_individual_file.R index 2c93f243e..a9d193465 100644 --- a/R/process_tests_individual_file.R +++ b/R/process_tests_individual_file.R @@ -64,9 +64,8 @@ produce_individual_file_tests <- function(data) { create_demog_test_flags() %>% create_hb_test_flags(.data$hbrescode) %>% create_hb_cost_test_flags(.data$hbrescode, .data$health_net_cost) %>% - create_hscp_test_flags(.data$hscp2018) %>% # keep variables for comparison - dplyr::select("valid_chi":dplyr::last_col()) %>% + dplyr::select(c("valid_chi":dplyr::last_col())) %>% # use function to sum new test flags calculate_measures(measure = "sum") @@ -86,7 +85,9 @@ produce_individual_file_tests <- function(data) { min_max_measures <- data %>% calculate_measures( - vars = "health_net_cost", + vars = c( + "health_net_cost" + ), measure = "min-max" ) @@ -99,11 +100,18 @@ produce_individual_file_tests <- function(data) { measure = "sum" ) + dup_chi <- data.frame( + measure = "duplicated chi number", + value = duplicated(data$chi) %>% + sum() %>% as.integer() + ) + join_output <- list( test_flags, all_measures, min_max_measures, - sum_measures + sum_measures, + dup_chi ) %>% purrr::reduce(dplyr::full_join, by = c("measure", "value"))