Skip to content

Commit

Permalink
fix bugs of dd and populate cij_delay back to episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lizihao-anu committed Aug 27, 2024
1 parent 45ddf9a commit 500b166
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/create_episode_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ create_episode_file <- function(
fill_missing_cij_markers() %>%
add_homelessness_flag(year, lookup = homelessness_lookup) %>%
add_homelessness_date_flags(year, lookup = homelessness_lookup) %>%
link_delayed_discharge_eps(year, dd_data) %>%
add_ppa_flag() %>%
link_delayed_discharge_eps(year, dd_data) %>%
add_nsu_cohort(year, nsu_cohort) %>%
match_on_ltcs(year, ltc_data) %>%
correct_demographics(year) %>%
Expand Down
17 changes: 16 additions & 1 deletion R/link_delayed_discharge_eps.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ link_delayed_discharge_eps <- function(
)) %>%
dplyr::group_by(.data$chi, .data$cij_marker) %>%
dplyr::mutate(cij_delay = max(.data$has_delay)) %>%
dplyr::mutate(cij_delay = dplyr::if_else(cij_delay == "0",
FALSE,
TRUE,
missing = NA)) %>%
dplyr::ungroup() %>%
# add yearstay and monthly beddays
# count_last = TRUE because DD counts last day and not the first
Expand All @@ -299,6 +303,7 @@ link_delayed_discharge_eps <- function(
yearstay = rowSums(dplyr::pick(dplyr::ends_with("_beddays")))
) %>%
# tidy up and rename columns to match the format of episode files
# add variables that you want to keep
dplyr::select(
"year" = "year_dd",
"recid" = "recid_dd",
Expand All @@ -317,6 +322,7 @@ link_delayed_discharge_eps <- function(
"primary_delay_reason",
"secondary_delay_reason",
"cij_marker",
"cij_ppa",
"cij_start_date",
"cij_end_date",
"cij_pattype_code",
Expand Down Expand Up @@ -345,7 +351,16 @@ link_delayed_discharge_eps <- function(
"dummy_cij_end"
)
)
)
) %>%
# populate cij_delay dd details back to ep
dplyr::group_by(chi, cij_marker) %>%
dplyr::mutate(has_dd = any(recid == "DD"),
delay_dd = any(cij_delay)) %>%
dplyr::ungroup() %>%
dplyr::mutate(cij_delay = dplyr::if_else(has_dd,
delay_dd,
cij_delay)) %>%
dplyr::select(-c("has_dd", "delay_dd"))

return(linked_data)
}

0 comments on commit 500b166

Please sign in to comment.