Skip to content

Commit

Permalink
Merge branch 'september-2024' into add_client_flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 authored Jul 19, 2024
2 parents 37a0021 + 9dac223 commit dc4e67b
Show file tree
Hide file tree
Showing 30 changed files with 742 additions and 200 deletions.
20 changes: 10 additions & 10 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Accom
Admissio
admloc
admtype
ADPE
adpe
adtf
alstr
arrivalmode
Expand All @@ -20,12 +20,12 @@ bodyloc
boxi
CAK
callr
Canx
canx
carehome
careinspectorate
categorises
cattend
CCYY
ccyy
cdn
cennum
CEREBROVASC
Expand All @@ -36,9 +36,9 @@ chpstart
cij
Classificat
cmh
CNWs
cnws
codecov
Comhairle
comhairle
commhosp
congen
copd
Expand Down Expand Up @@ -158,7 +158,7 @@ keytime
kis
knitr
lcap
LCHO
lcho
lgl
linetype
lintr
Expand All @@ -168,8 +168,8 @@ ltd
lubridate
magrittr
markdownguide
Matern
Mcbride
matern
mcbride
mcmahon
microsoft
MIU
Expand Down Expand Up @@ -215,7 +215,7 @@ PLICS
popluation
Posix
postcodes
PPAs
ppas
prac
praccode
ptypes
Expand Down Expand Up @@ -268,7 +268,7 @@ simd
slf
slfhelper
smr
SMRA
smra
smrtype
sourcedev
sparra
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ 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)
export(process_costs_hc_rmd)
export(process_deaths_lookup)
export(process_extract_acute)
export(process_extract_ae)
export(process_extract_alarms_telecare)
Expand Down
4 changes: 2 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,8 @@ 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
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
2 changes: 1 addition & 1 deletion R/process_extract_alarms_telecare.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ process_extract_alarms_telecare <- function(
"smrtype",
"chi",
"dob",
"person_id",
"gender",
"postcode",
"sc_send_lca",
"record_keydate1",
"record_keydate2",
"person_id",
"sc_latest_submission"
) %>%
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
4 changes: 3 additions & 1 deletion R/process_extract_sds.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ process_extract_sds <- function(
"smrtype",
"chi",
"dob",
"person_id",
"gender",
"postcode",
"sc_send_lca",
"record_keydate1",
"record_keydate2",
"sc_send_lca"
"sc_latest_submission"
) %>%
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
1 change: 1 addition & 0 deletions R/read_lookup_sc_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ read_lookup_sc_client <- function(fyyear,
"day_care"
) %>%
dplyr::filter(.data$financial_year == year) %>%
dplyr::collect() %>%
dplyr::mutate(
dplyr::across(
c(
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 ##
Loading

0 comments on commit dc4e67b

Please sign in to comment.