Skip to content

Commit

Permalink
Archive social care extracts (#927)
Browse files Browse the repository at this point in the history
* Set up `get_sandpit_extract_path`

* Update documentation

* Update sc `all` data paths

* Write sandpit extract if file does not exist

* Style code

---------

Co-authored-by: Jennit07 <[email protected]>
  • Loading branch information
Jennit07 and Jennit07 authored Mar 20, 2024
1 parent 54b61a7 commit 3aa3198
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions R/get_sandpit_extract_path.R
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 4 additions & 4 deletions R/get_sc_episodes_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
...
)
Expand All @@ -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"),
...
)
Expand All @@ -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"),
...
)
Expand All @@ -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"),
...
)
Expand Down
4 changes: 2 additions & 2 deletions R/get_sc_lookup_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
...
)
Expand All @@ -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"),
...
)
Expand Down
7 changes: 7 additions & 0 deletions R/read_lookup_sc_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
11 changes: 10 additions & 1 deletion R/read_lookup_sc_demographics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion R/read_sc_all_alarms_telecare.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion R/read_sc_all_care_home.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion R/read_sc_all_home_care.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion R/read_sc_all_sds.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions man/get_sandpit_extract_path.Rd

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

0 comments on commit 3aa3198

Please sign in to comment.