Skip to content

Commit

Permalink
Rename the IT CHI deaths file functions (#698)
Browse files Browse the repository at this point in the history
* Rename the IT CHI deaths file functions

* Update documentation

* [check-spelling] Update metadata

Update for https://github.com/Public-Health-Scotland/source-linkage-files/actions/runs/5331531642/attempts/1
Accepted in #698 (comment)

Signed-off-by: check-spelling-bot <[email protected]>

---------

Signed-off-by: check-spelling-bot <[email protected]>
Co-authored-by: Moohan <[email protected]>
Co-authored-by: Jennit07 <[email protected]>
  • Loading branch information
3 people authored Jun 23, 2023
1 parent 52ed1a0 commit 3daca4f
Show file tree
Hide file tree
Showing 49 changed files with 193 additions and 165 deletions.
3 changes: 2 additions & 1 deletion .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,5 @@ xlsx
yearstay
YYYYQX
zsav
zstd
zstd
zstd
8 changes: 4 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export(get_service_use_cohorts_path)
export(get_sg_homelessness_pub_path)
export(get_simd_path)
export(get_slf_ch_name_lookup_path)
export(get_slf_deaths_path)
export(get_slf_chi_deaths_path)
export(get_slf_dir)
export(get_slf_ep_temp_path)
export(get_slf_gpprac_path)
Expand Down Expand Up @@ -94,7 +94,7 @@ export(process_extract_nrs_deaths)
export(process_extract_outpatients)
export(process_extract_prescribing)
export(process_extract_sds)
export(process_lookup_chi_deaths)
export(process_it_chi_deaths)
export(process_lookup_gpprac)
export(process_lookup_ltc)
export(process_lookup_postcode)
Expand All @@ -115,6 +115,7 @@ export(process_tests_gp_ooh)
export(process_tests_home_care)
export(process_tests_homelessness)
export(process_tests_individual_file)
export(process_tests_it_chi_deaths)
export(process_tests_lookup_gpprac)
export(process_tests_lookup_pc)
export(process_tests_ltcs)
Expand All @@ -126,7 +127,6 @@ export(process_tests_prescribing)
export(process_tests_sc_ch_episodes)
export(process_tests_sc_demographics)
export(process_tests_sds)
export(produce_slf_deaths_tests)
export(produce_source_extract_tests)
export(produce_test_comparison)
export(read_extract_acute)
Expand All @@ -142,7 +142,7 @@ export(read_extract_nrs_deaths)
export(read_extract_outpatients)
export(read_extract_prescribing)
export(read_file)
export(read_lookup_chi_deaths)
export(read_it_chi_deaths)
export(read_lookup_ltc)
export(read_lookup_sc_client)
export(read_lookup_sc_demographics)
Expand Down
11 changes: 7 additions & 4 deletions R/get_slf_lookup_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ get_slf_gpprac_path <- function(update = latest_update(), ...) {
#'
#' @description Get the full path to the SLF deaths lookup file
#'
#'
#' @description Get the full path to the CHI deaths file
#'
#' @param update The update month to use,
#' defaults to [latest_update()]
#' @param ... additional arguments passed to [get_file_path()]
Expand All @@ -48,14 +51,14 @@ get_slf_gpprac_path <- function(update = latest_update(), ...) {
#' @export
#' @family slf lookup file path
#' @seealso [get_file_path()] for the generic function.
get_slf_deaths_path <- function(update = latest_update(), ...) {
slf_deaths_file_path <- get_file_path(
get_slf_chi_deaths_path <- function(update = latest_update(), ...) {
slf_chi_deaths_path <- get_file_path(
directory = fs::path(get_slf_dir(), "Deaths"),
file_name = stringr::str_glue("all_deaths_{update}.rds"),
file_name = stringr::str_glue("chi_deaths_{update}.parquet"),
...
)

return(slf_deaths_file_path)
return(slf_chi_deaths_path)
}

#' Get the full path to the SLF read code lookup
Expand Down
31 changes: 31 additions & 0 deletions R/process_it_chi_deaths.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Process the CHI deaths extract
#'
#' @description This will process the CHI deaths extract, it will return the
#' final data and write the data out.
#'
#' @param data The extract to process
#' @param write_to_disk (optional) Should the data be written to disk default is
#' `TRUE` i.e. write the data to disk.
#'
#' @return the final data as a [tibble][tibble::tibble-package].
#' @export
#' @family process extracts
process_it_chi_deaths <- function(data, write_to_disk = TRUE) {
it_chi_deaths_clean <- data %>%
dplyr::arrange(
dplyr::desc(.data$death_date_nrs),
dplyr::desc(.data$death_date_chi)
) %>%
dplyr::distinct(.data$chi, .keep_all = TRUE) %>%
# Use the NRS death_date unless it isn't there
dplyr::mutate(
death_date = dplyr::coalesce(.data$death_date_nrs, .data$death_date_chi)
)

if (write_to_disk) {
it_chi_deaths_clean %>%
write_file(get_slf_chi_deaths_path(check_mode = "write"))
}

return(it_chi_deaths_clean)
}
40 changes: 0 additions & 40 deletions R/process_lookup_chi_deaths.R

This file was deleted.

26 changes: 21 additions & 5 deletions R/produce_slf_deaths_tests.R → R/process_tests_it_chi_deaths.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
#' SLF Deaths Lookup Tests
#' Process CHI Deaths tests
#'
#' @description Produce the tests for SLF deaths lookup
#' @inherit process_tests_lookup_pc
#'
#' @export
process_tests_it_chi_deaths <- function(data, update = previous_update()) {
comparison <- produce_test_comparison(
old_data = produce_it_chi_deaths_tests(
read_file(get_slf_chi_deaths_path(update = update))
),
new_data = produce_it_chi_deaths_tests(data)
) %>%
write_tests_xlsx(sheet_name = "it_chi_deaths")

return(comparison)
}

#' CHI death tests
#'
#' @description Produce the tests for IT CHI deaths
#'
#' @param data new or old data for testing summary
#' flags (data is from [get_slf_deaths_path()])
#' flags (data is from [get_slf_chi_deaths_path()])
#
#' @return a dataframe with a count of each flag
#' from [calculate_measures()]
#' @export
#' @family slf test functions
produce_slf_deaths_tests <- function(data) {
produce_it_chi_deaths_tests <- function(data) {
data %>%
# create test flags
dplyr::mutate(
Expand Down
16 changes: 5 additions & 11 deletions R/read_lookup_chi_deaths.R → R/read_it_chi_deaths.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
#' Process the CHI deaths lookup
#'
#' @description This will read and process the
#' CHI deaths lookup, it will return the final data
#' but also write this out as an rds.
#' Read the CHI deaths extract
#'
#' @description This will read the CHI deaths extract and return the data.
#' @param file_path Path to CHI Deaths file
#'
#' @return the final data as a [tibble][tibble::tibble-package].
#' @export
#' @family process extracts

read_lookup_chi_deaths <- function(file_path = get_it_deaths_path()) {
# Read data -------------------------------------------------------
deaths_data <- read_file(file_path,
read_it_chi_deaths <- function(file_path = get_it_deaths_path()) {
it_chi_deaths <- read_file(file_path,
col_type = cols(
"PATIENT_UPI [C]" = col_character(),
"PATIENT DoD DATE (NRS)" = col_date(format = "%d-%m-%Y"),
"PATIENT DoD DATE (CHI)" = col_date(format = "%d-%m-%Y")
)
) %>%
# rename variables
dplyr::rename(
chi = "PATIENT_UPI [C]",
death_date_nrs = "PATIENT DoD DATE (NRS)",
death_date_chi = "PATIENT DoD DATE (CHI)"
)

return(deaths_data)
return(it_chi_deaths)
}
15 changes: 9 additions & 6 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ list(
tar_target(locality_path, get_locality_path(), format = "file"),
tar_target(simd_path, get_simd_path(), format = "file"),
tar_target(spd_path, get_spd_path(), format = "file"),
tar_file_read(chi_deaths_data,
tar_file_read(it_chi_deaths_extract,
command = get_it_deaths_path(),
read = read_lookup_chi_deaths(!!.x)
read = read_it_chi_deaths(!!.x)
),
tar_file_read(dd_data, get_dd_path(), read_extract_delayed_discharges(!!.x)),
tar_file_read(ltc_data, get_it_ltc_path(), read_lookup_ltc(!!.x)),
Expand All @@ -56,14 +56,17 @@ list(
sc_demog_lookup_tests,
process_tests_sc_demographics(sc_demog_lookup)
),
# TODO add tests for the CHI deaths lookup
tar_target(
slf_chi_deaths_lookup,
process_lookup_chi_deaths(
data = chi_deaths_data,
it_chi_deaths_data,
process_it_chi_deaths(
data = it_chi_deaths_extract,
write_to_disk = write_to_disk
)
),
tar_target(
it_chi_deaths_tests,
process_tests_it_chi_deaths(it_chi_deaths_data)
),
tar_target(
source_gp_lookup,
process_lookup_gpprac(
Expand Down
2 changes: 1 addition & 1 deletion man/get_slf_ch_name_lookup_path.Rd

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

8 changes: 5 additions & 3 deletions man/get_slf_deaths_path.Rd → man/get_slf_chi_deaths_path.Rd

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

2 changes: 1 addition & 1 deletion man/get_slf_gpprac_path.Rd

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

2 changes: 1 addition & 1 deletion man/get_slf_postcode_path.Rd

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

4 changes: 2 additions & 2 deletions man/process_extract_acute.Rd

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

4 changes: 2 additions & 2 deletions man/process_extract_ae.Rd

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

4 changes: 2 additions & 2 deletions man/process_extract_alarms_telecare.Rd

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

4 changes: 2 additions & 2 deletions man/process_extract_care_home.Rd

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

4 changes: 2 additions & 2 deletions man/process_extract_cmh.Rd

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

Loading

0 comments on commit 3daca4f

Please sign in to comment.