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

September 2024 update #1004

Merged
merged 117 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
b829eab
update documentation
Jennit07 Mar 26, 2024
99f9c2d
Update sc connection name
Jennit07 Mar 26, 2024
298e613
Update documentation
Jennit07 Mar 26, 2024
fe189a9
936 - Update parameters with file paths (#939)
Jennit07 Apr 8, 2024
6fe98c8
Merge branch 'master' into June-24-update
lizihao-anu Apr 15, 2024
f03c5c6
remove and merge overlapping records in GP OoHs
lizihao-anu Mar 29, 2024
fda0c51
Style code
lizihao-anu Mar 29, 2024
713e7a7
update spelling to lowercases
lizihao-anu Apr 15, 2024
a0ac030
update spelling
lizihao-anu Apr 15, 2024
2cff80d
Create tests for social care sandpit extracts (#943)
Jennit07 Apr 17, 2024
6baad29
only select columns we want in ltc raw data
lizihao-anu Apr 30, 2024
211c8a7
[check-spelling] Update metadata
lizihao-anu Apr 30, 2024
86efa00
for some reason the latest scid code was overwritten after the march …
May 3, 2024
08d0066
only select columns we want in ltc raw data (#947)
SwiftySalmon May 3, 2024
d571cb6
Style code
SwiftySalmon May 3, 2024
fa5cdcd
latest social care ID update (#948)
rchlv May 3, 2024
a75374e
Merge May24 NI update into June update branch (#949)
Jennit07 May 7, 2024
08b9f80
Update NEWS.md
Jennit07 May 13, 2024
7f569d3
link GP-OoH with CUP markers
lizihao-anu May 17, 2024
20cdf4d
Style code
lizihao-anu May 17, 2024
3869b09
update gp ooh cup
lizihao-anu May 23, 2024
a967d5c
link cup to acute
lizihao-anu May 23, 2024
a989b3f
Update documentation
lizihao-anu May 23, 2024
ce90a45
adding the death dates to activity after death cases (#972)
SwiftySalmon Jun 24, 2024
4e761ec
Add sys time to functions (#971)
SwiftySalmon Jun 24, 2024
5beee76
Update slf deaths lookup function name
Jennit07 Jun 25, 2024
33278ef
automate combined deaths lookup
Jennit07 Jun 26, 2024
59235a3
Merge branch 'combined_deaths' into targets_deaths
Jennit07 Jun 26, 2024
a7f983a
Automate the combined slf deaths lookup (#973)
SwiftySalmon Jun 28, 2024
1d2562d
Merge branch 'september-2024' into gpooh_cup
Jennit07 Jul 2, 2024
16f5852
Update documentation
Jennit07 Jul 2, 2024
dbb118a
Update targets script
Jennit07 Jul 2, 2024
623b222
Update years
Jennit07 Jul 2, 2024
d319c85
Update running process manually
Jennit07 Jul 2, 2024
ca2d033
re-arrange brackets
Jennit07 Jul 3, 2024
f15ca4e
Style code
Jennit07 Jul 3, 2024
61baf02
Update run targets scripts
Jennit07 Jul 3, 2024
379b137
Set up all-targets script
Jennit07 Jul 3, 2024
3fb27ae
Style code
Jennit07 Jul 3, 2024
ceb526a
Update documentation
Jennit07 Jul 3, 2024
a521206
Update targets script
Jennit07 Jul 2, 2024
585db7f
Update years
Jennit07 Jul 2, 2024
dada9cb
Update running process manually
Jennit07 Jul 2, 2024
bf63d73
re-arrange brackets
Jennit07 Jul 3, 2024
ba2be19
Style code
Jennit07 Jul 3, 2024
a4cf7b6
Update run targets scripts
Jennit07 Jul 3, 2024
f840c53
Set up all-targets script
Jennit07 Jul 3, 2024
6d20852
Style code
Jennit07 Jul 3, 2024
1cbfb51
Merge branch 'targets_deaths' of github.com:Public-Health-Scotland/so…
Jennit07 Jul 3, 2024
5482a75
Style code
lizihao-anu Jul 4, 2024
91e5946
Automate the combined slf deaths lookup (#973)
SwiftySalmon Jun 28, 2024
010d78e
Merge branch 'september-2024' into gpooh_cup
Jennit07 Jul 5, 2024
5ee009b
Merge branch 'september-2024' into targets_deaths
Jennit07 Jul 5, 2024
c3fb9d5
Update documentation
Jennit07 Jul 5, 2024
a0d796c
Merge branch 'september-2024' into gpooh_cup
Jennit07 Jul 5, 2024
fa3ee85
Merge branch 'september-2024' into targets_deaths
Jennit07 Jul 5, 2024
f30344c
Update Run_SLF_Files_targets/run_all_targets.R
SwiftySalmon Jul 8, 2024
06813ab
Style code
SwiftySalmon Jul 8, 2024
adae79b
Update Targets to include combined deaths processing (#980)
SwiftySalmon Jul 8, 2024
afb356e
Merge branch 'september-2024' into gpooh_cup
lizihao-anu Jul 8, 2024
8b4706d
remove combined_deaths_lookup from targets
lizihao-anu Jul 8, 2024
f20a5f7
Merge branch 'september-2024' into gpooh_cup
lizihao-anu Jul 8, 2024
09076f4
Style code
lizihao-anu Jul 8, 2024
c54aa04
Merge branch 'september-2024' into gpooh_cup
lizihao-anu Jul 8, 2024
400841e
fix acute_cup and gp_ooh_cup paths
lizihao-anu Jul 8, 2024
5879fe4
Update documentation
lizihao-anu Jul 8, 2024
2e4b160
fix typo
lizihao-anu Jul 8, 2024
8951d98
Merge branch 'september-2024' of github.com:Public-Health-Scotland/so…
Jul 9, 2024
b56ef25
adapt acute_cup for anon_chi
lizihao-anu Jul 9, 2024
8c3873c
Style code
lizihao-anu Jul 9, 2024
283e004
minor changes
lizihao-anu Jul 10, 2024
70b1850
Style code
lizihao-anu Jul 10, 2024
a7bac73
Update documentation
lizihao-anu Jul 10, 2024
8d8872d
GPooh and acute cup (#982)
SwiftySalmon Jul 10, 2024
7c4ded5
Merge branch 'september-2024' of github.com:Public-Health-Scotland/so…
Jul 10, 2024
9dac223
Person id sds (#981)
SwiftySalmon Jul 19, 2024
419720b
Update NEWS.md
Jennit07 Jul 19, 2024
7509d73
unify file names for cup files
lizihao-anu Jul 23, 2024
3e06476
Add client flags (#979)
SwiftySalmon Jul 24, 2024
bc06622
Update lookup to use anon-chi
Jennit07 Jul 26, 2024
60d6eb1
Remove redundant code
Jennit07 Jul 26, 2024
4dd9b51
Update documentation
Jennit07 Jul 26, 2024
3e07838
remove weekly nrs date variable
Jennit07 Jul 29, 2024
3e9c362
Use boxi nrs date or chi death date
Jennit07 Jul 29, 2024
76afd97
Use `get_combined_slf_deaths_path`
Jennit07 Jul 29, 2024
7491dc8
add catch for NAs
Jennit07 Jul 29, 2024
519b0c3
add notes
Jennit07 Jul 29, 2024
f7536e8
Fix typo
Jennit07 Jul 30, 2024
1347c79
remove redundant code
Jennit07 Jul 30, 2024
214bc3b
Style code
Jennit07 Jul 30, 2024
c493a80
add a function of combine nrs and it_chi death
lizihao-anu Aug 2, 2024
516cf9f
Update documentation
lizihao-anu Aug 2, 2024
f0babdb
Style code
lizihao-anu Aug 2, 2024
b57c69f
minor changes
lizihao-anu Aug 2, 2024
5d78180
remove process_slf_deaths_lookup
lizihao-anu Aug 5, 2024
03b41c3
Update documentation
lizihao-anu Aug 5, 2024
d186a3d
Major update of Care Home script (#945)
SwiftySalmon Aug 7, 2024
8f4a06a
update `ch_chi_cis` methodology
Jennit07 Aug 7, 2024
4c8bbf3
update `ch_sc_id_cis` methodology
Jennit07 Aug 7, 2024
b96feb1
Update notes
Jennit07 Aug 8, 2024
c01b7f6
Merge branch 'september-2024' of github.com:Public-Health-Scotland/so…
Aug 12, 2024
46a668c
Use `right_join`
Jennit07 Aug 12, 2024
f7caaea
Update process_sc_all_care_home.R
SwiftySalmon Aug 12, 2024
f48dfae
Investigate care home cis markers (#989)
SwiftySalmon Aug 12, 2024
e672d4a
Latest scid update (#990)
SwiftySalmon Aug 12, 2024
439e430
Add new nsu (#991)
Jennit07 Aug 16, 2024
72a66f8
update reference
lizihao-anu Aug 19, 2024
fce3249
Reduce dependencies (#984)
SwiftySalmon Aug 20, 2024
7146a11
minor changes to social care code
Aug 21, 2024
5e31183
Style code
SwiftySalmon Aug 21, 2024
962f7a3
Update process_sc_all_care_home.R
SwiftySalmon Aug 21, 2024
b24399e
Update NEWS.md
Jennit07 Aug 27, 2024
86424a5
merge Sep2024 fix into sep24 branch (#1003)
Jennit07 Sep 16, 2024
69ce173
update copy_to_hscdiip.R
lizihao-anu Sep 17, 2024
1ab7e7f
Update older years to bring the data in line with our newest processe…
Jennit07 Sep 17, 2024
4e3e185
Update `replace_sc_id_with_latest` function
Jennit07 Sep 17, 2024
27ac757
Style code
Jennit07 Sep 17, 2024
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: 9 additions & 3 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ admtype
ADPE
adtf
alstr
anomymous
arrivalmode
arth
atlassian
Expand Down Expand Up @@ -40,6 +41,7 @@ CNWs
codecov
Comhairle
commhosp
communicty
congen
copd
costinc
Expand All @@ -53,6 +55,7 @@ customise
cvd
dataframe
datamart
datas
datazone
datediff
dateformat
Expand Down Expand Up @@ -169,8 +172,8 @@ lubridate
magrittr
markdownguide
Matern
Mcbride
mcmahon
mcnicol
megan
microsoft
MIU
MMMYY
Expand Down Expand Up @@ -203,6 +206,7 @@ parkinsons
patflow
pattype
PCEC
pcs
PERTH
PHIBCS
phs
Expand All @@ -215,13 +219,15 @@ PLICS
popluation
Posix
postcodes
Postcodesio
PPAs
prac
praccode
ptypes
purrr
quickstart
rankdir
rbindlist
rcmdcheck
rdd
rdname
Expand All @@ -232,13 +238,13 @@ readr
readxl
reasonwait
recid
recordlinkage
refailure
reflectoring
refsource
reftype
relaint
renviron
returnsthe
rlang
rmarkdown
Rnw
Expand Down
15 changes: 2 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ Title: Create the Source Linkage Files
Version: 0.0.0.9000
Authors@R: c(
person("Public Health Scotland", , , "[email protected]", role = c("cre", "cph")),
person("Megan", "McNicol", , "[email protected]", role = "aut"),
person("Jennifer", "Thom", , "[email protected]", role = "aut"),
person("James", "McMahon", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-5380-2029")),
person("Catherine", "Holland", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-3259-5745")),
person("Bateman", "McBride", , "[email protected]", role = "aut"),
person("Zihao", "Li", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-5178-2124"))
)
Expand All @@ -25,25 +21,19 @@ Imports:
data.table (>= 1.14.6),
dbplyr (>= 2.3.1),
dplyr (>= 1.1.1),
dtplyr (>= 1.3.0),
fs (>= 1.6.1),
fst (>= 0.9.8),
future (>= 1.33.0),
future.callr (>= 0.8.1),
glue (>= 1.6.2),
haven (>= 2.5.2),
hms (>= 1.1.0),
janitor (>= 2.2.0),
keyring (>= 1.3.0),
lubridate (>= 1.9.2),
magrittr (>= 2.0.3),
odbc (>= 1.3.1),
openssl (>= 2.0.5),
openxlsx (>= 4.2.5),
phsmethods (>= 0.2.2),
phsopendata (>= 0.0.1.0),
purrr (>= 1.0.1),
qs (>= 0.25.5),
R.utils (>= 2.12.2),
readr (>= 2.1.0),
rlang (>= 1.1.0),
Expand Down Expand Up @@ -73,5 +63,4 @@ Encoding: UTF-8
Language: en-GB
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1

RoxygenNote: 7.3.2
7 changes: 5 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(add_deceased_flag)
export(add_homelessness_date_flags)
export(add_homelessness_flag)
export(add_hri_variables)
Expand All @@ -25,9 +26,9 @@ export(end_fy_quarter)
export(end_next_fy_quarter)
export(find_latest_file)
export(fy_interval)
export(get_all_slf_deaths_lookup_path)
export(get_boxi_extract_path)
export(get_ch_costs_path)
export(get_combined_slf_deaths_lookup_path)
export(get_dd_path)
export(get_dd_period)
export(get_demographic_cohorts_path)
Expand Down Expand Up @@ -88,11 +89,11 @@ export(midpoint_fy)
export(next_fy)
export(phs_db_connection)
export(previous_update)
export(process_combined_deaths_lookup)
export(process_costs_ch_rmd)
export(process_costs_dn_rmd)
export(process_costs_gp_ooh_rmd)
export(process_costs_hc_rmd)
export(process_deaths_lookup)
export(process_extract_acute)
export(process_extract_ae)
export(process_extract_alarms_telecare)
Expand All @@ -115,6 +116,7 @@ export(process_lookup_ltc)
export(process_lookup_postcode)
export(process_lookup_sc_client)
export(process_lookup_sc_demographics)
export(process_refined_death)
export(process_sc_all_alarms_telecare)
export(process_sc_all_care_home)
export(process_sc_all_home_care)
Expand Down Expand Up @@ -182,6 +184,7 @@ export(start_fy)
export(start_fy_quarter)
export(start_next_fy_quarter)
export(write_file)
export(years_to_run)
importFrom(data.table,.N)
importFrom(data.table,.SD)
importFrom(magrittr,"%>%")
Expand Down
16 changes: 15 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# June 2024 Update - Unreleased
# September 2024 Update - Unreleased
* New 24/25 files created
* New NSU cohort for 23/24 available
* New SPARRA scores calculated from April 24/25
* Death dates attached to activity after death flag
* Care home methodology updated
* New cup marker for Acute and GP OOH
* Bug fix:
* person id for SDS and client
* DD data:
* The variable `cij_delay` is only attached to the `recid = DD` rows, not all the rows in the CIJ as we'd expect.
* The `cij_delay` variable is showing as 1 against the Delay records (NA otherwise) - We expect this to be `TRUE/FALSE` to match the other flags.
* The `cij_ppa` variable isn't attaching to the `recid = DD` rows.

# June 2024 Update - released 06-Jun-24
* Update of 2017/18 onwards to include bug fixes within the files.
* Removal of extra variable caused by the LTCs not matching properly.
* New NRS mid-2022 population estimates.
Expand Down
20 changes: 13 additions & 7 deletions R/00-update_refs.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' @family initialisation
latest_update <- function() {
"Jun_2024"
"Sep_2024"
}

#' Previous update
Expand Down Expand Up @@ -61,18 +61,24 @@ previous_update <- function(months_ago = 3L, override = NULL) {
#'
#' @family initialisation
get_dd_period <- function() {
"Jul16_Mar24"
"Jul16_Jun24"
}

#' The latest financial year for Cost uplift setting
#' The year list for slf to update
#'
#' @description Get the latest year for cost uplift
#' @description Get the vector of years to update slf
#'
#' @return The financial year format
#' @return The vector of financial years
#'
#' @export
#'
#' @family initialisation
latest_cost_year <- function() {
"2223"
years_to_run <- function() {
fy_start_2digit <- 17
fy_end_2digit <- 24
years_to_run <- paste0(
fy_start_2digit:fy_end_2digit,
(fy_start_2digit + 1):(fy_end_2digit + 1)
)
return(years_to_run)
}
57 changes: 27 additions & 30 deletions R/add_activity_after_death_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
add_activity_after_death_flag <- function(
data,
year,
deaths_data = read_file(get_all_slf_deaths_lookup_path()) %>%
deaths_data = read_file(get_combined_slf_deaths_lookup_path()) %>%
slfhelper::get_chi()) {
cli::cli_alert_info("Add activity after death flag function started at {Sys.time()}")

# to skip warnings no visible binding for global variable ‘.’
. <- NULL

Expand All @@ -24,7 +26,7 @@ add_activity_after_death_flag <- function(
by = "chi",
suffix = c("", "_boxi")
) %>%
dplyr::filter(.data$deceased == TRUE | .data$deceased_boxi == TRUE) %>%
dplyr::filter(.data$deceased == TRUE) %>%
dplyr::distinct()


Expand Down Expand Up @@ -70,31 +72,28 @@ add_activity_after_death_flag <- function(
))


# Check and print error message for records which already are TRUE for the deceased variable in the episode file, but this doesn't match the
# BOXI deceased variable
check_deceased_match <- flag_data %>%
dplyr::filter(.data$deceased != .data$deceased_boxi)

if (nrow(check_deceased_match) != 0) {
warning("There were records in the episode file which have a deceased variable which does not match the BOXI NRS deceased variable")
}


# Fill in date of death if missing in the episode file but available in BOXI lookup, due to historic dates of death not being carried
# over from previous financial years
flag_data <- flag_data %>%
dplyr::filter(.data$activity_after_death == 1) %>%
# Remove temporary flag variables used to create activity after death flag and fill in missing death_date
dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$activity_after_death) %>%
dplyr::select(.data$year, .data$chi, .data$record_keydate1, .data$record_keydate2, .data$activity_after_death, .data$death_date_boxi) %>%
dplyr::distinct()

# Match activity after death flag back to episode file
final_data <- data %>%
dplyr::left_join(
flag_data,
# TODO: this join_by is not 100% accurate. Consider use ep_file_row_id to join
by = c("year", "chi", "record_keydate1", "record_keydate2"),
na_matches = "never"
)
) %>%
dplyr::mutate(death_date = lubridate::as_date(ifelse(is.na(death_date) & !(is.na(death_date_boxi)),
death_date_boxi, death_date
))) %>%
dplyr::select(-death_date_boxi) %>%
dplyr::distinct()



return(final_data)
Expand All @@ -118,19 +117,19 @@ add_activity_after_death_flag <- function(
#'
#'
# Read data------------------------------------------------
process_deaths_lookup <- function(update = latest_update(),
write_to_disk = TRUE, ...) {
all_boxi_deaths <- read_file(get_slf_deaths_lookup_path("1415")) %>%
rbind(read_file(get_slf_deaths_lookup_path("1516"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("1617"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("1718"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("1819"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("1920"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("2021"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("2122"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("2223"))) %>%
rbind(read_file(get_slf_deaths_lookup_path("2324"))) %>%
# TODO: make this automated to pick up files starting with name "get_slf_deaths_lookup_path"

process_combined_deaths_lookup <- function(update = latest_update(),
write_to_disk = TRUE, ...) {
dir_folder <- "/conf/hscdiip/SLF_Extracts/Deaths"
file_names <- list.files(dir_folder,
pattern = "^anon-slf_deaths_lookup_.*parquet",
full.names = TRUE
)

# read all year specific deaths lookups and bind them together
all_boxi_deaths <- lapply(file_names, arrow::read_parquet) %>%
data.table::rbindlist() %>%
# convert to chi for processing
slfhelper::get_chi() %>%
# Remove rows with missing or blank CHI number - could also use na.omit?
# na.omit(all_boxi_deaths)
Expand Down Expand Up @@ -177,9 +176,7 @@ process_deaths_lookup <- function(update = latest_update(),
if (write_to_disk) {
write_file(
all_boxi_deaths,
fs::path(get_slf_dir(), "Deaths",
file_name = stringr::str_glue("anon-all_slf_deaths_lookup_{update}.parquet")
)
get_combined_slf_deaths_lookup_path()
)
}

Expand Down
40 changes: 40 additions & 0 deletions R/add_deceased_flag.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Create the SLF Deaths lookup
#'
#' @description Currently this just uses the NRS death dates 'as is', with no
#' corrections or modifications, it is expected that this will be expanded to
#' use the CHI deaths extract from IT as well as taking into account data in
#' the episode file to assess the validity of a death date.
#'
#' @param year The year to process, in FY format.
#' @param nrs_deaths_data NRS deaths data.
#' @param chi_deaths_data IT CHI deaths data.
#' @param write_to_disk (optional) Should the data be written to disk default is
#' `TRUE` i.e. write the data to disk.
#'
#' @return a [tibble][tibble::tibble-package] containing the episode file
#' @export
add_deceased_flag <- function(
year,
refined_death = read_file(get_combined_slf_deaths_lookup_path()) %>% slfhelper::get_chi(),
write_to_disk = TRUE) {
# create slf deaths lookup

dplyr::mutate(
death_date = dplyr::if_else(is.na(.data$record_keydate1),
.data$death_date_chi, .data$record_keydate1
),
deceased = TRUE,
.keep = "unused"
) %>%
# save anon chi on disk
slfhelper::get_anon_chi()

if (write_to_disk) {
write_file(
slf_deaths_lookup,
get_slf_deaths_lookup_path(year, check_mode = "write")
)
}

return(slf_deaths_lookup)
}
2 changes: 2 additions & 0 deletions R/add_nsu_cohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ add_nsu_cohort <- function(
data,
year,
nsu_cohort = read_file(get_nsu_path(year)) %>% slfhelper::get_chi()) {
cli::cli_alert_info("Add NSU cohort function started at {Sys.time()}")

year_param <- year

if (!check_year_valid(year, "nsu")) {
Expand Down
2 changes: 2 additions & 0 deletions R/add_ppa_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @return A data frame to use as a lookup of PPAs
#' @family episode_file
add_ppa_flag <- function(data) {
cli::cli_alert_info("Add PPA flag function started at {Sys.time()}")

check_variables_exist(
data,
variables = c(
Expand Down
Loading