From bfec3ea7212194f78dba66948f2c5bff0e677cb4 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Tue, 1 Aug 2023 15:02:11 +0100 Subject: [PATCH 1/6] Format postcode into `pc7` format --- R/process_extract_ae.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/process_extract_ae.R b/R/process_extract_ae.R index 1be6efe39..4b85f2018 100644 --- a/R/process_extract_ae.R +++ b/R/process_extract_ae.R @@ -35,6 +35,10 @@ process_extract_ae <- function(data, year, write_to_disk = TRUE) { .data$postcode_chi, .data$postcode_epi )) %>% + # Use phs methods to format postcode in pc7 + dplyr::mutate( + postcode = phsmethods::format_postcode(.data$postcode, "pc7") + ) %>% ## recode cypher HB codes ## dplyr::mutate( dplyr::across(c("hbtreatcode", "hbrescode"), ~ dplyr::case_when( From c3ab5a4bf3d8bd65cdcbc10f46faefd49bb5f2b1 Mon Sep 17 00:00:00 2001 From: Jennit07 Date: Tue, 1 Aug 2023 14:05:07 +0000 Subject: [PATCH 2/6] Style code --- _targets.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_targets.R b/_targets.R index f1cb1771f..8267794a5 100644 --- a/_targets.R +++ b/_targets.R @@ -562,7 +562,7 @@ list( data = individual_file, year = year ) - )#, + ) # , # tar_target( # episode_file_dataset, # arrow::write_dataset( From 4f1270152efcaf6954969db0e422aad422854b80 Mon Sep 17 00:00:00 2001 From: Moohan Date: Tue, 1 Aug 2023 16:33:36 +0000 Subject: [PATCH 3/6] Style code --- R/create_individual_file.R | 3 ++- R/process_lookup_gpprac.R | 3 ++- R/read_lookup_sc_client.R | 5 ++--- R/read_lookup_sc_demographics.R | 3 +-- R/read_sc_all_alarms_telecare.R | 3 +-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/R/create_individual_file.R b/R/create_individual_file.R index a5960595d..72045ea95 100644 --- a/R/create_individual_file.R +++ b/R/create_individual_file.R @@ -846,7 +846,8 @@ join_slf_lookup_vars <- function(individual_file, #' @param year financial year. #' @param sc_client SC client lookup #' @param sc_demographics SC Demographic lookup -join_sc_client <- function(individual_file, +join_sc_client <- function( + individual_file, year, sc_client = read_file(get_source_extract_path(year, "Client")), sc_demographics = read_file(get_sc_demog_lookup_path(), diff --git a/R/process_lookup_gpprac.R b/R/process_lookup_gpprac.R index e34b67f16..2afe1affd 100644 --- a/R/process_lookup_gpprac.R +++ b/R/process_lookup_gpprac.R @@ -12,7 +12,8 @@ #' @return the final data as a [tibble][tibble::tibble-package]. #' @export #' @family process extracts -process_lookup_gpprac <- function(open_data = get_gpprac_opendata(), +process_lookup_gpprac <- function( + open_data = get_gpprac_opendata(), gpprac_ref_path = get_gpprac_ref_path(), spd_path = get_spd_path(), write_to_disk = TRUE) { diff --git a/R/read_lookup_sc_client.R b/R/read_lookup_sc_client.R index a370340a6..cc98060f3 100644 --- a/R/read_lookup_sc_client.R +++ b/R/read_lookup_sc_client.R @@ -9,9 +9,8 @@ #' @return the final data as a [tibble][tibble::tibble-package]. #' @export #' @family process extracts -read_lookup_sc_client <- function( - fyyear, - sc_dvprod_connection = phs_db_connection(dsn = "DVPROD")) { +read_lookup_sc_client <- function(fyyear, + sc_dvprod_connection = phs_db_connection(dsn = "DVPROD")) { check_year_format(fyyear) year <- convert_fyyear_to_year(fyyear) diff --git a/R/read_lookup_sc_demographics.R b/R/read_lookup_sc_demographics.R index 831d2de75..fcdde5417 100644 --- a/R/read_lookup_sc_demographics.R +++ b/R/read_lookup_sc_demographics.R @@ -5,8 +5,7 @@ #' @return a [tibble][tibble::tibble-package] #' @export #' -read_lookup_sc_demographics <- function( - sc_connection = phs_db_connection(dsn = "DVPROD")) { +read_lookup_sc_demographics <- function(sc_connection = phs_db_connection(dsn = "DVPROD")) { sc_demog <- dplyr::tbl( sc_connection, dbplyr::in_schema("social_care_2", "demographic_snapshot") diff --git a/R/read_sc_all_alarms_telecare.R b/R/read_sc_all_alarms_telecare.R index b4149d65d..ac3ac206d 100644 --- a/R/read_sc_all_alarms_telecare.R +++ b/R/read_sc_all_alarms_telecare.R @@ -6,8 +6,7 @@ #' #' @export #' -read_sc_all_alarms_telecare <- function( - sc_dvprod_connection = phs_db_connection(dsn = "DVPROD")) { +read_sc_all_alarms_telecare <- function(sc_dvprod_connection = phs_db_connection(dsn = "DVPROD")) { # Read in data--------------------------------------- ## read in data - social care 2 demographic From 7b9b8af5c2d75fb65f0bad779ea5f20a94c1b9c3 Mon Sep 17 00:00:00 2001 From: Moohan Date: Tue, 1 Aug 2023 16:43:32 +0000 Subject: [PATCH 4/6] Update documentation --- NAMESPACE | 2 -- man/add_operation_flag.Rd | 3 ++- man/assign_cohort_names.Rd | 3 ++- man/assign_s_cohort_limited_daycases.Rd | 4 ++-- man/assign_s_cohort_outpatient.Rd | 3 ++- man/assign_s_cohort_prescribing.Rd | 3 ++- man/assign_s_cohort_routine_daycase.Rd | 4 ++-- man/compute_mid_year_age.Rd | 3 ++- man/get_slf_ep_temp_path.Rd | 19 ------------------- man/get_slf_indiv_temp_path.Rd | 19 ------------------- man/get_slf_temp_path.Rd | 25 ------------------------- man/read_lookup_sc_client.Rd | 8 ++++---- 12 files changed, 18 insertions(+), 78 deletions(-) delete mode 100644 man/get_slf_ep_temp_path.Rd delete mode 100644 man/get_slf_indiv_temp_path.Rd delete mode 100644 man/get_slf_temp_path.Rd diff --git a/NAMESPACE b/NAMESPACE index d87bf9397..fda9822ed 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,9 +59,7 @@ export(get_slf_ch_name_lookup_path) export(get_slf_chi_deaths_path) export(get_slf_deaths_lookup_path) export(get_slf_dir) -export(get_slf_ep_temp_path) export(get_slf_gpprac_path) -export(get_slf_indiv_temp_path) export(get_slf_postcode_path) export(get_source_extract_path) export(get_sparra_path) diff --git a/man/add_operation_flag.Rd b/man/add_operation_flag.Rd index cb7dff76d..bda825a7c 100644 --- a/man/add_operation_flag.Rd +++ b/man/add_operation_flag.Rd @@ -10,7 +10,8 @@ add_operation_flag(op1a) \item{op1a}{A vector of operation codes} } \value{ -A boolean vector showing whether a record contains an operation or not +A boolean vector showing whether a record contains an operation or +not. } \description{ Add operation flag diff --git a/man/assign_cohort_names.Rd b/man/assign_cohort_names.Rd index a0edb373d..e68ad7c42 100644 --- a/man/assign_cohort_names.Rd +++ b/man/assign_cohort_names.Rd @@ -10,7 +10,8 @@ assign_cohort_names(data) \item{data}{A data frame} } \value{ -A data frame with an additional variable containing the assigned cohort +A data frame with an additional variable containing the assigned +cohort } \description{ Assign service use cohort into string format diff --git a/man/assign_s_cohort_limited_daycases.Rd b/man/assign_s_cohort_limited_daycases.Rd index c63569e5c..69f49b4dc 100644 --- a/man/assign_s_cohort_limited_daycases.Rd +++ b/man/assign_s_cohort_limited_daycases.Rd @@ -15,8 +15,8 @@ assign_s_cohort_limited_daycases(elective_inpatient_flag, elective_instances) A boolean vector of limited daycases cohort flags } \description{ -If the record does not have an elective inpatient flag and they have -3 or fewer elective instances, return \code{TRUE} +If the record does not have an elective inpatient flag +and they have 3 or fewer elective instances, return \code{TRUE}. } \seealso{ Other Demographic and Service Use Cohort functions: diff --git a/man/assign_s_cohort_outpatient.Rd b/man/assign_s_cohort_outpatient.Rd index 264044b2c..5d811b6af 100644 --- a/man/assign_s_cohort_outpatient.Rd +++ b/man/assign_s_cohort_outpatient.Rd @@ -13,7 +13,8 @@ assign_s_cohort_outpatient(outpatient_cost) A boolean vector of outpatient cohort flags } \description{ -If the record has a outpatient cost greater than zero, assign \code{TRUE} +If the record has a outpatient cost greater than zero, +assign \code{TRUE}. } \seealso{ Other Demographic and Service Use Cohort functions: diff --git a/man/assign_s_cohort_prescribing.Rd b/man/assign_s_cohort_prescribing.Rd index 34ead6130..4b938f518 100644 --- a/man/assign_s_cohort_prescribing.Rd +++ b/man/assign_s_cohort_prescribing.Rd @@ -13,7 +13,8 @@ assign_s_cohort_prescribing(prescribing_cost) A boolean vector of prescribing cohort flags } \description{ -If the record has a prescribing cost greater than zero, assign \code{TRUE} +If the record has a prescribing cost greater than zero, +assign \code{TRUE}. } \seealso{ Other Demographic and Service Use Cohort functions: diff --git a/man/assign_s_cohort_routine_daycase.Rd b/man/assign_s_cohort_routine_daycase.Rd index af67448a9..03f5f51e0 100644 --- a/man/assign_s_cohort_routine_daycase.Rd +++ b/man/assign_s_cohort_routine_daycase.Rd @@ -15,8 +15,8 @@ assign_s_cohort_routine_daycase(elective_inpatient_flag, elective_instances) A boolean vector of routine daycase cohort flags } \description{ -If the record does not have an elective inpatient flag and they have -4 or more elective instances, return \code{TRUE} +If the record does not have an elective inpatient flag and +they have 4 or more elective instances, return \code{TRUE}. } \seealso{ Other Demographic and Service Use Cohort functions: diff --git a/man/compute_mid_year_age.Rd b/man/compute_mid_year_age.Rd index 4892ce7f4..c27e32af5 100644 --- a/man/compute_mid_year_age.Rd +++ b/man/compute_mid_year_age.Rd @@ -15,7 +15,8 @@ compute_mid_year_age(fyyear, dob) a vector of ages at the financial year midpoint } \description{ -Compute the age of a client at the midpoint of the year - 30-09-YYYY +Compute the age of a client at the midpoint of the year - +30-09-YYYY } \examples{ dob <- as.Date(c("01-01-1990", "31-10-1997"), format = "\%d-\%m-\%Y") diff --git a/man/get_slf_ep_temp_path.Rd b/man/get_slf_ep_temp_path.Rd deleted file mode 100644 index 44e1a44db..000000000 --- a/man/get_slf_ep_temp_path.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_temp_file_paths.R -\name{get_slf_ep_temp_path} -\alias{get_slf_ep_temp_path} -\title{Get a temporary version of the SLF episode file} -\usage{ -get_slf_ep_temp_path(year, temp_version) -} -\arguments{ -\item{year}{The financial year} - -\item{temp_version}{The temp version e.g. 1 or 7} -} -\value{ -The path to the file (\code{.rds}) -} -\description{ -Get a temporary version of the SLF episode file -} diff --git a/man/get_slf_indiv_temp_path.Rd b/man/get_slf_indiv_temp_path.Rd deleted file mode 100644 index 6ff1c70bd..000000000 --- a/man/get_slf_indiv_temp_path.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_temp_file_paths.R -\name{get_slf_indiv_temp_path} -\alias{get_slf_indiv_temp_path} -\title{Get a temporary version of the SLF individual file} -\usage{ -get_slf_indiv_temp_path(year, temp_version) -} -\arguments{ -\item{year}{The financial year} - -\item{temp_version}{The temp version e.g. 1 or 7} -} -\value{ -The path to the file (\code{.rds}) -} -\description{ -Get a temporary version of the SLF individual file -} diff --git a/man/get_slf_temp_path.Rd b/man/get_slf_temp_path.Rd deleted file mode 100644 index 31f4dde38..000000000 --- a/man/get_slf_temp_path.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_temp_file_paths.R -\name{get_slf_temp_path} -\alias{get_slf_temp_path} -\title{Get a temporary version of the SLF} -\usage{ -get_slf_temp_path( - year, - temp_version, - file_version = c("episode", "individual") -) -} -\arguments{ -\item{year}{The financial year} - -\item{temp_version}{The temp version e.g. 1 or 7} - -\item{file_version}{Episode or Individual file} -} -\value{ -The path to the file (\code{.rds}) -} -\description{ -Get a temporary version of the SLF -} diff --git a/man/read_lookup_sc_client.Rd b/man/read_lookup_sc_client.Rd index 6579fa9f7..267d452bd 100644 --- a/man/read_lookup_sc_client.Rd +++ b/man/read_lookup_sc_client.Rd @@ -5,14 +5,14 @@ \title{Process the social care client lookup} \usage{ read_lookup_sc_client( - sc_dvprod_connection = phs_db_connection(dsn = "DVPROD"), - fyyear + fyyear, + sc_dvprod_connection = phs_db_connection(dsn = "DVPROD") ) } \arguments{ -\item{sc_dvprod_connection}{The connection to the SC platform.} - \item{fyyear}{The year to process, in the standard format '1718'} + +\item{sc_dvprod_connection}{The connection to the SC platform.} } \value{ the final data as a \link[tibble:tibble-package]{tibble}. From 5d709460b497c48aa5f26327661d4d8f90a42255 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Tue, 1 Aug 2023 17:50:58 +0100 Subject: [PATCH 5/6] Update comment in R/process_extract_ae.R --- R/process_extract_ae.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/process_extract_ae.R b/R/process_extract_ae.R index 4b85f2018..7e61db018 100644 --- a/R/process_extract_ae.R +++ b/R/process_extract_ae.R @@ -35,7 +35,7 @@ process_extract_ae <- function(data, year, write_to_disk = TRUE) { .data$postcode_chi, .data$postcode_epi )) %>% - # Use phs methods to format postcode in pc7 + # A&E data has postcode in PC8 format but we need it in PC7 format dplyr::mutate( postcode = phsmethods::format_postcode(.data$postcode, "pc7") ) %>% From ca27b79d1d99544d4ee2cd31420552da7013dbd7 Mon Sep 17 00:00:00 2001 From: Jennifer Thom Date: Wed, 2 Aug 2023 09:55:31 +0100 Subject: [PATCH 6/6] Implement catch-all for PC7 format --- R/run_episode_file.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/run_episode_file.R b/R/run_episode_file.R index 0f8f07d59..19c2481f2 100644 --- a/R/run_episode_file.R +++ b/R/run_episode_file.R @@ -93,7 +93,9 @@ run_episode_file <- function( NA_character_, .data$chi ), - gpprac = convert_eng_gpprac_to_dummy(.data[["gpprac"]]) + gpprac = convert_eng_gpprac_to_dummy(.data[["gpprac"]]), + # PC8 format may still be used. Ensure here that all datasets are in PC7 format. + postcode = phsmethods::format_postcode(.data$postcode, "pc7") ) %>% correct_cij_vars() %>% fill_missing_cij_markers() %>%