Skip to content

Commit

Permalink
Merge branch 'mar-23-update' into check_snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennit07 authored Jan 29, 2024
2 parents 3055d54 + 3233bfb commit acb2639
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 49 deletions.
10 changes: 5 additions & 5 deletions R/create_demog_test_flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#' @description Create the demographic flags for testing
#'
#' @param data a dataframe containing demographic variables e.g. chi
#' @param chi Specify chi or anon_chi.
#'
#' @return a dataframe with flag (1 or 0) for each demographic variable.
#' Missing value flag from [is_missing()]
#'
#' @family flag functions
create_demog_test_flags <- function(data) {
create_demog_test_flags <- function(data, chi = c(chi, anon_chi)) {
data %>%
dplyr::arrange(.data$chi) %>%
dplyr::arrange({{ chi }}) %>%
# create test flags
dplyr::mutate(
valid_chi = phsmethods::chi_check(.data$chi) == "Valid CHI",
unique_chi = dplyr::lag(.data$chi) != .data$chi,
n_missing_chi = is_missing(.data$chi),
unique_chi = dplyr::lag({{ chi }}) != {{ chi }},
n_missing_chi = is_missing({{ chi }}),
n_males = .data$gender == 1L,
n_females = .data$gender == 2L,
n_postcode = !is.na(.data$postcode) | !.data$postcode == "",
Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_alarms_telecare.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ produce_source_at_tests <- function(data,
max_min_vars = c("record_keydate1", "record_keydate2")) {
test_flags <- data %>%
# create test flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
dplyr::mutate(
n_at_alarms = .data$smrtype == "AT-Alarm",
n_at_telecare = .data$smrtype == "AT-Tele"
) %>%
create_lca_test_flags(.data$sc_send_lca) %>%
# remove variables that won't be summed
dplyr::select(.data$valid_chi:.data$West_Lothian) %>%
dplyr::select(.data$unique_chi:.data$West_Lothian) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_care_home.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ produce_source_ch_tests <- function(data,
)) {
test_flags <- data %>%
# use functions to create HB and partnership flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
dplyr::mutate(
n_episodes = 1L,
ch_name_missing = is.na(.data$ch_name),
Expand All @@ -60,7 +60,7 @@ produce_source_ch_tests <- function(data,
) %>%
create_lca_test_flags(.data$sc_send_lca) %>%
# keep variables for comparison
dplyr::select("valid_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_cmh.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ process_tests_cmh <- function(data, year) {
produce_source_cmh_tests <- function(data) {
test_flags <- data %>%
# create test flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
create_hb_test_flags(hb_var = .data$hbrescode) %>%
dplyr::mutate(n_episodes = 1L) %>%
# keep variables for comparison
dplyr::select("valid_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_district_nursing.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ produce_source_dn_tests <- function(data,
)) {
test_flags <- data %>%
# use functions to create HB and partnership flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
create_hb_test_flags(.data$hbtreatcode) %>%
create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net) %>%
# keep variables for comparison
dplyr::select(.data$valid_chi:.data$NHS_Lanarkshire_cost) %>%
dplyr::select(.data$unique_chi:.data$NHS_Lanarkshire_cost) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
12 changes: 2 additions & 10 deletions R/process_tests_episode_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,7 @@ produce_episode_file_tests <- function(
test_flags <- data %>%
dplyr::group_by(.data$recid) %>%
# use functions to create HB and partnership flags
dplyr::mutate(
unique_anon_chi = dplyr::lag(.data$anon_chi) != .data$anon_chi,
n_missing_anon_chi = is_missing(.data$anon_chi),
n_males = .data$gender == 1L,
n_females = .data$gender == 2L,
n_postcode = !is.na(.data$postcode) | !.data$postcode == "",
n_missing_postcode = is_missing(.data$postcode),
missing_dob = is.na(.data$dob)
) %>%
create_demog_test_flags(chi = anon_chi) %>%
create_hb_test_flags(.data$hbtreatcode) %>%
create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net) %>%
create_hscp_test_flags(.data$hscp2018) %>%
Expand Down Expand Up @@ -111,7 +103,7 @@ produce_episode_file_tests <- function(

test_flags <- test_flags %>%
# keep variables for comparison
dplyr::select("unique_anon_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum", group_by = "recid")

Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_home_care.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ produce_source_hc_tests <- function(data,
)) {
test_flags <- data %>%
# use functions to create HB and partnership flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
dplyr::mutate(
n_episodes = 1L,
hc_per = dplyr::if_else(.data$smrtype == "HC-Per", 1L, 0L),
Expand All @@ -61,7 +61,7 @@ produce_source_hc_tests <- function(data,
) %>%
create_lca_test_flags(.data$sc_send_lca) %>%
# keep variables for comparison
dplyr::select("valid_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_homelessness.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ produce_slf_homelessness_tests <- function(data,
test_flags <- data %>%
dplyr::arrange(.data$chi) %>%
# create test flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
create_lca_test_flags(.data$hl1_sending_lca) %>%
# keep variables for comparison
dplyr::select("valid_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
12 changes: 2 additions & 10 deletions R/process_tests_individual_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,11 @@ produce_individual_file_tests <- function(data) {

test_flags <- data %>%
# use functions to create HB and partnership flags
dplyr::mutate(
unique_anon_chi = dplyr::lag(.data$anon_chi) != .data$anon_chi,
n_missing_anon_chi = is_missing(.data$anon_chi),
n_males = .data$gender == 1L,
n_females = .data$gender == 2L,
n_postcode = !is.na(.data$postcode) | !.data$postcode == "",
n_missing_postcode = is_missing(.data$postcode),
missing_dob = is.na(.data$dob)
) %>%
create_demog_test_flags(chi = anon_chi) %>%
create_hb_test_flags(.data$hbrescode) %>%
create_hb_cost_test_flags(.data$hbrescode, .data$health_net_cost) %>%
# keep variables for comparison
dplyr::select(c("unique_anon_chi":dplyr::last_col())) %>%
dplyr::select(c("unique_chi":dplyr::last_col())) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_nrs_deaths.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ process_tests_nrs_deaths <- function(data, year) {
produce_source_nrs_tests <- function(data) {
test_flags <- data %>%
# create test flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
dplyr::mutate(n_deaths = 1L) %>%
# keep variables for comparison
dplyr::select("valid_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_prescribing.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ process_tests_prescribing <- function(data, year) {
produce_source_pis_tests <- function(data) {
test_flags <- data %>%
# use functions to create HB and partnership flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
dplyr::mutate(n_episodes = 1L) %>%
# keep variables for comparison
dplyr::select("valid_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
2 changes: 1 addition & 1 deletion R/process_tests_sc_demographics.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ process_tests_sc_demographics <- function(data) {
produce_sc_demog_lookup_tests <- function(data) {
data %>%
# create test flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
dplyr::mutate(
n_missing_sending_loc = is.na(.data$sending_location),
n_missing_sc_id = is.na(.data$social_care_id)
Expand Down
4 changes: 2 additions & 2 deletions R/process_tests_sds.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ produce_source_sds_tests <- function(data,
max_min_vars = c("record_keydate1", "record_keydate2")) {
test_flags <- data %>%
# create test flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
create_lca_test_flags(.data$sc_send_lca) %>%
# remove variables that won't be summed
dplyr::select("valid_chi":"West_Lothian") %>%
dplyr::select("unique_chi":"West_Lothian") %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 2 additions & 2 deletions R/produce_sc_all_episodes_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
produce_sc_all_episodes_tests <- function(data) {
data %>%
# create test flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
dplyr::mutate(
n_missing_sending_loc = dplyr::if_else(
is.na(.data$sending_location),
Expand All @@ -24,7 +24,7 @@ produce_sc_all_episodes_tests <- function(data) {
)
) %>%
# keep variables for comparison
dplyr::select(c("valid_chi":dplyr::last_col())) %>%
dplyr::select(c("unique_chi":dplyr::last_col())) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")
}
4 changes: 2 additions & 2 deletions R/produce_source_extract_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ produce_source_extract_tests <- function(data,
add_hscp_count = TRUE) {
test_flags <- data %>%
# use functions to create HB and partnership flags
create_demog_test_flags() %>%
create_demog_test_flags(chi = chi) %>%
create_hb_test_flags(.data$hbtreatcode) %>%
create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net)

Expand All @@ -43,7 +43,7 @@ produce_source_extract_tests <- function(data,

test_flags <- test_flags %>%
# keep variables for comparison
dplyr::select("valid_chi":dplyr::last_col()) %>%
dplyr::select("unique_chi":dplyr::last_col()) %>%
# use function to sum new test flags
calculate_measures(measure = "sum")

Expand Down
4 changes: 3 additions & 1 deletion man/create_demog_test_flags.Rd

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

0 comments on commit acb2639

Please sign in to comment.