Skip to content

Commit

Permalink
Merge branch 'september-2024' into care_home_update
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftySalmon authored Jul 16, 2024
2 parents bdc4f86 + 8d8872d commit 5d1e27c
Show file tree
Hide file tree
Showing 27 changed files with 751 additions and 183 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export(midpoint_fy)
export(next_fy)
export(phs_db_connection)
export(previous_update)
export(process_combined_deaths_lookup)
export(process_costs_ch_rmd)
export(process_costs_dn_rmd)
export(process_costs_gp_ooh_rmd)
Expand Down
6 changes: 4 additions & 2 deletions R/add_activity_after_death_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ add_activity_after_death_flag <- function(
#'
#'
# Read data------------------------------------------------
process_deaths_lookup <- function(update = latest_update(),
write_to_disk = TRUE, ...) {

process_combined_deaths_lookup <- function(update = latest_update(),
write_to_disk = TRUE, ...) {

dir_folder <- "/conf/hscdiip/SLF_Extracts/Deaths"
file_names <- list.files(dir_folder,
pattern = "^anon-slf_deaths_lookup_.*parquet",
Expand Down
2 changes: 2 additions & 0 deletions R/fill_ch_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ fill_ch_names <- function(ch_data,
"unique_identifier",
"matching_quality_indicator",
"sending_location",
"latest_sc_id",
"chi",
"ch_name",
"ch_postcode",
Expand Down Expand Up @@ -759,6 +760,7 @@ fill_ch_names <- function(ch_data,
## produce output ----
col_output <- c(
"sending_location",
"latest_sc_id",
"chi",
"ch_name",
"ch_postcode",
Expand Down
4 changes: 4 additions & 0 deletions R/get_boxi_extract_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ get_boxi_extract_path <- function(
"ae",
"ae_cup",
"acute",
"acute_cup",
"cmh",
"deaths",
"dn",
"gp_ooh-c",
"gp_ooh-d",
"gp_ooh-o",
"gp_ooh_cup",
"homelessness",
"maternity",
"mh",
Expand All @@ -44,11 +46,13 @@ get_boxi_extract_path <- function(
"ae" ~ "anon-A&E-episode-level-extract",
"ae_cup" ~ "anon-A&E-UCD-CUP-extract",
"acute" ~ "anon-Acute-episode-level-extract",
"acute_cup" ~ "anon-Acute-cup-extract",
"cmh" ~ "anon-Community-MH-contact-level-extract",
"dn" ~ "anon-District-Nursing-contact-level-extract",
"gp_ooh-c" ~ "anon-GP-OoH-consultations-extract",
"gp_ooh-d" ~ "anon-GP-OoH-diagnosis-extract",
"gp_ooh-o" ~ "anon-GP-OoH-outcomes-extract",
"gp_ooh_cup" ~ "anon-GP-OoH-cup-extract",
"homelessness" ~ "anon-Homelessness-extract",
"maternity" ~ "anon-Maternity-episode-level-extract",
"mh" ~ "anon-Mental-Health-episode-level-extract",
Expand Down
52 changes: 49 additions & 3 deletions R/process_extract_acute.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#' @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 @@ -59,7 +62,48 @@ 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
))
)) %>%
dplyr::mutate(
unique_row_num = dplyr::row_number()
)

acute_cup <- read_file(
path = acute_cup_path,
col_type = readr::cols(
"anon_chi" = readr::col_character(),
"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(),
"CUP Marker" = readr::col_integer(),
"CUP Pathway Name" = readr::col_character()
)
) %>%
dplyr::select(
anon_chi = "anon_chi",
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() %>%
slfhelper::get_chi()

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 +150,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) %>%
slfhelper::get_anon_chi()
Expand Down
42 changes: 40 additions & 2 deletions R/process_extract_gp_ooh.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#' @return the final data as a [tibble][tibble::tibble-package].
#' @export
#' @family process extracts
process_extract_gp_ooh <- function(year, data_list, write_to_disk = TRUE) {
process_extract_gp_ooh <- function(year,
data_list,
gp_ooh_cup_path = get_boxi_extract_path(year, "gp_ooh_cup"),
write_to_disk = TRUE) {
diagnosis_extract <- process_extract_ooh_diagnosis(data_list[["diagnosis"]], year)
outcomes_extract <- process_extract_ooh_outcomes(data_list[["outcomes"]], year)
consultations_extract <- process_extract_ooh_consultations(data_list[["consultations"]], year)
Expand Down Expand Up @@ -93,6 +96,39 @@ process_extract_gp_ooh <- function(year, data_list, write_to_disk = TRUE) {
) %>%
dplyr::ungroup()

## Link CUP Marker -----
gp_ooh_cup_file <- read_file(
path = gp_ooh_cup_path,
col_type = readr::cols(
"GP OOH Consultation Start Date" = readr::col_date(format = "%Y/%m/%d %T"),
"GP OOH Consultation Start Time" = readr::col_time(""),
"GUID" = readr::col_character(),
"CUP Marker" = readr::col_integer(),
"CUP Pathway Name" = readr::col_character()
)
) %>%
dplyr::select(
record_keydate1 = "GP OOH Consultation Start Date",
keytime1 = "GP OOH Consultation Start Time",
ooh_case_id = "GUID",
cup_marker = "CUP Marker",
cup_pathway = "CUP Pathway Name"
) %>%
dplyr::distinct(
.data$record_keydate1,
.data$keytime1,
.data$ooh_case_id,
.keep_all = TRUE
)

ooh_clean <- ooh_clean %>%
dplyr::left_join(gp_ooh_cup_file,
by = dplyr::join_by(
"ooh_case_id",
"record_keydate1",
"keytime1"
)
)

## Save Outfile -------------------------------------

Expand Down Expand Up @@ -122,7 +158,9 @@ process_extract_gp_ooh <- function(year, data_list, write_to_disk = TRUE) {
tidyselect::starts_with("ooh_outcome"),
"cost_total_net",
tidyselect::ends_with("_cost"),
"ooh_case_id"
"ooh_case_id",
cup_marker,
cup_pathway
) %>%
slfhelper::get_anon_chi()

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
71 changes: 69 additions & 2 deletions Run_SLF_Files_manually/run_episode_file_1718.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,77 @@ library(createslf)

year <- "1718"

processed_data_list <- targets::tar_read("processed_data_list_1718",
store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")
targets_store <- fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")

processed_data_list <- list(
acute = targets::tar_read(
"source_acute_extract_1718",
store = targets_store
),
ae = targets::tar_read(
"source_ae_extract_1718",
store = targets_store
),
cmh = targets::tar_read(
"source_cmh_extract_1718",
store = targets_store
),
cmh = targets::tar_read(
"source_cmh_extract_1718",
store = targets_store
),
dn = targets::tar_read(
"source_dn_extract_1718",
store = targets_store
),
deaths = targets::tar_read(
"source_nrs_deaths_extract_1718",
store = targets_store
),
homelessness = targets::tar_read(
"source_homelessness_extract_1718",
store = targets_store
),
maternity = targets::tar_read(
"source_maternity_extract_1718",
store = targets_store
),
mental_health = targets::tar_read(
"source_mental_health_extract_1718",
store = targets_store
),
outpatients = targets::tar_read(
"source_outpatients_extract_1718",
store = targets_store
),
gp_ooh = targets::tar_read(
"source_ooh_extract_1718",
store = targets_store
),
prescribing = targets::tar_read(
"source_prescribing_extract_1718",
store = targets_store
),
care_home = targets::tar_read(
"source_sc_care_home_1718",
store = targets_store
),
home_care = targets::tar_read(
"source_sc_home_care_1718",
store = targets_store
),
at = targets::tar_read(
"source_sc_alarms_tele_1718",
store = targets_store
),
sds = targets::tar_read(
"source_sc_sds_1718",
store = targets_store
)
)

# Run episode file
create_episode_file(processed_data_list, year = year) %>%
process_tests_episode_file(year = year)

## End of Script ##
71 changes: 69 additions & 2 deletions Run_SLF_Files_manually/run_episode_file_1819.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,77 @@ library(createslf)

year <- "1819"

processed_data_list <- targets::tar_read("processed_data_list_1819",
store = fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")
targets_store <- fs::path("/conf/sourcedev/Source_Linkage_File_Updates/", "_targets")

processed_data_list <- list(
acute = targets::tar_read(
"source_acute_extract_1819",
store = targets_store
),
ae = targets::tar_read(
"source_ae_extract_1819",
store = targets_store
),
cmh = targets::tar_read(
"source_cmh_extract_1819",
store = targets_store
),
cmh = targets::tar_read(
"source_cmh_extract_1819",
store = targets_store
),
dn = targets::tar_read(
"source_dn_extract_1819",
store = targets_store
),
deaths = targets::tar_read(
"source_nrs_deaths_extract_1819",
store = targets_store
),
homelessness = targets::tar_read(
"source_homelessness_extract_1819",
store = targets_store
),
maternity = targets::tar_read(
"source_maternity_extract_1819",
store = targets_store
),
mental_health = targets::tar_read(
"source_mental_health_extract_1819",
store = targets_store
),
outpatients = targets::tar_read(
"source_outpatients_extract_1819",
store = targets_store
),
gp_ooh = targets::tar_read(
"source_ooh_extract_1819",
store = targets_store
),
prescribing = targets::tar_read(
"source_prescribing_extract_1819",
store = targets_store
),
care_home = targets::tar_read(
"source_sc_care_home_1819",
store = targets_store
),
home_care = targets::tar_read(
"source_sc_home_care_1819",
store = targets_store
),
at = targets::tar_read(
"source_sc_alarms_tele_1819",
store = targets_store
),
sds = targets::tar_read(
"source_sc_sds_1819",
store = targets_store
)
)

# Run episode file
create_episode_file(processed_data_list, year = year) %>%
process_tests_episode_file(year = year)

## End of Script ##
Loading

0 comments on commit 5d1e27c

Please sign in to comment.