Skip to content

Commit

Permalink
Merge branch 'development' into documentation/remove_rds_references
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftySalmon authored Sep 25, 2023
2 parents 61d76d4 + bc2e4b3 commit c3eace0
Show file tree
Hide file tree
Showing 74 changed files with 656 additions and 246 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
^_targets\.R$
^_targets\.yaml$
^_SPSS_archived$
^run_targets_
3 changes: 3 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ hjust
hms
homecare
homev
hscdiip
hscp
hscpnames
IDPC
Expand All @@ -107,6 +108,7 @@ keyring
keytime
keytimex
kis
lazydt
lgl
los
ltc
Expand Down Expand Up @@ -166,6 +168,7 @@ readxl
reasonwait
recid
refsource
renviron
rlang
rmarkdown
roxygen
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(convert_hscp_to_hscpnames)
export(convert_numeric_to_date)
export(convert_sending_location_to_lca)
export(convert_year_to_fyyear)
export(create_episode_file)
export(create_individual_file)
export(create_service_use_cohorts)
export(end_fy)
Expand Down Expand Up @@ -155,7 +156,7 @@ export(read_sc_all_alarms_telecare)
export(read_sc_all_care_home)
export(read_sc_all_home_care)
export(read_sc_all_sds)
export(run_episode_file)
export(setup_keyring)
export(start_fy)
export(start_fy_quarter)
export(start_next_fy_quarter)
Expand Down
44 changes: 43 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
# March 2023 Update - Unreleased
# September 2023 Update - Unreleased
* Update of 2017/18 onwards to include bug fixes within the files.
* New 2023/24 files.
* New NSU cohort for 2022/23 file.
* Re addition of:
* HRIs in individual file.
* Homelessness Flags.
* Bug fixes:
* Blank `datazone` in A&E. This has been fixed and was due to PC8 postcode format matching onto SLF pc lookup.
* Large increase in preventable beddays. This was caused due to an SPSS vs R logic difference. Uses SPSS logic which
brings the difference down to `3.3%`.
* Issue with `locality` which showed `locality` in each row instead of its true `locality`. This has now been fixed.
* Duplicated CHI in the individual file. The issue was identified when trying to include HRIs. This has now been corrected.
* Internal changes to SLF development:
* `DN` and `CMH` data are now archived in an HSCDIIP folder as the BOXI datamart is now closed down for these. Function `get_boxi_extract_path` has been updated to reflect this.
* Tests updated to include `HSCP`count.
* Tests created for `Delayed Discharges` extract and `Social care Client lookup`.


# June 2023 Update - Released 24-Jul-2023
* 2011/12 -> 2013/14 – These files have not been altered, other than to make them available in a new file type (parquet).
* 2017/18 – These files have been recreated using our new R pipeline, but the data has not changed. We did this so that we would have a good comparator file.
* 2018/19 -> 2022/23 – These files have been recreated using the R pipeline and are also using updated data (as in a ‘normal’ update).
* Files changed into parquet format.
* SLFhelper updated.
* Removal of `keydate1_dateformat` and `keydate2_dateformat`.
* `dd_responsible_lca` – This variable now uses CA2019 codes instead of the 2-digit ‘old’ LCA code.
* Preventable beddays - not able to calculate these correctly. * Death fixes not included.
* Variables not ordered in R like they used to be in SPSS.
* End of HHG.
* New variable `ch_postcode`.
* rename of variables `cost_total_net_incdnas`, `ooh_outcome.1`, `ooh_outcome.2`, `ooh_outcome.3`, `ooh_outcome.4`, `totalnodncontacts`.
* HRI's not included.
* Homelessness flags not included.
* Keep_population flag not included.


# March 2023 Update - Released 10-Mar-2023
* 2021/22 episode and individual files refreshed with updated activity.
* 2022/23 file updated and contains data up to the end of Q3.
* Social care data is available for 2022/23.
* Typo in the variable name `ooh_covid_assessment`
* Next update in May as a test run in R but won't be released.
* Next release in June.

# December 2022 Update - Released 07-Dec-2022
* Now using the 2022v2 Scottish Postcode Directory.
* Now using the 2020 Urban Rural classifications (instead of the older 2016 ones), this means variables such as `URx_2016` will now be called `URx_2020`.
Expand Down
25 changes: 16 additions & 9 deletions R/aggregate_by_chi.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ aggregate_by_chi <- function(episode_file) {
individual_file_cols6 <- episode_file[,
.(
preventable_beddays = ifelse(
max(cij_ppa, na.rm = TRUE),
max(cij_end_date) - min(cij_start_date),
NA_real_
any(cij_ppa, na.rm = TRUE),
as.integer(min(cij_end_date, end_fy(year)) - max(cij_start_date, start_fy(year))),
NA_integer_
)
),
# cij_marker has been renamed as cij_total
Expand Down Expand Up @@ -203,12 +203,19 @@ aggregate_ch_episodes <- function(episode_file) {
data.table::setDT(episode_file)

# Perform grouping and aggregation
episode_file <- episode_file[, `:=`(
ch_no_cost = max(ch_no_cost),
ch_ep_start = min(record_keydate1),
ch_ep_end = max(ch_ep_end),
ch_cost_per_day = mean(ch_cost_per_day)
), by = c("chi", "ch_chi_cis")]
episode_file[, c(
"ch_no_cost",
"ch_ep_start",
"ch_ep_end",
"ch_cost_per_day"
) := list(
max(ch_no_cost),
min(record_keydate1),
max(ch_ep_end),
mean(ch_cost_per_day)
),
by = c("chi", "ch_chi_cis")
]

# Convert back to tibble if needed
episode_file <- tibble::as_tibble(episode_file)
Expand Down
2 changes: 1 addition & 1 deletion R/check_year_valid.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ check_year_valid <- function(
return(FALSE)
} else if (year >= "2122" && type %in% c("CMH", "DN")) {
return(FALSE)
} else if (year >= "2223" && type %in% "NSU") {
} else if (year >= "2324" && type %in% "NSU") {
return(FALSE)
} else if (year >= "2324" && type %in% c("SPARRA", "HHG")) {
return(FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/compute_mid_year_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
compute_mid_year_age <- function(fyyear, dob) {
age_intervals <- lubridate::interval(
start = dob,
end = as.Date(midpoint_fy(fyyear))
end = midpoint_fy(fyyear)
)

ages <- lubridate::as.period(age_intervals)$year
Expand Down
68 changes: 35 additions & 33 deletions R/convert_sending_location_to_lca.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @export
#'
#' @examples
#' sending_location <- c("100", "120")
#' sending_location <- c(100, 120)
#' convert_sending_location_to_lca(sending_location)
#'
#' @family code functions
Expand All @@ -18,38 +18,40 @@
convert_sending_location_to_lca <- function(sending_location) {
lca <- dplyr::case_match(
sending_location,
"100" ~ "01", # Aberdeen City
"110" ~ "02", # Aberdeenshire
"120" ~ "03", # Angus
"130" ~ "04", # Argyll and Bute
"355" ~ "05", # Scottish Borders
"150" ~ "06", # Clackmannanshire
"395" ~ "07", # West Dumbartonshire
"170" ~ "08", # Dumfries and Galloway
"180" ~ "09", # Dundee City
"190" ~ "10", # East Ayrshire
"200" ~ "11", # East Dunbartonshire
"210" ~ "12", # East Lothian
"220" ~ "13", # East Renfrewshire
"230" ~ "14", # City of Edinburgh
"240" ~ "15", # Falkirk
"250" ~ "16", # Fife
"260" ~ "17", # Glasgow City
"270" ~ "18", # Highland
"280" ~ "19", # Inverclyde
"290" ~ "20", # Midlothian
"300" ~ "21", # Moray
"310" ~ "22", # North Ayrshire
"320" ~ "23", # North Lanarkshire
"330" ~ "24", # Orkney Islands
"340" ~ "25", # Perth and Kinross
"350" ~ "26", # Renfrewshire
"360" ~ "27", # Shetland Islands
"370" ~ "28", # South Ayrshire
"380" ~ "29", # South Lanarkshire
"390" ~ "30", # Stirling
"400" ~ "31", # West Lothian
"235" ~ "32" # Na_h_Eileanan_Siar
100L ~ "01", # Aberdeen City
110L ~ "02", # Aberdeenshire
120L ~ "03", # Angus
130L ~ "04", # Argyll and Bute
355L ~ "05", # Scottish Borders
150L ~ "06", # Clackmannanshire
395L ~ "07", # West Dunbartonshire
170L ~ "08", # Dumfries and Galloway
180L ~ "09", # Dundee City
190L ~ "10", # East Ayrshire
200L ~ "11", # East Dunbartonshire
210L ~ "12", # East Lothian
220L ~ "13", # East Renfrewshire
230L ~ "14", # City of Edinburgh
240L ~ "15", # Falkirk
250L ~ "16", # Fife
260L ~ "17", # Glasgow City
270L ~ "18", # Highland
280L ~ "19", # Inverclyde
290L ~ "20", # Midlothian
300L ~ "21", # Moray
310L ~ "22", # North Ayrshire
320L ~ "23", # North Lanarkshire
330L ~ "24", # Orkney Islands
340L ~ "25", # Perth and Kinross
350L ~ "26", # Renfrewshire
360L ~ "27", # Shetland Islands
370L ~ "28", # South Ayrshire
380L ~ "29", # South Lanarkshire
390L ~ "30", # Stirling
400L ~ "31", # West Lothian
235L ~ "32", # Na_h_Eileanan_Siar
.default = NA_character_
)

return(lca)
}
13 changes: 6 additions & 7 deletions R/run_episode_file.R → R/create_episode_file.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#' Produce the Source Episode file
#' Create the Source Episode file
#'
#' @param processed_data_list containing data from processed extracts.
#' @param year The year to process, in FY format.
#' @param write_to_disk (optional) Should the data be written to disk default is
#' `TRUE` i.e. write the data to disk.
#' @param anon_chi_out (Default:TRUE) Should `anon_chi` be used in the output
#' (instead of chi)
#' (instead of chi).
#'
#' @return a [tibble][tibble::tibble-package] containing the episode file
#' @return the Source Episode file as a [tibble][tibble::tibble-package].
#' @export
#'
run_episode_file <- function(
create_episode_file <- function(
processed_data_list,
year,
write_to_disk = TRUE,
Expand Down Expand Up @@ -134,7 +133,7 @@ run_episode_file <- function(
#' Store the unneeded episode file variables
#'
#' @param data The in-progress episode file data.
#' @inheritParams run_episode_file
#' @inheritParams create_episode_file
#' @param vars_to_keep a character vector of the variables to keep, all others
#' will be stored.
#'
Expand Down Expand Up @@ -172,7 +171,7 @@ store_ep_file_vars <- function(data, year, vars_to_keep) {

#' Load the unneeded episode file variables
#'
#' @inheritParams run_episode_file
#' @inheritParams create_episode_file
#' @inheritParams store_ep_file_vars
#'
#' @return The full SLF data.
Expand Down
28 changes: 20 additions & 8 deletions R/create_individual_file.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Create individual file
#' Create the Source Individual file
#'
#' @description Creates individual file from episode file
#' @description Creates the individual file from the episode file.
#'
#' @param episode_file Tibble containing episodic data
#' @param episode_file Tibble containing episodic data.
#' @param anon_chi_in (Default:TRUE) Is `anon_chi` used in the input
#' (instead of chi)
#' @inheritParams run_episode_file
#' (instead of chi).
#' @inheritParams create_episode_file
#'
#' @return The processed individual file
#' @export
Expand Down Expand Up @@ -61,7 +61,7 @@ create_individual_file <- function(
remove_blank_chi() %>%
add_cij_columns() %>%
add_all_columns() %>%
aggregate_ch_episodes_zihao() %>%
aggregate_ch_episodes() %>%
clean_up_ch(year) %>%
recode_gender() %>%
aggregate_by_chi() %>%
Expand Down Expand Up @@ -741,13 +741,25 @@ join_sc_client <- function(
sc_demographics %>%
dplyr::select("sending_location", "social_care_id", "chi"),
by = c("sending_location", "social_care_id")
)
) %>%
dplyr::mutate(count_not_known = rowSums(dplyr::select(., all_of(
c(
"sc_living_alone",
"sc_support_from_unpaid_carer",
"sc_social_worker",
"sc_meals",
"sc_day_care"
)
)) == "Not Known")) %>%
dplyr::arrange(chi, count_not_known) %>%
dplyr::distinct(chi, .keep_all = TRUE)

# Match on client variables by chi
individual_file <- individual_file %>%
dplyr::left_join(
join_client_demog,
by = "chi"
by = "chi",
relationship = "one-to-one"
) %>%
dplyr::select(!c("sending_location", "social_care_id", "sc_latest_submission"))

Expand Down
11 changes: 8 additions & 3 deletions R/get_boxi_extract_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ get_boxi_extract_path <- function(
)) {
type <- match.arg(type)

year_dir <- get_year_dir(year, extracts_dir = TRUE)
if (type %in% c("DN", "CMH")) {
dir <- fs::path(get_slf_dir(), "Archived_data")
} else {
dir <- get_year_dir(year, extracts_dir = TRUE)
}

if (!check_year_valid(year, type)) {
return(get_dummy_boxi_extract_path())
Expand All @@ -53,11 +57,12 @@ get_boxi_extract_path <- function(
)

boxi_extract_path_csv_gz <- fs::path(
year_dir,
dir,
stringr::str_glue("{file_name}-20{year}.csv.gz")
)

boxi_extract_path_csv <- fs::path(
year_dir,
dir,
stringr::str_glue("{file_name}-20{year}.csv")
)

Expand Down
Loading

0 comments on commit c3eace0

Please sign in to comment.