Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions R/get_slf_lookup_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,21 @@ get_combined_slf_deaths_lookup_path <- function(update = latest_update(), ...) {
#' @export
#' @family slf lookup file path
#' @seealso [get_file_path()] for the generic function.
get_slf_chi_deaths_path <- function(update = latest_update(), ...) {
slf_chi_deaths_path <- get_file_path(
directory = fs::path(get_slf_dir(), "Deaths"),
file_name = stringr::str_glue("anon-chi_deaths_{update}.parquet"),
...
)
get_slf_chi_deaths_path <- function(update = latest_update(), BYOC_MODE = FALSE, ...) {
file_name <- stringr::str_glue("anon-chi_deaths_{update}.parquet")

if (BYOC_MODE) {
slf_chi_deaths_path <- file.path(
directory = denodo_output_path(), ## TO-DO: waiting to be finalised
file_name = file_name
)
} else {
slf_chi_deaths_path <- get_file_path(
directory = fs::path(get_slf_dir(), "Deaths"),
file_name = file_name,
...
)
}

return(slf_chi_deaths_path)
}
Expand Down
30 changes: 23 additions & 7 deletions R/process_it_chi_deaths.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
#' @return the final data as a [tibble][tibble::tibble-package].
#' @export
#' @family process extracts
process_it_chi_deaths <- function(data, write_to_disk = TRUE) {
process_it_chi_deaths <- function(data,
write_to_disk = TRUE,
BYOC_MODE = FALSE,
run_id = NA,
run_date_time = NA) {
log_slf_event(stage = "process", status = "start", type = "it_chi_deaths", year = "all")

it_chi_deaths_clean <- data %>%
Expand All @@ -21,16 +25,28 @@ process_it_chi_deaths <- function(data, write_to_disk = TRUE) {
dplyr::distinct(.data$anon_chi, .keep_all = TRUE) %>%
# remove death_date_nrs as this is the nrs weekly unvalidated data and we should not use this.
# the boxi nrs death date is more reliable as this is provided monthly and is validated.
dplyr::select(.data$anon_chi, .data$death_date_chi) %>%
dplyr::mutate(
death_date_chi = lubridate::ymd(.data$death_date_chi)
death_date_chi = lubridate::ymd(.data$death_date_chi),
run_id = run_id,
run_date_time = run_date_time
) %>%
dplyr::select(
"run_id",
"run_date_time",
"anon_chi",
"death_date_chi"
)

if (write_to_disk) {
it_chi_deaths_clean %>%
write_file(get_slf_chi_deaths_path(check_mode = "write"),
group_id = 3206 # hscdiip owner
)
write_file(
it_chi_deaths_clean,
get_slf_chi_deaths_path(
BYOC_MODE,
check_mode = "write"
),
BYOC_MODE = BYOC_MODE,
group_id = 3206 # hscdiip owner
)
}

log_slf_event(stage = "process", status = "complete", type = "it_chi_deaths", year = "all")
Expand Down
24 changes: 18 additions & 6 deletions R/read_it_chi_deaths.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@
#' @return the final data as a [tibble][tibble::tibble-package].
#' @export
#' @family process extracts
read_it_chi_deaths <- function(file_path = get_it_deaths_path()) {
read_it_chi_deaths <- function(denodo_connect = get_denodo_connection(BYOC_MODE = BYOC_MODE),
file_path = get_it_deaths_path(), ## CHECK + Is this needed?
BYOC_MODE ## Is this needed?
) {
log_slf_event(stage = "read", status = "start", type = "it_chi_deaths", year = "all")

it_chi_deaths <- read_file(file_path) %>%
on.exit(try(DBI::dbDisconnect(denodo_connect), silent = TRUE), add = TRUE)

it_chi_deaths <- dplyr::tbl(
denodo_connect,
dbplyr::in_schema("sdl", "sdl_XXX")
) %>% ## PLACEHOLDER
dplyr::select(
anon_chi = "anon_chi",
death_date_nrs = "PATIENT DoD DATE (NRS)",
death_date_chi = "PATIENT DoD DATE (CHI)"
anon_chi = "patient_upi", ## CHECK
death_date_nrs = "patient_dod_nrs", ## CHECK
death_date_chi = "patient_dod_chi" ## CHECK
) %>%
dplyr::mutate(
death_date_nrs = lubridate::dmy(.data$death_date_nrs),
death_date_chi = lubridate::dmy(.data$death_date_chi)
)
) %>%
dplyr::collect() %>%
slfhelper::get_anon_chi("anon_chi") ## CHECK

log_slf_event(stage = "read", status = "complete", type = "it_chi_deaths", year = "all")

log_slf_event(stage = "read", status = "complete", type = "it_chi_deaths", year = "all")

Expand Down
15 changes: 14 additions & 1 deletion SDL_process/run_sdl.r
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ year <- "1920"
# Build BYOC Output File Paths
byoc_output_files <- get_byoc_output_files(
year = year,
types = c("homelessness", "maternity") # using homelessness for test purpose. When development is complete, we change to "types = "byoc_input_files""
types = c("homelessness", "maternity", "it_chi_deaths") # using homelessness for test purpose. When development is complete, we change to "types = "byoc_input_files""
) # can always use any other type for testing also

## targets ----
Expand Down Expand Up @@ -207,4 +207,17 @@ maternity <- read_extract_maternity(
run_date_time = run_date_time
)

# Logger is included within each function so is excluded here?
it_chi_deaths <- read_it_chi_deaths(
denodo_connect = get_denodo_connection(BYOC_MODE = BYOC_MODE),
file_path = get_it_deaths_path(),
BYOC_MODE = BYOC_MODE
) %>%
process_it_chi_deaths(
write_to_disk = TRUE,
BYOC_MODE = BYOC_MODE,
run_id = run_id,
run_date_time = run_date_time
)

logger::log_info("Run SDL ended.")
17 changes: 13 additions & 4 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,15 @@ list(
),
# IT deaths-----------------------------------------------------------------
# READ - IT CHI deaths------
tar_file_read(it_chi_deaths_extract,
command = get_it_deaths_path(),
read = read_it_chi_deaths(!!.x)
tar_target(
# Target name
it_chi_deaths_extract,
# Function
read_it_chi_deaths(
denodo_connect = get_denodo_connection(BYOC_MODE = BYOC_MODE),
file_path = get_it_deaths_path(),
BYOC_MODE = BYOC_MODE
)
),
# PROCESS - IT CHI deaths------
tar_target(
Expand All @@ -269,7 +275,10 @@ list(
# Function
process_it_chi_deaths(
data = it_chi_deaths_extract,
write_to_disk = write_to_disk
write_to_disk = write_to_disk,
BYOC_MODE = BYOC_MODE,
run_id = run_id,
run_date_time = run_date_time
),
priority = 0.9
),
Expand Down
2 changes: 1 addition & 1 deletion man/get_slf_chi_deaths_path.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/process_it_chi_deaths.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/read_it_chi_deaths.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.