From 7787668984b5e240de1c3bc0a77ad8e92dbed677 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Wed, 16 Oct 2024 12:09:09 +0100 Subject: [PATCH] Sc latest quarter (#1012) * prompt warnings of latest period when reading in sc data * Style code * add warning to show latest quarter for sc client * Style code * Update R/read_lookup_sc_client.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> * Update R/read_lookup_sc_demographics.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> * Update R/read_sc_all_alarms_telecare.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> * Update R/read_sc_all_care_home.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> * Update R/read_sc_all_home_care.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> * Update R/read_sc_all_sds.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --------- Co-authored-by: lizihao-anu Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/read_lookup_sc_client.R | 12 ++++++++---- R/read_lookup_sc_demographics.R | 12 ++++++++---- R/read_sc_all_alarms_telecare.R | 13 +++++++++---- R/read_sc_all_care_home.R | 13 +++++++++---- R/read_sc_all_home_care.R | 13 +++++++++---- R/read_sc_all_sds.R | 12 ++++++++---- 6 files changed, 51 insertions(+), 24 deletions(-) diff --git a/R/read_lookup_sc_client.R b/R/read_lookup_sc_client.R index 6128a1be5..7bcaaf256 100644 --- a/R/read_lookup_sc_client.R +++ b/R/read_lookup_sc_client.R @@ -16,9 +16,6 @@ read_lookup_sc_client <- function(fyyear, # read in data - social care 2 client client_data <- dplyr::tbl(sc_dvprod_connection, dbplyr::in_schema("social_care_2", "client")) %>% - dplyr::collect() - - client_data <- client_data %>% dplyr::select( "sending_location", "social_care_id", @@ -79,7 +76,14 @@ read_lookup_sc_client <- function(fyyear, .data$financial_year, .data$financial_quarter ) %>% - dplyr::rename("mental_health_disorders" = "mental_health_problems") + dplyr::rename("mental_health_disorders" = "mental_health_problems") %>% + dplyr::collect() + + latest_quarter <- client_data %>% + dplyr::arrange(desc(financial_quarter)) %>% + dplyr::pull(financial_quarter) %>% + head(1) + cli::cli_alert_info(stringr::str_glue("Social care client data for Year {fyyear} is available up to Q{latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "client", year = fyyear))) { diff --git a/R/read_lookup_sc_demographics.R b/R/read_lookup_sc_demographics.R index 1d97e7c30..644554b42 100644 --- a/R/read_lookup_sc_demographics.R +++ b/R/read_lookup_sc_demographics.R @@ -10,9 +10,6 @@ read_lookup_sc_demographics <- function(sc_dvprod_connection = phs_db_connection sc_dvprod_connection, dbplyr::in_schema("social_care_2", "demographic_snapshot") ) %>% - dplyr::collect() - - sc_demog <- sc_demog %>% dplyr::select( "latest_record_flag", "period", @@ -25,7 +22,14 @@ read_lookup_sc_demographics <- function(sc_dvprod_connection = phs_db_connection "chi_postcode", "submitted_postcode", "chi_gender_code" - ) + ) %>% + dplyr::collect() + + latest_quarter <- sc_demog %>% + dplyr::arrange(desc(period)) %>% + dplyr::pull(period) %>% + head(1) + cli::cli_alert_info(stringr::str_glue("Demographics data is available up to {latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "demographics"))) { diff --git a/R/read_sc_all_alarms_telecare.R b/R/read_sc_all_alarms_telecare.R index 0106bcbda..8fbbc1a58 100644 --- a/R/read_sc_all_alarms_telecare.R +++ b/R/read_sc_all_alarms_telecare.R @@ -13,9 +13,7 @@ read_sc_all_alarms_telecare <- function(sc_dvprod_connection = phs_db_connection at_full_data <- dplyr::tbl( sc_dvprod_connection, dbplyr::in_schema("social_care_2", "equipment_snapshot") - ) %>% dplyr::collect() - - at_full_data <- at_full_data %>% + ) %>% dplyr::select( "sending_location", "social_care_id", @@ -27,7 +25,14 @@ read_sc_all_alarms_telecare <- function(sc_dvprod_connection = phs_db_connection "service_end_date", "service_start_date_after_period_end_date" ) %>% - dplyr::distinct() + dplyr::distinct() %>% + dplyr::collect() + + latest_quarter <- at_full_data %>% + dplyr::arrange(desc(period)) %>% + dplyr::pull(period) %>% + head(1) + cli::cli_alert_info(stringr::str_glue("Alarm Telecare data is available up to {latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "at"))) { at_full_data %>% diff --git a/R/read_sc_all_care_home.R b/R/read_sc_all_care_home.R index b11879487..1c93591de 100644 --- a/R/read_sc_all_care_home.R +++ b/R/read_sc_all_care_home.R @@ -10,9 +10,7 @@ read_sc_all_care_home <- function(sc_dvprod_connection = phs_db_connection(dsn = ch_data <- dplyr::tbl( sc_dvprod_connection, dbplyr::in_schema("social_care_2", "carehome_snapshot") - ) %>% dplyr::collect() - - ch_data <- ch_data %>% + ) %>% dplyr::select( "ch_name", "ch_postcode", @@ -29,7 +27,14 @@ read_sc_all_care_home <- function(sc_dvprod_connection = phs_db_connection(dsn = "ch_discharge_date", "age" ) %>% - dplyr::distinct() + dplyr::distinct() %>% + dplyr::collect() + + latest_quarter <- ch_data %>% + dplyr::arrange(desc(period)) %>% + dplyr::pull(period) %>% + head(1) + cli::cli_alert_info(stringr::str_glue("Care Home data is available up to {latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "ch"))) { ch_data %>% diff --git a/R/read_sc_all_home_care.R b/R/read_sc_all_home_care.R index 2349cf1cd..db5b9186d 100644 --- a/R/read_sc_all_home_care.R +++ b/R/read_sc_all_home_care.R @@ -10,9 +10,7 @@ read_sc_all_home_care <- function(sc_dvprod_connection = phs_db_connection(dsn = home_care_data <- dplyr::tbl( sc_dvprod_connection, dbplyr::in_schema("social_care_2", "homecare_snapshot") - ) %>% dplyr::collect() - - home_care_data <- home_care_data %>% + ) %>% dplyr::select( "sending_location", "sending_location_name", @@ -46,7 +44,14 @@ read_sc_all_home_care <- function(sc_dvprod_connection = phs_db_connection(dsn = .data$period )) %>% # drop rows start date after end date - dplyr::distinct() + dplyr::distinct() %>% + dplyr::collect() + + latest_quarter <- home_care_data %>% + dplyr::arrange(desc(period)) %>% + dplyr::pull(period) %>% + head(1) + cli::cli_alert_info(stringr::str_glue("Home Care data is available up to {latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "hc"))) { home_care_data %>% diff --git a/R/read_sc_all_sds.R b/R/read_sc_all_sds.R index 54d3d31ed..affdfe29b 100644 --- a/R/read_sc_all_sds.R +++ b/R/read_sc_all_sds.R @@ -11,9 +11,6 @@ read_sc_all_sds <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPR sc_dvprod_connection, dbplyr::in_schema("social_care_2", "sds_snapshot") ) %>% - dplyr::collect() - - sds_full_data <- sds_full_data %>% dplyr::select( "sending_location", "social_care_id", @@ -28,7 +25,14 @@ read_sc_all_sds <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPR "sds_start_date_after_end_date", # get fixed "sds_start_date_after_period_end_date" # get removed ) %>% - dplyr::distinct() + dplyr::distinct() %>% + dplyr::collect() + + latest_quarter <- sds_full_data %>% + dplyr::arrange(desc(period)) %>% + dplyr::pull(period) %>% + head(1) + cli::cli_alert_info(stringr::str_glue("SDS data is available up to {latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "sds"))) { sds_full_data %>%