Skip to content

Commit

Permalink
Merge branch 'development' into fix_pkgdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 authored Sep 25, 2023
2 parents b34ad69 + ff4d35f commit 6e437f3
Show file tree
Hide file tree
Showing 29 changed files with 281 additions and 144 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_
2 changes: 2 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
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 @@ -127,9 +127,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 @@ -205,12 +205,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
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)
}
16 changes: 14 additions & 2 deletions R/create_individual_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,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
4 changes: 2 additions & 2 deletions R/get_existing_data_for_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ get_existing_data_for_tests <- function(new_data, file_version = "episode") {
slf_data <- suppressMessages(slfhelper::read_slf_episode(
year = year,
recids = recids,
columns = variable_names
col_select = variable_names
))
if ("hscp2018" %in% variable_names) {
slf_data <- dplyr::rename(slf_data, "hscp" = "hscp2018")
}
} else {
slf_data <- suppressMessages(slfhelper::read_slf_individual(
year = year,
columns = variable_names
col_select = variable_names
))
}

Expand Down
49 changes: 28 additions & 21 deletions R/get_source_extract_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,34 @@
#' @export
#'
#' @family extract file paths
get_source_extract_path <- function(year,
type = c(
"Acute",
"AE",
"AT",
"CH",
"Client",
"CMH",
"DD",
"Deaths",
"DN",
"GPOoH",
"HC",
"Homelessness",
"Maternity",
"MH",
"Outpatients",
"PIS",
"SDS"
),
...) {
get_source_extract_path <- function(
year,
type = c(
"Acute",
"AE",
"AT",
"CH",
"Client",
"CMH",
"DD",
"Deaths",
"DN",
"GPOoH",
"HC",
"Homelessness",
"Maternity",
"MH",
"Outpatients",
"PIS",
"SDS"
),
...) {
if (year %in% type) {
cli::cli_abort("{.val {year}} was supplied to the {.arg year} argument.")
}

year <- check_year_format(year)

type <- match.arg(type)

if (!check_year_valid(year, type)) {
Expand Down
13 changes: 7 additions & 6 deletions R/process_extract_homelessness.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ process_extract_homelessness <- function(
)

if (write_to_disk) {
final_data %>%
write_file(get_file_path(
get_year_dir(year),
stringr::str_glue("homelessness_for_source-20{year}"),
ext = "rds",
write_file(
final_data,
get_source_extract_path(
year = year,
type = "Homelessness",
check_mode = "write"
))
)
)
}

return(final_data)
Expand Down
2 changes: 1 addition & 1 deletion R/process_lookup_postcode.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ process_lookup_postcode <- function(spd_path = get_spd_path(),
tidyselect::matches("datazone\\d{4}$")
) %>%
dplyr::mutate(
locality = tidyr::replace_na("locality", "No Locality Information")
locality = tidyr::replace_na(.data$locality, "No Locality Information")
)


Expand Down
Loading

0 comments on commit 6e437f3

Please sign in to comment.