diff --git a/NAMESPACE b/NAMESPACE index 6c4f3cd52..ca901a8c2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/get_boxi_extract_path.R b/R/get_boxi_extract_path.R index 60dd7857a..7606014f9 100644 --- a/R/get_boxi_extract_path.R +++ b/R/get_boxi_extract_path.R @@ -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)) { @@ -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( + 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) +} diff --git a/man/get_csv_gz_path.Rd b/man/get_csv_gz_path.Rd new file mode 100644 index 000000000..6d151e014 --- /dev/null +++ b/man/get_csv_gz_path.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_boxi_extract_path.R +\name{get_csv_gz_path} +\alias{get_csv_gz_path} +\title{Get path as a csv or csv.gz} +\usage{ +get_csv_gz_path(year, type, ext = c("csv", "csv.gz")) +} +\arguments{ +\item{year}{Year of extract} + +\item{type}{Name of BOXI extract passed from \link{get_boxi_extract_path}} + +\item{ext}{Choice of extension between csv or csv.gz for zipped extracts} +} +\value{ +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. +} +\description{ +Get path as a csv or csv.gz +}