Skip to content

Commit

Permalink
Fix for years with no DN data
Browse files Browse the repository at this point in the history
21/22 and 22/23 we're failing because they didn't have `total_no_dn_contacts` this is a bit of a crude fix but should work for any year, and if the variable doesn't exist in the episode file it will be created as `NA` in the individual file.
  • Loading branch information
Moohan committed Jul 20, 2023
1 parent e4c1465 commit 1571ade
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions R/create_individual_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ create_individual_file <- function(
}

individual_file <- episode_file %>%
dplyr::select(
dplyr::select(dplyr::any_of(c(
"year",
"chi",
"dob",
Expand Down Expand Up @@ -57,7 +57,7 @@ create_individual_file <- function(
"hc_hours_annual",
"hc_reablement",
"ooh_case_id"
) %>%
))) %>%
remove_blank_chi() %>%
add_cij_columns() %>%
add_all_columns() %>%
Expand Down Expand Up @@ -321,9 +321,21 @@ add_ooh_columns <- function(episode_file, prefix, condition) {
#' @inheritParams add_acute_columns
add_dn_columns <- function(episode_file, prefix, condition) {
condition <- substitute(condition)
episode_file %>%
add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>%
dplyr::mutate("{prefix}_contacts" := dplyr::if_else(eval(condition), .data$total_no_dn_contacts, NA_integer_))
if ("total_no_dn_contacts" %in% names(episode_file)) {
episode_file %>%
add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>%
dplyr::mutate(
"{prefix}_contacts" := dplyr::if_else(
eval(condition),
.data$total_no_dn_contacts,
NA_integer_
)
)
} else {
episode_file %>%
add_standard_cols(prefix, condition, episode = TRUE, cost = TRUE) %>%
dplyr::mutate("{prefix}_contacts" := NA_integer_)
}
}

#' Add CMH columns
Expand Down

0 comments on commit 1571ade

Please sign in to comment.