Skip to content

Commit

Permalink
Remove extra function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 committed Aug 9, 2023
1 parent 0f6282b commit 9093049
Showing 1 changed file with 31 additions and 45 deletions.
76 changes: 31 additions & 45 deletions R/get_boxi_extract_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,42 @@ get_boxi_extract_path <- function(
)) {
type <- match.arg(type)

if (type %in% c("DN", "CMH")) {
dir <- fs::path(get_slf_dir(), "Archived_data")
} else {
dir <- get_year_dir(year, extracts_dir = TRUE)
}

if (!check_year_valid(year, type)) {
return(get_dummy_boxi_extract_path())
}

boxi_extract_path_csv_gz <- get_csv_gz_path(year, type, ext = "csv.gz")
file_name <- dplyr::case_match(
type,
"AE" ~ "A&E-episode-level-extract",
"AE_CUP" ~ "A&E-UCD-CUP-extract",
"Acute" ~ "Acute-episode-level-extract",
"CMH" ~ "Community-MH-contact-level-extract",
"DN" ~ "District-Nursing-contact-level-extract",
"GP_OoH-c" ~ "GP-OoH-consultations-extract",
"GP_OoH-d" ~ "GP-OoH-diagnosis-extract",
"GP_OoH-o" ~ "GP-OoH-outcomes-extract",
"Homelessness" ~ "Homelessness-extract",
"Maternity" ~ "Maternity-episode-level-extract",
"MH" ~ "Mental-Health-episode-level-extract",
"Deaths" ~ "NRS-death-registrations-extract",
"Outpatients" ~ "Outpatients-episode-level-extract"
)

boxi_extract_path_csv_gz <- fs::path(
dir,
stringr::str_glue("{file_name}-20{year}.csv.gz")
)

boxi_extract_path_csv <- get_csv_gz_path(year, type, ext = "csv")
boxi_extract_path_csv <- fs::path(
dir,
stringr::str_glue("{file_name}-20{year}.csv")
)

# If the csv.gz file doesn't exist look for the unzipped csv.
if (fs::file_exists(boxi_extract_path_csv_gz)) {
Expand All @@ -59,46 +88,3 @@ get_dummy_boxi_extract_path <- function() {
create = TRUE
)
}

#' Get path as a csv or csv.gz
#'
#' @param year Year of extract
#' @param type Name of BOXI extract passed from [get_boxi_extract_path]
#' @param ext Choice of extension between csv or csv.gz for zipped extracts
#'
#' @return The file path to boxi extracts. Note for DN and CMH data this is
#' now in an archived folder which is set up to point to this in
#' the selections.
#' @export
#'
get_csv_gz_path <- function(year, type, ext = c("csv", "csv.gz")) {
if (type %in% c("DN", "CMH")) {
dir <- fs::path(get_slf_dir(), "Archived_data")
} else {
dir <- get_year_dir(year, extracts_dir = TRUE)
}

file_name <- dplyr::case_match(
type,
"AE" ~ "A&E-episode-level-extract",
"AE_CUP" ~ "A&E-UCD-CUP-extract",
"Acute" ~ "Acute-episode-level-extract",
"CMH" ~ "Community-MH-contact-level-extract",
"DN" ~ "District-Nursing-contact-level-extract",
"GP_OoH-c" ~ "GP-OoH-consultations-extract",
"GP_OoH-d" ~ "GP-OoH-diagnosis-extract",
"GP_OoH-o" ~ "GP-OoH-outcomes-extract",
"Homelessness" ~ "Homelessness-extract",
"Maternity" ~ "Maternity-episode-level-extract",
"MH" ~ "Mental-Health-episode-level-extract",
"Deaths" ~ "NRS-death-registrations-extract",
"Outpatients" ~ "Outpatients-episode-level-extract"
)

csv_gz_path <- fs::path(
dir,
stringr::str_glue("{file_name}-20{year}.{ext}")
)

return(csv_gz_path)
}

0 comments on commit 9093049

Please sign in to comment.