diff --git a/R/create_demog_test_flags.R b/R/create_demog_test_flags.R index 0968eec06..3023292ce 100644 --- a/R/create_demog_test_flags.R +++ b/R/create_demog_test_flags.R @@ -13,45 +13,13 @@ create_demog_test_flags <- function(data) { dplyr::arrange(.data$chi) %>% # create test flags dplyr::mutate( - valid_chi = dplyr::if_else( - phsmethods::chi_check(.data$chi) == "Valid CHI", - 1L, - 0L - ), - unique_chi = dplyr::if_else( - dplyr::lag(.data$chi) != .data$chi, - 1L, - 0L - ), - n_missing_chi = dplyr::if_else( - is_missing(.data$chi), - 1L, - 0L - ), - n_males = dplyr::if_else( - .data$gender == 1L, - 1L, - 0L - ), - n_females = dplyr::if_else( - .data$gender == 2L, - 1L, - 0L - ), - # n_postcode = dplyr::if_else( - # is.na(.data$postcode) | .data$postcode == "", - # 0L, - # 1L - # ), - # n_missing_postcode = dplyr::if_else( - # is_missing(.data$postcode), - # 1L, - # 0L - # ), - missing_dob = dplyr::if_else( - is.na(.data$dob), - 1L, - 0L - ) + valid_chi = phsmethods::chi_check(.data$chi) == "Valid CHI", + unique_chi = dplyr::lag(.data$chi) != .data$chi, + n_missing_chi = is_missing(.data$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) ) } diff --git a/R/create_hb_test_flags.R b/R/create_hb_test_flags.R index cb5855c1e..d21f1662a 100644 --- a/R/create_hb_test_flags.R +++ b/R/create_hb_test_flags.R @@ -11,67 +11,19 @@ create_hb_test_flags <- function(data, hb_var) { data <- data %>% dplyr::mutate( - NHS_Ayrshire_and_Arran = dplyr::if_else( - {{ hb_var }} == "S08000015", - 1L, - 0L - ), - NHS_Borders = dplyr::if_else({{ hb_var }} == "S08000016", 1L, 0L), - NHS_Dumfries_and_Galloway = dplyr::if_else( - {{ hb_var }} == "S08000017", - 1L, - 0L - ), - NHS_Forth_Valley = dplyr::if_else({{ hb_var }} == "S08000019", 1L, 0L), - NHS_Grampian = dplyr::if_else( - {{ hb_var }} == "S08000020", - 1L, - 0L - ), - NHS_Highland = dplyr::if_else( - {{ hb_var }} == "S08000022", - 1L, - 0L - ), - NHS_Lothian = dplyr::if_else( - {{ hb_var }} == "S08000024", - 1L, - 0L - ), - NHS_Orkney = dplyr::if_else( - {{ hb_var }} == "S08000025", - 1L, - 0L - ), - NHS_Shetland = dplyr::if_else( - {{ hb_var }} == "S08000026", - 1L, - 0L - ), - NHS_Western_Isles = dplyr::if_else( - {{ hb_var }} == "S08000028", - 1L, - 0L - ), - NHS_Fife = dplyr::if_else( - {{ hb_var }} == "S08000029", - 1L, - 0L - ), - NHS_Tayside = dplyr::if_else( - {{ hb_var }} == "S08000030", - 1L, - 0L - ), - NHS_Greater_Glasgow_and_Clyde = dplyr::if_else( - {{ hb_var }} %in% c("S08000031", "S08000021"), - 1L, - 0L - ), - NHS_Lanarkshire = dplyr::if_else( - {{ hb_var }} %in% c("S08000032", "S08000023"), - 1L, - 0L - ) + NHS_Ayrshire_and_Arran = {{ hb_var }} == "S08000015", + NHS_Borders = {{ hb_var }} == "S08000016", + NHS_Dumfries_and_Galloway = {{ hb_var }} == "S08000017", + NHS_Forth_Valley = {{ hb_var }} == "S08000019", + NHS_Grampian = {{ hb_var }} == "S08000020", + NHS_Highland = {{ hb_var }} == "S08000022", + NHS_Lothian = {{ hb_var }} == "S08000024", + NHS_Orkney = {{ hb_var }} == "S08000025", + NHS_Shetland = {{ hb_var }} == "S08000026", + NHS_Western_Isles = {{ hb_var }} == "S08000028", + NHS_Fife = {{ hb_var }} == "S08000029", + NHS_Tayside = {{ hb_var }} == "S08000030", + NHS_Greater_Glasgow_and_Clyde = {{ hb_var }} %in% c("S08000031", "S08000021"), + NHS_Lanarkshire = {{ hb_var }} %in% c("S08000032", "S08000023") ) } diff --git a/R/create_hscp_test_flags.R b/R/create_hscp_test_flags.R index b7dd0a02e..55e67b67c 100644 --- a/R/create_hscp_test_flags.R +++ b/R/create_hscp_test_flags.R @@ -5,166 +5,42 @@ #' @param data the data containing a HSCP variable #' @param hscp_var HSCP variable e.g. HSCP2019 HSCP2018 #' -#' @return a dataframe with flag (1 or 0) for each HSCP +#' @return a dataframe with flag (TRUE or FALSE) for each HSCP #' #' @family flag functions create_hscp_test_flags <- function(data, hscp_var) { data <- data %>% dplyr::mutate( - Aberdeen_City = dplyr::if_else( - {{ hscp_var }} == "S37000001", - 1L, - 0L - ), - Aberdeenshire = dplyr::if_else( - {{ hscp_var }} == "S37000002", - 1L, - 0L - ), - Angus = dplyr::if_else( - {{ hscp_var }} == "S37000003", - 1L, - 0L - ), - Argyll_and_Bute = dplyr::if_else( - {{ hscp_var }} == "S37000004", - 1L, - 0L - ), - Clackmannanshire_and_Stirling = dplyr::if_else( - {{ hscp_var }} == "S37000005", - 1L, - 0L - ), - Dumfries_and_Galloway = dplyr::if_else( - {{ hscp_var }} == "S37000006", - 1L, - 0L - ), - Dundee_City = dplyr::if_else( - {{ hscp_var }} == "S37000007", - 1L, - 0L - ), - East_Ayrshire = dplyr::if_else( - {{ hscp_var }} == "S37000008", - 1L, - 0L - ), - East_Dunbartonshire = dplyr::if_else( - {{ hscp_var }} == "S37000009", - 1L, - 0L - ), - East_Lothian = dplyr::if_else( - {{ hscp_var }} == "S37000010", - 1L, - 0L - ), - East_Renfrewshire = dplyr::if_else( - {{ hscp_var }} == "S37000011", - 1L, - 0L - ), - Edinburgh = dplyr::if_else( - {{ hscp_var }} == "S37000012", - 1L, - 0L - ), - Falkirk = dplyr::if_else( - {{ hscp_var }} == "S37000013", - 1L, - 0L - ), - Highland = dplyr::if_else( - {{ hscp_var }} == "S37000016", - 1L, - 0L - ), - Inverclyde = dplyr::if_else( - {{ hscp_var }} == "S37000017", - 1L, - 0L - ), - Midlothian = dplyr::if_else( - {{ hscp_var }} == "S37000018", - 1L, - 0L - ), - Moray = dplyr::if_else( - {{ hscp_var }} == "S37000019", - 1L, - 0L - ), - North_Ayrshire = dplyr::if_else( - {{ hscp_var }} == "S37000020", - 1L, - 0L - ), - Orkney_Islands = dplyr::if_else( - {{ hscp_var }} == "S37000022", - 1L, - 0L - ), - Renfrewshire = dplyr::if_else( - {{ hscp_var }} == "S37000024", - 1L, - 0L - ), - Scottish_Borders = dplyr::if_else( - {{ hscp_var }} == "S37000025", - 1L, - 0L - ), - Shetland_Islands = dplyr::if_else( - {{ hscp_var }} == "S37000026", - 1L, - 0L - ), - South_Ayrshire = dplyr::if_else( - {{ hscp_var }} == "S37000027", - 1L, - 0L - ), - South_Lanarkshire = dplyr::if_else( - {{ hscp_var }} == "S37000028", - 1L, - 0L - ), - West_Dunbartonshire = dplyr::if_else( - {{ hscp_var }} == "S37000029", - 1L, - 0L - ), - West_Lothian = dplyr::if_else( - {{ hscp_var }} == "S37000030", - 1L, - 0L - ), - Western_Isles = dplyr::if_else( - {{ hscp_var }} == "S37000031", - 1L, - 0L - ), - Fife = dplyr::if_else( - {{ hscp_var }} == "S37000032", - 1L, - 0L - ), - Perth_and_Kinross = dplyr::if_else( - {{ hscp_var }} == "S37000033", - 1L, - 0L - ), - Glasgow_City = dplyr::if_else( - {{ hscp_var }} %in% c("S37000015", "S37000034"), - 1L, - 0L - ), - North_Lanarkshire = dplyr::if_else( - {{ hscp_var }} %in% c("S37000021", "S37000035"), - 1L, - 0L - ) + Aberdeen_City = {{ hscp_var }} == "S37000001", + Aberdeenshire = {{ hscp_var }} == "S37000002", + Angus = {{ hscp_var }} == "S37000003", + Argyll_and_Bute = {{ hscp_var }} == "S37000004", + Clackmannanshire_and_Stirling = {{ hscp_var }} == "S37000005", + Dumfries_and_Galloway = {{ hscp_var }} == "S37000006", + Dundee_City = {{ hscp_var }} == "S37000007", + East_Ayrshire = {{ hscp_var }} == "S37000008", + East_Dunbartonshire = {{ hscp_var }} == "S37000009", + East_Lothian = {{ hscp_var }} == "S37000010", + East_Renfrewshire = {{ hscp_var }} == "S37000011", + Edinburgh = {{ hscp_var }} == "S37000012", + Falkirk = {{ hscp_var }} == "S37000013", + Highland = {{ hscp_var }} == "S37000016", + Inverclyde = {{ hscp_var }} == "S37000017", + Midlothian = {{ hscp_var }} == "S37000018", + Moray = {{ hscp_var }} == "S37000019", + North_Ayrshire = {{ hscp_var }} == "S37000020", + Orkney_Islands = {{ hscp_var }} == "S37000022", + Renfrewshire = {{ hscp_var }} == "S37000024", + Scottish_Borders = {{ hscp_var }} == "S37000025", + Shetland_Islands = {{ hscp_var }} == "S37000026", + South_Ayrshire = {{ hscp_var }} == "S37000027", + South_Lanarkshire = {{ hscp_var }} == "S37000028", + West_Dunbartonshire = {{ hscp_var }} == "S37000029", + West_Lothian = {{ hscp_var }} == "S37000030", + Western_Isles = {{ hscp_var }} == "S37000031", + Fife = {{ hscp_var }} == "S37000032", + Perth_and_Kinross = {{ hscp_var }} == "S37000033", + Glasgow_City = {{ hscp_var }} %in% c("S37000015", "S37000034"), + North_Lanarkshire = {{ hscp_var }} %in% c("S37000021", "S37000035"), ) } diff --git a/R/process_tests_episode_file.R b/R/process_tests_episode_file.R index d77cd9372..827009fc1 100644 --- a/R/process_tests_episode_file.R +++ b/R/process_tests_episode_file.R @@ -75,6 +75,7 @@ produce_episode_file_tests <- function( create_demog_test_flags() %>% create_hb_test_flags(.data$hbtreatcode) %>% create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net) %>% + create_hscp_test_flags(.data$hscp2018) %>% # Flags to count stay types dplyr::mutate( cij_elective = dplyr::if_else( diff --git a/R/process_tests_individual_file.R b/R/process_tests_individual_file.R index bdbe8aaa2..2c93f243e 100644 --- a/R/process_tests_individual_file.R +++ b/R/process_tests_individual_file.R @@ -64,6 +64,7 @@ produce_individual_file_tests <- function(data) { create_demog_test_flags() %>% create_hb_test_flags(.data$hbrescode) %>% create_hb_cost_test_flags(.data$hbrescode, .data$health_net_cost) %>% + create_hscp_test_flags(.data$hscp2018) %>% # keep variables for comparison dplyr::select("valid_chi":dplyr::last_col()) %>% # use function to sum new test flags diff --git a/R/produce_source_extract_tests.R b/R/produce_source_extract_tests.R index 33e2da734..10f842fc6 100644 --- a/R/produce_source_extract_tests.R +++ b/R/produce_source_extract_tests.R @@ -34,6 +34,7 @@ produce_source_extract_tests <- function(data, create_demog_test_flags() %>% create_hb_test_flags(.data$hbtreatcode) %>% create_hb_cost_test_flags(.data$hbtreatcode, .data$cost_total_net) %>% + create_hscp_test_flags(.data$hscp) %>% # keep variables for comparison dplyr::select("valid_chi":dplyr::last_col()) %>% # use function to sum new test flags diff --git a/man/create_hscp_test_flags.Rd b/man/create_hscp_test_flags.Rd index d9cc25a72..9f881e8fc 100644 --- a/man/create_hscp_test_flags.Rd +++ b/man/create_hscp_test_flags.Rd @@ -12,7 +12,7 @@ create_hscp_test_flags(data, hscp_var) \item{hscp_var}{HSCP variable e.g. HSCP2019 HSCP2018} } \value{ -a dataframe with flag (1 or 0) for each HSCP +a dataframe with flag (TRUE or FALSE) for each HSCP } \description{ Create flags for Health & Social Care Partnerships