Skip to content

Commit

Permalink
Sc latest quarter (#1012)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update R/read_lookup_sc_demographics.R

Co-authored-by: Jennit07 <[email protected]>

* Update R/read_sc_all_alarms_telecare.R

Co-authored-by: Jennit07 <[email protected]>

* Update R/read_sc_all_care_home.R

Co-authored-by: Jennit07 <[email protected]>

* Update R/read_sc_all_home_care.R

Co-authored-by: Jennit07 <[email protected]>

* Update R/read_sc_all_sds.R

Co-authored-by: Jennit07 <[email protected]>

---------

Co-authored-by: lizihao-anu <[email protected]>
Co-authored-by: Jennit07 <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent 74947ce commit 7787668
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
12 changes: 8 additions & 4 deletions R/read_lookup_sc_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))) {
Expand Down
12 changes: 8 additions & 4 deletions R/read_lookup_sc_demographics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"))) {
Expand Down
13 changes: 9 additions & 4 deletions R/read_sc_all_alarms_telecare.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 %>%
Expand Down
13 changes: 9 additions & 4 deletions R/read_sc_all_care_home.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 %>%
Expand Down
13 changes: 9 additions & 4 deletions R/read_sc_all_home_care.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 %>%
Expand Down
12 changes: 8 additions & 4 deletions R/read_sc_all_sds.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 %>%
Expand Down

0 comments on commit 7787668

Please sign in to comment.