diff --git a/NAMESPACE b/NAMESPACE index 670ed1932..91f6b66d9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,6 +54,7 @@ export(get_nsu_path) export(get_pop_path) export(get_practice_details_path) export(get_readcode_lookup_path) +export(get_sandpit_extract_path) export(get_sc_at_episodes_path) export(get_sc_ch_episodes_path) export(get_sc_client_lookup_path) diff --git a/R/get_sandpit_extract_path.R b/R/get_sandpit_extract_path.R new file mode 100644 index 000000000..9d8089122 --- /dev/null +++ b/R/get_sandpit_extract_path.R @@ -0,0 +1,39 @@ +#' Sandpit Extract File Path +#' +#' @description Get the file path for sandpit extracts +#' +#' @param update The update month to use, +#' defaults to [latest_update()] +#' +#' @param ... additional arguments passed to [get_file_path()] +#' +#' @return The path to the sandpit extracts as an [fs::path()] +#' @export +#' @family social care sandpit extract paths +#' @seealso [get_file_path()] for the generic function. +get_sandpit_extract_path <- function(type = c( + "at", "ch", "hc", + "sds", "client", "demographics" + ), + year = NULL, + update = latest_update(), ...) { + dir <- fs::path(get_slf_dir(), "Social_care", "Sandpit_Extracts") + + file_name <- dplyr::case_match( + type, + "at" ~ "sandpit_at_extract", + "ch" ~ "sandpit_ch_extract", + "hc" ~ "sandpit_hc_extract", + "sds" ~ "sandpit_sds_extract", + "client" ~ "sandpit_sc_client_extract", + "demographics" ~ "sandpit_sc_demographics_extract" + ) + + if (type == "client") { + sandpit_extract_path <- fs::path(dir, stringr::str_glue("{file_name}_{year}_{update}.parquet")) + } else { + sandpit_extract_path <- fs::path(dir, stringr::str_glue("{file_name}_{update}.parquet")) + } + + return(sandpit_extract_path) +} diff --git a/R/get_sc_episodes_path.R b/R/get_sc_episodes_path.R index 501def708..230b69727 100644 --- a/R/get_sc_episodes_path.R +++ b/R/get_sc_episodes_path.R @@ -13,7 +13,7 @@ #' @seealso [get_file_path()] for the generic function. get_sc_ch_episodes_path <- function(update = latest_update(), ...) { sc_ch_episodes_path <- get_file_path( - directory = fs::path(get_slf_dir(), "Social_care"), + directory = fs::path(get_slf_dir(), "Social_care", "processed_sc_all_care_home"), file_name = stringr::str_glue("all_ch_episodes_{update}.parquet"), ... ) @@ -33,7 +33,7 @@ get_sc_ch_episodes_path <- function(update = latest_update(), ...) { #' @seealso [get_file_path()] for the generic function. get_sc_at_episodes_path <- function(update = latest_update(), ...) { sc_at_episodes_path <- get_file_path( - directory = fs::path(get_slf_dir(), "Social_care"), + directory = fs::path(get_slf_dir(), "Social_care", "processed_sc_all_alarms_telecare"), file_name = stringr::str_glue("all_at_episodes_{update}.parquet"), ... ) @@ -53,7 +53,7 @@ get_sc_at_episodes_path <- function(update = latest_update(), ...) { #' @seealso [get_file_path()] for the generic function. get_sc_hc_episodes_path <- function(update = latest_update(), ...) { sc_hc_episodes_path <- get_file_path( - directory = fs::path(get_slf_dir(), "Social_care"), + directory = fs::path(get_slf_dir(), "Social_care", "processed_sc_all_home_care"), file_name = stringr::str_glue("all_hc_episodes_{update}.parquet"), ... ) @@ -73,7 +73,7 @@ get_sc_hc_episodes_path <- function(update = latest_update(), ...) { #' @seealso [get_file_path()] for the generic function. get_sc_sds_episodes_path <- function(update = latest_update(), ...) { sc_sds_episodes_path <- get_file_path( - directory = fs::path(get_slf_dir(), "Social_care"), + directory = fs::path(get_slf_dir(), "Social_care", "processed_sc_all_sds"), file_name = stringr::str_glue("all_sds_episodes_{update}.parquet"), ... ) diff --git a/R/get_sc_lookup_paths.R b/R/get_sc_lookup_paths.R index 5add38b08..be0fa3eb6 100644 --- a/R/get_sc_lookup_paths.R +++ b/R/get_sc_lookup_paths.R @@ -14,7 +14,7 @@ #' @seealso [get_file_path()] for the generic function. get_sc_demog_lookup_path <- function(update = latest_update(), ...) { sc_demog_lookup_path <- get_file_path( - directory = fs::path(get_slf_dir(), "Social_care"), + directory = fs::path(get_slf_dir(), "Social_care", "processed_sc_demographic_lookup"), file_name = stringr::str_glue("sc_demographics_lookup_{update}.parquet"), ... ) @@ -39,7 +39,7 @@ get_sc_demog_lookup_path <- function(update = latest_update(), ...) { #' @seealso [get_file_path()] for the generic function. get_sc_client_lookup_path <- function(year, update = latest_update(), ...) { sc_client_lookup_path <- get_file_path( - directory = fs::path(get_slf_dir(), "Social_care"), + directory = fs::path(get_slf_dir(), "Social_care", "processed_sc_client_lookup"), file_name = stringr::str_glue("sc_client_lookup_{year}_{update}.parquet"), ... ) diff --git a/R/read_lookup_sc_client.R b/R/read_lookup_sc_client.R index cc98060f3..370a15722 100644 --- a/R/read_lookup_sc_client.R +++ b/R/read_lookup_sc_client.R @@ -77,5 +77,12 @@ read_lookup_sc_client <- function(fyyear, ) %>% dplyr::collect() + if (!fs::file_exists(get_sandpit_extract_path(type = "client", year = fyyear))) { + client_data %>% + write_file(get_sandpit_extract_path(type = "client", year = fyyear)) + } else { + client_data <- client_data + } + return(client_data) } diff --git a/R/read_lookup_sc_demographics.R b/R/read_lookup_sc_demographics.R index fe9a5e71f..020542baa 100644 --- a/R/read_lookup_sc_demographics.R +++ b/R/read_lookup_sc_demographics.R @@ -23,7 +23,16 @@ read_lookup_sc_demographics <- function(sc_connection = phs_db_connection(dsn = "submitted_postcode", "chi_gender_code" ) %>% - dplyr::collect() %>% + dplyr::collect() + + if (!fs::file_exists(get_sandpit_extract_path(type = "demographics"))) { + sc_demog %>% + write_file(get_sandpit_extract_path(type = "demographics")) + } else { + sc_demog <- sc_demog + } + + sc_demog <- sc_demog %>% dplyr::mutate( dplyr::across(c( "latest_record_flag", diff --git a/R/read_sc_all_alarms_telecare.R b/R/read_sc_all_alarms_telecare.R index 9d4be2be4..5abd9bc7b 100644 --- a/R/read_sc_all_alarms_telecare.R +++ b/R/read_sc_all_alarms_telecare.R @@ -26,7 +26,16 @@ read_sc_all_alarms_telecare <- function(sc_dvprod_connection = phs_db_connection "service_start_date_after_period_end_date" ) %>% dplyr::collect() %>% - dplyr::distinct() %>% + dplyr::distinct() + + if (!fs::file_exists(get_sandpit_extract_path(type = "at"))) { + at_full_data %>% + write_file(get_sandpit_extract_path(type = "at")) + } else { + at_full_data <- at_full_data + } + + at_full_data <- at_full_data %>% dplyr::mutate( period_start_date = dplyr::if_else( .data$period == "2017", diff --git a/R/read_sc_all_care_home.R b/R/read_sc_all_care_home.R index 505222747..870a94ded 100644 --- a/R/read_sc_all_care_home.R +++ b/R/read_sc_all_care_home.R @@ -28,7 +28,16 @@ read_sc_all_care_home <- function(sc_dvprod_connection = phs_db_connection(dsn = "age" ) %>% dplyr::collect() %>% - dplyr::distinct() %>% + dplyr::distinct() + + if (!fs::file_exists(get_sandpit_extract_path(type = "ch"))) { + ch_data %>% + write_file(get_sandpit_extract_path(type = "ch")) + } else { + ch_data <- ch_data + } + + ch_data <- ch_data %>% # Correct FY 2017 dplyr::mutate(period = dplyr::if_else( .data$period == "2017", diff --git a/R/read_sc_all_home_care.R b/R/read_sc_all_home_care.R index bfccf4428..cca2d0a9b 100644 --- a/R/read_sc_all_home_care.R +++ b/R/read_sc_all_home_care.R @@ -45,7 +45,16 @@ read_sc_all_home_care <- function(sc_dvprod_connection = phs_db_connection(dsn = )) %>% # drop rows start date after end date dplyr::collect() %>% - dplyr::distinct() %>% + dplyr::distinct() + + if (!fs::file_exists(get_sandpit_extract_path(type = "hc"))) { + home_care_data %>% + write_file(get_sandpit_extract_path(type = "hc")) + } else { + home_care_data <- home_care_data + } + + home_care_data <- home_care_data %>% dplyr::mutate(dplyr::across(c( "sending_location", "financial_year", diff --git a/R/read_sc_all_sds.R b/R/read_sc_all_sds.R index ab9bb20e1..d9d5b8b1d 100644 --- a/R/read_sc_all_sds.R +++ b/R/read_sc_all_sds.R @@ -26,7 +26,16 @@ read_sc_all_sds <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPR "sds_start_date_after_period_end_date" # get removed ) %>% dplyr::collect() %>% - dplyr::distinct() %>% + dplyr::distinct() + + if (!fs::file_exists(get_sandpit_extract_path(type = "sds"))) { + sds_full_data %>% + write_file(get_sandpit_extract_path(type = "sds")) + } else { + sds_full_data <- sds_full_data + } + + sds_full_data <- sds_full_data %>% dplyr::mutate(dplyr::across(c( "sending_location", "sds_option_1", diff --git a/man/get_sandpit_extract_path.Rd b/man/get_sandpit_extract_path.Rd new file mode 100644 index 000000000..c938b45ea --- /dev/null +++ b/man/get_sandpit_extract_path.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_sandpit_extract_path.R +\name{get_sandpit_extract_path} +\alias{get_sandpit_extract_path} +\title{Sandpit Extract File Path} +\usage{ +get_sandpit_extract_path( + type = c("at", "ch", "hc", "sds", "client", "demographics"), + year = NULL, + update = latest_update(), + ... +) +} +\arguments{ +\item{update}{The update month to use, +defaults to \code{\link[=latest_update]{latest_update()}}} + +\item{...}{additional arguments passed to \code{\link[=get_file_path]{get_file_path()}}} +} +\value{ +The path to the sandpit extracts as an \code{\link[fs:path]{fs::path()}} +} +\description{ +Get the file path for sandpit extracts +} +\seealso{ +\code{\link[=get_file_path]{get_file_path()}} for the generic function. +} +\concept{social care sandpit extract paths}