Skip to content
Open
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
12 changes: 10 additions & 2 deletions R/process_extract_ooh_outcomes.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
#'
#' @return the final data as a [tibble][tibble::tibble-package].
#' @family process extracts
process_extract_ooh_outcomes <- function(data, year) {
process_extract_ooh_outcomes <- function(
data,
year,
run_id = NA,
run_date_time = NA
) {
log_slf_event(stage = "process", status = "start", type = "gp_ooh-o", year = year)

Check warning on line 18 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=18,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 84 characters.

# Only run for a single year
stopifnot(length(year) == 1L)
Expand All @@ -18,11 +23,10 @@
# Check that the supplied year is in the correct format
year <- check_year_format(year)


# Outcomes Data ---------------------------------
## Data Cleaning
outcomes_clean <- data %>%

Check warning on line 28 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=28,col=26,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
data.table::as.data.table() %>%

Check warning on line 29 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=29,col=33,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
# Recode outcome
dplyr::mutate(
outcome = dplyr::case_match(
Expand All @@ -40,18 +44,22 @@
"OTHER" ~ "99",
.default = .data$outcome
)
) %>%

Check warning on line 47 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=47,col=7,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
# Sort so we prefer 'lower' outcomes e.g. Death, over things like 'Other'
dplyr::group_by(.data$ooh_case_id) %>%

Check warning on line 49 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=49,col=40,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
dplyr::arrange(.data$outcome) %>%

Check warning on line 50 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=50,col=35,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
dplyr::mutate(outcome_n = dplyr::row_number()) %>%

Check warning on line 51 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=51,col=52,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
dplyr::ungroup() %>%

Check warning on line 52 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=52,col=22,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
# use row order to pivot outcomes
tidyr::pivot_wider(
names_from = .data$outcome_n,
names_prefix = "ooh_outcome",
values_from = .data$outcome
) %>%

Check warning on line 58 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=58,col=7,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
dplyr::mutate(
run_id = run_id,
run_date_time = run_date_time
) %>%

Check warning on line 62 in R/process_extract_ooh_outcomes.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/process_extract_ooh_outcomes.R,line=62,col=7,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
dplyr::select(
"ooh_case_id",
tidyselect::any_of(c(
Expand Down
39 changes: 29 additions & 10 deletions R/read_extract_ooh_outcomes.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,41 @@
#' @return a [tibble][tibble::tibble-package] with OOH Outcomes extract data
read_extract_ooh_outcomes <- function(
year,
file_path = get_boxi_extract_path(year = year, type = "gp_ooh-o")
denodo_connect = get_denodo_connection(BYOC_MODE = BYOC_MODE),
file_path = get_boxi_extract_path(
year = year,
type = "gp_ooh-o",
BYOC_MODE = BYOC_MODE
),
BYOC_MODE
) {
log_slf_event(stage = "read", status = "start", type = "gp_ooh-o", year = year)

year <- check_year_format(year, format = "fyyear")
c_year <- convert_fyyear_to_year(year)

on.exit(try(DBI::dbDisconnect(denodo_connect), silent = TRUE), add = TRUE)

# Specify years available for running
if (file_path == get_dummy_boxi_extract_path(BYOC_MODE = BYOC_MODE)) {
return(tibble::tibble())
}

## Load extract file
outcomes_extract <- read_file(file_path,
# All columns are character type
col_types = readr::cols(.default = readr::col_character())
outcomes_extract <- dplyr::tbl(
denodo_connect,
dbplyr::in_schema("sdl", "sdl_gp_ooh_outcome_source")
) %>%
# rename variables
dplyr::rename(
ooh_case_id = "GUID",
outcome = "Case Outcome"
dplyr::filter(
.data$sc_start_financial_year == !!c_year,
.data$case_outcome != "",
.data$out_of_hours_services_flag == "Y"
) %>%
dplyr::select(
ooh_case_id = "guid",
outcome = "case_outcome"
) %>%
# Remove blank outcomes
dplyr::filter(.data$outcome != "") %>%
dplyr::collect() %>%
dplyr::distinct()

log_slf_event(stage = "read", status = "complete", type = "gp_ooh-o", year = year)
Expand Down
2 changes: 1 addition & 1 deletion man/process_extract_ooh_outcomes.Rd

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

5 changes: 4 additions & 1 deletion man/read_extract_ooh_outcomes.Rd

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

Loading