From 387fe8617b76523f3a7a0a375dbdbdf08a6fd112 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Mon, 28 Oct 2024 10:40:16 +0000 Subject: [PATCH] Update process_extract_ae.R --- R/process_extract_ae.R | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/R/process_extract_ae.R b/R/process_extract_ae.R index 9a5829cc5..33c23d8d6 100644 --- a/R/process_extract_ae.R +++ b/R/process_extract_ae.R @@ -196,6 +196,8 @@ process_extract_ae <- function(data, year, write_to_disk = TRUE) { col_type = readr::cols( "ED Arrival Date" = readr::col_date(format = "%Y/%m/%d %T"), "ED Arrival Time" = readr::col_time(""), + "ED Discharge Date" = readr::col_date(format = "%Y/%m/%d %T"), + "ED Discharge Time" = readr::col_time(""), "ED Case Reference Number [C]" = readr::col_character(), "CUP Marker" = readr::col_double(), "CUP Pathway Name" = readr::col_character() @@ -205,6 +207,8 @@ process_extract_ae <- function(data, year, write_to_disk = TRUE) { dplyr::rename( record_keydate1 = "ED Arrival Date", keytime1 = "ED Arrival Time", + record_keydate2 = "ED Discharge Date", + keytime2 = "ED Discharge Time", case_ref_number = "ED Case Reference Number [C]", cup_marker = "CUP Marker", cup_pathway = "CUP Pathway Name" @@ -216,19 +220,20 @@ process_extract_ae <- function(data, year, write_to_disk = TRUE) { ae_cup_clean <- ae_cup_file %>% # Remove any duplicates dplyr::distinct(.data$record_keydate1, - .data$keytime1, - .data$case_ref_number, - .keep_all = TRUE - ) + .data$keytime1, + .data$record_keydate2, + .data$keytime2, + .data$case_ref_number, + .keep_all = TRUE) # Join data-------------------------------------------- matched_ae_data <- outfile %>% - dplyr::left_join( - ae_cup_clean, - by = c("record_keydate1", "keytime1", "case_ref_number") - ) %>% + dplyr::left_join(ae_cup_clean, + by = c("record_keydate1", "keytime1", + "record_keydate2", "keytime2", + "case_ref_number")) %>% dplyr::arrange( .data$chi, .data$record_keydate1,