Skip to content

Commit

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

* Clean up the NRS processing functions

* Update documentation

* [check-spelling] Update metadata

Update for https://github.com/Public-Health-Scotland/source-linkage-files/actions/runs/5331571060/attempts/1
Accepted in #699 (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 3daca4f commit 74502a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
22 changes: 7 additions & 15 deletions R/process_extract_nrs_deaths.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#' Process the Nation Records of Scotland (NRS) Deaths extract
#'
#' @description This will read and process the
#' NRS deaths extract, it will return the final data
#' but also write this out an rds.
#' @description This will process the NRS deaths extract, it will return the
#' final data and write this out.
#'
#' @param data The extract to process
#' @param year The year to process, in FY format.
Expand All @@ -13,27 +12,20 @@
#' @export
#' @family process extracts
process_extract_nrs_deaths <- function(data, year, write_to_disk = TRUE) {
# Only run for a single year
stopifnot(length(year) == 1L)

# Check that the supplied year is in the correct format
year <- check_year_format(year)

# Data Cleaning ---------------------------------------

deaths_clean <- data %>%
dplyr::mutate(record_keydate2 = .data$record_keydate1) %>%
# create recid and year variables
dplyr::mutate(
record_keydate2 = .data$record_keydate1,
recid = "NRS",
year = year
) %>%
# fix dummy gpprac codes
dplyr::mutate(gpprac = convert_eng_gpprac_to_dummy(.data$gpprac)) %>%
dplyr::mutate(smrtype = add_smr_type(.data$recid))
year = year,
gpprac = convert_eng_gpprac_to_dummy(.data$gpprac),
smrtype = add_smr_type(.data$recid)
)

if (write_to_disk) {
# Save as rds file
deaths_clean %>%
write_file(get_source_extract_path(year, "Deaths", check_mode = "write"))
}
Expand Down
7 changes: 3 additions & 4 deletions R/read_extract_nrs_deaths.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#' @inherit read_extract_acute
#'
#' @export
#'
read_extract_nrs_deaths <- function(year, file_path = get_boxi_extract_path(year = year, type = "Deaths")) {
# Read BOXI extract
read_extract_nrs_deaths <- function(
year,
file_path = get_boxi_extract_path(year = year, type = "Deaths")) {
extract_nrs_deaths <- read_file(file_path,
col_types = cols_only(
"Death Location Code" = col_character(),
Expand Down Expand Up @@ -36,7 +36,6 @@ read_extract_nrs_deaths <- function(year, file_path = get_boxi_extract_path(year
"GP practice code(99)" = col_character()
)
) %>%
# rename variables
dplyr::rename(
death_location_code = "Death Location Code",
lca = "Geo Council Area Code",
Expand Down
5 changes: 2 additions & 3 deletions man/process_extract_nrs_deaths.Rd

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

0 comments on commit 74502a9

Please sign in to comment.