Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to SC client #707

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions R/process_extract_alarms_telecare.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ process_extract_alarms_telecare <- function(
}

# Now select episodes for given FY
at_data <- data %>%
at_processed <- data %>%
dplyr::filter(is_date_in_fyyear(
year,
.data[["record_keydate1"]],
Expand All @@ -52,21 +52,15 @@ process_extract_alarms_telecare <- function(
"record_keydate1",
"record_keydate2",
"person_id",
"sc_latest_submission",
"sc_living_alone",
"sc_support_from_unpaid_carer",
"sc_social_worker",
"sc_type_of_housing",
"sc_meals",
"sc_day_care"
tidyselect::starts_with("sc_")
)

if (write_to_disk) {
at_data %>%
write_file(
get_source_extract_path(year, type = "AT", check_mode = "write")
)
write_file(
at_processed,
get_source_extract_path(year, type = "AT", check_mode = "write")
)
}

return(at_data)
return(at_processed)
}
5 changes: 4 additions & 1 deletion R/process_extract_home_care.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ process_extract_home_care <- function(
# remove any episodes where the latest submission was before the current year
dplyr::filter(substr(.data$sc_latest_submission, 1, 4) >= convert_fyyear_to_year(year)) %>%
# Match to client data
dplyr::left_join(client_lookup, by = c("sending_location", "social_care_id")) %>%
dplyr::left_join(
client_lookup,
by = c("sending_location", "social_care_id")
) %>%
dplyr::mutate(year = year)

# Home Care Hours ---------------------------------------
Expand Down
22 changes: 11 additions & 11 deletions R/process_extract_sds.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ process_extract_sds <- function(
return(tibble::tibble())
}

outfile <- data %>%
sds_processed <- data %>%
# Select episodes for given FY
dplyr::filter(is_date_in_fyyear(
year,
.data[["record_keydate1"]],
.data[["record_keydate2"]]
)) %>%
dplyr::left_join(client_lookup, by = c("sending_location", "social_care_id")) %>%
dplyr::left_join(
client_lookup,
by = c("sending_location", "social_care_id")
) %>%
dplyr::mutate(
year = year
) %>%
Expand All @@ -48,18 +51,15 @@ process_extract_sds <- function(
"record_keydate1",
"record_keydate2",
"sc_send_lca",
"sc_living_alone",
"sc_support_from_unpaid_carer",
"sc_social_worker",
"sc_type_of_housing",
"sc_meals",
"sc_day_care"
tidyselect::starts_with("sc_")
)

if (write_to_disk) {
outfile %>%
write_file(get_source_extract_path(year, type = "SDS", check_mode = "write"))
write_file(
sds_processed,
get_source_extract_path(year, type = "SDS", check_mode = "write")
)
}

return(outfile)
return(sds_processed)
}
45 changes: 16 additions & 29 deletions R/process_lookup_sc_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ process_lookup_sc_client <- function(data, year, write_to_disk = TRUE) {
),
type_of_housing = tidyr::replace_na(.data$type_of_housing, 6L)
) %>%
# factor labels
# Create factors with labels
dplyr::mutate(
dplyr::across(
c(
Expand All @@ -82,9 +82,11 @@ process_lookup_sc_client <- function(data, year, write_to_disk = TRUE) {
"autism",
"other_vulnerable_groups"
),
factor,
levels = c(0L, 1L),
labels = c("No", "Yes")
~ factor(
.x,
levels = c(0L, 1L),
labels = c("No", "Yes")
)
),
dplyr::across(
c(
Expand All @@ -94,41 +96,26 @@ process_lookup_sc_client <- function(data, year, write_to_disk = TRUE) {
"meals",
"day_care"
),
factor,
levels = c(0L, 1L, 9L),
labels = c("No", "Yes", "Not Known")
~ factor(
.x,
levels = c(0L, 1L, 9L),
labels = c("No", "Yes", "Not Known")
)
),
type_of_housing = factor(.data$type_of_housing,
levels = 1L:6L
type_of_housing = factor(
.data$type_of_housing,
levels = c(1L:6L, 8L, 9L)
)
) %>%
# rename variables
dplyr::rename_with(
.cols = -c("sending_location", "social_care_id"),
.fn = ~ paste0("sc_", .x)
)


## save outfile ---------------------------------------
outfile <-
client_clean %>%
# reorder
dplyr::select(
"sending_location",
"social_care_id",
"sc_living_alone",
"sc_support_from_unpaid_carer",
"sc_social_worker",
"sc_type_of_housing",
"sc_meals",
"sc_day_care"
)

if (write_to_disk) {
# Save .rds file
outfile %>%
client_clean %>%
write_file(get_source_extract_path(year, "Client", check_mode = "write"))
}

return(outfile)
return(client_clean)
}
20 changes: 9 additions & 11 deletions R/read_lookup_sc_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
#' @return the final data as a [tibble][tibble::tibble-package].
#' @export
#' @family process extracts
read_lookup_sc_client <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPROD"), fyyear) {
read_lookup_sc_client <- function(
sc_dvprod_connection = phs_db_connection(dsn = "DVPROD"),
fyyear) {
check_year_format(fyyear)
year <- convert_fyyear_to_year(fyyear)

# read in data - social care 2 client
client_data <- dplyr::tbl(sc_dvprod_connection, dbplyr::in_schema("social_care_2", "client")) %>%
client_query <- dplyr::tbl(
sc_dvprod_connection,
dbplyr::in_schema("social_care_2", "client")
) %>%
dplyr::select(
"sending_location",
"social_care_id",
Expand Down Expand Up @@ -67,14 +72,7 @@ read_lookup_sc_client <- function(sc_dvprod_connection = phs_db_connection(dsn =
),
as.integer
)
) %>%
dplyr::arrange(
.data$sending_location,
.data$social_care_id,
.data$financial_year,
.data$financial_quarter
) %>%
dplyr::collect()
)

return(client_data)
return(dplyr::collect(client_query))
}