Skip to content

Commit

Permalink
Update get_boxi_extract_path for DN/CMH data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 committed Aug 8, 2023
1 parent bb3dbd5 commit 0f6282b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 26 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(find_latest_file)
export(fy_interval)
export(get_boxi_extract_path)
export(get_ch_costs_path)
export(get_csv_gz_path)
export(get_datazone_pop_path)
export(get_dd_path)
export(get_dd_period)
Expand Down
71 changes: 45 additions & 26 deletions R/get_boxi_extract_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,13 @@ get_boxi_extract_path <- function(
)) {
type <- match.arg(type)

year_dir <- get_year_dir(year, extracts_dir = TRUE)

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

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 <- get_csv_gz_path(year, type, ext = "csv.gz")

boxi_extract_path_csv_gz <- fs::path(
year_dir,
stringr::str_glue("{file_name}-20{year}.csv.gz")
)
boxi_extract_path_csv <- fs::path(
year_dir,
stringr::str_glue("{file_name}-20{year}.csv")
)
boxi_extract_path_csv <- get_csv_gz_path(year, type, ext = "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 @@ -83,3 +59,46 @@ 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(

Check warning on line 81 in R/get_boxi_extract_path.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/get_boxi_extract_path.R,line=81,col=3,[object_usage_linter] local variable 'file_name' assigned but may not be used
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)
}
23 changes: 23 additions & 0 deletions man/get_csv_gz_path.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f6282b

Please sign in to comment.