From bbdbeab4e772a82b8b6e1b6aea55231777d571c6 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Thu, 26 Sep 2024 16:40:57 +0100 Subject: [PATCH 01/10] prompt warnings of latest period when reading in sc data --- 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 ++++++++---- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/R/read_lookup_sc_demographics.R b/R/read_lookup_sc_demographics.R index 1d97e7c30..25136060a 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 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..8cfb65202 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 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..f80072a1f 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 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..6f3f0870c 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 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..d454ef0ab 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 up to {latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "sds"))) { sds_full_data %>% From a15a6276bf1d70e35f7ab6aa31aa02f5a8499176 Mon Sep 17 00:00:00 2001 From: lizihao-anu Date: Thu, 26 Sep 2024 15:44:19 +0000 Subject: [PATCH 02/10] Style code --- R/read_lookup_sc_demographics.R | 2 +- R/read_sc_all_alarms_telecare.R | 2 +- R/read_sc_all_care_home.R | 2 +- R/read_sc_all_home_care.R | 2 +- R/read_sc_all_sds.R | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/read_lookup_sc_demographics.R b/R/read_lookup_sc_demographics.R index 25136060a..53f619df5 100644 --- a/R/read_lookup_sc_demographics.R +++ b/R/read_lookup_sc_demographics.R @@ -25,7 +25,7 @@ read_lookup_sc_demographics <- function(sc_dvprod_connection = phs_db_connection ) %>% dplyr::collect() - latest_quarter = sc_demog %>% + latest_quarter <- sc_demog %>% dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) diff --git a/R/read_sc_all_alarms_telecare.R b/R/read_sc_all_alarms_telecare.R index 8cfb65202..edecb63fd 100644 --- a/R/read_sc_all_alarms_telecare.R +++ b/R/read_sc_all_alarms_telecare.R @@ -28,7 +28,7 @@ read_sc_all_alarms_telecare <- function(sc_dvprod_connection = phs_db_connection dplyr::distinct() %>% dplyr::collect() - latest_quarter = at_full_data %>% + latest_quarter <- at_full_data %>% dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) diff --git a/R/read_sc_all_care_home.R b/R/read_sc_all_care_home.R index f80072a1f..325522e05 100644 --- a/R/read_sc_all_care_home.R +++ b/R/read_sc_all_care_home.R @@ -30,7 +30,7 @@ read_sc_all_care_home <- function(sc_dvprod_connection = phs_db_connection(dsn = dplyr::distinct() %>% dplyr::collect() - latest_quarter = ch_data %>% + latest_quarter <- ch_data %>% dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) diff --git a/R/read_sc_all_home_care.R b/R/read_sc_all_home_care.R index 6f3f0870c..042c4ffd8 100644 --- a/R/read_sc_all_home_care.R +++ b/R/read_sc_all_home_care.R @@ -47,7 +47,7 @@ read_sc_all_home_care <- function(sc_dvprod_connection = phs_db_connection(dsn = dplyr::distinct() %>% dplyr::collect() - latest_quarter = home_care_data %>% + latest_quarter <- home_care_data %>% dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) diff --git a/R/read_sc_all_sds.R b/R/read_sc_all_sds.R index d454ef0ab..3f43aff66 100644 --- a/R/read_sc_all_sds.R +++ b/R/read_sc_all_sds.R @@ -28,7 +28,7 @@ read_sc_all_sds <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPR dplyr::distinct() %>% dplyr::collect() - latest_quarter = sds_full_data %>% + latest_quarter <- sds_full_data %>% dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) From b42f199ab4dee9e5fb5843cfbf9cda5f217246f0 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Mon, 30 Sep 2024 09:58:34 +0100 Subject: [PATCH 03/10] add warning to show latest quarter for sc client --- R/read_lookup_sc_client.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/R/read_lookup_sc_client.R b/R/read_lookup_sc_client.R index 6128a1be5..102b5038f 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 lookup for Year {fyyear} is up to {latest_quarter}.")) if (!fs::file_exists(get_sandpit_extract_path(type = "client", year = fyyear))) { From 94b2c92148f2829e1bfc2e399b9ed50c16a8081e Mon Sep 17 00:00:00 2001 From: lizihao-anu Date: Mon, 30 Sep 2024 09:00:18 +0000 Subject: [PATCH 04/10] Style code --- R/read_lookup_sc_client.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_lookup_sc_client.R b/R/read_lookup_sc_client.R index 102b5038f..3d785cd6b 100644 --- a/R/read_lookup_sc_client.R +++ b/R/read_lookup_sc_client.R @@ -79,7 +79,7 @@ read_lookup_sc_client <- function(fyyear, dplyr::rename("mental_health_disorders" = "mental_health_problems") %>% dplyr::collect() - latest_quarter = client_data %>% + latest_quarter <- client_data %>% dplyr::arrange(desc(financial_quarter)) %>% dplyr::pull(financial_quarter) %>% head(1) From 6a247267c487e8c99e4e352f6f6c432b6c303b70 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 11 Oct 2024 11:02:24 +0100 Subject: [PATCH 05/10] Update R/read_lookup_sc_client.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/read_lookup_sc_client.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_lookup_sc_client.R b/R/read_lookup_sc_client.R index 3d785cd6b..7bcaaf256 100644 --- a/R/read_lookup_sc_client.R +++ b/R/read_lookup_sc_client.R @@ -83,7 +83,7 @@ read_lookup_sc_client <- function(fyyear, dplyr::arrange(desc(financial_quarter)) %>% dplyr::pull(financial_quarter) %>% head(1) - cli::cli_alert_info(stringr::str_glue("Social care client lookup for Year {fyyear} is up to {latest_quarter}.")) + 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))) { From 82d39661f1a47e3089852e6d7d165552deedf214 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 11 Oct 2024 11:02:37 +0100 Subject: [PATCH 06/10] Update R/read_lookup_sc_demographics.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/read_lookup_sc_demographics.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_lookup_sc_demographics.R b/R/read_lookup_sc_demographics.R index 53f619df5..644554b42 100644 --- a/R/read_lookup_sc_demographics.R +++ b/R/read_lookup_sc_demographics.R @@ -29,7 +29,7 @@ read_lookup_sc_demographics <- function(sc_dvprod_connection = phs_db_connection dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) - cli::cli_alert_info(stringr::str_glue("Demographics data is up to {latest_quarter}.")) + 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"))) { From 5b596241f6c02fa36de15738fd510d67bff3dad5 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 11 Oct 2024 11:02:44 +0100 Subject: [PATCH 07/10] Update R/read_sc_all_alarms_telecare.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/read_sc_all_alarms_telecare.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_sc_all_alarms_telecare.R b/R/read_sc_all_alarms_telecare.R index edecb63fd..8fbbc1a58 100644 --- a/R/read_sc_all_alarms_telecare.R +++ b/R/read_sc_all_alarms_telecare.R @@ -32,7 +32,7 @@ read_sc_all_alarms_telecare <- function(sc_dvprod_connection = phs_db_connection dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) - cli::cli_alert_info(stringr::str_glue("Alarm Telecare data is up to {latest_quarter}.")) + 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 %>% From e7f2d6c2c2324d485788ef2e662fd0ea7c290cb6 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 11 Oct 2024 11:02:53 +0100 Subject: [PATCH 08/10] Update R/read_sc_all_care_home.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/read_sc_all_care_home.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_sc_all_care_home.R b/R/read_sc_all_care_home.R index 325522e05..1c93591de 100644 --- a/R/read_sc_all_care_home.R +++ b/R/read_sc_all_care_home.R @@ -34,7 +34,7 @@ read_sc_all_care_home <- function(sc_dvprod_connection = phs_db_connection(dsn = dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) - cli::cli_alert_info(stringr::str_glue("Care Home data is up to {latest_quarter}.")) + 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 %>% From fa28172b00141d539b9f00019e055eaeb6757769 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 11 Oct 2024 11:03:00 +0100 Subject: [PATCH 09/10] Update R/read_sc_all_home_care.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/read_sc_all_home_care.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_sc_all_home_care.R b/R/read_sc_all_home_care.R index 042c4ffd8..db5b9186d 100644 --- a/R/read_sc_all_home_care.R +++ b/R/read_sc_all_home_care.R @@ -51,7 +51,7 @@ read_sc_all_home_care <- function(sc_dvprod_connection = phs_db_connection(dsn = dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) - cli::cli_alert_info(stringr::str_glue("Home Care data is up to {latest_quarter}.")) + 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 %>% From f64ac5b31892f9b765311aff43cb66206bdebdb5 Mon Sep 17 00:00:00 2001 From: Zihao Li Date: Fri, 11 Oct 2024 11:03:07 +0100 Subject: [PATCH 10/10] Update R/read_sc_all_sds.R Co-authored-by: Jennit07 <67372904+Jennit07@users.noreply.github.com> --- R/read_sc_all_sds.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/read_sc_all_sds.R b/R/read_sc_all_sds.R index 3f43aff66..affdfe29b 100644 --- a/R/read_sc_all_sds.R +++ b/R/read_sc_all_sds.R @@ -32,7 +32,7 @@ read_sc_all_sds <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPR dplyr::arrange(desc(period)) %>% dplyr::pull(period) %>% head(1) - cli::cli_alert_info(stringr::str_glue("SDS data is up to {latest_quarter}.")) + 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 %>%