Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify create_hscp_test_flags #772

Merged
merged 9 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 14 additions & 62 deletions R/create_hb_test_flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
}
188 changes: 32 additions & 156 deletions R/create_hscp_test_flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
}
3 changes: 2 additions & 1 deletion R/create_individual_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion R/process_lookup_gpprac.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions R/read_lookup_sc_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions R/read_lookup_sc_demographics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions R/read_sc_all_alarms_telecare.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/create_hscp_test_flags.Rd

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

Loading