Skip to content

Commit

Permalink
link cup to acute
Browse files Browse the repository at this point in the history
  • Loading branch information
lizihao-anu committed May 23, 2024
1 parent 3869b09 commit a967d5c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions R/get_boxi_extract_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ get_boxi_extract_path <- function(
"ae",
"ae_cup",
"acute",
"acute_cup",
"cmh",
"deaths",
"dn",
Expand Down Expand Up @@ -44,6 +45,7 @@ get_boxi_extract_path <- function(
"ae" ~ "A&E-episode-level-extract",
"ae_cup" ~ "A&E-UCD-CUP-extract",
"acute" ~ "Acute-episode-level-extract",
"acute_cup" ~ "Actue-cup-extract",

Check failure on line 48 in R/get_boxi_extract_path.R

View workflow job for this annotation

GitHub Actions / Check Spelling

`Actue` is not a recognized word. (unrecognized-spelling)
"cmh" ~ "Community-MH-contact-level-extract",
"dn" ~ "District-Nursing-contact-level-extract",
"gp_ooh-c" ~ "GP-OoH-consultations-extract",
Expand Down
49 changes: 45 additions & 4 deletions R/process_extract_acute.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#' @return the final data as a [tibble][tibble::tibble-package].
#' @export
#' @family process extracts
process_extract_acute <- function(data, year, write_to_disk = TRUE) {
process_extract_acute <- function(data,
year,
acute_cup_path = get_boxi_extract_path(year, "acute_cup"),
write_to_disk = TRUE) {

# Only run for a single year
stopifnot(length(year) == 1L)

Expand Down Expand Up @@ -58,8 +62,43 @@ process_extract_acute <- function(data, year, write_to_disk = TRUE) {
) %>%
# Add oldtadm as a factor with labels
dplyr::mutate(oldtadm = factor(.data$oldtadm,
levels = 0L:8L
))
levels = 0L:8L
)) %>%
dplyr::mutate(
unique_row_num = dplyr::row_number()
)

acute_cup <- read_file(
path = acute_cup_path,
col_type = readr::cols(
"Acute Admission Date" = readr::col_date(format = "%Y/%m/%d %T"),
"Acute Discharge Date" = readr::col_date(format = "%Y/%m/%d %T"),
"Acute Admission Type Code" = readr::col_character(),
"Acute Discharge Type Code" = readr::col_character(),
"Case Reference Number [C]" = readr::col_character(),
"UPI Number [C]" = readr::col_character(),
"CUP Marker" = readr::col_integer(),
"CUP Pathway Name" = readr::col_character()
)
) %>% dplyr::select(
chi = "UPI Number [C]",
case_reference_number = "Case Reference Number [C]",
record_keydate1 = "Acute Admission Date",
record_keydate2 = "Acute Discharge Date",
tadm = "Acute Admission Type Code",
disch = "Acute Discharge Type Code",
cup_marker = "CUP Marker",
cup_pathway = "CUP Pathway Name"
) %>% dplyr::distinct()

acute_clean <- acute_clean %>%
dplyr::left_join(acute_cup,
by = c("record_keydate1",
"record_keydate2",
"case_reference_number",
"chi",
"tadm",
"disch"))

acute_processed <- acute_clean %>%
dplyr::select(
Expand Down Expand Up @@ -106,7 +145,9 @@ process_extract_acute <- function(data, year, write_to_disk = TRUE) {
"cost_total_net",
tidyselect::ends_with("_beddays"),
tidyselect::ends_with("_cost"),
"uri"
"uri",
"cup_marker",
"cup_pathway"
) %>%
dplyr::arrange(.data$chi, .data$record_keydate1)

Expand Down
1 change: 1 addition & 0 deletions R/read_extract_acute.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ read_extract_acute <- function(year, file_path = get_boxi_extract_path(year = ye
ipdc = "Inpatient Day Case Identifier Code",
cij_ipdc = "CIJ Inpatient Day Case Identifier Code (01)",
lineno = "Line Number (01)",
case_reference_number = "Case Reference Number [C]",
GLS_record = "GLS Record"
) %>%
# replace NA in cost_total_net by 0
Expand Down
12 changes: 12 additions & 0 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ list(
get_boxi_extract_path(year = year, type = "gp_ooh-c"),
format = "file"
),
tar_target(
acute_cup_path,
get_boxi_extract_path(year, type = "acute_cup"),
format = "file"
),
tar_target(
gp_ooh_cup_path,
get_boxi_extract_path(year, type = "gp_ooh_cup"),
format = "file"
),
tar_qs(
ooh_data,
read_extract_gp_ooh(
Expand All @@ -294,6 +304,7 @@ list(
tar_target(source_acute_extract, process_extract_acute(
acute_data,
year,
acute_cup_path,
write_to_disk = write_to_disk
)),
tar_target(
Expand Down Expand Up @@ -419,6 +430,7 @@ list(
tar_target(source_ooh_extract, process_extract_gp_ooh(
year,
ooh_data,
gp_ooh_cup_path,
write_to_disk = write_to_disk
)),
tar_target(
Expand Down

0 comments on commit a967d5c

Please sign in to comment.