From 9e5c6bed1cde8646be46b1e99ca9ad2ca05d74b2 Mon Sep 17 00:00:00 2001 From: There717 Date: Thu, 27 Jun 2024 10:12:55 +0100 Subject: [PATCH 01/38] Lines 60-63 and 80-87, dynamic text for emergency admissions and uscheduled bed days. Lines 43 and 45, updated names for dynamic text objects. --- .../Unscheduled-Care-Testing-Markdown.Rmd | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index b3a4bc5..144134a 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -23,9 +23,9 @@ options(kableExtra.auto_format = FALSE) LOCALITY <- "Inverness" #LOCALITY <- "East Dunbartonshire West" -source("~/localities/Master RMarkdown Document & Render Code/Global Script.R") +source("~/list-localities-profiles/Master RMarkdown Document & Render Code/Global Script.R") -source("~/localities/Unscheduled Care/2. Unscheduled Care outputs.R") +source("~/list-localities-profiles/Unscheduled Care/2. Unscheduled Care outputs.R") x <- 1 # object for figure numbers y <- 1 # object for table numbers @@ -40,9 +40,9 @@ This section includes acute hospital data, delayed discharge bed days and A&E at **For the most recent time periods available, `r LOCALITY` had:** - - **`r latest_emergency_adm_loc`** emergency hospital admissions per 100,000 population, compared to `r scot_emergency_adm` in Scotland. + - **`r latest_emergency_adm_loc1`** emergency hospital admissions per 100,000 population, compared to `r scot_emergency_adm1` in Scotland. - - **`r latest_bed_days_loc`** unscheduled acute specialty bed days per 100,000 population, compared to `r scot_bed_days` in Scotland. + - **`r latest_bed_days_loc1`** unscheduled acute specialty bed days per 100,000 population, compared to `r scot_bed_days1` in Scotland. - **`r latest_ae_att_loc`** A&E attendances per 100,000 population, compared to `r scot_ae_att` in Scotland. @@ -59,6 +59,8 @@ This section includes acute hospital data, delayed discharge bed days and A&E at ### Emergency Admissions +Figure `r x` presents the emergency admissions rate per 100,000 population in `r LOCALITY` from `r min_year_ea` to `r max_year_ea`. As presented Figure `r x`, the emergency admissions rate in `r LOCALITY` for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The HSCP rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. + ####Figure `r x`: Emergency admissions by geographical area \newline @@ -81,6 +83,8 @@ x <- x + 1 ### Unscheduled Acute Bed Days +Figure `r x` presents the emergency admissions rate per 100,000 population in `r LOCALITY` from `r min_year_ubd` to `r max_year_ubd`. As presented in Figure `r x`, the emergency admissions rate in `r LOCALITY` for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd`. The HSCP rate is `r hscp_bed_days1` in `r max_year_ubd`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. + ####Figure `r x`: Unscheduled acute bed days by geographical area \newline From ffbd58d97ebab24625d6bfe09958ee55a5d9bfbb Mon Sep 17 00:00:00 2001 From: There717 Date: Thu, 27 Jun 2024 10:14:30 +0100 Subject: [PATCH 02/38] Lines 326-327, filter out year with no data. Lines 336-398, add dynamic text objects for emergency admissions. Line 60-63, filter out year with no data. Lines 453-505, add dynamic text objects for unscheduled care beddays. --- .../2. Unscheduled Care outputs.R | 132 +++++++++++++----- 1 file changed, 100 insertions(+), 32 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 67aaf48..6203a00 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -10,7 +10,7 @@ ext_year <- 2023 # Set locality profiles file path -# lp_path <- "/conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/" +lp_path <- "/conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/" import_folder <- paste0(lp_path, "Unscheduled Care/DATA ", ext_year, "/") ## Packages @@ -29,11 +29,11 @@ library(fst) ### for testing run global script and locality placeholder below ## Functions -# source("./Master RMarkdown Document & Render Code/Global Script.R") +source("~/list-localities-profiles/Master RMarkdown Document & Render Code/Global Script.R") ## Define locality # LOCALITY <- "Stirling City with the Eastern Villages Bridge of Allan and Dunblane" -# LOCALITY <- "Inverness" + LOCALITY <- "Inverness" # LOCALITY <- "Ayr North and Former Coalfield Communities" # LOCALITY <- "Whalsay and Skerries" # LOCALITY <- "North Perthshire" @@ -323,7 +323,8 @@ emergency_adm_areas <- emergency_adm %>% rename(n = admissions) %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(n / pop * 100000)) + mutate(data = round_half_up(n / pop * 100000)) %>% + filter(!is.na(year)) EAs_loc_ts <- area_trend_usc( data_for_plot = emergency_adm_areas, @@ -333,30 +334,68 @@ EAs_loc_ts <- area_trend_usc( ) -# Objects for text and summary table +#Objects for text for Figures and Summary (Emergency Admissions) +min_year_ea <- min(emergency_adm_areas$financial_year) +max_year_ea <- max(emergency_adm_areas$financial_year) + +first_fy_rate <- filter( + emergency_adm_areas, + (financial_year == min(emergency_adm_areas$financial_year)) & + (location == LOCALITY & area_type == "Locality") +)$data + latest_emergency_adm_loc <- emergency_adm_areas %>% filter( location == LOCALITY, - year == max(year) + year == max(year, na.rm = TRUE) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +latest_emergency_adm_loc1 <- latest_emergency_adm_loc %>% pull(data2) +latest_emergency_adm_loc2 <- latest_emergency_adm_loc %>% pull(data) + +percent_rate_change <- round(abs(latest_emergency_adm_loc2 - first_fy_rate) / first_fy_rate * 100, digits = 1) +word_change_rate <- if_else(latest_emergency_adm_loc2 > first_fy_rate, + "increase", "decrease") +#HSCP hscp_emergency_adm <- emergency_adm_areas %>% filter( location == HSCP, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) #%>% + # pull(data) + +hscp_emergency_adm1 <- hscp_emergency_adm %>% pull(data2) +hscp_emergency_adm2 <- hscp_emergency_adm %>% pull(data) +first_fy_hscp <- filter(emergency_adm_areas, + (financial_year == min(emergency_adm_areas$financial_year)) & + (area_type == "HSCP"))$data + +hscp_rate_change <- round(abs(hscp_emergency_adm2 - first_fy_hscp) / first_fy_hscp * 100, digits = 1) +word_change_hscp <- if_else(hscp_emergency_adm2 > first_fy_hscp, "increase", "decrease") + +#Scotland scot_emergency_adm <- emergency_adm_areas %>% filter( location == "Scotland", year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) + +scot_emergency_adm1 <- scot_emergency_adm %>% pull(data2) +scot_emergency_adm2 <- scot_emergency_adm %>% pull(data) +first_fy_scot <- filter(emergency_adm_areas, + (financial_year == min(emergency_adm_areas$financial_year)) & + (location == "Scotland"))$data + +scot_rate_change <- round(abs(scot_emergency_adm2 - first_fy_scot) / first_fy_scot * 100, digits = 1) +word_change_scot <- if_else(scot_emergency_adm2 > first_fy_scot, + "increase", "decrease") + other_loc_emergency_adm <- emergency_adm %>% group_by(financial_year, hscp_locality) %>% @@ -401,7 +440,8 @@ bed_days_areas <- bed_days %>% rename(n = bed_days) %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(n / pop * 100000)) + mutate(data = round_half_up(n / pop * 100000)) %>% + filter(!is.na(year)) BDs_loc_ts <- area_trend_usc( data_for_plot = bed_days_areas, @@ -410,31 +450,59 @@ BDs_loc_ts <- area_trend_usc( source = "Source: PHS SMR01" ) +#Objects for text for Figures and Summary (Unscheduled Bed Days) +min_year_ubd <- min(bed_days_areas$financial_year) +max_year_ubd <- max(bed_days_areas$financial_year) + +#LOCALITY +first_fy_rate_ubd <- filter( + bed_days_areas, + (financial_year == min(bed_days_areas$financial_year)) & + (location == LOCALITY & area_type == "Locality"))$data -# Objects for text and summary table latest_bed_days_loc <- bed_days_areas %>% - filter( - location == LOCALITY, - year == max(year) - ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + filter(location == LOCALITY, year == max(year)) %>% + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +latest_bed_days_loc1 <- latest_bed_days_loc %>% pull(data2) +latest_bed_days_loc2 <- latest_bed_days_loc %>% pull(data) + +rate_change_ubd <- round(abs(latest_bed_days_loc2 - first_fy_rate_ubd) / first_fy_rate_ubd * 100, digits = 1) +word_change_ubd <- if_else(latest_bed_days_loc2 > first_fy_rate_ubd, + "increase", "decrease") +#HSCP +first_fy_hscp_ubd <- filter( + bed_days_areas, (financial_year == min(bed_days_areas$financial_year)) & (area_type == "HSCP"))$data hscp_bed_days <- bed_days_areas %>% - filter( - location == HSCP, - year == max(year) - ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + filter(location == HSCP, year == max(year)) %>% + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +hscp_bed_days1 <- hscp_bed_days %>% pull(data2) +hscp_bed_days2 <- hscp_bed_days %>% pull(data) + +hscp_rate_ubd <- round(abs(hscp_bed_days2 - first_fy_hscp_ubd) / first_fy_hscp_ubd * 100, digits = 1) +hscp_change_ubd <- if_else(hscp_bed_days2 > first_fy_hscp_ubd, + "increase", "decrease") + +#Scotland +first_fy_scot_ubd <- filter( + bed_days_areas, (financial_year == min(bed_days_areas$financial_year)) & (area_type == "Scotland"))$data scot_bed_days <- bed_days_areas %>% - filter( - location == "Scotland", - year == max(year) - ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + filter(location == "Scotland", year == max(year)) %>% + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +scot_bed_days1 <- scot_bed_days %>% pull(data2) +scot_bed_days2 <- scot_bed_days %>% pull(data) + +scot_rate_ubd <- round(abs(scot_bed_days2 - first_fy_scot_ubd) / first_fy_scot_ubd * 100, digits = 1) +scot_change_ubd <- if_else(scot_bed_days2 > first_fy_scot_ubd, + "increase", "decrease") + other_loc_bed_days <- bed_days %>% group_by(financial_year, hscp_locality) %>% From fdb2ae27655ebe560217672f1e1dcdcbdbefd014 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Thu, 27 Jun 2024 16:26:29 +0100 Subject: [PATCH 03/38] AE dynamic text --- .../2. Unscheduled Care outputs.R | 64 ++++++++++++++++--- .../Unscheduled-Care-Testing-Markdown.Rmd | 6 +- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 6203a00..7d2c6cd 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -611,7 +611,9 @@ ae_att_age <- ae_attendances %>% summarise(attendances = sum(attendances)) %>% ungroup() %>% left_join(loc_pop_age1) %>% - mutate(data = round_half_up(attendances / pop * 100000)) + mutate(data = round_half_up(attendances / pop * 100000))%>% + filter(!is.na(year)) + AandE_age_ts <- age_group_trend_usc( data_for_plot = ae_att_age, @@ -626,7 +628,9 @@ ae_att_areas <- ae_attendances %>% rename(n = attendances) %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(n / pop * 100000)) + mutate(data = round_half_up(n / pop * 100000))%>% + filter(!is.na(year)) + AandE_loc_ts <- area_trend_usc( data_for_plot = ae_att_areas, @@ -637,29 +641,73 @@ AandE_loc_ts <- area_trend_usc( # Objects for text and summary table + +min_year_ae_area <- min(ae_att_areas$financial_year) +max_year_ae_area <- max(ae_att_areas$financial_year) + +min_year_ae_age <- min(ae_att_age$financial_year) +max_year_ae_age <- max(ae_att_age$financial_year) + +first_fy_rate_ae_areas <- filter( + ae_att_areas, + (financial_year == min(ae_att_areas$financial_year)) & + (location == LOCALITY & area_type == "Locality") +)$data + latest_ae_att_loc <- ae_att_areas %>% filter( location == LOCALITY, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +latest_ae_att_loc1 <- latest_ae_att_loc %>% pull(data2) +latest_ae_att_loc2 <- latest_ae_att_loc %>% pull(data) + +percent_rate_change_ae_areas <- round(abs(latest_ae_att_loc2 - first_fy_rate_ae_areas) / first_fy_rate_ae_areas * 100, digits = 1) +word_change_rate_ae_areas <- if_else(latest_ae_att_loc2 > first_fy_rate_ae_areas, + "increase", "decrease") hscp_ae_att <- ae_att_areas %>% filter( location == HSCP, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +hscp_ae_att1 <- hscp_ae_att %>% pull(data2) +hscp_ae_att2 <- hscp_ae_att %>% pull(data) + +first_fy_hscp_ae <- filter(ae_att_areas, + (financial_year == min(ae_att_areas$financial_year)) & + (area_type == "HSCP"))$data + +percent_rate_change_ae_areas_hscp <- round(abs(hscp_ae_att2 - first_fy_hscp_ae) / first_fy_hscp_ae * 100, digits = 1) +word_change_rate_ae_areas_hscp <- if_else(hscp_ae_att2 > first_fy_hscp_ae, + "increase", "decrease") scot_ae_att <- ae_att_areas %>% filter( location == "Scotland", year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +scot_ae_att1 <- scot_ae_att %>% pull(data2) +scot_ae_att2 <- scot_ae_att %>% pull(data) + +first_fy_scot_ae <- filter(ae_att_areas, + (financial_year == min(ae_att_areas$financial_year)) & + (location == "Scotland"))$data + +percent_rate_change_ae_areas_scot <- round(abs(scot_ae_att2 - first_fy_scot_ae) / first_fy_scot_ae * 100, digits = 1) +word_change_rate_ae_areas_scot <- if_else(scot_ae_att2 > first_fy_scot_ae, + "increase", "decrease") + + other_loc_ae_att <- ae_attendances %>% group_by(financial_year, hscp_locality) %>% diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 144134a..bfe71f7 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -59,7 +59,7 @@ This section includes acute hospital data, delayed discharge bed days and A&E at ### Emergency Admissions -Figure `r x` presents the emergency admissions rate per 100,000 population in `r LOCALITY` from `r min_year_ea` to `r max_year_ea`. As presented Figure `r x`, the emergency admissions rate in `r LOCALITY` for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The HSCP rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. ####Figure `r x`: Emergency admissions by geographical area \newline @@ -83,7 +83,7 @@ x <- x + 1 ### Unscheduled Acute Bed Days -Figure `r x` presents the emergency admissions rate per 100,000 population in `r LOCALITY` from `r min_year_ubd` to `r max_year_ubd`. As presented in Figure `r x`, the emergency admissions rate in `r LOCALITY` for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd`. The HSCP rate is `r hscp_bed_days1` in `r max_year_ubd`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. As presented in Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd`. The `r HSCP` HSCP rate is `r hscp_bed_days1` in `r max_year_ubd`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. ####Figure `r x`: Unscheduled acute bed days by geographical area \newline @@ -108,6 +108,8 @@ x <- x + 1 ### A&E Attendances +Figure `r x` presents the A&E attendance rates per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by geographical area. As presented in Figure `r x`, the A&E attendance rates per 100,000 in `r LOCALITY` for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area`. The `r HSCP` HSCP rate is `r hscp_ae_att1` in `r max_year_ae_area`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. + ####Figure `r x`: A&E attendances by geographical area \newline From 46eeead795ccb4fd3554c3bebb520fee3ea5dd2f Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Tue, 2 Jul 2024 17:24:44 +0100 Subject: [PATCH 04/38] Addition of free text --- .../2. Unscheduled Care outputs.R | 129 +++++++++++++++++- .../Unscheduled-Care-Testing-Markdown.Rmd | 7 +- 2 files changed, 128 insertions(+), 8 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 7d2c6cd..b5645fc 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -639,15 +639,72 @@ AandE_loc_ts <- area_trend_usc( source = "Source: PHS A&E Datamart" ) +# Objects for text and summary table- age -# Objects for text and summary table +min_year_ae_age <- min(ae_att_age$financial_year) +max_year_ae_age <- max(ae_att_age$financial_year) + + +latest_ae_att_max_age <- ae_att_age %>% + filter( + year == max(year), + data== max(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) #%>% +#pull(data) + +latest_ae_att_loc1_age <- latest_ae_att_max_age %>% pull(data2) +latest_ae_att_loc2_age <- latest_ae_att_max_age %>% pull(data) +age_group_max <- latest_ae_att_max_age %>% pull(age_group) + +first_ae_att_max_age <- ae_att_age %>% + filter( + year == min(year), + age_group == age_group_max + ) %>% + mutate(data2 = format(data, big.mark = ",")) #%>% +#pull(data) + +first_ae_att_max_age_data <- first_ae_att_max_age %>% pull(data) + +percent_rate_change_ae_age <- round(abs(latest_ae_att_loc2_age - first_ae_att_max_age_data) / first_ae_att_max_age_data * 100, digits = 1) +word_change_rate_ae_age <- if_else(latest_ae_att_loc2_age > first_ae_att_max_age_data, + "increase", "decrease") + +latest_ae_att_min_age <- ae_att_age %>% + filter( + year == max(year)) %>% + filter( + data == min(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) #%>% +#pull(data) + +latest_ae_att_loc1_age_min <- latest_ae_att_min_age %>% pull(data2) +latest_ae_att_loc2_age_min <- latest_ae_att_min_age %>% pull(data) +age_group_min <- latest_ae_att_min_age %>% pull(age_group) + +first_ae_att_min_age <- ae_att_age %>% + filter( + year == min(year), + age_group == age_group_min + ) %>% + mutate(data2 = format(data, big.mark = ",")) #%>% +#pull(data) + +first_ae_att_min_data <- first_ae_att_min_age %>% pull(data) + +percent_rate_change_ae_age2 <- round(abs(latest_ae_att_loc2_age_min - first_ae_att_min_data) / first_ae_att_min_data * 100, digits = 1) +word_change_rate_ae_age2 <- if_else(latest_ae_att_loc2_age_min > first_ae_att_min_data, + "increase", "decrease") + + + +# Objects for text and summary table- area min_year_ae_area <- min(ae_att_areas$financial_year) max_year_ae_area <- max(ae_att_areas$financial_year) -min_year_ae_age <- min(ae_att_age$financial_year) -max_year_ae_age <- max(ae_att_age$financial_year) - first_fy_rate_ae_areas <- filter( ae_att_areas, (financial_year == min(ae_att_areas$financial_year)) & @@ -841,6 +898,7 @@ readmissions <- arrow::read_parquet(paste0(import_folder, "readmissions_smr.parq filter(financial_year <= max_fy) # Plotting by age + readmissions_age <- readmissions %>% filter(hscp_locality == LOCALITY) %>% drop_na(age_group) %>% @@ -850,7 +908,7 @@ readmissions_age <- readmissions %>% discharges = sum(discharges) ) %>% ungroup() %>% - mutate(data = round_half_up(read_28 / discharges * 1000, 1)) + mutate(data = round_half_up(read_28 / discharges * 1000, 1)) Read_age_ts <- age_group_trend_usc( data_for_plot = readmissions_age, @@ -878,7 +936,8 @@ read2 <- readmissions %>% readmissions_areas <- left_join(read1, read2) %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(read_28 / discharges * 1000, 1)) + mutate(data = round_half_up(read_28 / discharges * 1000, 1))%>% + filter(!is.na(year)) rm(read1, read2) @@ -889,14 +948,67 @@ Read_loc_ts <- area_trend_usc( source = "Source: PHS SMR01" ) -# Objects for text and summary table +# Objects for text and summary table-age +min_year_re_age <- min(readmissions_age$financial_year) +max_year_re_age <- max(readmissions_age$financial_year) + +latest_re_max_age <- readmissions_age %>% + filter( + financial_year == max(financial_year), + data== max(data) + )%>% +pull(data) + + + +# Objects for text and summary table-area +min_year_re_area <- min(readmissions_areas$financial_year) +max_year_re_area <- max(readmissions_areas$financial_year) + +first_read_loc <- readmissions_areas %>% + filter( + location == LOCALITY, + year == min(year)) + +first_read_loc1 <-first_read_loc %>% pull(data) + latest_read_loc <- readmissions_areas %>% filter( location == LOCALITY, + year == max(year)) + +latest_read_loc1 <-latest_read_loc %>% pull(data) + +percent_rate_change_re_area <- round(abs(latest_read_loc1 - first_read_loc1) / first_read_loc1 * 100, digits = 1) +word_change_rate_re_area <- if_else(latest_read_loc1 > first_read_loc1, + "increase", "decrease") + +first_hscp_read <- readmissions_areas %>% + filter( + location == HSCP, + year == min(year) + ) %>% + pull(data) + +hscp_read <- readmissions_areas %>% + filter( + location == HSCP, year == max(year) ) %>% pull(data) +percent_rate_change_re_area_hscp <- round(abs(hscp_read - first_hscp_read) / first_hscp_read * 100, digits = 1) +word_change_rate_re_area_hscp <- if_else(hscp_read > first_hscp_read, + "increase", "decrease") + +first_scot_read <- readmissions_areas %>% + filter( + location == "Scotland", + year == min(year) + ) %>% + pull(data) + + scot_read <- readmissions_areas %>% filter( location == "Scotland", @@ -904,6 +1016,9 @@ scot_read <- readmissions_areas %>% ) %>% pull(data) +percent_rate_change_re_area_scot <- round(abs(scot_read - first_scot_read) / first_scot_read * 100, digits = 1) +word_change_rate_re_area_scot <- if_else(scot_read > first_scot_read, + "increase", "decrease") # 7. Comm 6 months ---- # _________________________________________________________________________________ diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index bfe71f7..36ec058 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -119,6 +119,8 @@ AandE_loc_ts x <- x + 1 ``` +Figure `r x` presents the A&E attendance rates per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the greatest A&E attendance rates per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age` for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The smallest A&E attendance per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. + ####Figure `r x`: A&E attendances by age group \newline @@ -129,10 +131,13 @@ x <- x + 1 ``` + ##### Page break ### Emergency Readmissions (28 days) +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area` by geographical area. As presented in Figure `r x`, the emergency readmission rate per 1,000 discharges in `r LOCALITY` for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area`. The `r HSCP` HSCP rate is `r hscp_read` in `r max_year_re_area`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. + ####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline @@ -141,7 +146,7 @@ Read_loc_ts x <- x + 1 ``` - +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. ####Figure `r x`: Emergency readmissions (28 days) by age group \newline From 5c8847e4fc56a8347908ebed87815edc0baf1784 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 3 Jul 2024 10:27:41 +0100 Subject: [PATCH 05/38] Dynamic text for readmissions --- .../2. Unscheduled Care outputs.R | 37 ++++++++++++++++++- .../Unscheduled-Care-Testing-Markdown.Rmd | 10 +++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index b5645fc..0c33c37 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -956,9 +956,42 @@ latest_re_max_age <- readmissions_age %>% filter( financial_year == max(financial_year), data== max(data) - )%>% -pull(data) + )#%>% +#pull(data) + +latest_re_max_age_data <- latest_re_max_age %>% pull(data) +latest_re_max_age_group <- latest_re_max_age %>% pull(age_group) + +first_re_max_age <- readmissions_age %>% + filter( + financial_year == min(financial_year), + age_group == latest_re_max_age_group + ) %>% + pull(data) + + +percent_rate_change_re_age <- round(abs(latest_re_max_age_data - first_re_max_age) / first_re_max_age * 100, digits = 1) +word_change_rate_re_age <- if_else(latest_re_max_age_data > first_re_max_age, + "increase", "decrease") +latest_re_min_age <- readmissions_age %>% + filter( + financial_year == max(financial_year)) %>% + filter(data== min(data)) + +latest_re_min_age_data <- latest_re_min_age %>% pull(data) +latest_re_min_age_group <- latest_re_min_age %>% pull(age_group) + +first_re_min_age <- readmissions_age %>% + filter( + financial_year == min(financial_year), + age_group == latest_re_min_age_group + ) %>% + pull(data) + +percent_rate_change_re_age_min <- round(abs(latest_re_min_age_data - first_re_min_age) / first_re_min_age * 100, digits = 1) +word_change_rate_re_age_min <- if_else(latest_re_min_age_data > first_re_min_age, + "increase", "decrease") # Objects for text and summary table-area diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 36ec058..4a71aff 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -108,7 +108,7 @@ x <- x + 1 ### A&E Attendances -Figure `r x` presents the A&E attendance rates per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by geographical area. As presented in Figure `r x`, the A&E attendance rates per 100,000 in `r LOCALITY` for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area`. The `r HSCP` HSCP rate is `r hscp_ae_att1` in `r max_year_ae_area`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by geographical area. As presented in Figure `r x`, the A&E attendance rate per 100,000 in `r LOCALITY` for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area`. The `r HSCP` HSCP rate is `r hscp_ae_att1` in `r max_year_ae_area`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. ####Figure `r x`: A&E attendances by geographical area \newline @@ -119,7 +119,7 @@ AandE_loc_ts x <- x + 1 ``` -Figure `r x` presents the A&E attendance rates per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the greatest A&E attendance rates per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age` for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The smallest A&E attendance per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the greatest A&E attendance rate per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age` for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The smallest A&E attendance rate per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. ####Figure `r x`: A&E attendances by age group \newline @@ -136,7 +136,8 @@ x <- x + 1 ### Emergency Readmissions (28 days) -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area` by geographical area. As presented in Figure `r x`, the emergency readmission rate per 1,000 discharges in `r LOCALITY` for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area`. The `r HSCP` HSCP rate is `r hscp_read` in `r max_year_re_area`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. + +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area` by geographical area. As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in `r LOCALITY` for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area`. The `r HSCP` HSCP rate is `r hscp_read` in `r max_year_re_area`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. ####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline @@ -146,7 +147,8 @@ Read_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the greatest emergency readmission (28 days) rate per 1,000 discharges for `r LOCALITY` in `r max_year_re_age` is `r latest_re_max_age_data` for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The emergency readmission (28 days) rate per 1,000 discharges for `r LOCALITY` in `r max_year_re_age` is `r latest_re_min_age_data` for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. + ####Figure `r x`: Emergency readmissions (28 days) by age group \newline From 23bdce37cf6bd78c950e1b1551ad55fd7143572a Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 3 Jul 2024 16:20:17 +0100 Subject: [PATCH 06/38] Dynamic text edits --- .../2. Unscheduled Care outputs.R | 110 ++++++++++++++++-- .../Unscheduled-Care-Testing-Markdown.Rmd | 12 +- 2 files changed, 110 insertions(+), 12 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 0c33c37..863b516 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -611,7 +611,7 @@ ae_att_age <- ae_attendances %>% summarise(attendances = sum(attendances)) %>% ungroup() %>% left_join(loc_pop_age1) %>% - mutate(data = round_half_up(attendances / pop * 100000))%>% + mutate(data = round_half_up(attendances / pop * 100000)) %>% filter(!is.na(year)) @@ -797,7 +797,8 @@ delayed_disch_areas <- delayed_disch %>% rename(n = dd_bed_days) %>% aggregate_usc_area_data() %>% left_join(pop_areas_65plus) %>% - mutate(data = round_half_up(n / pop * 100000)) + mutate(data = round_half_up(n / pop * 100000)) %>% + filter(!is.na(year)) DD_loc_ts <- area_trend_usc( data_for_plot = delayed_disch_areas, @@ -811,30 +812,75 @@ DD_loc_ts <- area_trend_usc( # Objects for text and summary table +min_year_dd <- min(delayed_disch_areas$financial_year) +max_year_dd <- max(delayed_disch_areas$financial_year) + latest_dd_loc <- delayed_disch_areas %>% filter( location == LOCALITY, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_dd_loc1 <- latest_dd_loc %>% pull(data2) +latest_dd_loc2 <- latest_dd_loc %>% pull(data) + +first_dd_loc <- delayed_disch_areas %>% + filter( + location == LOCALITY, + year == min(year) + ) %>% pull(data) +percent_rate_change_dd_loc <- round(abs(latest_dd_loc2 - first_dd_loc) / first_dd_loc * 100, digits = 1) +word_change_rate_dd_loc <- if_else(latest_dd_loc2 > first_dd_loc, + "increase", "decrease") + + hscp_dd <- delayed_disch_areas %>% filter( location == HSCP, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +hscp_dd1 <- hscp_dd %>% pull(data2) +hscp_dd2 <- hscp_dd %>% pull(data) + +first_hscp_dd <- delayed_disch_areas %>% + filter( + location == HSCP, + year == min(year) + ) %>% pull(data) +percent_rate_change_dd_hscp <- round(abs(hscp_dd2 - first_hscp_dd) / first_hscp_dd * 100, digits = 1) +word_change_rate_dd_hscp <- if_else(hscp_dd2 > first_hscp_dd, + "increase", "decrease") + + scot_dd <- delayed_disch_areas %>% filter( location == "Scotland", year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +scot_dd1 <- scot_dd %>% pull(data2) +scot_dd2 <- scot_dd %>% pull(data) + +first_scot_dd <- delayed_disch_areas %>% + filter( + location == "Scotland", + year == min(year) + ) %>% pull(data) +percent_rate_change_dd_scot <- round(abs(scot_dd2 - first_scot_dd) / first_scot_dd * 100, digits = 1) +word_change_rate_dd_scot <- if_else(scot_dd2 > first_scot_dd, + "increase", "decrease") + + other_loc_dd <- delayed_disch %>% group_by(financial_year, hscp_locality) %>% summarise(dd_bed_days = sum(dd_bed_days)) %>% @@ -860,7 +906,8 @@ falls_areas <- falls %>% rename(n = admissions) %>% aggregate_usc_area_data() %>% left_join(pop_areas_65plus) %>% - mutate(data = round_half_up(n / pop * 100000)) + mutate(data = round_half_up(n / pop * 100000)) %>% + filter(!is.na(year)) Falls_loc_ts <- area_trend_usc( data_for_plot = falls_areas, @@ -874,22 +921,69 @@ Falls_loc_ts <- area_trend_usc( # Objects for text and summary table +min_year_falls <- min(falls_areas$financial_year) +max_year_falls <- max(falls_areas$financial_year) + latest_falls_loc <- falls_areas %>% filter( location == LOCALITY, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_falls_loc1 <- latest_falls_loc %>% pull(data2) +latest_falls_loc2 <- latest_falls_loc %>% pull(data) + +first_falls_loc <- falls_areas %>% + filter( + location == LOCALITY, + year == min(year) + ) %>% + pull(data) + +percent_rate_change_falls_loc <- round(abs(latest_falls_loc2 - first_falls_loc) / first_falls_loc * 100, digits = 1) +word_change_rate_falls_loc <- if_else(latest_falls_loc2 > first_falls_loc, + "increase", "decrease") +hscp_falls <- falls_areas %>% + filter( + location == HSCP, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hscp_falls1 <- hscp_falls %>% pull(data2) +hscp_falls2 <- hscp_falls %>% pull(data) + +first_falls_hscp <- falls_areas %>% + filter( + location == HSCP, + year == min(year) + ) %>% pull(data) +percent_rate_change_falls_hscp<- round(abs(hscp_falls2 - first_falls_hscp) / first_falls_hscp * 100, digits = 1) +word_change_rate_falls_hscp <- if_else(hscp_falls2 > first_falls_hscp, + "increase", "decrease") scot_falls <- falls_areas %>% filter( location == "Scotland", year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +scot_falls1 <- scot_falls %>% pull(data2) +scot_falls2 <- scot_falls %>% pull(data) + +first_falls_scot <- falls_areas %>% + filter( + location == "Scotland", + year == min(year) + ) %>% pull(data) +percent_rate_change_falls_scot<- round(abs(scot_falls2 - first_falls_scot) / first_falls_scot * 100, digits = 1) +word_change_rate_falls_scot <- if_else(scot_falls2 > first_falls_scot, + "increase", "decrease") # 6. Readmissions (28 days) ---- # _________________________________________________________________________ diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 4a71aff..cd0d8e6 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -108,7 +108,7 @@ x <- x + 1 ### A&E Attendances -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by geographical area. As presented in Figure `r x`, the A&E attendance rate per 100,000 in `r LOCALITY` for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area`. The `r HSCP` HSCP rate is `r hscp_ae_att1` in `r max_year_ae_area`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area`. The `r HSCP` HSCP rate is `r hscp_ae_att1` in `r max_year_ae_area`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. ####Figure `r x`: A&E attendances by geographical area \newline @@ -119,7 +119,7 @@ AandE_loc_ts x <- x + 1 ``` -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the greatest A&E attendance rate per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age` for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The smallest A&E attendance rate per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the greatest A&E attendance rate per 100,000 for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The smallest A&E attendance rate per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. ####Figure `r x`: A&E attendances by age group \newline @@ -137,7 +137,7 @@ x <- x + 1 ### Emergency Readmissions (28 days) -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area` by geographical area. As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in `r LOCALITY` for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area`. The `r HSCP` HSCP rate is `r hscp_read` in `r max_year_re_area`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area`. The `r HSCP` HSCP rate is `r hscp_read` in `r max_year_re_area`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. ####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline @@ -147,7 +147,7 @@ Read_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the greatest emergency readmission (28 days) rate per 1,000 discharges for `r LOCALITY` in `r max_year_re_age` is `r latest_re_max_age_data` for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The emergency readmission (28 days) rate per 1,000 discharges for `r LOCALITY` in `r max_year_re_age` is `r latest_re_min_age_data` for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the greatest emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. ####Figure `r x`: Emergency readmissions (28 days) by age group \newline @@ -163,6 +163,8 @@ x <- x + 1 ### Delayed Discharge Bed Days +Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. As presented in Figure `r x` the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd`. The `r HSCP` HSCP rate is `r hscp_dd1` in `r max_year_dd`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`, and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. + ####Figure `r x`: Delayed discharge bed days in population aged 65+ by geographical area \newline @@ -174,6 +176,8 @@ x <- x + 1 ### Emergency admissions from a fall +Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. As presented in Figure `r x` the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd`. The `r HSCP` HSCP rate is `r hscp_dd1` in `r max_year_dd`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`, and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. + ####Figure `r x`: Falls in population aged 65+ by geographical area \newline From d3ffca94eec0b5d9092efb6a83b582eac7ccd438 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Thu, 4 Jul 2024 14:21:18 +0100 Subject: [PATCH 07/38] Dynamic text updates --- .../2. Unscheduled Care outputs.R | 47 ++++++++++++++++--- .../Unscheduled-Care-Testing-Markdown.Rmd | 3 +- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 863b516..87756d4 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -530,7 +530,8 @@ bed_days_mh_age <- bed_days_mh %>% summarise(bed_days = sum(bed_days)) %>% ungroup() %>% left_join(loc_pop_age1) %>% - mutate(data = round_half_up(bed_days / pop * 100000)) + mutate(data = round_half_up(bed_days / pop * 100000)) %>% + filter(!is.na(year)) BDMH_age_ts <- age_group_trend_usc( @@ -546,7 +547,8 @@ bed_days_mh_areas <- bed_days_mh %>% rename(n = bed_days) %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(n / pop * 100000)) + mutate(data = round_half_up(n / pop * 100000)) %>% + filter(!is.na(year)) BDMH_loc_ts <- area_trend_usc( data_for_plot = bed_days_mh_areas, @@ -557,22 +559,46 @@ BDMH_loc_ts <- area_trend_usc( # Objects for text and summary table +max_year_bd_mh_areas <-max(bed_days_mh_areas$financial_year) +min_year_bd_mh_areas <-min(bed_days_mh_areas$financial_year) + latest_bed_days_mh_loc <- bed_days_mh_areas %>% filter( location == LOCALITY, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_bed_days_mh_loc1 <- latest_bed_days_mh_loc %>% pull(data2) +latest_bed_days_mh_loc2 <- latest_bed_days_mh_loc %>% pull(data) +latest_bed_days_mh_loc1 <- ifelse(is_empty(latest_bed_days_mh_loc1), "NA", latest_bed_days_mh_loc1) + +first_bed_days_mh_loc <- bed_days_mh_areas %>% + filter( + location == LOCALITY, + year == min(year) + ) %>% pull(data) -latest_bed_days_mh_loc <- ifelse(is_empty(latest_bed_days_mh_loc), "NA", latest_bed_days_mh_loc) +loc_rate_change_beds_mh <- round(abs(latest_bed_days_mh_loc2 - first_bed_days_mh_loc) / first_bed_days_mh_loc * 100, digits = 1) +loc_word_change_beds_mh <- if_else(latest_bed_days_mh_loc2 > first_bed_days_mh_loc, + "increase", "decrease") hscp_bed_days_mh <- bed_days_mh_areas %>% filter( location == HSCP, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +hscp_bed_days_mh1 <- hscp_bed_days_mh %>% pull(data2) +hscp_bed_days_mh2 <- hscp_bed_days_mh %>% pull(data) + +first_hscp_bed_days_mh <- bed_days_mh_areas %>% + filter( + location == HSCP, + year == min(year) + ) %>% pull(data) scot_bed_days_mh <- bed_days_mh_areas %>% @@ -580,7 +606,16 @@ scot_bed_days_mh <- bed_days_mh_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% + mutate(data2 = format(data, big.mark = ",")) + +scot_bed_days_mh1 <- scot_bed_days_mh %>% pull(data2) +scot_bed_days_mh2 <- scot_bed_days_mh %>% pull(data) + +first_scot_bed_days_mh <- bed_days_mh_areas %>% + filter( + location == "Scotland", + year == min(year) + ) %>% pull(data) other_loc_bed_days_mh <- bed_days_mh %>% diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index cd0d8e6..bd20036 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -176,7 +176,8 @@ x <- x + 1 ### Emergency admissions from a fall -Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. As presented in Figure `r x` the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd`. The `r HSCP` HSCP rate is `r hscp_dd1` in `r max_year_dd`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`, and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls`. The `r HSCP` HSCP rate is `r hscp_falls1` in `r max_year_falls`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls +`, and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. ####Figure `r x`: Falls in population aged 65+ by geographical area \newline From f1575707d6d472c79850e05c776cb88fa51aa597 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Tue, 9 Jul 2024 16:38:58 +0100 Subject: [PATCH 08/38] Dynamic text unscheduled care mh and missing data fixes --- .../2. Unscheduled Care outputs.R | 86 +++++++++++++++++-- .../Unscheduled-Care-Testing-Markdown.Rmd | 24 +++--- 2 files changed, 93 insertions(+), 17 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 87756d4..64a338d 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -558,7 +558,60 @@ BDMH_loc_ts <- area_trend_usc( ) -# Objects for text and summary table +# Objects for text and summary table- age +max_year_bd_mh_age <- max(bed_days_mh_age$financial_year) +min_year_bd_mh_age <- min(bed_days_mh_age$financial_year) + +latest_bd_mh_max_age <- bed_days_mh_age %>% + filter( + year == max(year)) %>% + filter( + data== max(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_bd_mh_max_age1 <- latest_bd_mh_max_age %>% pull(data2) +latest_bd_mh_max_age2 <- latest_bd_mh_max_age %>% pull(data) +age_group_max_mh <- latest_bd_mh_max_age %>% pull(age_group) + +first_bd_mh_max_age <- bed_days_mh_age %>% + filter( + year == min(year), + age_group == age_group_max_mh + ) %>% + pull(data) + +max_rate_change_beds_mh <- round(abs(latest_bd_mh_max_age2 - first_bd_mh_max_age) / first_bd_mh_max_age * 100, digits = 1) +max_word_change_beds_mh <- if_else(latest_bd_mh_max_age2 > first_bd_mh_max_age, + "increase", "decrease") + +latest_bd_mh_min_age <- bed_days_mh_age %>% + filter( + year == max(year)) %>% + filter( + data== min(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_bd_mh_min_age1 <- latest_bd_mh_min_age %>% pull(data2) +latest_bd_mh_min_age2 <- latest_bd_mh_min_age %>% pull(data) +age_group_min_mh <- latest_bd_mh_min_age %>% pull(age_group) + +first_bd_mh_min_age <- bed_days_mh_age %>% + filter( + age_group == age_group_min_mh + ) %>% + filter(year==min(year)) + +first_bd_mh_min_age1 <- first_bd_mh_min_age %>% pull(data) +min_year_bd_mh_age1<- first_bd_mh_min_age %>% pull(year) + + +min_rate_change_beds_mh <- round(abs(latest_bd_mh_min_age2 - first_bd_mh_min_age1) / first_bd_mh_min_age1 * 100, digits = 1) +min_word_change_beds_mh <- if_else(latest_bd_mh_min_age2 > first_bd_mh_min_age1, + "increase", "decrease") + +# Objects for text and summary table- area max_year_bd_mh_areas <-max(bed_days_mh_areas$financial_year) min_year_bd_mh_areas <-min(bed_days_mh_areas$financial_year) @@ -601,6 +654,10 @@ first_hscp_bed_days_mh <- bed_days_mh_areas %>% ) %>% pull(data) +hscp_rate_change_beds_mh <- round(abs(hscp_bed_days_mh2 - first_hscp_bed_days_mh) / first_hscp_bed_days_mh * 100, digits = 1) +hscp_word_change_beds_mh <- if_else(hscp_bed_days_mh2 > first_hscp_bed_days_mh, + "increase", "decrease") + scot_bed_days_mh <- bed_days_mh_areas %>% filter( location == "Scotland", @@ -618,6 +675,11 @@ first_scot_bed_days_mh <- bed_days_mh_areas %>% ) %>% pull(data) +scot_rate_change_beds_mh <- round(abs(scot_bed_days_mh2 - first_scot_bed_days_mh) / first_scot_bed_days_mh * 100, digits = 1) +scot_word_change_beds_mh <- if_else(scot_bed_days_mh2 > first_scot_bed_days_mh, + "increase", "decrease") + + other_loc_bed_days_mh <- bed_days_mh %>% group_by(financial_year, hscp_locality) %>% summarise(bed_days = sum(bed_days)) %>% @@ -1281,7 +1343,8 @@ ppa <- arrow::read_parquet(paste0(import_folder, "ppa_smr.parquet")) %>% # % PPAs in locality under and over 65 ppa_total <- ppa %>% rename(n = admissions) %>% - aggregate_usc_area_data() + aggregate_usc_area_data()%>% + filter(!is.na(year)) ppa_65plus <- ppa %>% filter(age_group %in% c("65 - 74", "75+")) %>% @@ -1290,7 +1353,8 @@ ppa_65plus <- ppa %>% rename(plus65tot = n) %>% left_join(ppa_total, by = c("financial_year", "location")) %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(plus65tot / n * 100, 1)) + mutate(data = round_half_up(plus65tot / n * 100, 1))%>% + filter(!is.na(year)) latest_ppa_65plus <- ppa_65plus %>% filter( @@ -1306,7 +1370,8 @@ ppa_under65 <- ppa %>% rename(under65tot = n) %>% left_join(ppa_total, by = c("financial_year", "location")) %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(under65tot / n * 100, 1)) + mutate(data = round_half_up(under65tot / n * 100, 1)) %>% + filter(!is.na(year)) latest_ppa_under65 <- ppa_under65 %>% filter( @@ -1323,7 +1388,8 @@ ppa_areas <- ppa %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(n / pop * 100000)) %>% mutate(location = factor(location, levels = c(LOCALITY, HSCP, HB, "Scotland"))) %>% - arrange(location) + arrange(location) %>% + filter(!is.na(year)) PPA_loc_ts <- area_trend_usc( @@ -1335,13 +1401,19 @@ PPA_loc_ts <- area_trend_usc( # Objects for text and summary table +max_year_ppa_areas <- max(ppa_areas$financial_year) +min_year_ppa_areas <- min(ppa_areas$financial_year) + + latest_ppa_loc <- ppa_areas %>% filter( location == LOCALITY, year == max(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) + +latest_ppa_loc1 <- latest_ppa_loc %>%pull(data2) +latest_ppa_loc2 <- latest_ppa_loc %>%pull(data) hscp_ppa <- ppa_areas %>% filter( diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index bd20036..865db7a 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -44,15 +44,15 @@ This section includes acute hospital data, delayed discharge bed days and A&E at - **`r latest_bed_days_loc1`** unscheduled acute specialty bed days per 100,000 population, compared to `r scot_bed_days1` in Scotland. - - **`r latest_ae_att_loc`** A&E attendances per 100,000 population, compared to `r scot_ae_att` in Scotland. + - **`r latest_ae_att_loc1`** A&E attendances per 100,000 population, compared to `r scot_ae_att1` in Scotland. - - **`r latest_dd_loc`** delayed discharge bed days per 100,000 population aged over 65, compared to `r scot_dd` in Scotland. + - **`r latest_dd_loc1`** delayed discharge bed days per 100,000 population aged over 65, compared to `r scot_dd1` in Scotland. - - **`r latest_falls_loc`** emergency hospital admissions from falls per 100,000 population aged over 65, compared to `r scot_falls` in Scotland. + - **`r latest_falls_loc1`** emergency hospital admissions from falls per 100,000 population aged over 65, compared to `r scot_falls1` in Scotland. - - **`r latest_read_loc`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. + - **`r latest_read_loc1`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. - - **`r latest_ppa_loc`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa` in Scotland. + - **`r latest_ppa_loc1`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa` in Scotland. #####Pagebreak @@ -147,7 +147,7 @@ Read_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the greatest emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the greatest emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The smallest emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. ####Figure `r x`: Emergency readmissions (28 days) by age group \newline @@ -176,8 +176,7 @@ x <- x + 1 ### Emergency admissions from a fall -Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls`. The `r HSCP` HSCP rate is `r hscp_falls1` in `r max_year_falls`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls -`, and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls`. The `r HSCP` HSCP rate is `r hscp_falls1` in `r max_year_falls`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`, and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. ####Figure `r x`: Falls in population aged 65+ by geographical area \newline @@ -193,7 +192,7 @@ x <- x + 1 ### Potentially Preventable Admissions (PPAs) -Information conditions included in PPAs is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. +Information conditions included in PPAs is available in Appendix 3. In `r max_year_ppa_areas`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. ####Figure `r x`: PPAs by geographical area \newline @@ -217,7 +216,7 @@ This section looks at mental health related unscheduled care indicators. **For the most recent time periods available, `r LOCALITY` had:** - **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp` in Scotland^4^. - - **`r latest_bed_days_mh_loc`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh` in Scotland. + - **`r latest_bed_days_mh_loc1`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh1` in Scotland. \newline @@ -237,6 +236,8 @@ x <- x + 1 ### Unscheduled Mental Health Specialty Bed Days +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HSCP` HSCP rate is `r hscp_bed_days_mh1` in `r max_year_bd_mh_areas`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`, and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. + ####Figure `r x`: Unscheduled mental health specialty bed days by geographical area \newline @@ -246,6 +247,9 @@ BDMH_loc_ts x <- x + 1 ``` +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. As presented in Figure `r x`, the greatest unscheduled mental health bed days rate per 100,000 for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The smallest unschedule mental health bed days rate per 100,000 for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. + + ####Figure `r x`: Unscheduled mental health specialty bed days by age group \newline From 71b39a11b590a0770f32e9aeaf9859cf99bd17b4 Mon Sep 17 00:00:00 2001 From: There717 Date: Thu, 11 Jul 2024 13:31:38 +0100 Subject: [PATCH 09/38] Added further dynamic text and included Health Board in Dynamic text. --- .../2. Unscheduled Care outputs.R | 332 +++++++++++++++++- 1 file changed, 321 insertions(+), 11 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 64a338d..57528bf 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -308,7 +308,8 @@ emergency_adm_age <- emergency_adm %>% summarise(adm = sum(admissions)) %>% ungroup() %>% left_join(loc_pop_age1) %>% - mutate(data = round_half_up(adm / pop * 100000)) + mutate(data = round_half_up(adm / pop * 100000)) %>% + filter(!is.na(year)) EAs_age_ts <- age_group_trend_usc( @@ -396,7 +397,25 @@ scot_rate_change <- round(abs(scot_emergency_adm2 - first_fy_scot) / first_fy_sc word_change_scot <- if_else(scot_emergency_adm2 > first_fy_scot, "increase", "decrease") +#NHS health board +hb_emergency_adm <- emergency_adm_areas %>% + filter( + location == HB, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hb_emergency_adm1 <- hb_emergency_adm %>% pull(data2) +hb_emergency_adm2 <- hb_emergency_adm %>% pull(data) +first_fy_hb <- filter(emergency_adm_areas, + (financial_year == min(emergency_adm_areas$financial_year)) & + (location == HB))$data +hb_rate_change <- round(abs(hb_emergency_adm2 - first_fy_hb) / first_fy_hb * 100, digits = 1) +word_change_hb <- if_else(hb_emergency_adm2 > first_fy_hb, + "increase", "decrease") + +#other locations other_loc_emergency_adm <- emergency_adm %>% group_by(financial_year, hscp_locality) %>% summarise(adm = sum(admissions)) %>% @@ -408,7 +427,58 @@ other_loc_emergency_adm <- emergency_adm %>% select(hscp_locality, data) %>% pivot_wider(names_from = hscp_locality, values_from = data) +# Create objects for text emergency admissions by age group +max_ea_age <- max(emergency_adm_age$financial_year) +min_ea_age <- min(emergency_adm_age$financial_year) + +latest_ea_max_age <- emergency_adm_age %>% + filter( + year == max(year)) %>% + filter( + data== max(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_ea_max_age1 <- latest_ea_max_age %>% pull(data2) +latest_ea_max_age2 <- latest_ea_max_age %>% pull(data) +age_group_max_ea <- latest_ea_max_age %>% pull(age_group) + +first_ea_max_age <- emergency_adm_age %>% + filter( + year == min(year), + age_group == age_group_max_ea + ) %>% + pull(data) + +max_rate_change_ea <- round(abs(latest_ea_max_age2 - first_ea_max_age) / first_ea_max_age * 100, digits = 1) +max_word_change_ea <- if_else(latest_ea_max_age2 > first_ea_max_age, + "increase", "decrease") + +latest_ea_min_age <- emergency_adm_age %>% + filter( + year == max(year)) %>% + filter( + data== min(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_ea_min_age1 <- latest_ea_min_age %>% pull(data2) +latest_ea_min_age2 <- latest_ea_min_age %>% pull(data) +age_group_min_ea <- latest_ea_min_age %>% pull(age_group) + +first_ea_min_age <- emergency_adm_age %>% + filter( + age_group == age_group_min_ea + ) %>% + filter(year==min(year)) + +first_ea_min_age1 <- first_ea_min_age %>% pull(data) +min_year_ea_age1<- first_ea_min_age %>% pull(year) + +min_rate_change_ea <- round(abs(latest_ea_min_age2 - first_ea_min_age1) / first_ea_min_age1 * 100, digits = 1) +min_word_change_ea <- if_else(latest_ea_min_age2 > first_ea_min_age1, + "increase", "decrease") # 2a. Unscheduled bed days ---- # _________________________________________________________________________ @@ -424,7 +494,8 @@ bed_days_age <- bed_days %>% summarise(bed_days = sum(bed_days)) %>% ungroup() %>% left_join(loc_pop_age1) %>% - mutate(data = round_half_up(bed_days / pop * 100000)) + mutate(data = round_half_up(bed_days / pop * 100000)) %>% + filter(!is.na(year)) BDs_age_ts <- age_group_trend_usc( @@ -503,6 +574,24 @@ scot_rate_ubd <- round(abs(scot_bed_days2 - first_fy_scot_ubd) / first_fy_scot_u scot_change_ubd <- if_else(scot_bed_days2 > first_fy_scot_ubd, "increase", "decrease") +#NHS health board +hb_bed_days <- bed_days_areas %>% + filter( + location == HB, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hb_bed_days1 <- hb_bed_days %>% pull(data2) +hb_bed_days2 <- hb_bed_days %>% pull(data) +first_fy_hb_ubd <- filter(bed_days_areas, + (financial_year == min(bed_days_areas$financial_year)) & + (location == HB))$data + +hb_rate_change_ubd <- round(abs(hb_bed_days2 - first_fy_hb_ubd) / first_fy_hb_ubd * 100, digits = 1) +word_change_hb_ubd <- if_else(hb_bed_days2 > first_fy_hb_ubd, + "increase", "decrease") + other_loc_bed_days <- bed_days %>% group_by(financial_year, hscp_locality) %>% @@ -515,6 +604,58 @@ other_loc_bed_days <- bed_days %>% select(hscp_locality, data) %>% pivot_wider(names_from = hscp_locality, values_from = data) +# Create objects for text emergency admissions by age group +max_ubd_age <- max(bed_days_age$financial_year) +min_ubd_age <- min(bed_days_age$financial_year) + +latest_ubd_max_age <- bed_days_age %>% + filter( + year == max(year)) %>% + filter( + data== max(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_ubd_max_age1 <- latest_ubd_max_age %>% pull(data2) +latest_ubd_max_age2 <- latest_ubd_max_age %>% pull(data) +age_group_max_ubd <- latest_ubd_max_age %>% pull(age_group) + +first_ubd_max_age <- bed_days_age %>% + filter( + year == min(year), + age_group == age_group_max_ubd + ) %>% + pull(data) + +max_rate_change_ubd <- round(abs(latest_ubd_max_age2 - first_ubd_max_age) / first_ubd_max_age * 100, digits = 1) +max_word_change_ubd <- if_else(latest_ubd_max_age2 > first_ubd_max_age, + "increase", "decrease") + +latest_ubd_min_age <- bed_days_age %>% + filter( + year == max(year)) %>% + filter( + data== min(data) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +latest_ubd_min_age1 <- latest_ubd_min_age %>% pull(data2) +latest_ubd_min_age2 <- latest_ubd_min_age %>% pull(data) +age_group_min_ubd <- latest_ubd_min_age %>% pull(age_group) + +first_ubd_min_age <- bed_days_age %>% + filter( + age_group == age_group_min_ubd + ) %>% + filter(year==min(year)) + +first_ubd_min_age1 <- first_ubd_min_age %>% pull(data) +min_year_ubd_age1<- first_ubd_min_age %>% pull(year) + + +min_rate_change_ubd <- round(abs(latest_ubd_min_age2 - first_ubd_min_age1) / first_ubd_min_age1 * 100, digits = 1) +min_word_change_ubd <- if_else(latest_ubd_min_age2 > first_ubd_min_age1, + "increase", "decrease") # 2b. Unscheduled bed days - Mental Health ---- # _________________________________________________________________________ @@ -679,6 +820,23 @@ scot_rate_change_beds_mh <- round(abs(scot_bed_days_mh2 - first_scot_bed_days_mh scot_word_change_beds_mh <- if_else(scot_bed_days_mh2 > first_scot_bed_days_mh, "increase", "decrease") +#NHS health board +hb_mh_beddays <- bed_days_mh_areas %>% + filter( + location == HB, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hb_mh_beddays1 <- hb_mh_beddays %>% pull(data2) +hb_mh_beddays2 <- hb_mh_beddays %>% pull(data) +first_fy_hb_mh <- filter(bed_days_mh_areas, + (financial_year == min(bed_days_mh_areas$financial_year)) & + (location == HB))$data + +hb_rate_change_mh <- round(abs(hb_mh_beddays2 - first_fy_hb_mh) / first_fy_hb_mh * 100, digits = 1) +word_change_hb_mh <- if_else(hb_mh_beddays2 > first_fy_hb_mh, + "increase", "decrease") other_loc_bed_days_mh <- bed_days_mh %>% group_by(financial_year, hscp_locality) %>% @@ -861,7 +1019,23 @@ percent_rate_change_ae_areas_scot <- round(abs(scot_ae_att2 - first_fy_scot_ae) word_change_rate_ae_areas_scot <- if_else(scot_ae_att2 > first_fy_scot_ae, "increase", "decrease") +#NHS health board +hb_ae_att <- ae_att_areas %>% + filter( + location == HB, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hb_ae1 <- hb_ae_att %>% pull(data2) +hb_ae2 <- hb_ae_att %>% pull(data) +first_fy_hb_ae <- filter(ae_att_areas, + (financial_year == min(ae_att_areas$financial_year)) & + (location == HB))$data +hb_rate_change_ae <- round(abs(hb_ae2 - first_fy_hb_ae) / first_fy_hb_ae * 100, digits = 1) +word_change_hb_ae <- if_else(hb_ae2 > first_fy_hb_ae, + "increase", "decrease") other_loc_ae_att <- ae_attendances %>% group_by(financial_year, hscp_locality) %>% @@ -977,6 +1151,24 @@ percent_rate_change_dd_scot <- round(abs(scot_dd2 - first_scot_dd) / first_scot_ word_change_rate_dd_scot <- if_else(scot_dd2 > first_scot_dd, "increase", "decrease") +#NHS health board +hb_dd <- delayed_disch_areas %>% + filter( + location == HB, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hb_dd1 <- hb_dd %>% pull(data2) +hb_dd2 <- hb_dd %>% pull(data) +first_fy_hb_dd <- filter(delayed_disch_areas, + (financial_year == min(delayed_disch_areas$financial_year)) & + (location == HB))$data + +hb_rate_change_dd <- round(abs(hb_dd2 - first_fy_hb_dd) / first_fy_hb_dd * 100, digits = 1) +word_change_hb_dd <- if_else(hb_dd2 > first_fy_hb_dd, + "increase", "decrease") + other_loc_dd <- delayed_disch %>% group_by(financial_year, hscp_locality) %>% @@ -1082,6 +1274,24 @@ percent_rate_change_falls_scot<- round(abs(scot_falls2 - first_falls_scot) / fir word_change_rate_falls_scot <- if_else(scot_falls2 > first_falls_scot, "increase", "decrease") +#NHS health board +hb_falls <- falls_areas %>% + filter( + location == HB, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hb_falls1 <- hb_falls %>% pull(data2) +hb_falls2 <- hb_falls %>% pull(data) +first_fy_hb_falls <- filter(falls_areas, + (financial_year == min(falls_areas$financial_year)) & + (location == HB))$data + +hb_rate_change_falls <- round(abs(hb_falls2 - first_fy_hb_falls) / first_fy_hb_falls * 100, digits = 1) +word_change_hb_falls <- if_else(hb_falls2 > first_fy_hb_falls, + "increase", "decrease") + # 6. Readmissions (28 days) ---- # _________________________________________________________________________ @@ -1244,6 +1454,24 @@ percent_rate_change_re_area_scot <- round(abs(scot_read - first_scot_read) / fir word_change_rate_re_area_scot <- if_else(scot_read > first_scot_read, "increase", "decrease") +#NHS health board +hb_read <- readmissions_areas %>% + filter( + location == HB, + year == max(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +hb_read1 <- hb_read %>% pull(data2) +hb_read2 <- hb_read %>% pull(data) +first_fy_hb_read <- filter(readmissions_areas, + (financial_year == min(readmissions_areas$financial_year)) & + (location == HB))$data + +hb_rate_change_read <- round(abs(hb_read2 - first_fy_hb_read) / first_fy_hb_read * 100, digits = 1) +word_change_hb_read <- if_else(hb_read2 > first_fy_hb_read, + "increase", "decrease") + # 7. Comm 6 months ---- # _________________________________________________________________________________ # @@ -1408,28 +1636,49 @@ min_year_ppa_areas <- min(ppa_areas$financial_year) latest_ppa_loc <- ppa_areas %>% filter( location == LOCALITY, - year == max(year) + year == max(year) | year == min(year) ) %>% mutate(data2 = format(data, big.mark = ",")) -latest_ppa_loc1 <- latest_ppa_loc %>%pull(data2) -latest_ppa_loc2 <- latest_ppa_loc %>%pull(data) +ppa_diff <- round(abs(latest_ppa_loc$data[2] - latest_ppa_loc$data[1]) / latest_ppa_loc$data[1]* 100, digits = 1) +ppa_word_change <- if_else(latest_ppa_loc$data[2] > latest_ppa_loc$data[1], + "increase", "decrease") hscp_ppa <- ppa_areas %>% filter( location == HSCP, - year == max(year) + year == max(year) | year == min(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +ppa_diff_hscp <- round(abs(hscp_ppa$data[2] - hscp_ppa$data[1]) / hscp_ppa$data[1]* 100, digits = 1) +ppa_word_change_hscp <- if_else(hscp_ppa$data[2] > hscp_ppa$data[1], + "increase", "decrease") scot_ppa <- ppa_areas %>% filter( location == "Scotland", - year == max(year) + year == max(year) | year == min(year) ) %>% - mutate(data = format(data, big.mark = ",")) %>% - pull(data) + mutate(data2 = format(data, big.mark = ",")) #%>% + #pull(data) + +diff_scot_ppa <- round(abs(scot_ppa$data[2] - scot_ppa$data[1]) / scot_ppa$data[1] * 100, digits = 1) +word_change_scot_ppa <- if_else(scot_ppa$data[2] > scot_ppa$data[1], + "increase", "decrease") + +#NHS health board +hb_ppa <- ppa_areas %>% + filter( + location == HB, + year == max(year) | year == min(year) + ) %>% + mutate(data2 = format(data, big.mark = ",")) + +diff_hb_ppa <- round(abs(hb_ppa$data[2] - hb_ppa$data[1]) / hb_ppa$data[1] * 100, digits = 1) +word_change_hb_ppa <- if_else(hb_ppa$data[2] > hb_ppa$data[1], + "increase", "decrease") other_loc_ppa <- ppa %>% group_by(financial_year, hscp_locality) %>% @@ -1493,6 +1742,67 @@ hscp_psych_hosp <- round_half_up(filter(psych_hosp, year == max(year) & scot_psych_hosp <- round_half_up(filter(psych_hosp, year == max(year) & area_name == "Scotland")$measure, 1) +list_years <- unique(psych_hosp_time_trend$data[6]) +list_years_latest <- list_years$period + + +#Locality +loc_psych_hosp <- psych_hosp %>% + filter(period %in% list_years_latest) %>% + filter( + area_name == LOCALITY & + area_type == "Locality", + year == min(year) | year == max(year) + ) %>% + mutate(measure2 = format(measure, big.mark = ",")) + +diff_loc_psych <- round(abs(loc_psych_hosp$measure[2] - loc_psych_hosp$measure[1]) / loc_psych_hosp$measure[1] * 100, digits = 1) +word_change_loc_psych <- if_else(loc_psych_hosp$measure[2] > loc_psych_hosp$measure[1], + "increase", "decrease") + +#HSCP +hscp_psych_hosp <- psych_hosp %>% + filter(period %in% list_years_latest) %>% + filter( + area_name == HSCP & + area_type == "HSCP", + year == min(year) | year == max(year) + ) %>% + mutate(measure2 = format(measure, big.mark = ",")) + +diff_hscp_psych <- round(abs(hscp_psych_hosp$measure[2] - hscp_psych_hosp$measure[1]) / hscp_psych_hosp$measure[1] * 100, digits = 1) +word_change_hscp_psych <- if_else(hscp_psych_hosp$measure[2] > hscp_psych_hosp$measure[1], + "increase", "decrease") + +#NHS health board +hb_psych_hosp <- psych_hosp %>% + filter(period %in% list_years_latest) %>% + filter( + area_name == HB & + area_type == "Health board", + year == min(year) | year == max(year) + ) %>% + mutate(measure2 = format(measure, big.mark = ",")) + +diff_hb_psych <- round(abs(hb_psych_hosp$measure[2] - hb_psych_hosp$measure[1]) / hb_psych_hosp$measure[1] * 100, digits = 1) +word_change_hb_psych <- if_else(hb_psych_hosp$measure[2] > hb_psych_hosp$measure[1], + "increase", "decrease") + +#Scotland +scot_psych_hosp <- psych_hosp %>% + filter(period %in% list_years_latest) %>% + filter( + area_name == "Scotland" & + area_type == "Scotland", + year == min(year) | year == max(year) + ) %>% + mutate(measure2 = format(measure, big.mark = ",")) + +diff_scot_psych <- round(abs(scot_psych_hosp$measure[2] - scot_psych_hosp$measure[1]) / scot_psych_hosp$measure[1] * 100, digits = 1) +word_change_scot_psych <- if_else(scot_psych_hosp$measure[2] > scot_psych_hosp$measure[1], + "increase", "decrease") + + ## Stat disclosure control From d6d3adb8afb881e0271781f6117fa60a0ea4e18b Mon Sep 17 00:00:00 2001 From: There717 Date: Thu, 11 Jul 2024 13:34:03 +0100 Subject: [PATCH 10/38] Added dynamic text for emergency admissions age groups and acute bed days age groups. Added dynamic text for PPA and mental health and psychiatric stays. Replaced greatest and smallest with highest and lowest in text for all figures. --- .../Unscheduled-Care-Testing-Markdown.Rmd | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 865db7a..4cbbd7f 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -52,14 +52,14 @@ This section includes acute hospital data, delayed discharge bed days and A&E at - **`r latest_read_loc1`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. - - **`r latest_ppa_loc1`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa` in Scotland. + - **`r latest_ppa_loc$data2[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$data2[2]` in Scotland. #####Pagebreak ### Emergency Admissions -Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. ####Figure `r x`: Emergency admissions by geographical area \newline @@ -70,6 +70,8 @@ EAs_loc_ts x <- x + 1 ``` +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_ea_age` to `r max_ea_age` by age group. As presented in Figure `r x`, the highest emergency admissions rate for the `r LOCALITY` locality in `r max_ea_age` is `r latest_ea_max_age1` per 100,000 population for the `r age_group_max_ea` age group with a percentage `r max_word_change_ea` of `r max_rate_change_ea`% since `r min_ea_age`. The lowest emergency admissions rate for `r LOCALITY` in `r max_ea_age` is `r latest_ea_min_age1` per 100,000 population for the `r age_group_min_ea` age group with a percentage `r min_word_change_ea` of `r min_rate_change_ea`% since `r min_ea_age`. + ####Figure `r x`: Emergency admissions by age group \newline @@ -83,7 +85,7 @@ x <- x + 1 ### Unscheduled Acute Bed Days -Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. As presented in Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd`. The `r HSCP` HSCP rate is `r hscp_bed_days1` in `r max_year_ubd`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. ####Figure `r x`: Unscheduled acute bed days by geographical area \newline @@ -94,6 +96,8 @@ BDs_loc_ts x <- x + 1 ``` +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. As presented in Figure `r x`, the highest unscheduled bed days rate for the `r LOCALITY` locality in `r max_ubd_age` is `r latest_ubd_max_age1` bed days per 100,000 population for the `r age_group_max_ubd` age group with a percentage `r max_word_change_ubd` of `r max_rate_change_ubd`% since `r min_ubd_age`. The lowest unscheduled bed days rate for `r LOCALITY` in `r max_ubd_age` is `r latest_ubd_min_age1` bed days per 100,000 population for the `r age_group_min_ubd` age group with a percentage `r min_word_change_ubd` of `r min_rate_change_ubd`% since `r min_ubd_age`. + ####Figure `r x`: Unscheduled acute bed days by age group \newline @@ -108,7 +112,7 @@ x <- x + 1 ### A&E Attendances -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area`. The `r HSCP` HSCP rate is `r hscp_ae_att1` in `r max_year_ae_area`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. ####Figure `r x`: A&E attendances by geographical area \newline @@ -119,7 +123,7 @@ AandE_loc_ts x <- x + 1 ``` -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the greatest A&E attendance rate per 100,000 for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The smallest A&E attendance rate per 100,000 for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the highest A&E attendance rate for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` per 100,000 population for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The lowest A&E attendance rate for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` per 100,000 population for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. ####Figure `r x`: A&E attendances by age group \newline @@ -131,13 +135,12 @@ x <- x + 1 ``` - ##### Page break ### Emergency Readmissions (28 days) -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area`. The `r HSCP` HSCP rate is `r hscp_read` in `r max_year_re_area`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. The emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_ae_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. ####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline @@ -147,7 +150,7 @@ Read_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the greatest emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The smallest emergency readmission (28 days) rate per 1,000 discharges for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. The highest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` per 1,000 discharges for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The lowest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` per 1,000 discharges for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. ####Figure `r x`: Emergency readmissions (28 days) by age group \newline @@ -163,7 +166,7 @@ x <- x + 1 ### Delayed Discharge Bed Days -Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. As presented in Figure `r x` the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd`. The `r HSCP` HSCP rate is `r hscp_dd1` in `r max_year_dd`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`, and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. +Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. The number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. ####Figure `r x`: Delayed discharge bed days in population aged 65+ by geographical area \newline @@ -176,7 +179,8 @@ x <- x + 1 ### Emergency admissions from a fall -Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls`. The `r HSCP` HSCP rate is `r hscp_falls1` in `r max_year_falls`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`, and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. The emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. +The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. ####Figure `r x`: Falls in population aged 65+ by geographical area \newline @@ -194,6 +198,10 @@ x <- x + 1 Information conditions included in PPAs is available in Appendix 3. In `r max_year_ppa_areas`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. + +Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$data2[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. +The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$data2[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$data2[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. + ####Figure `r x`: PPAs by geographical area \newline @@ -215,12 +223,15 @@ This section looks at mental health related unscheduled care indicators. **For the most recent time periods available, `r LOCALITY` had:** - - **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp` in Scotland^4^. + - **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp$measure[2]` in Scotland^4^. - **`r latest_bed_days_mh_loc1`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh1` in Scotland. \newline ### Psychiatric patient hospitalisations +Figure `r x` presents the psychiatric patient hospitalisation 3-year aggregate rate per 100,000 population in the `r LOCALITY` locality from `r loc_psych_hosp$period_short[1]` to `r loc_psych_hosp$period_short[2]`. + +As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, a `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, a `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, a `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, a `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. ####Figure `r x`: Psychiatric patient hospitalisations by geographical area \newline @@ -236,7 +247,8 @@ x <- x + 1 ### Unscheduled Mental Health Specialty Bed Days -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HSCP` HSCP rate is `r hscp_bed_days_mh1` in `r max_year_bd_mh_areas`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`, and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` +and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. ####Figure `r x`: Unscheduled mental health specialty bed days by geographical area \newline @@ -247,7 +259,7 @@ BDMH_loc_ts x <- x + 1 ``` -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. As presented in Figure `r x`, the greatest unscheduled mental health bed days rate per 100,000 for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The smallest unschedule mental health bed days rate per 100,000 for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. As presented in Figure `r x`, the highest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` per 100,000 population for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The lowest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` per 100,000 population for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. ####Figure `r x`: Unscheduled mental health specialty bed days by age group From 0c07c1ff80a94e0c083e102534c2879632e2488d Mon Sep 17 00:00:00 2001 From: Craig Fraser Date: Thu, 11 Jul 2024 16:46:20 +0100 Subject: [PATCH 11/38] directory reminder --- Unscheduled Care/2. Unscheduled Care outputs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 57528bf..552766d 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -29,7 +29,7 @@ library(fst) ### for testing run global script and locality placeholder below ## Functions -source("~/list-localities-profiles/Master RMarkdown Document & Render Code/Global Script.R") +source("./Master RMarkdown Document & Render Code/Global Script.R") ## Define locality # LOCALITY <- "Stirling City with the Eastern Villages Bridge of Allan and Dunblane" From c475ec617c40fbda99cce0b386944395e40047af Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Thu, 25 Jul 2024 15:46:32 +0100 Subject: [PATCH 12/38] Changes to file paths --- Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 4cbbd7f..b03d2b4 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -23,9 +23,9 @@ options(kableExtra.auto_format = FALSE) LOCALITY <- "Inverness" #LOCALITY <- "East Dunbartonshire West" -source("~/list-localities-profiles/Master RMarkdown Document & Render Code/Global Script.R") +source("../Master RMarkdown Document & Render Code/Global Script.R") -source("~/list-localities-profiles/Unscheduled Care/2. Unscheduled Care outputs.R") +source("./2. Unscheduled Care outputs.R") x <- 1 # object for figure numbers y <- 1 # object for table numbers From 86602cb46be0edcd8b66542f8bc2f619b589fef8 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Tue, 6 Aug 2024 15:07:18 +0100 Subject: [PATCH 13/38] directory change --- Unscheduled Care/2. Unscheduled Care outputs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 552766d..c55a714 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -29,7 +29,7 @@ library(fst) ### for testing run global script and locality placeholder below ## Functions -source("./Master RMarkdown Document & Render Code/Global Script.R") +source("../Master RMarkdown Document & Render Code/Global Script.R") ## Define locality # LOCALITY <- "Stirling City with the Eastern Villages Bridge of Allan and Dunblane" From e40a132bc5639ea789714a6a9a41405aa78b3ba4 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 7 Aug 2024 09:46:40 +0100 Subject: [PATCH 14/38] Spacing updates --- .../Unscheduled-Care-Testing-Markdown.Rmd | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index b03d2b4..3bf485b 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -59,7 +59,9 @@ This section includes acute hospital data, delayed discharge bed days and A&E at ### Emergency Admissions -Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. + +As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. ####Figure `r x`: Emergency admissions by geographical area \newline @@ -70,7 +72,9 @@ EAs_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_ea_age` to `r max_ea_age` by age group. As presented in Figure `r x`, the highest emergency admissions rate for the `r LOCALITY` locality in `r max_ea_age` is `r latest_ea_max_age1` per 100,000 population for the `r age_group_max_ea` age group with a percentage `r max_word_change_ea` of `r max_rate_change_ea`% since `r min_ea_age`. The lowest emergency admissions rate for `r LOCALITY` in `r max_ea_age` is `r latest_ea_min_age1` per 100,000 population for the `r age_group_min_ea` age group with a percentage `r min_word_change_ea` of `r min_rate_change_ea`% since `r min_ea_age`. +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_ea_age` to `r max_ea_age` by age group. + +As presented in Figure `r x`, the highest emergency admissions rate for the `r LOCALITY` locality in `r max_ea_age` is `r latest_ea_max_age1` per 100,000 population for the `r age_group_max_ea` age group with a percentage `r max_word_change_ea` of `r max_rate_change_ea`% since `r min_ea_age`. The lowest emergency admissions rate for `r LOCALITY` in `r max_ea_age` is `r latest_ea_min_age1` per 100,000 population for the `r age_group_min_ea` age group with a percentage `r min_word_change_ea` of `r min_rate_change_ea`% since `r min_ea_age`. ####Figure `r x`: Emergency admissions by age group \newline @@ -85,7 +89,9 @@ x <- x + 1 ### Unscheduled Acute Bed Days -Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. + +As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. ####Figure `r x`: Unscheduled acute bed days by geographical area \newline @@ -96,7 +102,9 @@ BDs_loc_ts x <- x + 1 ``` -Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. As presented in Figure `r x`, the highest unscheduled bed days rate for the `r LOCALITY` locality in `r max_ubd_age` is `r latest_ubd_max_age1` bed days per 100,000 population for the `r age_group_max_ubd` age group with a percentage `r max_word_change_ubd` of `r max_rate_change_ubd`% since `r min_ubd_age`. The lowest unscheduled bed days rate for `r LOCALITY` in `r max_ubd_age` is `r latest_ubd_min_age1` bed days per 100,000 population for the `r age_group_min_ubd` age group with a percentage `r min_word_change_ubd` of `r min_rate_change_ubd`% since `r min_ubd_age`. +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. + +As presented in Figure `r x`, the highest unscheduled bed days rate for the `r LOCALITY` locality in `r max_ubd_age` is `r latest_ubd_max_age1` bed days per 100,000 population for the `r age_group_max_ubd` age group with a percentage `r max_word_change_ubd` of `r max_rate_change_ubd`% since `r min_ubd_age`. The lowest unscheduled bed days rate for `r LOCALITY` in `r max_ubd_age` is `r latest_ubd_min_age1` bed days per 100,000 population for the `r age_group_min_ubd` age group with a percentage `r min_word_change_ubd` of `r min_rate_change_ubd`% since `r min_ubd_age`. ####Figure `r x`: Unscheduled acute bed days by age group \newline @@ -112,7 +120,9 @@ x <- x + 1 ### A&E Attendances -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. + +As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. ####Figure `r x`: A&E attendances by geographical area \newline @@ -123,7 +133,9 @@ AandE_loc_ts x <- x + 1 ``` -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the highest A&E attendance rate for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` per 100,000 population for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The lowest A&E attendance rate for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` per 100,000 population for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. + +As presented in Figure `r x`, the highest A&E attendance rate for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` per 100,000 population for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The lowest A&E attendance rate for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` per 100,000 population for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. ####Figure `r x`: A&E attendances by age group \newline @@ -140,7 +152,9 @@ x <- x + 1 ### Emergency Readmissions (28 days) -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. The emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_ae_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. + +As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_ae_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. ####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline @@ -150,7 +164,9 @@ Read_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. The highest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` per 1,000 discharges for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The lowest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` per 1,000 discharges for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. + +As presented in Figure `r x`, the highest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` per 1,000 discharges for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The lowest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` per 1,000 discharges for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. ####Figure `r x`: Emergency readmissions (28 days) by age group \newline @@ -166,7 +182,9 @@ x <- x + 1 ### Delayed Discharge Bed Days -Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. The number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. +Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. + +As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. ####Figure `r x`: Delayed discharge bed days in population aged 65+ by geographical area \newline @@ -179,8 +197,9 @@ x <- x + 1 ### Emergency admissions from a fall -Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. The emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. -The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. + +As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. ####Figure `r x`: Falls in population aged 65+ by geographical area \newline @@ -247,7 +266,9 @@ x <- x + 1 ### Unscheduled Mental Health Specialty Bed Days -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. + +As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. ####Figure `r x`: Unscheduled mental health specialty bed days by geographical area @@ -259,7 +280,9 @@ BDMH_loc_ts x <- x + 1 ``` -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. As presented in Figure `r x`, the highest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` per 100,000 population for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The lowest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` per 100,000 population for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. + +As presented in Figure `r x`, the highest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` per 100,000 population for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The lowest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` per 100,000 population for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. ####Figure `r x`: Unscheduled mental health specialty bed days by age group From cbfd962aff44e6843fcb73cb0f88699c50b653c0 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 7 Aug 2024 10:35:50 +0100 Subject: [PATCH 15/38] Adding to main markdown --- .../Locality_Profiles_Master_Markdown.Rmd | 76 ++++++++++++++++--- .../Unscheduled-Care-Testing-Markdown.Rmd | 2 +- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index 7a61c91..4e9c2b7 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -656,27 +656,30 @@ x <- x + 1 **Summary** -This section includes acute hospital data, delayed discharge bed days and A&E attendances. For the most recent time period available, `r LOCALITY` had: +**For the most recent time periods available, `r LOCALITY` had:** - - **`r latest_emergency_adm_loc`** emergency hospital admissions per 100,000 population, compared to `r scot_emergency_adm` in Scotland. + - **`r latest_emergency_adm_loc1`** emergency hospital admissions per 100,000 population, compared to `r scot_emergency_adm1` in Scotland. - - **`r latest_bed_days_loc`** unscheduled acute specialty bed days per 100,000 population, compared to `r scot_bed_days` in Scotland. + - **`r latest_bed_days_loc1`** unscheduled acute specialty bed days per 100,000 population, compared to `r scot_bed_days1` in Scotland. - - **`r latest_ae_att_loc`** A&E attendances per 100,000 population, compared to `r scot_ae_att` in Scotland. + - **`r latest_ae_att_loc1`** A&E attendances per 100,000 population, compared to `r scot_ae_att1` in Scotland. - - **`r latest_dd_loc`** delayed discharge bed days per 100,000 population aged over 65, compared to `r scot_dd` in Scotland. + - **`r latest_dd_loc1`** delayed discharge bed days per 100,000 population aged over 65, compared to `r scot_dd1` in Scotland. - - **`r latest_falls_loc`** emergency hospital admissions from falls per 100,000 population aged over 65, compared to `r scot_falls` in Scotland. + - **`r latest_falls_loc1`** emergency hospital admissions from falls per 100,000 population aged over 65, compared to `r scot_falls1` in Scotland. - - **`r latest_read_loc`** emergency readmissions (28 days) per 1,000 discharges, compared to `r scot_read` in Scotland. + - **`r latest_read_loc1`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. - - **`r latest_ppa_loc`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa` in Scotland. - + - **`r latest_ppa_loc$data2[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$data2[2]` in Scotland. ##### Page break ### Emergency Admissions +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. + +As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. + #### Figure `r x`: Emergency admissions by geographical area \newline @@ -686,6 +689,10 @@ EAs_loc_ts x <- x + 1 ``` +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_ea_age` to `r max_ea_age` by age group. + +As presented in Figure `r x`, the highest emergency admissions rate for the `r LOCALITY` locality in `r max_ea_age` is `r latest_ea_max_age1` per 100,000 population for the `r age_group_max_ea` age group with a percentage `r max_word_change_ea` of `r max_rate_change_ea`% since `r min_ea_age`. The lowest emergency admissions rate for `r LOCALITY` in `r max_ea_age` is `r latest_ea_min_age1` per 100,000 population for the `r age_group_min_ea` age group with a percentage `r min_word_change_ea` of `r min_rate_change_ea`% since `r min_ea_age`. + #### Figure `r x`: Emergency admissions by age group \newline @@ -699,6 +706,10 @@ x <- x + 1 ### Unscheduled Acute Bed Days +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. + +As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. + #### Figure `r x`: Unscheduled acute bed days by geographical area \newline @@ -708,6 +719,10 @@ BDs_loc_ts x <- x + 1 ``` +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. + +As presented in Figure `r x`, the highest unscheduled bed days rate for the `r LOCALITY` locality in `r max_ubd_age` is `r latest_ubd_max_age1` bed days per 100,000 population for the `r age_group_max_ubd` age group with a percentage `r max_word_change_ubd` of `r max_rate_change_ubd`% since `r min_ubd_age`. The lowest unscheduled bed days rate for `r LOCALITY` in `r max_ubd_age` is `r latest_ubd_min_age1` bed days per 100,000 population for the `r age_group_min_ubd` age group with a percentage `r min_word_change_ubd` of `r min_rate_change_ubd`% since `r min_ubd_age`. + #### Figure `r x`: Unscheduled acute bed days by age group \newline @@ -722,6 +737,10 @@ x <- x + 1 ### A&E Attendances +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. + +As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. + #### Figure `r x`: A&E attendances by geographical area \newline @@ -731,6 +750,10 @@ AandE_loc_ts x <- x + 1 ``` +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. + +As presented in Figure `r x`, the highest A&E attendance rate for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` per 100,000 population for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The lowest A&E attendance rate for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` per 100,000 population for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. + #### Figure `r x`: A&E attendances by age group \newline @@ -745,6 +768,10 @@ x <- x + 1 ### Emergency Readmissions (28 days) +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. + +As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. + #### Figure `r x`: Emergency readmissions (28 days) by geographical area \newline @@ -754,6 +781,10 @@ Read_loc_ts x <- x + 1 ``` +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. + +As presented in Figure `r x`, the highest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` per 1,000 discharges for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The lowest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` per 1,000 discharges for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. + #### Figure `r x`: Emergency readmissions (28 days) by age group \newline @@ -768,6 +799,10 @@ x <- x + 1 ### Delayed Discharge Bed Days +Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. + +As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. + #### Figure `r x`: Delayed discharge bed days in the population aged 65+ by geographical area \newline @@ -779,6 +814,10 @@ x <- x + 1 ### Emergency admissions from a fall +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. + +As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. + #### Figure `r x`: Falls in the population aged 65+ by geographical area \newline @@ -795,6 +834,9 @@ x <- x + 1 Information on the conditions included in PPAs is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. +Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$data2[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. +The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$data2[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$data2[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. + #### Figure `r x`: Potentially Preventable Admissions (PPAs) by geographical area \newline @@ -817,13 +859,17 @@ x <- x + 1 This section looks at mental health-related unscheduled care indicators. For the most recent time period available, `r LOCALITY` had: - - **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp` in Scotland^4^. - - **`r latest_bed_days_mh_loc`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh` in Scotland. + - **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp$measure[2]` in Scotland^4^. + - **`r latest_bed_days_mh_loc1`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh1` in Scotland. \newline ### Psychiatric patient hospitalisations +Figure `r x` presents the psychiatric patient hospitalisation 3-year aggregate rate per 100,000 population in the `r LOCALITY` locality from `r loc_psych_hosp$period_short[1]` to `r loc_psych_hosp$period_short[2]`. + +As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, a `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, a `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, a `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, a `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. + #### Figure `r x`: Psychiatric patient hospitalisations by geographical area \newline @@ -838,6 +884,10 @@ x <- x + 1 ### Unscheduled Mental Health Specialty Bed Days +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. + +As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. + #### Figure `r x`: Unscheduled mental health specialty bed days by geographical area \newline @@ -847,6 +897,10 @@ BDMH_loc_ts x <- x + 1 ``` +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. + +As presented in Figure `r x`, the highest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` per 100,000 population for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The lowest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` per 100,000 population for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. + #### Figure `r x`: Unscheduled mental health specialty bed days by age group \newline diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 3bf485b..e7f204f 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -154,7 +154,7 @@ x <- x + 1 Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. -As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_ae_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. +As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. ####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline From a1be1b5c88702eba47bb82628824ef1a4aa6c237 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 7 Aug 2024 13:37:52 +0100 Subject: [PATCH 16/38] changes to work with render --- Unscheduled Care/2. Unscheduled Care outputs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index c55a714..4366cef 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -29,7 +29,7 @@ library(fst) ### for testing run global script and locality placeholder below ## Functions -source("../Master RMarkdown Document & Render Code/Global Script.R") +# source("../Master RMarkdown Document & Render Code/Global Script.R") ## Define locality # LOCALITY <- "Stirling City with the Eastern Villages Bridge of Allan and Dunblane" From 67db8840ef22c0b299467d60a9a8a3425c4fb35d Mon Sep 17 00:00:00 2001 From: James McMahon Date: Mon, 12 Aug 2024 09:31:09 +0100 Subject: [PATCH 17/38] minor wording and a typo fix --- .../Locality_Profiles_Master_Markdown.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index 4e9c2b7..7c758d8 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -915,11 +915,11 @@ x <- x + 1 ##### Page Break ### Footnotes -1. Population projections are not currently provided by NRS at the locality level. To explore how the population in `r LOCALITY` is expected to change in the future, the percent changes in population projection to 2025 for `r HSCP` by age group and gender were calculated from the NRS Local Authority Population Projections. These percent changes were then applied to the `r LOCALITY` 2018 mid-year population estimates (also split by age group and gender) to obtain population projection estimates for `r LOCALITY`, based on the projections for the HSCP and the current population structure of the locality. +1. Population projections are not currently provided by NRS at the locality level. To explore how the population in `r LOCALITY` is expected to change in the future, the percent changes in population projection to 2025 for `r HSCP` by age group and gender were calculated using the NRS Local Authority Population Projections. These percent changes were then applied to the `r LOCALITY` 2018 mid-year population estimates (also split by age group and gender) to obtain population projection estimates for `r LOCALITY`, based on the projections for the HSCP and the current population structure of the locality. -2. Care Home Data included in the Services Map and Table was sourced from the [Care Inspectorate](https://www.careinspectorate.com/images/documents/5713/MDSF_data_31%20May%202020.csv). [GP Practice](https://www.opendata.nhs.scot/dataset/gp-practice-contact-details-and-list-sizes) data from October 2021, and [Hospital](https://www.opendata.nhs.scot/dataset/hospital-codes) and [A&E](https://www.opendata.nhs.scot/dataset/nhs-scotland-accident-emergency-sites) data was sourced from Public Health Scotland Open Data. Only services that are within the physical boundary of the HSCP or Locality are included in the map and table, so there may be services outside `r HSCP` that people may use but are not shown. Information on access deprivation was taken from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). +2. Care Home data included in the Services Map and Table was sourced from the [Care Inspectorate](https://www.careinspectorate.com/images/documents/5713/MDSF_data_31%20May%202020.csv). [GP Practice](https://www.opendata.nhs.scot/dataset/gp-practice-contact-details-and-list-sizes) data from October 2021, and [Hospital](https://www.opendata.nhs.scot/dataset/hospital-codes) and [A&E](https://www.opendata.nhs.scot/dataset/nhs-scotland-accident-emergency-sites) data was sourced from Public Health Scotland Open Data. Only services that are within the physical boundary of the HSCP or Locality are included in the map and table, so there may be services outside `r HSCP` that people may use but are not shown. Information on access deprivation was taken from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). -3. Sourced from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). There may be more recent data available for the indicators elsewhere. +3. Sourced from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). More recent data may be available for the indicators elsewhere. 4. Data taken from ScotPHO is often reported using the European Age-Sex Standardised Rate per 100,000. This allows for comparisons across different areas to be made. For more information on how these rates are calculated, please refer to [www.isdscotland.org/Products-and-Services/GPD-Support/Population/Standard-Populations/](https://www.isdscotland.org/Products-and-Services/GPD-Support/Population/Standard-Populations/) From 95269e75eb91343cb1705ddfb17809d27f750b7f Mon Sep 17 00:00:00 2001 From: Josie Steele <166606214+JosieSteele@users.noreply.github.com> Date: Wed, 28 Aug 2024 12:29:12 +0100 Subject: [PATCH 18/38] Update Unscheduled Care/2. Unscheduled Care outputs.R Co-authored-by: James McMahon --- Unscheduled Care/2. Unscheduled Care outputs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 4366cef..484f8d1 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -10,7 +10,7 @@ ext_year <- 2023 # Set locality profiles file path -lp_path <- "/conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/" +# lp_path <- "/conf/LIST_analytics/West Hub/02 - Scaled Up Work/RMarkdown/Locality Profiles/" import_folder <- paste0(lp_path, "Unscheduled Care/DATA ", ext_year, "/") ## Packages From 2556257b09b508f305c065e3486c2eaf3c6de39b Mon Sep 17 00:00:00 2001 From: Josie Steele <166606214+JosieSteele@users.noreply.github.com> Date: Wed, 28 Aug 2024 12:55:04 +0100 Subject: [PATCH 19/38] Apply suggestions from code review Typos and wording Co-authored-by: James McMahon --- .../Locality_Profiles_Master_Markdown.Rmd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index 7c758d8..871c504 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -678,7 +678,7 @@ x <- x + 1 Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. -As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. +As presented in Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. #### Figure `r x`: Emergency admissions by geographical area \newline @@ -814,7 +814,7 @@ x <- x + 1 ### Emergency admissions from a fall -Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged 65 and over in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. @@ -832,9 +832,9 @@ x <- x + 1 ### Potentially Preventable Admissions (PPAs) -Information on the conditions included in PPAs is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. +Information on the conditions included in Potentially Preventable Admissions (PPA)s is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. -Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$data2[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. +Figure `r x` presents the PPA rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for PPAs in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$data2[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$data2[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$data2[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. #### Figure `r x`: Potentially Preventable Admissions (PPAs) by geographical area @@ -915,9 +915,9 @@ x <- x + 1 ##### Page Break ### Footnotes -1. Population projections are not currently provided by NRS at the locality level. To explore how the population in `r LOCALITY` is expected to change in the future, the percent changes in population projection to 2025 for `r HSCP` by age group and gender were calculated using the NRS Local Authority Population Projections. These percent changes were then applied to the `r LOCALITY` 2018 mid-year population estimates (also split by age group and gender) to obtain population projection estimates for `r LOCALITY`, based on the projections for the HSCP and the current population structure of the locality. +1. Population projections are not currently provided by the National Records Scotland (NRS) at the locality level. To explore how the population in `r LOCALITY` is expected to change in the future, the percent changes in population projection to 2025 for `r HSCP` by age group and gender were calculated using the NRS Local Authority Population Projections. These percent changes were then applied to the `r LOCALITY` 2018 mid-year population estimates (also split by age group and gender) to obtain population projection estimates for `r LOCALITY`, based on the projections for the HSCP and the current population structure of the locality. -2. Care Home data included in the Services Map and Table was sourced from the [Care Inspectorate](https://www.careinspectorate.com/images/documents/5713/MDSF_data_31%20May%202020.csv). [GP Practice](https://www.opendata.nhs.scot/dataset/gp-practice-contact-details-and-list-sizes) data from October 2021, and [Hospital](https://www.opendata.nhs.scot/dataset/hospital-codes) and [A&E](https://www.opendata.nhs.scot/dataset/nhs-scotland-accident-emergency-sites) data was sourced from Public Health Scotland Open Data. Only services that are within the physical boundary of the HSCP or Locality are included in the map and table, so there may be services outside `r HSCP` that people may use but are not shown. Information on access deprivation was taken from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). +2. Care Home data included in the Services Map and Table was sourced from the [Care Inspectorate](https://www.careinspectorate.com/images/documents/5713/MDSF_data_31%20May%202020.csv). [GP Practice](https://www.opendata.nhs.scot/dataset/gp-practice-contact-details-and-list-sizes) data from October 2021, and [Hospital](https://www.opendata.nhs.scot/dataset/hospital-codes) and [A&E](https://www.opendata.nhs.scot/dataset/nhs-scotland-accident-emergency-sites) data was sourced from Public Health Scotland Open Data platform. Only services that are within the physical boundary of the HSCP or Locality are included in the map and table, so there may be services outside `r HSCP` that people may use but are not shown. Information on access deprivation was taken from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). 3. Sourced from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). More recent data may be available for the indicators elsewhere. From 04bae621f6214853aaf707cb7f43b6bcbebc184e Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Tue, 3 Sep 2024 16:34:22 +0100 Subject: [PATCH 20/38] New link --- .../Locality_Profiles_Master_Markdown.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index 7c758d8..6ec2ec0 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -921,7 +921,7 @@ x <- x + 1 3. Sourced from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). More recent data may be available for the indicators elsewhere. -4. Data taken from ScotPHO is often reported using the European Age-Sex Standardised Rate per 100,000. This allows for comparisons across different areas to be made. For more information on how these rates are calculated, please refer to [www.isdscotland.org/Products-and-Services/GPD-Support/Population/Standard-Populations/](https://www.isdscotland.org/Products-and-Services/GPD-Support/Population/Standard-Populations/) +4. Data taken from ScotPHO is often reported using the European Age-Sex Standardised Rate per 100,000. This allows for comparisons across different areas to be made. For more information on how these rates are calculated, please refer to [https://publichealthscotland.scot/services/geography-population-and-deprivation-support/population/](https://publichealthscotland.scot/services/geography-population-and-deprivation-support/population/) 5. Physical long-term conditions data comes from the Source Linkage Files, and the conditions are identified using ICD-9 and ICD-10 codes in the diagnosis fields. Please note that the Source Linkage Files data only contains information on people who have had contact with the NHS through either inpatient admissions, outpatient attendances, daycase attendances, A&E attendances or through prescribed items, the data does not show all service users in Scotland who have been diagnosed with an LTC as not all of these individuals will have used these services. Also, note that LTC rates are based on an adjusted population indicator in the Source Linkage Files so that population sizes are closer to the official estimates. From 752c4833d4aee69c544639be372e60fc009e0e16 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 4 Sep 2024 09:34:00 +0100 Subject: [PATCH 21/38] Changing filters to drop_na --- .../2. Unscheduled Care outputs.R | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 484f8d1..d5ab185 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -309,7 +309,7 @@ emergency_adm_age <- emergency_adm %>% ungroup() %>% left_join(loc_pop_age1) %>% mutate(data = round_half_up(adm / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) EAs_age_ts <- age_group_trend_usc( @@ -325,7 +325,7 @@ emergency_adm_areas <- emergency_adm %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(n / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) EAs_loc_ts <- area_trend_usc( data_for_plot = emergency_adm_areas, @@ -495,7 +495,7 @@ bed_days_age <- bed_days %>% ungroup() %>% left_join(loc_pop_age1) %>% mutate(data = round_half_up(bed_days / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) BDs_age_ts <- age_group_trend_usc( @@ -512,7 +512,7 @@ bed_days_areas <- bed_days %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(n / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) BDs_loc_ts <- area_trend_usc( data_for_plot = bed_days_areas, @@ -672,7 +672,7 @@ bed_days_mh_age <- bed_days_mh %>% ungroup() %>% left_join(loc_pop_age1) %>% mutate(data = round_half_up(bed_days / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) BDMH_age_ts <- age_group_trend_usc( @@ -689,7 +689,7 @@ bed_days_mh_areas <- bed_days_mh %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(n / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) BDMH_loc_ts <- area_trend_usc( data_for_plot = bed_days_mh_areas, @@ -867,7 +867,7 @@ ae_att_age <- ae_attendances %>% ungroup() %>% left_join(loc_pop_age1) %>% mutate(data = round_half_up(attendances / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) AandE_age_ts <- age_group_trend_usc( @@ -884,7 +884,7 @@ ae_att_areas <- ae_attendances %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(n / pop * 100000))%>% - filter(!is.na(year)) + drop_na(year) AandE_loc_ts <- area_trend_usc( @@ -1069,7 +1069,7 @@ delayed_disch_areas <- delayed_disch %>% aggregate_usc_area_data() %>% left_join(pop_areas_65plus) %>% mutate(data = round_half_up(n / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) DD_loc_ts <- area_trend_usc( data_for_plot = delayed_disch_areas, @@ -1196,7 +1196,7 @@ falls_areas <- falls %>% aggregate_usc_area_data() %>% left_join(pop_areas_65plus) %>% mutate(data = round_half_up(n / pop * 100000)) %>% - filter(!is.na(year)) + drop_na(year) Falls_loc_ts <- area_trend_usc( data_for_plot = falls_areas, @@ -1338,7 +1338,7 @@ read2 <- readmissions %>% readmissions_areas <- left_join(read1, read2) %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(read_28 / discharges * 1000, 1))%>% - filter(!is.na(year)) + drop_na(year) rm(read1, read2) @@ -1572,7 +1572,7 @@ ppa <- arrow::read_parquet(paste0(import_folder, "ppa_smr.parquet")) %>% ppa_total <- ppa %>% rename(n = admissions) %>% aggregate_usc_area_data()%>% - filter(!is.na(year)) + drop_na(year) ppa_65plus <- ppa %>% filter(age_group %in% c("65 - 74", "75+")) %>% @@ -1582,7 +1582,7 @@ ppa_65plus <- ppa %>% left_join(ppa_total, by = c("financial_year", "location")) %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(plus65tot / n * 100, 1))%>% - filter(!is.na(year)) + drop_na(year) latest_ppa_65plus <- ppa_65plus %>% filter( @@ -1599,7 +1599,7 @@ ppa_under65 <- ppa %>% left_join(ppa_total, by = c("financial_year", "location")) %>% left_join(pop_areas_all_ages) %>% mutate(data = round_half_up(under65tot / n * 100, 1)) %>% - filter(!is.na(year)) + drop_na(year) latest_ppa_under65 <- ppa_under65 %>% filter( @@ -1617,7 +1617,7 @@ ppa_areas <- ppa %>% mutate(data = round_half_up(n / pop * 100000)) %>% mutate(location = factor(location, levels = c(LOCALITY, HSCP, HB, "Scotland"))) %>% arrange(location) %>% - filter(!is.na(year)) + drop_na(year) PPA_loc_ts <- area_trend_usc( From 1529dcabab477821add901245799dc68de9b05ce Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 4 Sep 2024 10:33:53 +0100 Subject: [PATCH 22/38] Fixes to filter structure --- .../2. Unscheduled Care outputs.R | 63 ++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index d5ab185..2d709ce 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -341,8 +341,9 @@ max_year_ea <- max(emergency_adm_areas$financial_year) first_fy_rate <- filter( emergency_adm_areas, - (financial_year == min(emergency_adm_areas$financial_year)) & - (location == LOCALITY & area_type == "Locality") + financial_year == min(financial_year), + location == LOCALITY, + area_type == "Locality" )$data latest_emergency_adm_loc <- emergency_adm_areas %>% @@ -373,8 +374,8 @@ hscp_emergency_adm1 <- hscp_emergency_adm %>% pull(data2) hscp_emergency_adm2 <- hscp_emergency_adm %>% pull(data) first_fy_hscp <- filter(emergency_adm_areas, - (financial_year == min(emergency_adm_areas$financial_year)) & - (area_type == "HSCP"))$data + financial_year == min(financial_year), + area_type == "HSCP")$data hscp_rate_change <- round(abs(hscp_emergency_adm2 - first_fy_hscp) / first_fy_hscp * 100, digits = 1) word_change_hscp <- if_else(hscp_emergency_adm2 > first_fy_hscp, "increase", "decrease") @@ -389,9 +390,10 @@ scot_emergency_adm <- emergency_adm_areas %>% scot_emergency_adm1 <- scot_emergency_adm %>% pull(data2) scot_emergency_adm2 <- scot_emergency_adm %>% pull(data) + first_fy_scot <- filter(emergency_adm_areas, - (financial_year == min(emergency_adm_areas$financial_year)) & - (location == "Scotland"))$data + financial_year == min(financial_year), + location == "Scotland")$data scot_rate_change <- round(abs(scot_emergency_adm2 - first_fy_scot) / first_fy_scot * 100, digits = 1) word_change_scot <- if_else(scot_emergency_adm2 > first_fy_scot, @@ -407,9 +409,10 @@ hb_emergency_adm <- emergency_adm_areas %>% hb_emergency_adm1 <- hb_emergency_adm %>% pull(data2) hb_emergency_adm2 <- hb_emergency_adm %>% pull(data) + first_fy_hb <- filter(emergency_adm_areas, - (financial_year == min(emergency_adm_areas$financial_year)) & - (location == HB))$data + financial_year == min(financial_year), + location == HB)$data hb_rate_change <- round(abs(hb_emergency_adm2 - first_fy_hb) / first_fy_hb * 100, digits = 1) word_change_hb <- if_else(hb_emergency_adm2 > first_fy_hb, @@ -528,8 +531,8 @@ max_year_ubd <- max(bed_days_areas$financial_year) #LOCALITY first_fy_rate_ubd <- filter( bed_days_areas, - (financial_year == min(bed_days_areas$financial_year)) & - (location == LOCALITY & area_type == "Locality"))$data + financial_year == min(financial_year), + location == LOCALITY & area_type == "Locality")$data latest_bed_days_loc <- bed_days_areas %>% filter(location == LOCALITY, year == max(year)) %>% @@ -585,8 +588,8 @@ hb_bed_days <- bed_days_areas %>% hb_bed_days1 <- hb_bed_days %>% pull(data2) hb_bed_days2 <- hb_bed_days %>% pull(data) first_fy_hb_ubd <- filter(bed_days_areas, - (financial_year == min(bed_days_areas$financial_year)) & - (location == HB))$data + financial_year == min(financial_year), + location == HB)$data hb_rate_change_ubd <- round(abs(hb_bed_days2 - first_fy_hb_ubd) / first_fy_hb_ubd * 100, digits = 1) word_change_hb_ubd <- if_else(hb_bed_days2 > first_fy_hb_ubd, @@ -830,9 +833,10 @@ hb_mh_beddays <- bed_days_mh_areas %>% hb_mh_beddays1 <- hb_mh_beddays %>% pull(data2) hb_mh_beddays2 <- hb_mh_beddays %>% pull(data) + first_fy_hb_mh <- filter(bed_days_mh_areas, - (financial_year == min(bed_days_mh_areas$financial_year)) & - (location == HB))$data + financial_year == min(financial_year), + location == HB)$data hb_rate_change_mh <- round(abs(hb_mh_beddays2 - first_fy_hb_mh) / first_fy_hb_mh * 100, digits = 1) word_change_hb_mh <- if_else(hb_mh_beddays2 > first_fy_hb_mh, @@ -962,8 +966,8 @@ max_year_ae_area <- max(ae_att_areas$financial_year) first_fy_rate_ae_areas <- filter( ae_att_areas, - (financial_year == min(ae_att_areas$financial_year)) & - (location == LOCALITY & area_type == "Locality") + financial_year == min(financial_year), + location == LOCALITY & area_type == "Locality", )$data latest_ae_att_loc <- ae_att_areas %>% @@ -993,8 +997,8 @@ hscp_ae_att1 <- hscp_ae_att %>% pull(data2) hscp_ae_att2 <- hscp_ae_att %>% pull(data) first_fy_hscp_ae <- filter(ae_att_areas, - (financial_year == min(ae_att_areas$financial_year)) & - (area_type == "HSCP"))$data + financial_year == min(financial_year), + area_type == "HSCP")$data percent_rate_change_ae_areas_hscp <- round(abs(hscp_ae_att2 - first_fy_hscp_ae) / first_fy_hscp_ae * 100, digits = 1) word_change_rate_ae_areas_hscp <- if_else(hscp_ae_att2 > first_fy_hscp_ae, @@ -1012,8 +1016,8 @@ scot_ae_att1 <- scot_ae_att %>% pull(data2) scot_ae_att2 <- scot_ae_att %>% pull(data) first_fy_scot_ae <- filter(ae_att_areas, - (financial_year == min(ae_att_areas$financial_year)) & - (location == "Scotland"))$data + financial_year == min(financial_year), + location == "Scotland")$data percent_rate_change_ae_areas_scot <- round(abs(scot_ae_att2 - first_fy_scot_ae) / first_fy_scot_ae * 100, digits = 1) word_change_rate_ae_areas_scot <- if_else(scot_ae_att2 > first_fy_scot_ae, @@ -1030,8 +1034,8 @@ hb_ae_att <- ae_att_areas %>% hb_ae1 <- hb_ae_att %>% pull(data2) hb_ae2 <- hb_ae_att %>% pull(data) first_fy_hb_ae <- filter(ae_att_areas, - (financial_year == min(ae_att_areas$financial_year)) & - (location == HB))$data + financial_year == min(financial_year), + location == HB)$data hb_rate_change_ae <- round(abs(hb_ae2 - first_fy_hb_ae) / first_fy_hb_ae * 100, digits = 1) word_change_hb_ae <- if_else(hb_ae2 > first_fy_hb_ae, @@ -1162,8 +1166,8 @@ hb_dd <- delayed_disch_areas %>% hb_dd1 <- hb_dd %>% pull(data2) hb_dd2 <- hb_dd %>% pull(data) first_fy_hb_dd <- filter(delayed_disch_areas, - (financial_year == min(delayed_disch_areas$financial_year)) & - (location == HB))$data + financial_year == min(financial_year), + location == HB)$data hb_rate_change_dd <- round(abs(hb_dd2 - first_fy_hb_dd) / first_fy_hb_dd * 100, digits = 1) word_change_hb_dd <- if_else(hb_dd2 > first_fy_hb_dd, @@ -1284,9 +1288,10 @@ hb_falls <- falls_areas %>% hb_falls1 <- hb_falls %>% pull(data2) hb_falls2 <- hb_falls %>% pull(data) + first_fy_hb_falls <- filter(falls_areas, - (financial_year == min(falls_areas$financial_year)) & - (location == HB))$data + financial_year == min(financial_year), + location == HB)$data hb_rate_change_falls <- round(abs(hb_falls2 - first_fy_hb_falls) / first_fy_hb_falls * 100, digits = 1) word_change_hb_falls <- if_else(hb_falls2 > first_fy_hb_falls, @@ -1464,9 +1469,10 @@ hb_read <- readmissions_areas %>% hb_read1 <- hb_read %>% pull(data2) hb_read2 <- hb_read %>% pull(data) + first_fy_hb_read <- filter(readmissions_areas, - (financial_year == min(readmissions_areas$financial_year)) & - (location == HB))$data + financial_year == min(financial_year), + location == HB)$data hb_rate_change_read <- round(abs(hb_read2 - first_fy_hb_read) / first_fy_hb_read * 100, digits = 1) word_change_hb_read <- if_else(hb_read2 > first_fy_hb_read, @@ -1822,3 +1828,4 @@ word_change_scot_psych <- if_else(scot_psych_hosp$measure[2] > scot_psych_hosp$m # "Readmissions 28" = readmissions, # "PPA" = ppa), # path = paste0(lp_path, "Publishing/SMR Data.xlsx")) + From a759679826625180319080c8ab62b47e30da4696 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 4 Sep 2024 10:40:43 +0100 Subject: [PATCH 23/38] Getting rid of commented out bits --- .../2. Unscheduled Care outputs.R | 47 ++++++------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 2d709ce..8f65d80 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -351,8 +351,7 @@ latest_emergency_adm_loc <- emergency_adm_areas %>% location == LOCALITY, year == max(year, na.rm = TRUE) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) + mutate(data2 = format(data, big.mark = ",")) latest_emergency_adm_loc1 <- latest_emergency_adm_loc %>% pull(data2) latest_emergency_adm_loc2 <- latest_emergency_adm_loc %>% pull(data) @@ -367,8 +366,7 @@ hscp_emergency_adm <- emergency_adm_areas %>% location == HSCP, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - # pull(data) + mutate(data2 = format(data, big.mark = ",")) hscp_emergency_adm1 <- hscp_emergency_adm %>% pull(data2) hscp_emergency_adm2 <- hscp_emergency_adm %>% pull(data) @@ -536,9 +534,7 @@ first_fy_rate_ubd <- filter( latest_bed_days_loc <- bed_days_areas %>% filter(location == LOCALITY, year == max(year)) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) - + mutate(data2 = format(data, big.mark = ",")) latest_bed_days_loc1 <- latest_bed_days_loc %>% pull(data2) latest_bed_days_loc2 <- latest_bed_days_loc %>% pull(data) @@ -551,8 +547,7 @@ first_fy_hscp_ubd <- filter( hscp_bed_days <- bed_days_areas %>% filter(location == HSCP, year == max(year)) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) + mutate(data2 = format(data, big.mark = ",")) hscp_bed_days1 <- hscp_bed_days %>% pull(data2) hscp_bed_days2 <- hscp_bed_days %>% pull(data) @@ -567,8 +562,7 @@ first_fy_scot_ubd <- filter( scot_bed_days <- bed_days_areas %>% filter(location == "Scotland", year == max(year)) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) + mutate(data2 = format(data, big.mark = ",")) scot_bed_days1 <- scot_bed_days %>% pull(data2) scot_bed_days2 <- scot_bed_days %>% pull(data) @@ -909,8 +903,7 @@ latest_ae_att_max_age <- ae_att_age %>% year == max(year), data== max(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% -#pull(data) + mutate(data2 = format(data, big.mark = ",")) latest_ae_att_loc1_age <- latest_ae_att_max_age %>% pull(data2) latest_ae_att_loc2_age <- latest_ae_att_max_age %>% pull(data) @@ -921,8 +914,7 @@ first_ae_att_max_age <- ae_att_age %>% year == min(year), age_group == age_group_max ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% -#pull(data) + mutate(data2 = format(data, big.mark = ",")) first_ae_att_max_age_data <- first_ae_att_max_age %>% pull(data) @@ -936,8 +928,7 @@ latest_ae_att_min_age <- ae_att_age %>% filter( data == min(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% -#pull(data) + mutate(data2 = format(data, big.mark = ",")) latest_ae_att_loc1_age_min <- latest_ae_att_min_age %>% pull(data2) latest_ae_att_loc2_age_min <- latest_ae_att_min_age %>% pull(data) @@ -948,8 +939,7 @@ first_ae_att_min_age <- ae_att_age %>% year == min(year), age_group == age_group_min ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% -#pull(data) + mutate(data2 = format(data, big.mark = ",")) first_ae_att_min_data <- first_ae_att_min_age %>% pull(data) @@ -975,8 +965,7 @@ latest_ae_att_loc <- ae_att_areas %>% location == LOCALITY, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) + mutate(data2 = format(data, big.mark = ",")) latest_ae_att_loc1 <- latest_ae_att_loc %>% pull(data2) latest_ae_att_loc2 <- latest_ae_att_loc %>% pull(data) @@ -990,8 +979,7 @@ hscp_ae_att <- ae_att_areas %>% location == HSCP, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) + mutate(data2 = format(data, big.mark = ",")) hscp_ae_att1 <- hscp_ae_att %>% pull(data2) hscp_ae_att2 <- hscp_ae_att %>% pull(data) @@ -1009,9 +997,7 @@ scot_ae_att <- ae_att_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) - + mutate(data2 = format(data, big.mark = ",")) scot_ae_att1 <- scot_ae_att %>% pull(data2) scot_ae_att2 <- scot_ae_att %>% pull(data) @@ -1362,8 +1348,7 @@ latest_re_max_age <- readmissions_age %>% filter( financial_year == max(financial_year), data== max(data) - )#%>% -#pull(data) + ) latest_re_max_age_data <- latest_re_max_age %>% pull(data) latest_re_max_age_group <- latest_re_max_age %>% pull(age_group) @@ -1655,8 +1640,7 @@ hscp_ppa <- ppa_areas %>% location == HSCP, year == max(year) | year == min(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) + mutate(data2 = format(data, big.mark = ",")) ppa_diff_hscp <- round(abs(hscp_ppa$data[2] - hscp_ppa$data[1]) / hscp_ppa$data[1]* 100, digits = 1) ppa_word_change_hscp <- if_else(hscp_ppa$data[2] > hscp_ppa$data[1], @@ -1667,8 +1651,7 @@ scot_ppa <- ppa_areas %>% location == "Scotland", year == max(year) | year == min(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) #%>% - #pull(data) + mutate(data2 = format(data, big.mark = ",")) diff_scot_ppa <- round(abs(scot_ppa$data[2] - scot_ppa$data[1]) / scot_ppa$data[1] * 100, digits = 1) word_change_scot_ppa <- if_else(scot_ppa$data[2] > scot_ppa$data[1], From fb67c62707a5adafaafdafbe9904606b790ff8ab Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 4 Sep 2024 10:51:41 +0100 Subject: [PATCH 24/38] Changing variable names --- .../Locality_Profiles_Master_Markdown.Rmd | 6 +- .../2. Unscheduled Care outputs.R | 144 +++++++++--------- .../Unscheduled-Care-Testing-Markdown.Rmd | 6 +- 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index 44f2019..a0c1134 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -670,7 +670,7 @@ x <- x + 1 - **`r latest_read_loc1`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. - - **`r latest_ppa_loc$data2[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$data2[2]` in Scotland. + - **`r latest_ppa_loc$formatted_data[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$formatted_data[2]` in Scotland. ##### Page break @@ -834,8 +834,8 @@ x <- x + 1 Information on the conditions included in Potentially Preventable Admissions (PPA)s is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. -Figure `r x` presents the PPA rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for PPAs in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$data2[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. -The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$data2[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$data2[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. +Figure `r x` presents the PPA rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for PPAs in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. +The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. #### Figure `r x`: Potentially Preventable Admissions (PPAs) by geographical area \newline diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 8f65d80..1f778d4 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -351,9 +351,9 @@ latest_emergency_adm_loc <- emergency_adm_areas %>% location == LOCALITY, year == max(year, na.rm = TRUE) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_emergency_adm_loc1 <- latest_emergency_adm_loc %>% pull(data2) +latest_emergency_adm_loc1 <- latest_emergency_adm_loc %>% pull(formatted_data) latest_emergency_adm_loc2 <- latest_emergency_adm_loc %>% pull(data) percent_rate_change <- round(abs(latest_emergency_adm_loc2 - first_fy_rate) / first_fy_rate * 100, digits = 1) @@ -366,9 +366,9 @@ hscp_emergency_adm <- emergency_adm_areas %>% location == HSCP, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hscp_emergency_adm1 <- hscp_emergency_adm %>% pull(data2) +hscp_emergency_adm1 <- hscp_emergency_adm %>% pull(formatted_data) hscp_emergency_adm2 <- hscp_emergency_adm %>% pull(data) first_fy_hscp <- filter(emergency_adm_areas, @@ -384,9 +384,9 @@ scot_emergency_adm <- emergency_adm_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -scot_emergency_adm1 <- scot_emergency_adm %>% pull(data2) +scot_emergency_adm1 <- scot_emergency_adm %>% pull(formatted_data) scot_emergency_adm2 <- scot_emergency_adm %>% pull(data) first_fy_scot <- filter(emergency_adm_areas, @@ -403,9 +403,9 @@ hb_emergency_adm <- emergency_adm_areas %>% location == HB, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hb_emergency_adm1 <- hb_emergency_adm %>% pull(data2) +hb_emergency_adm1 <- hb_emergency_adm %>% pull(formatted_data) hb_emergency_adm2 <- hb_emergency_adm %>% pull(data) first_fy_hb <- filter(emergency_adm_areas, @@ -438,9 +438,9 @@ latest_ea_max_age <- emergency_adm_age %>% filter( data== max(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_ea_max_age1 <- latest_ea_max_age %>% pull(data2) +latest_ea_max_age1 <- latest_ea_max_age %>% pull(formatted_data) latest_ea_max_age2 <- latest_ea_max_age %>% pull(data) age_group_max_ea <- latest_ea_max_age %>% pull(age_group) @@ -461,9 +461,9 @@ latest_ea_min_age <- emergency_adm_age %>% filter( data== min(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_ea_min_age1 <- latest_ea_min_age %>% pull(data2) +latest_ea_min_age1 <- latest_ea_min_age %>% pull(formatted_data) latest_ea_min_age2 <- latest_ea_min_age %>% pull(data) age_group_min_ea <- latest_ea_min_age %>% pull(age_group) @@ -534,8 +534,8 @@ first_fy_rate_ubd <- filter( latest_bed_days_loc <- bed_days_areas %>% filter(location == LOCALITY, year == max(year)) %>% - mutate(data2 = format(data, big.mark = ",")) -latest_bed_days_loc1 <- latest_bed_days_loc %>% pull(data2) + mutate(formatted_data = format(data, big.mark = ",")) +latest_bed_days_loc1 <- latest_bed_days_loc %>% pull(formatted_data) latest_bed_days_loc2 <- latest_bed_days_loc %>% pull(data) rate_change_ubd <- round(abs(latest_bed_days_loc2 - first_fy_rate_ubd) / first_fy_rate_ubd * 100, digits = 1) @@ -547,9 +547,9 @@ first_fy_hscp_ubd <- filter( hscp_bed_days <- bed_days_areas %>% filter(location == HSCP, year == max(year)) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hscp_bed_days1 <- hscp_bed_days %>% pull(data2) +hscp_bed_days1 <- hscp_bed_days %>% pull(formatted_data) hscp_bed_days2 <- hscp_bed_days %>% pull(data) hscp_rate_ubd <- round(abs(hscp_bed_days2 - first_fy_hscp_ubd) / first_fy_hscp_ubd * 100, digits = 1) @@ -562,9 +562,9 @@ first_fy_scot_ubd <- filter( scot_bed_days <- bed_days_areas %>% filter(location == "Scotland", year == max(year)) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -scot_bed_days1 <- scot_bed_days %>% pull(data2) +scot_bed_days1 <- scot_bed_days %>% pull(formatted_data) scot_bed_days2 <- scot_bed_days %>% pull(data) scot_rate_ubd <- round(abs(scot_bed_days2 - first_fy_scot_ubd) / first_fy_scot_ubd * 100, digits = 1) @@ -577,9 +577,9 @@ hb_bed_days <- bed_days_areas %>% location == HB, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hb_bed_days1 <- hb_bed_days %>% pull(data2) +hb_bed_days1 <- hb_bed_days %>% pull(formatted_data) hb_bed_days2 <- hb_bed_days %>% pull(data) first_fy_hb_ubd <- filter(bed_days_areas, financial_year == min(financial_year), @@ -611,9 +611,9 @@ latest_ubd_max_age <- bed_days_age %>% filter( data== max(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_ubd_max_age1 <- latest_ubd_max_age %>% pull(data2) +latest_ubd_max_age1 <- latest_ubd_max_age %>% pull(formatted_data) latest_ubd_max_age2 <- latest_ubd_max_age %>% pull(data) age_group_max_ubd <- latest_ubd_max_age %>% pull(age_group) @@ -634,9 +634,9 @@ latest_ubd_min_age <- bed_days_age %>% filter( data== min(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_ubd_min_age1 <- latest_ubd_min_age %>% pull(data2) +latest_ubd_min_age1 <- latest_ubd_min_age %>% pull(formatted_data) latest_ubd_min_age2 <- latest_ubd_min_age %>% pull(data) age_group_min_ubd <- latest_ubd_min_age %>% pull(age_group) @@ -706,9 +706,9 @@ latest_bd_mh_max_age <- bed_days_mh_age %>% filter( data== max(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_bd_mh_max_age1 <- latest_bd_mh_max_age %>% pull(data2) +latest_bd_mh_max_age1 <- latest_bd_mh_max_age %>% pull(formatted_data) latest_bd_mh_max_age2 <- latest_bd_mh_max_age %>% pull(data) age_group_max_mh <- latest_bd_mh_max_age %>% pull(age_group) @@ -729,9 +729,9 @@ latest_bd_mh_min_age <- bed_days_mh_age %>% filter( data== min(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_bd_mh_min_age1 <- latest_bd_mh_min_age %>% pull(data2) +latest_bd_mh_min_age1 <- latest_bd_mh_min_age %>% pull(formatted_data) latest_bd_mh_min_age2 <- latest_bd_mh_min_age %>% pull(data) age_group_min_mh <- latest_bd_mh_min_age %>% pull(age_group) @@ -758,9 +758,9 @@ latest_bed_days_mh_loc <- bed_days_mh_areas %>% location == LOCALITY, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_bed_days_mh_loc1 <- latest_bed_days_mh_loc %>% pull(data2) +latest_bed_days_mh_loc1 <- latest_bed_days_mh_loc %>% pull(formatted_data) latest_bed_days_mh_loc2 <- latest_bed_days_mh_loc %>% pull(data) latest_bed_days_mh_loc1 <- ifelse(is_empty(latest_bed_days_mh_loc1), "NA", latest_bed_days_mh_loc1) @@ -780,9 +780,9 @@ hscp_bed_days_mh <- bed_days_mh_areas %>% location == HSCP, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hscp_bed_days_mh1 <- hscp_bed_days_mh %>% pull(data2) +hscp_bed_days_mh1 <- hscp_bed_days_mh %>% pull(formatted_data) hscp_bed_days_mh2 <- hscp_bed_days_mh %>% pull(data) first_hscp_bed_days_mh <- bed_days_mh_areas %>% @@ -801,9 +801,9 @@ scot_bed_days_mh <- bed_days_mh_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -scot_bed_days_mh1 <- scot_bed_days_mh %>% pull(data2) +scot_bed_days_mh1 <- scot_bed_days_mh %>% pull(formatted_data) scot_bed_days_mh2 <- scot_bed_days_mh %>% pull(data) first_scot_bed_days_mh <- bed_days_mh_areas %>% @@ -823,9 +823,9 @@ hb_mh_beddays <- bed_days_mh_areas %>% location == HB, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hb_mh_beddays1 <- hb_mh_beddays %>% pull(data2) +hb_mh_beddays1 <- hb_mh_beddays %>% pull(formatted_data) hb_mh_beddays2 <- hb_mh_beddays %>% pull(data) first_fy_hb_mh <- filter(bed_days_mh_areas, @@ -903,9 +903,9 @@ latest_ae_att_max_age <- ae_att_age %>% year == max(year), data== max(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_ae_att_loc1_age <- latest_ae_att_max_age %>% pull(data2) +latest_ae_att_loc1_age <- latest_ae_att_max_age %>% pull(formatted_data) latest_ae_att_loc2_age <- latest_ae_att_max_age %>% pull(data) age_group_max <- latest_ae_att_max_age %>% pull(age_group) @@ -914,7 +914,7 @@ first_ae_att_max_age <- ae_att_age %>% year == min(year), age_group == age_group_max ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) first_ae_att_max_age_data <- first_ae_att_max_age %>% pull(data) @@ -928,9 +928,9 @@ latest_ae_att_min_age <- ae_att_age %>% filter( data == min(data) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_ae_att_loc1_age_min <- latest_ae_att_min_age %>% pull(data2) +latest_ae_att_loc1_age_min <- latest_ae_att_min_age %>% pull(formatted_data) latest_ae_att_loc2_age_min <- latest_ae_att_min_age %>% pull(data) age_group_min <- latest_ae_att_min_age %>% pull(age_group) @@ -939,7 +939,7 @@ first_ae_att_min_age <- ae_att_age %>% year == min(year), age_group == age_group_min ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) first_ae_att_min_data <- first_ae_att_min_age %>% pull(data) @@ -965,9 +965,9 @@ latest_ae_att_loc <- ae_att_areas %>% location == LOCALITY, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_ae_att_loc1 <- latest_ae_att_loc %>% pull(data2) +latest_ae_att_loc1 <- latest_ae_att_loc %>% pull(formatted_data) latest_ae_att_loc2 <- latest_ae_att_loc %>% pull(data) percent_rate_change_ae_areas <- round(abs(latest_ae_att_loc2 - first_fy_rate_ae_areas) / first_fy_rate_ae_areas * 100, digits = 1) @@ -979,9 +979,9 @@ hscp_ae_att <- ae_att_areas %>% location == HSCP, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hscp_ae_att1 <- hscp_ae_att %>% pull(data2) +hscp_ae_att1 <- hscp_ae_att %>% pull(formatted_data) hscp_ae_att2 <- hscp_ae_att %>% pull(data) first_fy_hscp_ae <- filter(ae_att_areas, @@ -997,8 +997,8 @@ scot_ae_att <- ae_att_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) -scot_ae_att1 <- scot_ae_att %>% pull(data2) + mutate(formatted_data = format(data, big.mark = ",")) +scot_ae_att1 <- scot_ae_att %>% pull(formatted_data) scot_ae_att2 <- scot_ae_att %>% pull(data) first_fy_scot_ae <- filter(ae_att_areas, @@ -1015,9 +1015,9 @@ hb_ae_att <- ae_att_areas %>% location == HB, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hb_ae1 <- hb_ae_att %>% pull(data2) +hb_ae1 <- hb_ae_att %>% pull(formatted_data) hb_ae2 <- hb_ae_att %>% pull(data) first_fy_hb_ae <- filter(ae_att_areas, financial_year == min(financial_year), @@ -1081,9 +1081,9 @@ latest_dd_loc <- delayed_disch_areas %>% location == LOCALITY, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_dd_loc1 <- latest_dd_loc %>% pull(data2) +latest_dd_loc1 <- latest_dd_loc %>% pull(formatted_data) latest_dd_loc2 <- latest_dd_loc %>% pull(data) first_dd_loc <- delayed_disch_areas %>% @@ -1103,9 +1103,9 @@ hscp_dd <- delayed_disch_areas %>% location == HSCP, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hscp_dd1 <- hscp_dd %>% pull(data2) +hscp_dd1 <- hscp_dd %>% pull(formatted_data) hscp_dd2 <- hscp_dd %>% pull(data) first_hscp_dd <- delayed_disch_areas %>% @@ -1125,9 +1125,9 @@ scot_dd <- delayed_disch_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -scot_dd1 <- scot_dd %>% pull(data2) +scot_dd1 <- scot_dd %>% pull(formatted_data) scot_dd2 <- scot_dd %>% pull(data) first_scot_dd <- delayed_disch_areas %>% @@ -1147,9 +1147,9 @@ hb_dd <- delayed_disch_areas %>% location == HB, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hb_dd1 <- hb_dd %>% pull(data2) +hb_dd1 <- hb_dd %>% pull(formatted_data) hb_dd2 <- hb_dd %>% pull(data) first_fy_hb_dd <- filter(delayed_disch_areas, financial_year == min(financial_year), @@ -1208,9 +1208,9 @@ latest_falls_loc <- falls_areas %>% location == LOCALITY, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -latest_falls_loc1 <- latest_falls_loc %>% pull(data2) +latest_falls_loc1 <- latest_falls_loc %>% pull(formatted_data) latest_falls_loc2 <- latest_falls_loc %>% pull(data) first_falls_loc <- falls_areas %>% @@ -1228,9 +1228,9 @@ hscp_falls <- falls_areas %>% location == HSCP, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hscp_falls1 <- hscp_falls %>% pull(data2) +hscp_falls1 <- hscp_falls %>% pull(formatted_data) hscp_falls2 <- hscp_falls %>% pull(data) first_falls_hscp <- falls_areas %>% @@ -1248,9 +1248,9 @@ scot_falls <- falls_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -scot_falls1 <- scot_falls %>% pull(data2) +scot_falls1 <- scot_falls %>% pull(formatted_data) scot_falls2 <- scot_falls %>% pull(data) first_falls_scot <- falls_areas %>% @@ -1270,9 +1270,9 @@ hb_falls <- falls_areas %>% location == HB, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hb_falls1 <- hb_falls %>% pull(data2) +hb_falls1 <- hb_falls %>% pull(formatted_data) hb_falls2 <- hb_falls %>% pull(data) first_fy_hb_falls <- filter(falls_areas, @@ -1450,9 +1450,9 @@ hb_read <- readmissions_areas %>% location == HB, year == max(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -hb_read1 <- hb_read %>% pull(data2) +hb_read1 <- hb_read %>% pull(formatted_data) hb_read2 <- hb_read %>% pull(data) first_fy_hb_read <- filter(readmissions_areas, @@ -1629,7 +1629,7 @@ latest_ppa_loc <- ppa_areas %>% location == LOCALITY, year == max(year) | year == min(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) ppa_diff <- round(abs(latest_ppa_loc$data[2] - latest_ppa_loc$data[1]) / latest_ppa_loc$data[1]* 100, digits = 1) ppa_word_change <- if_else(latest_ppa_loc$data[2] > latest_ppa_loc$data[1], @@ -1640,7 +1640,7 @@ hscp_ppa <- ppa_areas %>% location == HSCP, year == max(year) | year == min(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) ppa_diff_hscp <- round(abs(hscp_ppa$data[2] - hscp_ppa$data[1]) / hscp_ppa$data[1]* 100, digits = 1) ppa_word_change_hscp <- if_else(hscp_ppa$data[2] > hscp_ppa$data[1], @@ -1651,7 +1651,7 @@ scot_ppa <- ppa_areas %>% location == "Scotland", year == max(year) | year == min(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) diff_scot_ppa <- round(abs(scot_ppa$data[2] - scot_ppa$data[1]) / scot_ppa$data[1] * 100, digits = 1) word_change_scot_ppa <- if_else(scot_ppa$data[2] > scot_ppa$data[1], @@ -1663,7 +1663,7 @@ hb_ppa <- ppa_areas %>% location == HB, year == max(year) | year == min(year) ) %>% - mutate(data2 = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) diff_hb_ppa <- round(abs(hb_ppa$data[2] - hb_ppa$data[1]) / hb_ppa$data[1] * 100, digits = 1) word_change_hb_ppa <- if_else(hb_ppa$data[2] > hb_ppa$data[1], diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index e7f204f..b4d13b6 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -52,7 +52,7 @@ This section includes acute hospital data, delayed discharge bed days and A&E at - **`r latest_read_loc1`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. - - **`r latest_ppa_loc$data2[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$data2[2]` in Scotland. + - **`r latest_ppa_loc$formatted_data[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$formatted_data[2]` in Scotland. #####Pagebreak @@ -218,8 +218,8 @@ x <- x + 1 Information conditions included in PPAs is available in Appendix 3. In `r max_year_ppa_areas`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. -Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$data2[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. -The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$data2[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$data2[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. +Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. +The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. ####Figure `r x`: PPAs by geographical area \newline From d55c2fa2015189a90aa857dd96d423496246b578 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 4 Sep 2024 11:29:40 +0100 Subject: [PATCH 25/38] Helper functions --- .../2. Unscheduled Care outputs.R | 104 +++++++++--------- 1 file changed, 50 insertions(+), 54 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 1f778d4..103cca7 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -33,7 +33,7 @@ library(fst) ## Define locality # LOCALITY <- "Stirling City with the Eastern Villages Bridge of Allan and Dunblane" - LOCALITY <- "Inverness" +# LOCALITY <- "Inverness" # LOCALITY <- "Ayr North and Former Coalfield Communities" # LOCALITY <- "Whalsay and Skerries" # LOCALITY <- "North Perthshire" @@ -291,6 +291,19 @@ area_trend_usc <- function(data_for_plot, plot_title, yaxis_title, source) { ) } +# Functions for variables + +percent_change_calc <- function(numerator, denominator) { + round(abs(numerator - denominator) / denominator* 100, digits = 1) +} + +word_change_calc <- function(latest, first) { + case_when( + near(latest, first) ~ "same", + latest > first ~ "increase", + latest < first ~ "decrease" + ) +} ####################### SECTION 4: Data manipulation & outputs ######################### @@ -356,9 +369,8 @@ latest_emergency_adm_loc <- emergency_adm_areas %>% latest_emergency_adm_loc1 <- latest_emergency_adm_loc %>% pull(formatted_data) latest_emergency_adm_loc2 <- latest_emergency_adm_loc %>% pull(data) -percent_rate_change <- round(abs(latest_emergency_adm_loc2 - first_fy_rate) / first_fy_rate * 100, digits = 1) -word_change_rate <- if_else(latest_emergency_adm_loc2 > first_fy_rate, - "increase", "decrease") +percent_rate_change <- percent_change_calc(latest_emergency_adm_loc2, first_fy_rate) +word_change_rate <- word_change_calc(latest_emergency_adm_loc2, first_fy_rate) #HSCP hscp_emergency_adm <- emergency_adm_areas %>% @@ -918,9 +930,8 @@ first_ae_att_max_age <- ae_att_age %>% first_ae_att_max_age_data <- first_ae_att_max_age %>% pull(data) -percent_rate_change_ae_age <- round(abs(latest_ae_att_loc2_age - first_ae_att_max_age_data) / first_ae_att_max_age_data * 100, digits = 1) -word_change_rate_ae_age <- if_else(latest_ae_att_loc2_age > first_ae_att_max_age_data, - "increase", "decrease") +percent_rate_change_ae_age <- percent_change_calc(latest_ae_att_loc2_age, first_ae_att_max_age_data) +word_change_rate_ae_age <- word_change_calc(latest_ae_att_loc2_age, first_ae_att_max_age_data) latest_ae_att_min_age <- ae_att_age %>% filter( @@ -943,10 +954,8 @@ first_ae_att_min_age <- ae_att_age %>% first_ae_att_min_data <- first_ae_att_min_age %>% pull(data) -percent_rate_change_ae_age2 <- round(abs(latest_ae_att_loc2_age_min - first_ae_att_min_data) / first_ae_att_min_data * 100, digits = 1) -word_change_rate_ae_age2 <- if_else(latest_ae_att_loc2_age_min > first_ae_att_min_data, - "increase", "decrease") - +percent_rate_change_ae_age2 <- percent_change_calc(latest_ae_att_loc2_age_min, first_ae_att_min_data) +word_change_rate_ae_age2 <- word_change_calc(latest_ae_att_loc2_age_min, first_ae_att_min_data) # Objects for text and summary table- area @@ -970,9 +979,8 @@ latest_ae_att_loc <- ae_att_areas %>% latest_ae_att_loc1 <- latest_ae_att_loc %>% pull(formatted_data) latest_ae_att_loc2 <- latest_ae_att_loc %>% pull(data) -percent_rate_change_ae_areas <- round(abs(latest_ae_att_loc2 - first_fy_rate_ae_areas) / first_fy_rate_ae_areas * 100, digits = 1) -word_change_rate_ae_areas <- if_else(latest_ae_att_loc2 > first_fy_rate_ae_areas, - "increase", "decrease") +percent_rate_change_ae_areas <- percent_change_calc(latest_ae_att_loc2, first_fy_rate_ae_areas) +word_change_rate_ae_areas <- word_change_calc(latest_ae_att_loc2, first_fy_rate_ae_areas) hscp_ae_att <- ae_att_areas %>% filter( @@ -988,9 +996,8 @@ first_fy_hscp_ae <- filter(ae_att_areas, financial_year == min(financial_year), area_type == "HSCP")$data -percent_rate_change_ae_areas_hscp <- round(abs(hscp_ae_att2 - first_fy_hscp_ae) / first_fy_hscp_ae * 100, digits = 1) -word_change_rate_ae_areas_hscp <- if_else(hscp_ae_att2 > first_fy_hscp_ae, - "increase", "decrease") +percent_rate_change_ae_areas_hscp <- percent_change_calc(hscp_ae_att2, first_fy_hscp_ae) +word_change_rate_ae_areas_hscp <- word_change_calc(hscp_ae_att2, first_fy_hscp_ae) scot_ae_att <- ae_att_areas %>% filter( @@ -1005,9 +1012,8 @@ first_fy_scot_ae <- filter(ae_att_areas, financial_year == min(financial_year), location == "Scotland")$data -percent_rate_change_ae_areas_scot <- round(abs(scot_ae_att2 - first_fy_scot_ae) / first_fy_scot_ae * 100, digits = 1) -word_change_rate_ae_areas_scot <- if_else(scot_ae_att2 > first_fy_scot_ae, - "increase", "decrease") +percent_rate_change_ae_areas_scot <- percent_change_calc(scot_ae_att2, first_fy_scot_ae) +word_change_rate_ae_areas_scot <- word_change_calc(scot_ae_att2, first_fy_scot_ae) #NHS health board hb_ae_att <- ae_att_areas %>% @@ -1093,9 +1099,8 @@ first_dd_loc <- delayed_disch_areas %>% ) %>% pull(data) -percent_rate_change_dd_loc <- round(abs(latest_dd_loc2 - first_dd_loc) / first_dd_loc * 100, digits = 1) -word_change_rate_dd_loc <- if_else(latest_dd_loc2 > first_dd_loc, - "increase", "decrease") +percent_rate_change_dd_loc <- percent_change_calc(latest_dd_loc2, first_dd_loc) +word_change_rate_dd_loc <- word_change_calc(latest_dd_loc2, first_dd_loc) hscp_dd <- delayed_disch_areas %>% @@ -1115,9 +1120,8 @@ first_hscp_dd <- delayed_disch_areas %>% ) %>% pull(data) -percent_rate_change_dd_hscp <- round(abs(hscp_dd2 - first_hscp_dd) / first_hscp_dd * 100, digits = 1) -word_change_rate_dd_hscp <- if_else(hscp_dd2 > first_hscp_dd, - "increase", "decrease") +percent_rate_change_dd_hscp <- percent_change_calc(hscp_dd2, first_hscp_dd) +word_change_rate_dd_hscp <- word_change_calc(hscp_dd2, first_hscp_dd) scot_dd <- delayed_disch_areas %>% @@ -1137,9 +1141,8 @@ first_scot_dd <- delayed_disch_areas %>% ) %>% pull(data) -percent_rate_change_dd_scot <- round(abs(scot_dd2 - first_scot_dd) / first_scot_dd * 100, digits = 1) -word_change_rate_dd_scot <- if_else(scot_dd2 > first_scot_dd, - "increase", "decrease") +percent_rate_change_dd_scot <- percent_change_calc(scot_dd2, first_scot_dd) +word_change_rate_dd_scot <- word_change_calc(scot_dd2, first_scot_dd) #NHS health board hb_dd <- delayed_disch_areas %>% @@ -1220,9 +1223,9 @@ first_falls_loc <- falls_areas %>% ) %>% pull(data) -percent_rate_change_falls_loc <- round(abs(latest_falls_loc2 - first_falls_loc) / first_falls_loc * 100, digits = 1) -word_change_rate_falls_loc <- if_else(latest_falls_loc2 > first_falls_loc, - "increase", "decrease") +percent_rate_change_falls_loc <- percent_change_calc(latest_falls_loc2, first_falls_loc) +word_change_rate_falls_loc <- word_change_calc(latest_falls_loc2, first_falls_loc) + hscp_falls <- falls_areas %>% filter( location == HSCP, @@ -1240,9 +1243,9 @@ first_falls_hscp <- falls_areas %>% ) %>% pull(data) -percent_rate_change_falls_hscp<- round(abs(hscp_falls2 - first_falls_hscp) / first_falls_hscp * 100, digits = 1) -word_change_rate_falls_hscp <- if_else(hscp_falls2 > first_falls_hscp, - "increase", "decrease") +percent_rate_change_falls_hscp<- percent_change_calc(hscp_falls2, first_falls_hscp) +word_change_rate_falls_hscp <- word_change_calc(hscp_falls2, first_falls_hscp) + scot_falls <- falls_areas %>% filter( location == "Scotland", @@ -1260,9 +1263,8 @@ first_falls_scot <- falls_areas %>% ) %>% pull(data) -percent_rate_change_falls_scot<- round(abs(scot_falls2 - first_falls_scot) / first_falls_scot * 100, digits = 1) -word_change_rate_falls_scot <- if_else(scot_falls2 > first_falls_scot, - "increase", "decrease") +percent_rate_change_falls_scot<- percent_change_calc(scot_falls2, first_falls_scot) +word_change_rate_falls_scot <- word_change_calc(scot_falls2, first_falls_scot) #NHS health board hb_falls <- falls_areas %>% @@ -1361,9 +1363,8 @@ first_re_max_age <- readmissions_age %>% pull(data) -percent_rate_change_re_age <- round(abs(latest_re_max_age_data - first_re_max_age) / first_re_max_age * 100, digits = 1) -word_change_rate_re_age <- if_else(latest_re_max_age_data > first_re_max_age, - "increase", "decrease") +percent_rate_change_re_age <- percent_change_calc(latest_re_max_age_data, first_re_max_age) +word_change_rate_re_age <- word_change_calc(latest_re_max_age_data, first_re_max_age) latest_re_min_age <- readmissions_age %>% filter( @@ -1380,10 +1381,8 @@ first_re_min_age <- readmissions_age %>% ) %>% pull(data) -percent_rate_change_re_age_min <- round(abs(latest_re_min_age_data - first_re_min_age) / first_re_min_age * 100, digits = 1) -word_change_rate_re_age_min <- if_else(latest_re_min_age_data > first_re_min_age, - "increase", "decrease") - +percent_rate_change_re_age_min <- percent_change_calc(latest_re_min_age_data, first_re_min_age) +word_change_rate_re_age_min <- word_change_calc(latest_re_min_age_data, first_re_min_age) # Objects for text and summary table-area min_year_re_area <- min(readmissions_areas$financial_year) @@ -1403,9 +1402,8 @@ latest_read_loc <- readmissions_areas %>% latest_read_loc1 <-latest_read_loc %>% pull(data) -percent_rate_change_re_area <- round(abs(latest_read_loc1 - first_read_loc1) / first_read_loc1 * 100, digits = 1) -word_change_rate_re_area <- if_else(latest_read_loc1 > first_read_loc1, - "increase", "decrease") +percent_rate_change_re_area <- percent_change_calc(latest_read_loc1, first_read_loc1) +word_change_rate_re_area <- word_change_calc(latest_read_loc1, first_read_loc1) first_hscp_read <- readmissions_areas %>% filter( @@ -1421,9 +1419,8 @@ hscp_read <- readmissions_areas %>% ) %>% pull(data) -percent_rate_change_re_area_hscp <- round(abs(hscp_read - first_hscp_read) / first_hscp_read * 100, digits = 1) -word_change_rate_re_area_hscp <- if_else(hscp_read > first_hscp_read, - "increase", "decrease") +percent_rate_change_re_area_hscp <- percent_change_calc(hscp_read, first_hscp_read) +word_change_rate_re_area_hscp <- word_change_calc(hscp_read, first_hscp_read) first_scot_read <- readmissions_areas %>% filter( @@ -1440,9 +1437,8 @@ scot_read <- readmissions_areas %>% ) %>% pull(data) -percent_rate_change_re_area_scot <- round(abs(scot_read - first_scot_read) / first_scot_read * 100, digits = 1) -word_change_rate_re_area_scot <- if_else(scot_read > first_scot_read, - "increase", "decrease") +percent_rate_change_re_area_scot <- percent_change_calc(scot_read, first_scot_read) +word_change_rate_re_area_scot <- word_change_calc(scot_read, first_scot_read) #NHS health board hb_read <- readmissions_areas %>% From 50598fc5c92f9c6e12eba926a9f9d18e4a85c003 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 26 Sep 2024 16:45:45 +0100 Subject: [PATCH 26/38] Use `percent_change_calc` consistently. --- .../2. Unscheduled Care outputs.R | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index e981c73..7064111 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -384,7 +384,7 @@ first_fy_hscp <- filter(emergency_adm_areas, financial_year == min(financial_year), area_type == "HSCP")$data -hscp_rate_change <- round(abs(hscp_emergency_adm2 - first_fy_hscp) / first_fy_hscp * 100, digits = 1) +hscp_rate_change <- percent_change_calc(hscp_emergency_adm2, first_fy_hscp) word_change_hscp <- if_else(hscp_emergency_adm2 > first_fy_hscp, "increase", "decrease") #Scotland @@ -402,7 +402,7 @@ first_fy_scot <- filter(emergency_adm_areas, financial_year == min(financial_year), location == "Scotland")$data -scot_rate_change <- round(abs(scot_emergency_adm2 - first_fy_scot) / first_fy_scot * 100, digits = 1) +scot_rate_change <- percent_change_calc(scot_emergency_adm2, first_fy_scot) word_change_scot <- if_else(scot_emergency_adm2 > first_fy_scot, "increase", "decrease") @@ -421,7 +421,7 @@ first_fy_hb <- filter(emergency_adm_areas, financial_year == min(financial_year), location == HB)$data -hb_rate_change <- round(abs(hb_emergency_adm2 - first_fy_hb) / first_fy_hb * 100, digits = 1) +hb_rate_change <- percent_change_calc(hb_emergency_adm2, first_fy_hb) word_change_hb <- if_else(hb_emergency_adm2 > first_fy_hb, "increase", "decrease") @@ -460,7 +460,7 @@ first_ea_max_age <- emergency_adm_age %>% ) %>% pull(data) -max_rate_change_ea <- round(abs(latest_ea_max_age2 - first_ea_max_age) / first_ea_max_age * 100, digits = 1) +max_rate_change_ea <- percent_change_calc(latest_ea_max_age2, first_ea_max_age) max_word_change_ea <- if_else(latest_ea_max_age2 > first_ea_max_age, "increase", "decrease") @@ -486,7 +486,7 @@ first_ea_min_age1 <- first_ea_min_age %>% pull(data) min_year_ea_age1<- first_ea_min_age %>% pull(year) -min_rate_change_ea <- round(abs(latest_ea_min_age2 - first_ea_min_age1) / first_ea_min_age1 * 100, digits = 1) +min_rate_change_ea <- percent_change_calc(latest_ea_min_age2, first_ea_min_age1) min_word_change_ea <- if_else(latest_ea_min_age2 > first_ea_min_age1, "increase", "decrease") @@ -547,7 +547,7 @@ latest_bed_days_loc <- bed_days_areas %>% latest_bed_days_loc1 <- latest_bed_days_loc %>% pull(formatted_data) latest_bed_days_loc2 <- latest_bed_days_loc %>% pull(data) -rate_change_ubd <- round(abs(latest_bed_days_loc2 - first_fy_rate_ubd) / first_fy_rate_ubd * 100, digits = 1) +rate_change_ubd <- percent_change_calc(latest_bed_days_loc2, first_fy_rate_ubd) word_change_ubd <- if_else(latest_bed_days_loc2 > first_fy_rate_ubd, "increase", "decrease") #HSCP @@ -561,7 +561,7 @@ hscp_bed_days <- bed_days_areas %>% hscp_bed_days1 <- hscp_bed_days %>% pull(formatted_data) hscp_bed_days2 <- hscp_bed_days %>% pull(data) -hscp_rate_ubd <- round(abs(hscp_bed_days2 - first_fy_hscp_ubd) / first_fy_hscp_ubd * 100, digits = 1) +hscp_rate_ubd <- percent_change_calc(hscp_bed_days2, first_fy_hscp_ubd) hscp_change_ubd <- if_else(hscp_bed_days2 > first_fy_hscp_ubd, "increase", "decrease") @@ -576,7 +576,7 @@ scot_bed_days <- bed_days_areas %>% scot_bed_days1 <- scot_bed_days %>% pull(formatted_data) scot_bed_days2 <- scot_bed_days %>% pull(data) -scot_rate_ubd <- round(abs(scot_bed_days2 - first_fy_scot_ubd) / first_fy_scot_ubd * 100, digits = 1) +scot_rate_ubd <- percent_change_calc(scot_bed_days2, first_fy_scot_ubd) scot_change_ubd <- if_else(scot_bed_days2 > first_fy_scot_ubd, "increase", "decrease") @@ -594,7 +594,7 @@ first_fy_hb_ubd <- filter(bed_days_areas, financial_year == min(financial_year), location == HB)$data -hb_rate_change_ubd <- round(abs(hb_bed_days2 - first_fy_hb_ubd) / first_fy_hb_ubd * 100, digits = 1) +hb_rate_change_ubd <- percent_change_calc(hb_bed_days2, first_fy_hb_ubd) word_change_hb_ubd <- if_else(hb_bed_days2 > first_fy_hb_ubd, "increase", "decrease") @@ -633,7 +633,7 @@ first_ubd_max_age <- bed_days_age %>% ) %>% pull(data) -max_rate_change_ubd <- round(abs(latest_ubd_max_age2 - first_ubd_max_age) / first_ubd_max_age * 100, digits = 1) +max_rate_change_ubd <- percent_change_calc(latest_ubd_max_age2, first_ubd_max_age) max_word_change_ubd <- if_else(latest_ubd_max_age2 > first_ubd_max_age, "increase", "decrease") @@ -659,7 +659,7 @@ first_ubd_min_age1 <- first_ubd_min_age %>% pull(data) min_year_ubd_age1<- first_ubd_min_age %>% pull(year) -min_rate_change_ubd <- round(abs(latest_ubd_min_age2 - first_ubd_min_age1) / first_ubd_min_age1 * 100, digits = 1) +min_rate_change_ubd <- percent_change_calc(latest_ubd_min_age2, first_ubd_min_age1) min_word_change_ubd <- if_else(latest_ubd_min_age2 > first_ubd_min_age1, "increase", "decrease") @@ -728,7 +728,7 @@ first_bd_mh_max_age <- bed_days_mh_age %>% ) %>% pull(data) -max_rate_change_beds_mh <- round(abs(latest_bd_mh_max_age2 - first_bd_mh_max_age) / first_bd_mh_max_age * 100, digits = 1) +max_rate_change_beds_mh <- percent_change_calc(latest_bd_mh_max_age2, first_bd_mh_max_age) max_word_change_beds_mh <- if_else(latest_bd_mh_max_age2 > first_bd_mh_max_age, "increase", "decrease") @@ -754,7 +754,7 @@ first_bd_mh_min_age1 <- first_bd_mh_min_age %>% pull(data) min_year_bd_mh_age1<- first_bd_mh_min_age %>% pull(year) -min_rate_change_beds_mh <- round(abs(latest_bd_mh_min_age2 - first_bd_mh_min_age1) / first_bd_mh_min_age1 * 100, digits = 1) +min_rate_change_beds_mh <- percent_change_calc(latest_bd_mh_min_age2, first_bd_mh_min_age1) min_word_change_beds_mh <- if_else(latest_bd_mh_min_age2 > first_bd_mh_min_age1, "increase", "decrease") @@ -780,7 +780,7 @@ first_bed_days_mh_loc <- bed_days_mh_areas %>% ) %>% pull(data) -loc_rate_change_beds_mh <- round(abs(latest_bed_days_mh_loc2 - first_bed_days_mh_loc) / first_bed_days_mh_loc * 100, digits = 1) +loc_rate_change_beds_mh <- percent_change_calc(latest_bed_days_mh_loc2, first_bed_days_mh_loc) loc_word_change_beds_mh <- if_else(latest_bed_days_mh_loc2 > first_bed_days_mh_loc, "increase", "decrease") @@ -801,7 +801,7 @@ first_hscp_bed_days_mh <- bed_days_mh_areas %>% ) %>% pull(data) -hscp_rate_change_beds_mh <- round(abs(hscp_bed_days_mh2 - first_hscp_bed_days_mh) / first_hscp_bed_days_mh * 100, digits = 1) +hscp_rate_change_beds_mh <- percent_change_calc(hscp_bed_days_mh2, first_hscp_bed_days_mh) hscp_word_change_beds_mh <- if_else(hscp_bed_days_mh2 > first_hscp_bed_days_mh, "increase", "decrease") @@ -822,7 +822,7 @@ first_scot_bed_days_mh <- bed_days_mh_areas %>% ) %>% pull(data) -scot_rate_change_beds_mh <- round(abs(scot_bed_days_mh2 - first_scot_bed_days_mh) / first_scot_bed_days_mh * 100, digits = 1) +scot_rate_change_beds_mh <- percent_change_calc(scot_bed_days_mh2, first_scot_bed_days_mh) scot_word_change_beds_mh <- if_else(scot_bed_days_mh2 > first_scot_bed_days_mh, "increase", "decrease") @@ -1026,7 +1026,7 @@ first_fy_hb_ae <- filter(ae_att_areas, financial_year == min(financial_year), location == HB)$data -hb_rate_change_ae <- round(abs(hb_ae2 - first_fy_hb_ae) / first_fy_hb_ae * 100, digits = 1) +hb_rate_change_ae <- percent_change_calc(hb_ae2, first_fy_hb_ae) word_change_hb_ae <- if_else(hb_ae2 > first_fy_hb_ae, "increase", "decrease") @@ -1155,7 +1155,7 @@ first_fy_hb_dd <- filter(delayed_disch_areas, financial_year == min(financial_year), location == HB)$data -hb_rate_change_dd <- round(abs(hb_dd2 - first_fy_hb_dd) / first_fy_hb_dd * 100, digits = 1) +hb_rate_change_dd <- percent_change_calc(hb_dd2, first_fy_hb_dd) word_change_hb_dd <- if_else(hb_dd2 > first_fy_hb_dd, "increase", "decrease") @@ -1452,7 +1452,7 @@ first_fy_hb_read <- filter(readmissions_areas, financial_year == min(financial_year), location == HB)$data -hb_rate_change_read <- round(abs(hb_read2 - first_fy_hb_read) / first_fy_hb_read * 100, digits = 1) +hb_rate_change_read <- percent_change_calc(hb_read2, first_fy_hb_read) word_change_hb_read <- if_else(hb_read2 > first_fy_hb_read, "increase", "decrease") @@ -1624,7 +1624,7 @@ latest_ppa_loc <- ppa_areas %>% ) %>% mutate(formatted_data = format(data, big.mark = ",")) -ppa_diff <- round(abs(latest_ppa_loc$data[2] - latest_ppa_loc$data[1]) / latest_ppa_loc$data[1]* 100, digits = 1) +ppa_diff <- percent_change_calc(latest_ppa_loc$data[2], latest_ppa_loc$data[1]) ppa_word_change <- if_else(latest_ppa_loc$data[2] > latest_ppa_loc$data[1], "increase", "decrease") @@ -1635,7 +1635,7 @@ hscp_ppa <- ppa_areas %>% ) %>% mutate(formatted_data = format(data, big.mark = ",")) -ppa_diff_hscp <- round(abs(hscp_ppa$data[2] - hscp_ppa$data[1]) / hscp_ppa$data[1]* 100, digits = 1) +ppa_diff_hscp <- percent_change_calc(hscp_ppa$data[2], hscp_ppa$data[1]) ppa_word_change_hscp <- if_else(hscp_ppa$data[2] > hscp_ppa$data[1], "increase", "decrease") @@ -1646,7 +1646,7 @@ scot_ppa <- ppa_areas %>% ) %>% mutate(formatted_data = format(data, big.mark = ",")) -diff_scot_ppa <- round(abs(scot_ppa$data[2] - scot_ppa$data[1]) / scot_ppa$data[1] * 100, digits = 1) +diff_scot_ppa <- percent_change_calc(scot_ppa$data[2], scot_ppa$data[1]) word_change_scot_ppa <- if_else(scot_ppa$data[2] > scot_ppa$data[1], "increase", "decrease") @@ -1658,7 +1658,7 @@ hb_ppa <- ppa_areas %>% ) %>% mutate(formatted_data = format(data, big.mark = ",")) -diff_hb_ppa <- round(abs(hb_ppa$data[2] - hb_ppa$data[1]) / hb_ppa$data[1] * 100, digits = 1) +diff_hb_ppa <- percent_change_calc(hb_ppa$data[2], hb_ppa$data[1]) word_change_hb_ppa <- if_else(hb_ppa$data[2] > hb_ppa$data[1], "increase", "decrease") @@ -1738,7 +1738,7 @@ loc_psych_hosp <- psych_hosp %>% ) %>% mutate(measure2 = format(measure, big.mark = ",")) -diff_loc_psych <- round(abs(loc_psych_hosp$measure[2] - loc_psych_hosp$measure[1]) / loc_psych_hosp$measure[1] * 100, digits = 1) +diff_loc_psych <- percent_change_calc(loc_psych_hosp$measure[2], loc_psych_hosp$measure[1]) word_change_loc_psych <- if_else(loc_psych_hosp$measure[2] > loc_psych_hosp$measure[1], "increase", "decrease") @@ -1752,7 +1752,7 @@ hscp_psych_hosp <- psych_hosp %>% ) %>% mutate(measure2 = format(measure, big.mark = ",")) -diff_hscp_psych <- round(abs(hscp_psych_hosp$measure[2] - hscp_psych_hosp$measure[1]) / hscp_psych_hosp$measure[1] * 100, digits = 1) +diff_hscp_psych <- percent_change_calc(hscp_psych_hosp$measure[2], hscp_psych_hosp$measure[1]) word_change_hscp_psych <- if_else(hscp_psych_hosp$measure[2] > hscp_psych_hosp$measure[1], "increase", "decrease") @@ -1766,7 +1766,7 @@ hb_psych_hosp <- psych_hosp %>% ) %>% mutate(measure2 = format(measure, big.mark = ",")) -diff_hb_psych <- round(abs(hb_psych_hosp$measure[2] - hb_psych_hosp$measure[1]) / hb_psych_hosp$measure[1] * 100, digits = 1) +diff_hb_psych <- percent_change_calc(hb_psych_hosp$measure[2], hb_psych_hosp$measure[1]) word_change_hb_psych <- if_else(hb_psych_hosp$measure[2] > hb_psych_hosp$measure[1], "increase", "decrease") @@ -1780,7 +1780,7 @@ scot_psych_hosp <- psych_hosp %>% ) %>% mutate(measure2 = format(measure, big.mark = ",")) -diff_scot_psych <- round(abs(scot_psych_hosp$measure[2] - scot_psych_hosp$measure[1]) / scot_psych_hosp$measure[1] * 100, digits = 1) +diff_scot_psych <- percent_change_calc(scot_psych_hosp$measure[2], scot_psych_hosp$measure[1]) word_change_scot_psych <- if_else(scot_psych_hosp$measure[2] > scot_psych_hosp$measure[1], "increase", "decrease") From 53f7da594f66faa6e758b3b08243a1946122d83f Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 26 Sep 2024 16:52:50 +0100 Subject: [PATCH 27/38] Style code --- .../2. Unscheduled Care outputs.R | 404 ++++++++++-------- 1 file changed, 233 insertions(+), 171 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 7064111..642642f 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -345,7 +345,7 @@ EAs_loc_ts <- area_trend_usc( ) -#Objects for text for Figures and Summary (Emergency Admissions) +# Objects for text for Figures and Summary (Emergency Admissions) min_year_ea <- min(emergency_adm_areas$financial_year) max_year_ea <- max(emergency_adm_areas$financial_year) @@ -369,7 +369,7 @@ latest_emergency_adm_loc2 <- latest_emergency_adm_loc %>% pull(data) percent_rate_change <- percent_change_calc(latest_emergency_adm_loc2, first_fy_rate) word_change_rate <- word_change_calc(latest_emergency_adm_loc2, first_fy_rate) -#HSCP +# HSCP hscp_emergency_adm <- emergency_adm_areas %>% filter( location == HSCP, @@ -380,52 +380,60 @@ hscp_emergency_adm <- emergency_adm_areas %>% hscp_emergency_adm1 <- hscp_emergency_adm %>% pull(formatted_data) hscp_emergency_adm2 <- hscp_emergency_adm %>% pull(data) -first_fy_hscp <- filter(emergency_adm_areas, +first_fy_hscp <- filter( + emergency_adm_areas, financial_year == min(financial_year), - area_type == "HSCP")$data + area_type == "HSCP" +)$data hscp_rate_change <- percent_change_calc(hscp_emergency_adm2, first_fy_hscp) word_change_hscp <- if_else(hscp_emergency_adm2 > first_fy_hscp, "increase", "decrease") -#Scotland +# Scotland scot_emergency_adm <- emergency_adm_areas %>% filter( location == "Scotland", year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) scot_emergency_adm1 <- scot_emergency_adm %>% pull(formatted_data) scot_emergency_adm2 <- scot_emergency_adm %>% pull(data) -first_fy_scot <- filter(emergency_adm_areas, +first_fy_scot <- filter( + emergency_adm_areas, financial_year == min(financial_year), - location == "Scotland")$data + location == "Scotland" +)$data scot_rate_change <- percent_change_calc(scot_emergency_adm2, first_fy_scot) word_change_scot <- if_else(scot_emergency_adm2 > first_fy_scot, - "increase", "decrease") + "increase", "decrease" +) -#NHS health board +# NHS health board hb_emergency_adm <- emergency_adm_areas %>% filter( location == HB, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hb_emergency_adm1 <- hb_emergency_adm %>% pull(formatted_data) hb_emergency_adm2 <- hb_emergency_adm %>% pull(data) -first_fy_hb <- filter(emergency_adm_areas, - financial_year == min(financial_year), - location == HB)$data +first_fy_hb <- filter( + emergency_adm_areas, + financial_year == min(financial_year), + location == HB +)$data hb_rate_change <- percent_change_calc(hb_emergency_adm2, first_fy_hb) word_change_hb <- if_else(hb_emergency_adm2 > first_fy_hb, - "increase", "decrease") + "increase", "decrease" +) -#other locations +# other locations other_loc_emergency_adm <- emergency_adm %>% group_by(financial_year, hscp_locality) %>% summarise(adm = sum(admissions)) %>% @@ -443,11 +451,12 @@ min_ea_age <- min(emergency_adm_age$financial_year) latest_ea_max_age <- emergency_adm_age %>% filter( - year == max(year)) %>% + year == max(year) + ) %>% filter( - data== max(data) + data == max(data) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_ea_max_age1 <- latest_ea_max_age %>% pull(formatted_data) latest_ea_max_age2 <- latest_ea_max_age %>% pull(data) @@ -462,15 +471,17 @@ first_ea_max_age <- emergency_adm_age %>% max_rate_change_ea <- percent_change_calc(latest_ea_max_age2, first_ea_max_age) max_word_change_ea <- if_else(latest_ea_max_age2 > first_ea_max_age, - "increase", "decrease") + "increase", "decrease" +) latest_ea_min_age <- emergency_adm_age %>% filter( - year == max(year)) %>% + year == max(year) + ) %>% filter( - data== min(data) + data == min(data) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_ea_min_age1 <- latest_ea_min_age %>% pull(formatted_data) latest_ea_min_age2 <- latest_ea_min_age %>% pull(data) @@ -480,15 +491,16 @@ first_ea_min_age <- emergency_adm_age %>% filter( age_group == age_group_min_ea ) %>% - filter(year==min(year)) + filter(year == min(year)) first_ea_min_age1 <- first_ea_min_age %>% pull(data) -min_year_ea_age1<- first_ea_min_age %>% pull(year) +min_year_ea_age1 <- first_ea_min_age %>% pull(year) min_rate_change_ea <- percent_change_calc(latest_ea_min_age2, first_ea_min_age1) min_word_change_ea <- if_else(latest_ea_min_age2 > first_ea_min_age1, - "increase", "decrease") + "increase", "decrease" +) # 2a. Unscheduled bed days ---- # _________________________________________________________________________ @@ -531,72 +543,81 @@ BDs_loc_ts <- area_trend_usc( source = "Source: PHS SMR01" ) -#Objects for text for Figures and Summary (Unscheduled Bed Days) +# Objects for text for Figures and Summary (Unscheduled Bed Days) min_year_ubd <- min(bed_days_areas$financial_year) max_year_ubd <- max(bed_days_areas$financial_year) -#LOCALITY +# LOCALITY first_fy_rate_ubd <- filter( bed_days_areas, financial_year == min(financial_year), - location == LOCALITY & area_type == "Locality")$data + location == LOCALITY & area_type == "Locality" +)$data latest_bed_days_loc <- bed_days_areas %>% filter(location == LOCALITY, year == max(year)) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_bed_days_loc1 <- latest_bed_days_loc %>% pull(formatted_data) latest_bed_days_loc2 <- latest_bed_days_loc %>% pull(data) rate_change_ubd <- percent_change_calc(latest_bed_days_loc2, first_fy_rate_ubd) word_change_ubd <- if_else(latest_bed_days_loc2 > first_fy_rate_ubd, - "increase", "decrease") -#HSCP + "increase", "decrease" +) +# HSCP first_fy_hscp_ubd <- filter( - bed_days_areas, (financial_year == min(bed_days_areas$financial_year)) & (area_type == "HSCP"))$data + bed_days_areas, (financial_year == min(bed_days_areas$financial_year)) & (area_type == "HSCP") +)$data hscp_bed_days <- bed_days_areas %>% filter(location == HSCP, year == max(year)) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hscp_bed_days1 <- hscp_bed_days %>% pull(formatted_data) hscp_bed_days2 <- hscp_bed_days %>% pull(data) hscp_rate_ubd <- percent_change_calc(hscp_bed_days2, first_fy_hscp_ubd) hscp_change_ubd <- if_else(hscp_bed_days2 > first_fy_hscp_ubd, - "increase", "decrease") + "increase", "decrease" +) -#Scotland +# Scotland first_fy_scot_ubd <- filter( - bed_days_areas, (financial_year == min(bed_days_areas$financial_year)) & (area_type == "Scotland"))$data + bed_days_areas, (financial_year == min(bed_days_areas$financial_year)) & (area_type == "Scotland") +)$data scot_bed_days <- bed_days_areas %>% filter(location == "Scotland", year == max(year)) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) scot_bed_days1 <- scot_bed_days %>% pull(formatted_data) scot_bed_days2 <- scot_bed_days %>% pull(data) scot_rate_ubd <- percent_change_calc(scot_bed_days2, first_fy_scot_ubd) scot_change_ubd <- if_else(scot_bed_days2 > first_fy_scot_ubd, - "increase", "decrease") + "increase", "decrease" +) -#NHS health board +# NHS health board hb_bed_days <- bed_days_areas %>% filter( location == HB, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hb_bed_days1 <- hb_bed_days %>% pull(formatted_data) hb_bed_days2 <- hb_bed_days %>% pull(data) -first_fy_hb_ubd <- filter(bed_days_areas, - financial_year == min(financial_year), - location == HB)$data +first_fy_hb_ubd <- filter( + bed_days_areas, + financial_year == min(financial_year), + location == HB +)$data hb_rate_change_ubd <- percent_change_calc(hb_bed_days2, first_fy_hb_ubd) word_change_hb_ubd <- if_else(hb_bed_days2 > first_fy_hb_ubd, - "increase", "decrease") + "increase", "decrease" +) other_loc_bed_days <- bed_days %>% @@ -616,11 +637,12 @@ min_ubd_age <- min(bed_days_age$financial_year) latest_ubd_max_age <- bed_days_age %>% filter( - year == max(year)) %>% + year == max(year) + ) %>% filter( - data== max(data) + data == max(data) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_ubd_max_age1 <- latest_ubd_max_age %>% pull(formatted_data) latest_ubd_max_age2 <- latest_ubd_max_age %>% pull(data) @@ -635,15 +657,17 @@ first_ubd_max_age <- bed_days_age %>% max_rate_change_ubd <- percent_change_calc(latest_ubd_max_age2, first_ubd_max_age) max_word_change_ubd <- if_else(latest_ubd_max_age2 > first_ubd_max_age, - "increase", "decrease") + "increase", "decrease" +) latest_ubd_min_age <- bed_days_age %>% filter( - year == max(year)) %>% + year == max(year) + ) %>% filter( - data== min(data) + data == min(data) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_ubd_min_age1 <- latest_ubd_min_age %>% pull(formatted_data) latest_ubd_min_age2 <- latest_ubd_min_age %>% pull(data) @@ -653,15 +677,16 @@ first_ubd_min_age <- bed_days_age %>% filter( age_group == age_group_min_ubd ) %>% - filter(year==min(year)) + filter(year == min(year)) first_ubd_min_age1 <- first_ubd_min_age %>% pull(data) -min_year_ubd_age1<- first_ubd_min_age %>% pull(year) +min_year_ubd_age1 <- first_ubd_min_age %>% pull(year) min_rate_change_ubd <- percent_change_calc(latest_ubd_min_age2, first_ubd_min_age1) min_word_change_ubd <- if_else(latest_ubd_min_age2 > first_ubd_min_age1, - "increase", "decrease") + "increase", "decrease" +) # 2b. Unscheduled bed days - Mental Health ---- # _________________________________________________________________________ @@ -677,7 +702,7 @@ bed_days_mh_age <- bed_days_mh %>% summarise(bed_days = sum(bed_days)) %>% ungroup() %>% left_join(loc_pop_age1) %>% - mutate(data = round_half_up(bed_days / pop * 100000)) %>% + mutate(data = round_half_up(bed_days / pop * 100000)) %>% drop_na(year) @@ -694,7 +719,7 @@ bed_days_mh_areas <- bed_days_mh %>% rename(n = bed_days) %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(n / pop * 100000)) %>% + mutate(data = round_half_up(n / pop * 100000)) %>% drop_na(year) BDMH_loc_ts <- area_trend_usc( @@ -711,11 +736,12 @@ min_year_bd_mh_age <- min(bed_days_mh_age$financial_year) latest_bd_mh_max_age <- bed_days_mh_age %>% filter( - year == max(year)) %>% + year == max(year) + ) %>% filter( - data== max(data) + data == max(data) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_bd_mh_max_age1 <- latest_bd_mh_max_age %>% pull(formatted_data) latest_bd_mh_max_age2 <- latest_bd_mh_max_age %>% pull(data) @@ -730,15 +756,17 @@ first_bd_mh_max_age <- bed_days_mh_age %>% max_rate_change_beds_mh <- percent_change_calc(latest_bd_mh_max_age2, first_bd_mh_max_age) max_word_change_beds_mh <- if_else(latest_bd_mh_max_age2 > first_bd_mh_max_age, - "increase", "decrease") + "increase", "decrease" +) latest_bd_mh_min_age <- bed_days_mh_age %>% filter( - year == max(year)) %>% + year == max(year) + ) %>% filter( - data== min(data) + data == min(data) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_bd_mh_min_age1 <- latest_bd_mh_min_age %>% pull(formatted_data) latest_bd_mh_min_age2 <- latest_bd_mh_min_age %>% pull(data) @@ -748,26 +776,27 @@ first_bd_mh_min_age <- bed_days_mh_age %>% filter( age_group == age_group_min_mh ) %>% - filter(year==min(year)) + filter(year == min(year)) first_bd_mh_min_age1 <- first_bd_mh_min_age %>% pull(data) -min_year_bd_mh_age1<- first_bd_mh_min_age %>% pull(year) +min_year_bd_mh_age1 <- first_bd_mh_min_age %>% pull(year) min_rate_change_beds_mh <- percent_change_calc(latest_bd_mh_min_age2, first_bd_mh_min_age1) min_word_change_beds_mh <- if_else(latest_bd_mh_min_age2 > first_bd_mh_min_age1, - "increase", "decrease") + "increase", "decrease" +) # Objects for text and summary table- area -max_year_bd_mh_areas <-max(bed_days_mh_areas$financial_year) -min_year_bd_mh_areas <-min(bed_days_mh_areas$financial_year) +max_year_bd_mh_areas <- max(bed_days_mh_areas$financial_year) +min_year_bd_mh_areas <- min(bed_days_mh_areas$financial_year) latest_bed_days_mh_loc <- bed_days_mh_areas %>% filter( location == LOCALITY, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_bed_days_mh_loc1 <- latest_bed_days_mh_loc %>% pull(formatted_data) latest_bed_days_mh_loc2 <- latest_bed_days_mh_loc %>% pull(data) @@ -782,7 +811,8 @@ first_bed_days_mh_loc <- bed_days_mh_areas %>% loc_rate_change_beds_mh <- percent_change_calc(latest_bed_days_mh_loc2, first_bed_days_mh_loc) loc_word_change_beds_mh <- if_else(latest_bed_days_mh_loc2 > first_bed_days_mh_loc, - "increase", "decrease") + "increase", "decrease" +) hscp_bed_days_mh <- bed_days_mh_areas %>% filter( @@ -803,14 +833,15 @@ first_hscp_bed_days_mh <- bed_days_mh_areas %>% hscp_rate_change_beds_mh <- percent_change_calc(hscp_bed_days_mh2, first_hscp_bed_days_mh) hscp_word_change_beds_mh <- if_else(hscp_bed_days_mh2 > first_hscp_bed_days_mh, - "increase", "decrease") + "increase", "decrease" +) scot_bed_days_mh <- bed_days_mh_areas %>% filter( location == "Scotland", year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) scot_bed_days_mh1 <- scot_bed_days_mh %>% pull(formatted_data) scot_bed_days_mh2 <- scot_bed_days_mh %>% pull(data) @@ -824,26 +855,30 @@ first_scot_bed_days_mh <- bed_days_mh_areas %>% scot_rate_change_beds_mh <- percent_change_calc(scot_bed_days_mh2, first_scot_bed_days_mh) scot_word_change_beds_mh <- if_else(scot_bed_days_mh2 > first_scot_bed_days_mh, - "increase", "decrease") + "increase", "decrease" +) -#NHS health board +# NHS health board hb_mh_beddays <- bed_days_mh_areas %>% filter( location == HB, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hb_mh_beddays1 <- hb_mh_beddays %>% pull(formatted_data) hb_mh_beddays2 <- hb_mh_beddays %>% pull(data) -first_fy_hb_mh <- filter(bed_days_mh_areas, - financial_year == min(financial_year), - location == HB)$data +first_fy_hb_mh <- filter( + bed_days_mh_areas, + financial_year == min(financial_year), + location == HB +)$data hb_rate_change_mh <- round(abs(hb_mh_beddays2 - first_fy_hb_mh) / first_fy_hb_mh * 100, digits = 1) word_change_hb_mh <- if_else(hb_mh_beddays2 > first_fy_hb_mh, - "increase", "decrease") + "increase", "decrease" +) other_loc_bed_days_mh <- bed_days_mh %>% group_by(financial_year, hscp_locality) %>% @@ -890,7 +925,7 @@ ae_att_areas <- ae_attendances %>% rename(n = attendances) %>% aggregate_usc_area_data() %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(n / pop * 100000))%>% + mutate(data = round_half_up(n / pop * 100000)) %>% drop_na(year) @@ -910,7 +945,7 @@ max_year_ae_age <- max(ae_att_age$financial_year) latest_ae_att_max_age <- ae_att_age %>% filter( year == max(year), - data== max(data) + data == max(data) ) %>% mutate(formatted_data = format(data, big.mark = ",")) @@ -932,11 +967,12 @@ word_change_rate_ae_age <- word_change_calc(latest_ae_att_loc2_age, first_ae_att latest_ae_att_min_age <- ae_att_age %>% filter( - year == max(year)) %>% + year == max(year) + ) %>% filter( data == min(data) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_ae_att_loc1_age_min <- latest_ae_att_min_age %>% pull(formatted_data) latest_ae_att_loc2_age_min <- latest_ae_att_min_age %>% pull(data) @@ -947,7 +983,7 @@ first_ae_att_min_age <- ae_att_age %>% year == min(year), age_group == age_group_min ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) first_ae_att_min_data <- first_ae_att_min_age %>% pull(data) @@ -984,14 +1020,16 @@ hscp_ae_att <- ae_att_areas %>% location == HSCP, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hscp_ae_att1 <- hscp_ae_att %>% pull(formatted_data) hscp_ae_att2 <- hscp_ae_att %>% pull(data) -first_fy_hscp_ae <- filter(ae_att_areas, - financial_year == min(financial_year), - area_type == "HSCP")$data +first_fy_hscp_ae <- filter( + ae_att_areas, + financial_year == min(financial_year), + area_type == "HSCP" +)$data percent_rate_change_ae_areas_hscp <- percent_change_calc(hscp_ae_att2, first_fy_hscp_ae) word_change_rate_ae_areas_hscp <- word_change_calc(hscp_ae_att2, first_fy_hscp_ae) @@ -1001,34 +1039,39 @@ scot_ae_att <- ae_att_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) scot_ae_att1 <- scot_ae_att %>% pull(formatted_data) scot_ae_att2 <- scot_ae_att %>% pull(data) -first_fy_scot_ae <- filter(ae_att_areas, - financial_year == min(financial_year), - location == "Scotland")$data +first_fy_scot_ae <- filter( + ae_att_areas, + financial_year == min(financial_year), + location == "Scotland" +)$data percent_rate_change_ae_areas_scot <- percent_change_calc(scot_ae_att2, first_fy_scot_ae) word_change_rate_ae_areas_scot <- word_change_calc(scot_ae_att2, first_fy_scot_ae) -#NHS health board +# NHS health board hb_ae_att <- ae_att_areas %>% filter( location == HB, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hb_ae1 <- hb_ae_att %>% pull(formatted_data) hb_ae2 <- hb_ae_att %>% pull(data) -first_fy_hb_ae <- filter(ae_att_areas, - financial_year == min(financial_year), - location == HB)$data +first_fy_hb_ae <- filter( + ae_att_areas, + financial_year == min(financial_year), + location == HB +)$data -hb_rate_change_ae <- percent_change_calc(hb_ae2, first_fy_hb_ae) +hb_rate_change_ae <- percent_change_calc(hb_ae2, first_fy_hb_ae) word_change_hb_ae <- if_else(hb_ae2 > first_fy_hb_ae, - "increase", "decrease") + "increase", "decrease" +) other_loc_ae_att <- ae_attendances %>% group_by(financial_year, hscp_locality) %>% @@ -1084,7 +1127,7 @@ latest_dd_loc <- delayed_disch_areas %>% location == LOCALITY, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) latest_dd_loc1 <- latest_dd_loc %>% pull(formatted_data) latest_dd_loc2 <- latest_dd_loc %>% pull(data) @@ -1126,7 +1169,7 @@ scot_dd <- delayed_disch_areas %>% location == "Scotland", year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) scot_dd1 <- scot_dd %>% pull(formatted_data) scot_dd2 <- scot_dd %>% pull(data) @@ -1141,23 +1184,26 @@ first_scot_dd <- delayed_disch_areas %>% percent_rate_change_dd_scot <- percent_change_calc(scot_dd2, first_scot_dd) word_change_rate_dd_scot <- word_change_calc(scot_dd2, first_scot_dd) -#NHS health board +# NHS health board hb_dd <- delayed_disch_areas %>% filter( location == HB, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hb_dd1 <- hb_dd %>% pull(formatted_data) hb_dd2 <- hb_dd %>% pull(data) -first_fy_hb_dd <- filter(delayed_disch_areas, - financial_year == min(financial_year), - location == HB)$data +first_fy_hb_dd <- filter( + delayed_disch_areas, + financial_year == min(financial_year), + location == HB +)$data -hb_rate_change_dd <- percent_change_calc(hb_dd2, first_fy_hb_dd) +hb_rate_change_dd <- percent_change_calc(hb_dd2, first_fy_hb_dd) word_change_hb_dd <- if_else(hb_dd2 > first_fy_hb_dd, - "increase", "decrease") + "increase", "decrease" +) other_loc_dd <- delayed_disch %>% @@ -1240,7 +1286,7 @@ first_falls_hscp <- falls_areas %>% ) %>% pull(data) -percent_rate_change_falls_hscp<- percent_change_calc(hscp_falls2, first_falls_hscp) +percent_rate_change_falls_hscp <- percent_change_calc(hscp_falls2, first_falls_hscp) word_change_rate_falls_hscp <- word_change_calc(hscp_falls2, first_falls_hscp) scot_falls <- falls_areas %>% @@ -1260,27 +1306,30 @@ first_falls_scot <- falls_areas %>% ) %>% pull(data) -percent_rate_change_falls_scot<- percent_change_calc(scot_falls2, first_falls_scot) +percent_rate_change_falls_scot <- percent_change_calc(scot_falls2, first_falls_scot) word_change_rate_falls_scot <- word_change_calc(scot_falls2, first_falls_scot) -#NHS health board +# NHS health board hb_falls <- falls_areas %>% filter( location == HB, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hb_falls1 <- hb_falls %>% pull(formatted_data) hb_falls2 <- hb_falls %>% pull(data) -first_fy_hb_falls <- filter(falls_areas, - financial_year == min(financial_year), - location == HB)$data +first_fy_hb_falls <- filter( + falls_areas, + financial_year == min(financial_year), + location == HB +)$data hb_rate_change_falls <- round(abs(hb_falls2 - first_fy_hb_falls) / first_fy_hb_falls * 100, digits = 1) word_change_hb_falls <- if_else(hb_falls2 > first_fy_hb_falls, - "increase", "decrease") + "increase", "decrease" +) # 6. Readmissions (28 days) ---- # _________________________________________________________________________ @@ -1299,7 +1348,7 @@ readmissions_age <- readmissions %>% discharges = sum(discharges) ) %>% ungroup() %>% - mutate(data = round_half_up(read_28 / discharges * 1000, 1)) + mutate(data = round_half_up(read_28 / discharges * 1000, 1)) Read_age_ts <- age_group_trend_usc( data_for_plot = readmissions_age, @@ -1327,7 +1376,7 @@ read2 <- readmissions %>% readmissions_areas <- left_join(read1, read2) %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(read_28 / discharges * 1000, 1))%>% + mutate(data = round_half_up(read_28 / discharges * 1000, 1)) %>% drop_na(year) rm(read1, read2) @@ -1346,7 +1395,7 @@ max_year_re_age <- max(readmissions_age$financial_year) latest_re_max_age <- readmissions_age %>% filter( financial_year == max(financial_year), - data== max(data) + data == max(data) ) latest_re_max_age_data <- latest_re_max_age %>% pull(data) @@ -1365,8 +1414,9 @@ word_change_rate_re_age <- word_change_calc(latest_re_max_age_data, first_re_max latest_re_min_age <- readmissions_age %>% filter( - financial_year == max(financial_year)) %>% - filter(data== min(data)) + financial_year == max(financial_year) + ) %>% + filter(data == min(data)) latest_re_min_age_data <- latest_re_min_age %>% pull(data) latest_re_min_age_group <- latest_re_min_age %>% pull(age_group) @@ -1388,18 +1438,20 @@ max_year_re_area <- max(readmissions_areas$financial_year) first_read_loc <- readmissions_areas %>% filter( location == LOCALITY, - year == min(year)) + year == min(year) + ) -first_read_loc1 <-first_read_loc %>% pull(data) +first_read_loc1 <- first_read_loc %>% pull(data) latest_read_loc <- readmissions_areas %>% filter( location == LOCALITY, - year == max(year)) + year == max(year) + ) -latest_read_loc1 <-latest_read_loc %>% pull(data) +latest_read_loc1 <- latest_read_loc %>% pull(data) -percent_rate_change_re_area <- percent_change_calc(latest_read_loc1, first_read_loc1) +percent_rate_change_re_area <- percent_change_calc(latest_read_loc1, first_read_loc1) word_change_rate_re_area <- word_change_calc(latest_read_loc1, first_read_loc1) first_hscp_read <- readmissions_areas %>% @@ -1437,24 +1489,27 @@ scot_read <- readmissions_areas %>% percent_rate_change_re_area_scot <- percent_change_calc(scot_read, first_scot_read) word_change_rate_re_area_scot <- word_change_calc(scot_read, first_scot_read) -#NHS health board +# NHS health board hb_read <- readmissions_areas %>% filter( location == HB, year == max(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) hb_read1 <- hb_read %>% pull(formatted_data) hb_read2 <- hb_read %>% pull(data) -first_fy_hb_read <- filter(readmissions_areas, - financial_year == min(financial_year), - location == HB)$data +first_fy_hb_read <- filter( + readmissions_areas, + financial_year == min(financial_year), + location == HB +)$data -hb_rate_change_read <- percent_change_calc(hb_read2, first_fy_hb_read) +hb_rate_change_read <- percent_change_calc(hb_read2, first_fy_hb_read) word_change_hb_read <- if_else(hb_read2 > first_fy_hb_read, - "increase", "decrease") + "increase", "decrease" +) # 7. Comm 6 months ---- # _________________________________________________________________________________ @@ -1555,7 +1610,7 @@ ppa <- arrow::read_parquet(paste0(import_folder, "ppa_smr.parquet")) %>% # % PPAs in locality under and over 65 ppa_total <- ppa %>% rename(n = admissions) %>% - aggregate_usc_area_data()%>% + aggregate_usc_area_data() %>% drop_na(year) ppa_65plus <- ppa %>% @@ -1565,7 +1620,7 @@ ppa_65plus <- ppa %>% rename(plus65tot = n) %>% left_join(ppa_total, by = c("financial_year", "location")) %>% left_join(pop_areas_all_ages) %>% - mutate(data = round_half_up(plus65tot / n * 100, 1))%>% + mutate(data = round_half_up(plus65tot / n * 100, 1)) %>% drop_na(year) latest_ppa_65plus <- ppa_65plus %>% @@ -1622,22 +1677,24 @@ latest_ppa_loc <- ppa_areas %>% location == LOCALITY, year == max(year) | year == min(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -ppa_diff <- percent_change_calc(latest_ppa_loc$data[2], latest_ppa_loc$data[1]) +ppa_diff <- percent_change_calc(latest_ppa_loc$data[2], latest_ppa_loc$data[1]) ppa_word_change <- if_else(latest_ppa_loc$data[2] > latest_ppa_loc$data[1], - "increase", "decrease") + "increase", "decrease" +) hscp_ppa <- ppa_areas %>% filter( location == HSCP, year == max(year) | year == min(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -ppa_diff_hscp <- percent_change_calc(hscp_ppa$data[2], hscp_ppa$data[1]) +ppa_diff_hscp <- percent_change_calc(hscp_ppa$data[2], hscp_ppa$data[1]) ppa_word_change_hscp <- if_else(hscp_ppa$data[2] > hscp_ppa$data[1], - "increase", "decrease") + "increase", "decrease" +) scot_ppa <- ppa_areas %>% filter( @@ -1646,21 +1703,23 @@ scot_ppa <- ppa_areas %>% ) %>% mutate(formatted_data = format(data, big.mark = ",")) -diff_scot_ppa <- percent_change_calc(scot_ppa$data[2], scot_ppa$data[1]) +diff_scot_ppa <- percent_change_calc(scot_ppa$data[2], scot_ppa$data[1]) word_change_scot_ppa <- if_else(scot_ppa$data[2] > scot_ppa$data[1], - "increase", "decrease") + "increase", "decrease" +) -#NHS health board +# NHS health board hb_ppa <- ppa_areas %>% filter( location == HB, - year == max(year) | year == min(year) + year == max(year) | year == min(year) ) %>% - mutate(formatted_data = format(data, big.mark = ",")) + mutate(formatted_data = format(data, big.mark = ",")) -diff_hb_ppa <- percent_change_calc(hb_ppa$data[2], hb_ppa$data[1]) +diff_hb_ppa <- percent_change_calc(hb_ppa$data[2], hb_ppa$data[1]) word_change_hb_ppa <- if_else(hb_ppa$data[2] > hb_ppa$data[1], - "increase", "decrease") + "increase", "decrease" +) other_loc_ppa <- ppa %>% group_by(financial_year, hscp_locality) %>% @@ -1728,61 +1787,65 @@ list_years <- unique(psych_hosp_time_trend$data[6]) list_years_latest <- list_years$period -#Locality +# Locality loc_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( area_name == LOCALITY & area_type == "Locality", - year == min(year) | year == max(year) + year == min(year) | year == max(year) ) %>% - mutate(measure2 = format(measure, big.mark = ",")) + mutate(measure2 = format(measure, big.mark = ",")) -diff_loc_psych <- percent_change_calc(loc_psych_hosp$measure[2], loc_psych_hosp$measure[1]) +diff_loc_psych <- percent_change_calc(loc_psych_hosp$measure[2], loc_psych_hosp$measure[1]) word_change_loc_psych <- if_else(loc_psych_hosp$measure[2] > loc_psych_hosp$measure[1], - "increase", "decrease") + "increase", "decrease" +) -#HSCP +# HSCP hscp_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( area_name == HSCP & area_type == "HSCP", - year == min(year) | year == max(year) + year == min(year) | year == max(year) ) %>% - mutate(measure2 = format(measure, big.mark = ",")) + mutate(measure2 = format(measure, big.mark = ",")) -diff_hscp_psych <- percent_change_calc(hscp_psych_hosp$measure[2], hscp_psych_hosp$measure[1]) +diff_hscp_psych <- percent_change_calc(hscp_psych_hosp$measure[2], hscp_psych_hosp$measure[1]) word_change_hscp_psych <- if_else(hscp_psych_hosp$measure[2] > hscp_psych_hosp$measure[1], - "increase", "decrease") + "increase", "decrease" +) -#NHS health board +# NHS health board hb_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( area_name == HB & - area_type == "Health board", - year == min(year) | year == max(year) + area_type == "Health board", + year == min(year) | year == max(year) ) %>% - mutate(measure2 = format(measure, big.mark = ",")) + mutate(measure2 = format(measure, big.mark = ",")) -diff_hb_psych <- percent_change_calc(hb_psych_hosp$measure[2], hb_psych_hosp$measure[1]) +diff_hb_psych <- percent_change_calc(hb_psych_hosp$measure[2], hb_psych_hosp$measure[1]) word_change_hb_psych <- if_else(hb_psych_hosp$measure[2] > hb_psych_hosp$measure[1], - "increase", "decrease") + "increase", "decrease" +) -#Scotland +# Scotland scot_psych_hosp <- psych_hosp %>% filter(period %in% list_years_latest) %>% filter( area_name == "Scotland" & area_type == "Scotland", - year == min(year) | year == max(year) + year == min(year) | year == max(year) ) %>% - mutate(measure2 = format(measure, big.mark = ",")) + mutate(measure2 = format(measure, big.mark = ",")) -diff_scot_psych <- percent_change_calc(scot_psych_hosp$measure[2], scot_psych_hosp$measure[1]) +diff_scot_psych <- percent_change_calc(scot_psych_hosp$measure[2], scot_psych_hosp$measure[1]) word_change_scot_psych <- if_else(scot_psych_hosp$measure[2] > scot_psych_hosp$measure[1], - "increase", "decrease") + "increase", "decrease" +) @@ -1804,4 +1867,3 @@ word_change_scot_psych <- if_else(scot_psych_hosp$measure[2] > scot_psych_hosp$m # "Readmissions 28" = readmissions, # "PPA" = ppa), # path = paste0(lp_path, "Publishing/SMR Data.xlsx")) - From 2865f7485c11c19d32949a339db1147cd3c6fbf8 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 26 Sep 2024 16:53:21 +0100 Subject: [PATCH 28/38] Add digits as an argument to `percent_change_calc` --- Unscheduled Care/2. Unscheduled Care outputs.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 642642f..d5f0d37 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -288,10 +288,10 @@ area_trend_usc <- function(data_for_plot, plot_title, yaxis_title, source) { ) } -# Functions for variables +# Functions for text variables -percent_change_calc <- function(numerator, denominator) { - round(abs(numerator - denominator) / denominator* 100, digits = 1) +percent_change_calc <- function(numerator, denominator, digits = 1) { + round(abs(numerator - denominator) / denominator * 100, digits = digits) } word_change_calc <- function(latest, first) { From 3bc4536a781cf14c2ee6340146e56c8e3f6e9b25 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 26 Sep 2024 17:02:32 +0100 Subject: [PATCH 29/38] Apply `word_change_calc` consistently --- .../2. Unscheduled Care outputs.R | 114 +++++------------- 1 file changed, 29 insertions(+), 85 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index d5f0d37..5cfeca6 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -387,7 +387,7 @@ first_fy_hscp <- filter( )$data hscp_rate_change <- percent_change_calc(hscp_emergency_adm2, first_fy_hscp) -word_change_hscp <- if_else(hscp_emergency_adm2 > first_fy_hscp, "increase", "decrease") +word_change_hscp <- word_change_calc(hscp_emergency_adm2, first_fy_hscp) # Scotland scot_emergency_adm <- emergency_adm_areas %>% @@ -407,9 +407,7 @@ first_fy_scot <- filter( )$data scot_rate_change <- percent_change_calc(scot_emergency_adm2, first_fy_scot) -word_change_scot <- if_else(scot_emergency_adm2 > first_fy_scot, - "increase", "decrease" -) +word_change_scot <- word_change_calc(scot_emergency_adm2, first_fy_scot) # NHS health board hb_emergency_adm <- emergency_adm_areas %>% @@ -429,9 +427,7 @@ first_fy_hb <- filter( )$data hb_rate_change <- percent_change_calc(hb_emergency_adm2, first_fy_hb) -word_change_hb <- if_else(hb_emergency_adm2 > first_fy_hb, - "increase", "decrease" -) +word_change_hb <- word_change_calc(hb_emergency_adm2, first_fy_hb) # other locations other_loc_emergency_adm <- emergency_adm %>% @@ -470,9 +466,7 @@ first_ea_max_age <- emergency_adm_age %>% pull(data) max_rate_change_ea <- percent_change_calc(latest_ea_max_age2, first_ea_max_age) -max_word_change_ea <- if_else(latest_ea_max_age2 > first_ea_max_age, - "increase", "decrease" -) +max_word_change_ea <- word_change_calc(latest_ea_max_age2, first_ea_max_age) latest_ea_min_age <- emergency_adm_age %>% filter( @@ -498,9 +492,7 @@ min_year_ea_age1 <- first_ea_min_age %>% pull(year) min_rate_change_ea <- percent_change_calc(latest_ea_min_age2, first_ea_min_age1) -min_word_change_ea <- if_else(latest_ea_min_age2 > first_ea_min_age1, - "increase", "decrease" -) +min_word_change_ea <- word_change_calc(latest_ea_min_age2, first_ea_min_age1) # 2a. Unscheduled bed days ---- # _________________________________________________________________________ @@ -561,9 +553,7 @@ latest_bed_days_loc1 <- latest_bed_days_loc %>% pull(formatted_data) latest_bed_days_loc2 <- latest_bed_days_loc %>% pull(data) rate_change_ubd <- percent_change_calc(latest_bed_days_loc2, first_fy_rate_ubd) -word_change_ubd <- if_else(latest_bed_days_loc2 > first_fy_rate_ubd, - "increase", "decrease" -) +word_change_ubd <- word_change_calc(latest_bed_days_loc2, first_fy_rate_ubd) # HSCP first_fy_hscp_ubd <- filter( bed_days_areas, (financial_year == min(bed_days_areas$financial_year)) & (area_type == "HSCP") @@ -577,9 +567,7 @@ hscp_bed_days1 <- hscp_bed_days %>% pull(formatted_data) hscp_bed_days2 <- hscp_bed_days %>% pull(data) hscp_rate_ubd <- percent_change_calc(hscp_bed_days2, first_fy_hscp_ubd) -hscp_change_ubd <- if_else(hscp_bed_days2 > first_fy_hscp_ubd, - "increase", "decrease" -) +hscp_change_ubd <- word_change_calc(hscp_bed_days2, first_fy_hscp_ubd) # Scotland first_fy_scot_ubd <- filter( @@ -594,9 +582,7 @@ scot_bed_days1 <- scot_bed_days %>% pull(formatted_data) scot_bed_days2 <- scot_bed_days %>% pull(data) scot_rate_ubd <- percent_change_calc(scot_bed_days2, first_fy_scot_ubd) -scot_change_ubd <- if_else(scot_bed_days2 > first_fy_scot_ubd, - "increase", "decrease" -) +scot_change_ubd <- word_change_calc(scot_bed_days2, first_fy_scot_ubd) # NHS health board hb_bed_days <- bed_days_areas %>% @@ -615,9 +601,7 @@ first_fy_hb_ubd <- filter( )$data hb_rate_change_ubd <- percent_change_calc(hb_bed_days2, first_fy_hb_ubd) -word_change_hb_ubd <- if_else(hb_bed_days2 > first_fy_hb_ubd, - "increase", "decrease" -) +word_change_hb_ubd <- word_change_calc(hb_bed_days2, first_fy_hb_ubd) other_loc_bed_days <- bed_days %>% @@ -656,9 +640,7 @@ first_ubd_max_age <- bed_days_age %>% pull(data) max_rate_change_ubd <- percent_change_calc(latest_ubd_max_age2, first_ubd_max_age) -max_word_change_ubd <- if_else(latest_ubd_max_age2 > first_ubd_max_age, - "increase", "decrease" -) +max_word_change_ubd <- word_change_calc(latest_ubd_max_age2, first_ubd_max_age) latest_ubd_min_age <- bed_days_age %>% filter( @@ -684,9 +666,7 @@ min_year_ubd_age1 <- first_ubd_min_age %>% pull(year) min_rate_change_ubd <- percent_change_calc(latest_ubd_min_age2, first_ubd_min_age1) -min_word_change_ubd <- if_else(latest_ubd_min_age2 > first_ubd_min_age1, - "increase", "decrease" -) +min_word_change_ubd <- word_change_calc(latest_ubd_min_age2, first_ubd_min_age1) # 2b. Unscheduled bed days - Mental Health ---- # _________________________________________________________________________ @@ -755,9 +735,7 @@ first_bd_mh_max_age <- bed_days_mh_age %>% pull(data) max_rate_change_beds_mh <- percent_change_calc(latest_bd_mh_max_age2, first_bd_mh_max_age) -max_word_change_beds_mh <- if_else(latest_bd_mh_max_age2 > first_bd_mh_max_age, - "increase", "decrease" -) +max_word_change_beds_mh <- word_change_calc(latest_bd_mh_max_age2, first_bd_mh_max_age) latest_bd_mh_min_age <- bed_days_mh_age %>% filter( @@ -783,9 +761,7 @@ min_year_bd_mh_age1 <- first_bd_mh_min_age %>% pull(year) min_rate_change_beds_mh <- percent_change_calc(latest_bd_mh_min_age2, first_bd_mh_min_age1) -min_word_change_beds_mh <- if_else(latest_bd_mh_min_age2 > first_bd_mh_min_age1, - "increase", "decrease" -) +min_word_change_beds_mh <- word_change_calc(latest_bd_mh_min_age2, first_bd_mh_min_age1) # Objects for text and summary table- area max_year_bd_mh_areas <- max(bed_days_mh_areas$financial_year) @@ -810,9 +786,7 @@ first_bed_days_mh_loc <- bed_days_mh_areas %>% pull(data) loc_rate_change_beds_mh <- percent_change_calc(latest_bed_days_mh_loc2, first_bed_days_mh_loc) -loc_word_change_beds_mh <- if_else(latest_bed_days_mh_loc2 > first_bed_days_mh_loc, - "increase", "decrease" -) +loc_word_change_beds_mh <- word_change_calc(latest_bed_days_mh_loc2, first_bed_days_mh_loc) hscp_bed_days_mh <- bed_days_mh_areas %>% filter( @@ -832,9 +806,7 @@ first_hscp_bed_days_mh <- bed_days_mh_areas %>% pull(data) hscp_rate_change_beds_mh <- percent_change_calc(hscp_bed_days_mh2, first_hscp_bed_days_mh) -hscp_word_change_beds_mh <- if_else(hscp_bed_days_mh2 > first_hscp_bed_days_mh, - "increase", "decrease" -) +hscp_word_change_beds_mh <- word_change_calc(hscp_bed_days_mh2, first_hscp_bed_days_mh) scot_bed_days_mh <- bed_days_mh_areas %>% filter( @@ -854,9 +826,7 @@ first_scot_bed_days_mh <- bed_days_mh_areas %>% pull(data) scot_rate_change_beds_mh <- percent_change_calc(scot_bed_days_mh2, first_scot_bed_days_mh) -scot_word_change_beds_mh <- if_else(scot_bed_days_mh2 > first_scot_bed_days_mh, - "increase", "decrease" -) +scot_word_change_beds_mh <- word_change_calc(scot_bed_days_mh2, first_scot_bed_days_mh) # NHS health board hb_mh_beddays <- bed_days_mh_areas %>% @@ -876,9 +846,7 @@ first_fy_hb_mh <- filter( )$data hb_rate_change_mh <- round(abs(hb_mh_beddays2 - first_fy_hb_mh) / first_fy_hb_mh * 100, digits = 1) -word_change_hb_mh <- if_else(hb_mh_beddays2 > first_fy_hb_mh, - "increase", "decrease" -) +word_change_hb_mh <- word_change_calc(hb_mh_beddays2, first_fy_hb_mh) other_loc_bed_days_mh <- bed_days_mh %>% group_by(financial_year, hscp_locality) %>% @@ -1069,9 +1037,7 @@ first_fy_hb_ae <- filter( )$data hb_rate_change_ae <- percent_change_calc(hb_ae2, first_fy_hb_ae) -word_change_hb_ae <- if_else(hb_ae2 > first_fy_hb_ae, - "increase", "decrease" -) +word_change_hb_ae <- word_change_calc(hb_ae2, first_fy_hb_ae) other_loc_ae_att <- ae_attendances %>% group_by(financial_year, hscp_locality) %>% @@ -1201,9 +1167,7 @@ first_fy_hb_dd <- filter( )$data hb_rate_change_dd <- percent_change_calc(hb_dd2, first_fy_hb_dd) -word_change_hb_dd <- if_else(hb_dd2 > first_fy_hb_dd, - "increase", "decrease" -) +word_change_hb_dd <- word_change_calc(hb_dd2, first_fy_hb_dd) other_loc_dd <- delayed_disch %>% @@ -1327,9 +1291,7 @@ first_fy_hb_falls <- filter( )$data hb_rate_change_falls <- round(abs(hb_falls2 - first_fy_hb_falls) / first_fy_hb_falls * 100, digits = 1) -word_change_hb_falls <- if_else(hb_falls2 > first_fy_hb_falls, - "increase", "decrease" -) +word_change_hb_falls <- word_change_calc(hb_falls2, first_fy_hb_falls) # 6. Readmissions (28 days) ---- # _________________________________________________________________________ @@ -1507,9 +1469,7 @@ first_fy_hb_read <- filter( )$data hb_rate_change_read <- percent_change_calc(hb_read2, first_fy_hb_read) -word_change_hb_read <- if_else(hb_read2 > first_fy_hb_read, - "increase", "decrease" -) +word_change_hb_read <- word_change_calc(hb_read2, first_fy_hb_read) # 7. Comm 6 months ---- # _________________________________________________________________________________ @@ -1680,9 +1640,7 @@ latest_ppa_loc <- ppa_areas %>% mutate(formatted_data = format(data, big.mark = ",")) ppa_diff <- percent_change_calc(latest_ppa_loc$data[2], latest_ppa_loc$data[1]) -ppa_word_change <- if_else(latest_ppa_loc$data[2] > latest_ppa_loc$data[1], - "increase", "decrease" -) +ppa_word_change <- word_change_calc(latest_ppa_loc$data[2], latest_ppa_loc$data[1]) hscp_ppa <- ppa_areas %>% filter( @@ -1692,9 +1650,7 @@ hscp_ppa <- ppa_areas %>% mutate(formatted_data = format(data, big.mark = ",")) ppa_diff_hscp <- percent_change_calc(hscp_ppa$data[2], hscp_ppa$data[1]) -ppa_word_change_hscp <- if_else(hscp_ppa$data[2] > hscp_ppa$data[1], - "increase", "decrease" -) +ppa_word_change_hscp <- word_change_calc(hscp_ppa$data[2], hscp_ppa$data[1]) scot_ppa <- ppa_areas %>% filter( @@ -1704,9 +1660,7 @@ scot_ppa <- ppa_areas %>% mutate(formatted_data = format(data, big.mark = ",")) diff_scot_ppa <- percent_change_calc(scot_ppa$data[2], scot_ppa$data[1]) -word_change_scot_ppa <- if_else(scot_ppa$data[2] > scot_ppa$data[1], - "increase", "decrease" -) +word_change_scot_ppa <- word_change_calc(scot_ppa$data[2], scot_ppa$data[1]) # NHS health board hb_ppa <- ppa_areas %>% @@ -1717,9 +1671,7 @@ hb_ppa <- ppa_areas %>% mutate(formatted_data = format(data, big.mark = ",")) diff_hb_ppa <- percent_change_calc(hb_ppa$data[2], hb_ppa$data[1]) -word_change_hb_ppa <- if_else(hb_ppa$data[2] > hb_ppa$data[1], - "increase", "decrease" -) +word_change_hb_ppa <- word_change_calc(hb_ppa$data[2], hb_ppa$data[1]) other_loc_ppa <- ppa %>% group_by(financial_year, hscp_locality) %>% @@ -1798,9 +1750,7 @@ loc_psych_hosp <- psych_hosp %>% mutate(measure2 = format(measure, big.mark = ",")) diff_loc_psych <- percent_change_calc(loc_psych_hosp$measure[2], loc_psych_hosp$measure[1]) -word_change_loc_psych <- if_else(loc_psych_hosp$measure[2] > loc_psych_hosp$measure[1], - "increase", "decrease" -) +word_change_loc_psych <- word_change_calc(loc_psych_hosp$measure[2], loc_psych_hosp$measure[1]) # HSCP hscp_psych_hosp <- psych_hosp %>% @@ -1813,9 +1763,7 @@ hscp_psych_hosp <- psych_hosp %>% mutate(measure2 = format(measure, big.mark = ",")) diff_hscp_psych <- percent_change_calc(hscp_psych_hosp$measure[2], hscp_psych_hosp$measure[1]) -word_change_hscp_psych <- if_else(hscp_psych_hosp$measure[2] > hscp_psych_hosp$measure[1], - "increase", "decrease" -) +word_change_hscp_psych <- word_change_calc(hscp_psych_hosp$measure[2], hscp_psych_hosp$measure[1]) # NHS health board hb_psych_hosp <- psych_hosp %>% @@ -1828,9 +1776,7 @@ hb_psych_hosp <- psych_hosp %>% mutate(measure2 = format(measure, big.mark = ",")) diff_hb_psych <- percent_change_calc(hb_psych_hosp$measure[2], hb_psych_hosp$measure[1]) -word_change_hb_psych <- if_else(hb_psych_hosp$measure[2] > hb_psych_hosp$measure[1], - "increase", "decrease" -) +word_change_hb_psych <- word_change_calc(hb_psych_hosp$measure[2], hb_psych_hosp$measure[1]) # Scotland scot_psych_hosp <- psych_hosp %>% @@ -1843,9 +1789,7 @@ scot_psych_hosp <- psych_hosp %>% mutate(measure2 = format(measure, big.mark = ",")) diff_scot_psych <- percent_change_calc(scot_psych_hosp$measure[2], scot_psych_hosp$measure[1]) -word_change_scot_psych <- if_else(scot_psych_hosp$measure[2] > scot_psych_hosp$measure[1], - "increase", "decrease" -) +word_change_scot_psych <- word_change_calc(scot_psych_hosp$measure[2], scot_psych_hosp$measure[1]) From d851360fe4e4173baa6369eed31fa5cb807f0af8 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 26 Sep 2024 17:13:10 +0100 Subject: [PATCH 30/38] Rename some variables to snake_case --- .../Locality_Profiles_Master_Markdown.Rmd | 6 +++--- Unscheduled Care/2. Unscheduled Care outputs.R | 6 +++--- Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index ea211f2..f5eb52b 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -778,7 +778,7 @@ As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for emergency readmissions per 1,000 discharges split by geographical area."} -Read_loc_ts +read_loc_ts x <- x + 1 ``` @@ -791,7 +791,7 @@ As presented in Figure `r x`, the highest emergency readmission (28 days) rate f \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for emergency readmissions per 1,000 discharges split by age group."} -Read_age_ts +read_age_ts x <- x + 1 ``` @@ -843,7 +843,7 @@ The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$forma \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for potentially preventable admissions per 100,000 population split by geographical area."} -PPA_loc_ts +ppa_loc_ts x <- x + 1 ``` diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 5cfeca6..8282bba 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -1312,7 +1312,7 @@ readmissions_age <- readmissions %>% ungroup() %>% mutate(data = round_half_up(read_28 / discharges * 1000, 1)) -Read_age_ts <- age_group_trend_usc( +read_age_ts <- age_group_trend_usc( data_for_plot = readmissions_age, plot_title = paste("Readmission rate (28 days) per 1,000 discharges by age group\n for", LOCALITY), yaxis_title = "Readmission rate (28 days)\n per 1,000 discharges", @@ -1343,7 +1343,7 @@ readmissions_areas <- left_join(read1, read2) %>% rm(read1, read2) -Read_loc_ts <- area_trend_usc( +read_loc_ts <- area_trend_usc( data_for_plot = readmissions_areas, plot_title = paste("Readmission rate (28 days) per 1,000 discharges over time by residence"), yaxis_title = "Readmission rate (28 days)\n per 1,000 discharges", @@ -1619,7 +1619,7 @@ ppa_areas <- ppa %>% drop_na(year) -PPA_loc_ts <- area_trend_usc( +ppa_loc_ts <- area_trend_usc( data_for_plot = ppa_areas, plot_title = paste("Potentially Preventable Emergency Admissions per 100,000 by residence"), yaxis_title = "PPA rate\nper 100,000 population", diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 0f979d2..7512446 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -160,7 +160,7 @@ As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} -Read_loc_ts +read_loc_ts x <- x + 1 ``` @@ -172,7 +172,7 @@ As presented in Figure `r x`, the highest emergency readmission (28 days) rate f \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} -Read_age_ts +read_age_ts x <- x + 1 ``` @@ -225,7 +225,7 @@ The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$forma \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} -PPA_loc_ts +ppa_loc_ts x <- x + 1 ``` From 4280f0632b25537e9f789d3e91b57d58520f9c51 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 26 Sep 2024 17:13:47 +0100 Subject: [PATCH 31/38] Tidy USC code --- .../2. Unscheduled Care outputs.R | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 8282bba..d6e0a0e 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -75,8 +75,6 @@ populations22 <- read_in_dz_pops22() populations <- rbind(populations, populations22) -# pop_max_year <- max(populations$year) - # compute age bands populations$"Pop0_17" <- rowSums(subset(populations, select = age0:age17)) populations$"Pop18_44" <- rowSums(subset(populations, select = age18:age44)) @@ -291,12 +289,15 @@ area_trend_usc <- function(data_for_plot, plot_title, yaxis_title, source) { # Functions for text variables percent_change_calc <- function(numerator, denominator, digits = 1) { - round(abs(numerator - denominator) / denominator * 100, digits = digits) + janitor::round_half_up( + abs(numerator - denominator) / denominator * 100, + digits = digits + ) } word_change_calc <- function(latest, first) { - case_when( - near(latest, first) ~ "same", + dplyr::case_when( + dplyr::near(latest, first) ~ "same", latest > first ~ "increase", latest < first ~ "decrease" ) @@ -1729,10 +1730,15 @@ other_locs_psych_hosp <- psych_hosp %>% mutate(measure = as.character(round_half_up(measure, 1))) %>% pivot_wider(names_from = hscp_locality, values_from = measure) -hscp_psych_hosp <- round_half_up(filter(psych_hosp, year == max(year) & - (area_name == HSCP & area_type == "HSCP"))$measure, 1) +hscp_psych_hosp <- round_half_up( + filter(psych_hosp, year == max(year) & (area_name == HSCP & area_type == "HSCP"))$measure, + 1 +) -scot_psych_hosp <- round_half_up(filter(psych_hosp, year == max(year) & area_name == "Scotland")$measure, 1) +scot_psych_hosp <- round_half_up( + filter(psych_hosp, year == max(year) & area_name == "Scotland")$measure, + 1 +) list_years <- unique(psych_hosp_time_trend$data[6]) From de46a210b6bacab9b561a73d14eb2bb4891c79ba Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 26 Sep 2024 17:31:05 +0100 Subject: [PATCH 32/38] Tidy Markdown --- .../Locality_Profiles_Master_Markdown.Rmd | 71 +++++----- .../Unscheduled-Care-Testing-Markdown.Rmd | 125 +++++++----------- 2 files changed, 85 insertions(+), 111 deletions(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index f5eb52b..1282671 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -713,6 +713,7 @@ Figure `r x` presents the unscheduled bed days rate per 100,000 population in th As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. #### Figure `r x`: Unscheduled acute bed days by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing six-year time trends for unscheduled acute bed days per 100,000 population for Locality, HSCP, Health Board and all Scotland."} @@ -721,11 +722,12 @@ BDs_loc_ts x <- x + 1 ``` -Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. As presented in Figure `r x`, the highest unscheduled bed days rate for the `r LOCALITY` locality in `r max_ubd_age` is `r latest_ubd_max_age1` bed days per 100,000 population for the `r age_group_max_ubd` age group with a percentage `r max_word_change_ubd` of `r max_rate_change_ubd`% since `r min_ubd_age`. The lowest unscheduled bed days rate for `r LOCALITY` in `r max_ubd_age` is `r latest_ubd_min_age1` bed days per 100,000 population for the `r age_group_min_ubd` age group with a percentage `r min_word_change_ubd` of `r min_rate_change_ubd`% since `r min_ubd_age`. #### Figure `r x`: Unscheduled acute bed days by age group + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing six-year time trends for emergency admissions per 100,000 population split by age group."} @@ -734,16 +736,16 @@ BDs_age_ts x <- x + 1 ``` - ##### Page break ### A&E Attendances -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. #### Figure `r x`: A&E attendances by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing six-year time trends for A&E attendancess per 100,000 population for Locality, HSCP, Health Board and all Scotland."} @@ -752,11 +754,12 @@ AandE_loc_ts x <- x + 1 ``` -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the highest A&E attendance rate for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` per 100,000 population for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The lowest A&E attendance rate for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` per 100,000 population for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. #### Figure `r x`: A&E attendances by age group + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing six-year time trends for A&E attendancess per 100,000 population split by age group."} @@ -765,16 +768,16 @@ AandE_age_ts x <- x + 1 ``` - ##### Page break ### Emergency Readmissions (28 days) -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. #### Figure `r x`: Emergency readmissions (28 days) by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for emergency readmissions per 1,000 discharges split by geographical area."} @@ -783,11 +786,12 @@ read_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the highest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` per 1,000 discharges for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The lowest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` per 1,000 discharges for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. #### Figure `r x`: Emergency readmissions (28 days) by age group + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for emergency readmissions per 1,000 discharges split by age group."} @@ -796,16 +800,16 @@ read_age_ts x <- x + 1 ``` - ##### Page break ### Delayed Discharge Bed Days -Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. +Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. -As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. +As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. #### Figure `r x`: Delayed discharge bed days in the population aged 65+ by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for delayed discharge beddays per 100,000 population aged 65+ split by geographical area."} @@ -816,11 +820,12 @@ x <- x + 1 ### Emergency admissions from a fall -Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged 65 and over in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged 65 and over in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. -As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. +As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. #### Figure `r x`: Falls in the population aged 65+ by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for emergency admissions from a fall per 100,000 population aged 65+ split by geographical area."} @@ -829,17 +834,16 @@ Falls_loc_ts x <- x + 1 ``` - ##### Page break ### Potentially Preventable Admissions (PPAs) -Information on the conditions included in Potentially Preventable Admissions (PPA)s is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. +Information on the conditions included in Potentially Preventable Admissions (PPA)s is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. -Figure `r x` presents the PPA rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for PPAs in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. -The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. +Figure `r x` presents the PPA rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for PPAs in the `r LOCALITY` locality for `r max_year_ppa_areas` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. #### Figure `r x`: Potentially Preventable Admissions (PPAs) by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing seven-year time trends for potentially preventable admissions per 100,000 population split by geographical area."} @@ -847,9 +851,8 @@ ppa_loc_ts x <- x + 1 ``` -\newline - +\newline ##### Page break @@ -861,8 +864,8 @@ x <- x + 1 This section looks at mental health-related unscheduled care indicators. For the most recent time period available, `r LOCALITY` had: - - **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp$measure[2]` in Scotland^4^. - - **`r latest_bed_days_mh_loc1`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh1` in Scotland. +- **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp$measure[2]` in Scotland^4^. +- **`r latest_bed_days_mh_loc1`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh1` in Scotland. \newline @@ -873,6 +876,7 @@ Figure `r x` presents the psychiatric patient hospitalisation 3-year aggregate r As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, a `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, a `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, a `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, a `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. #### Figure `r x`: Psychiatric patient hospitalisations by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4.5, warning = FALSE, fig.cap = "A line graph showing ten-year time trends grouped into 3 year aggregates for psychiatric patient hospitalisations per 100,000 population split by geographical area."} @@ -881,16 +885,16 @@ psych_hosp_time_trend x <- x + 1 ``` - ##### Page break ### Unscheduled Mental Health Specialty Bed Days -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. -As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. +As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. #### Figure `r x`: Unscheduled mental health specialty bed days by geographical area + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4, warning = FALSE, fig.cap = "A line graph showing six-year time trends for uncscheduled mental health specialty bed days per 100,000 population split by geographical area."} @@ -899,11 +903,12 @@ BDMH_loc_ts x <- x + 1 ``` -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. As presented in Figure `r x`, the highest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` per 100,000 population for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The lowest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` per 100,000 population for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. #### Figure `r x`: Unscheduled mental health specialty bed days by age group + \newline ```{r echo = FALSE, fig.width = 8.5, fig.height = 4.5, warning = FALSE, fig.cap = "A line graph showing six-year time trends for uncscheduled mental health specialty bed days per 100,000 population split by geographical area."} @@ -912,23 +917,22 @@ BDMH_age_ts x <- x + 1 ``` - - ##### Page Break -### Footnotes -1. Population projections are not currently provided by the National Records Scotland (NRS) at the locality level. To explore how the population in `r LOCALITY` is expected to change in the future, the percent changes in population projection to 2025 for `r HSCP` by age group and gender were calculated using the NRS Local Authority Population Projections. These percent changes were then applied to the `r LOCALITY` 2018 mid-year population estimates (also split by age group and gender) to obtain population projection estimates for `r LOCALITY`, based on the projections for the HSCP and the current population structure of the locality. +### Footnotes -2. Care Home data included in the Services Map and Table was sourced from the [Care Inspectorate](https://www.careinspectorate.com/images/documents/5713/MDSF_data_31%20May%202020.csv). [GP Practice](https://www.opendata.nhs.scot/dataset/gp-practice-contact-details-and-list-sizes) data from October 2021, and [Hospital](https://www.opendata.nhs.scot/dataset/hospital-codes) and [A&E](https://www.opendata.nhs.scot/dataset/nhs-scotland-accident-emergency-sites) data was sourced from Public Health Scotland Open Data platform. Only services that are within the physical boundary of the HSCP or Locality are included in the map and table, so there may be services outside `r HSCP` that people may use but are not shown. Information on access deprivation was taken from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). +1. Population projections are not currently provided by the National Records Scotland (NRS) at the locality level. To explore how the population in `r LOCALITY` is expected to change in the future, the percent changes in population projection to 2025 for `r HSCP` by age group and gender were calculated using the NRS Local Authority Population Projections. These percent changes were then applied to the `r LOCALITY` 2018 mid-year population estimates (also split by age group and gender) to obtain population projection estimates for `r LOCALITY`, based on the projections for the HSCP and the current population structure of the locality. -3. Sourced from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). More recent data may be available for the indicators elsewhere. +2. Care Home data included in the Services Map and Table was sourced from the [Care Inspectorate](https://www.careinspectorate.com/images/documents/5713/MDSF_data_31%20May%202020.csv). [GP Practice](https://www.opendata.nhs.scot/dataset/gp-practice-contact-details-and-list-sizes) data from October 2021, and [Hospital](https://www.opendata.nhs.scot/dataset/hospital-codes) and [A&E](https://www.opendata.nhs.scot/dataset/nhs-scotland-accident-emergency-sites) data was sourced from Public Health Scotland Open Data platform. Only services that are within the physical boundary of the HSCP or Locality are included in the map and table, so there may be services outside `r HSCP` that people may use but are not shown. Information on access deprivation was taken from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). -4. Data taken from ScotPHO is often reported using the European Age-Sex Standardised Rate per 100,000. This allows for comparisons across different areas to be made. For more information on how these rates are calculated, please refer to [https://publichealthscotland.scot/services/geography-population-and-deprivation-support/population/](https://publichealthscotland.scot/services/geography-population-and-deprivation-support/population/) +3. Sourced from [ScotPHO](https://scotland.shinyapps.io/ScotPHO_profiles_tool/). More recent data may be available for the indicators elsewhere. -5. Physical long-term conditions data comes from the Source Linkage Files, and the conditions are identified using ICD-9 and ICD-10 codes in the diagnosis fields. Please note that the Source Linkage Files data only contains information on people who have had contact with the NHS through either inpatient admissions, outpatient attendances, daycase attendances, A&E attendances or through prescribed items, the data does not show all service users in Scotland who have been diagnosed with an LTC as not all of these individuals will have used these services. Also, note that LTC rates are based on an adjusted population indicator in the Source Linkage Files so that population sizes are closer to the official estimates. +4. Data taken from ScotPHO is often reported using the European Age-Sex Standardised Rate per 100,000. This allows for comparisons across different areas to be made. For more information on how these rates are calculated, please refer to +5. Physical long-term conditions data comes from the Source Linkage Files, and the conditions are identified using ICD-9 and ICD-10 codes in the diagnosis fields. Please note that the Source Linkage Files data only contains information on people who have had contact with the NHS through either inpatient admissions, outpatient attendances, daycase attendances, A&E attendances or through prescribed items, the data does not show all service users in Scotland who have been diagnosed with an LTC as not all of these individuals will have used these services. Also, note that LTC rates are based on an adjusted population indicator in the Source Linkage Files so that population sizes are closer to the official estimates. ##### Page Break + ## Appendices ### Appendix 1: Indicator Definitions @@ -939,7 +943,6 @@ x <- x + 1 knitr::kable(indicator_defs, format = "markdown") ``` - ##### Page break ### Appendix 2: Date of Indicator Data Extractions @@ -950,12 +953,10 @@ knitr::kable(indicator_defs, format = "markdown") knitr::kable(dates_extract, col.names = c("**Section**", "**Indicator**", "**Date of data extraction**"), format = "markdown") ``` - ##### Page Break ### Appendix 3: Conditions included as Potentially Preventable Admissions (PPAs) - ```{r echo = FALSE, fig.width = 7, fig.height = 10, warning = FALSE} knitr::kable(ppa_def, format = "markdown") ``` diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 7512446..442f2fe 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -8,7 +8,6 @@ output: df_print: paged --- - ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) options(kableExtra.auto_format = FALSE) @@ -31,7 +30,6 @@ x <- 1 # object for figure numbers y <- 1 # object for table numbers ``` - ## Hospital and Community Care ###Summary @@ -40,31 +38,29 @@ This section includes acute hospital data, delayed discharge bed days and A&E at **For the most recent time periods available, `r LOCALITY` had:** - - **`r latest_emergency_adm_loc1`** emergency hospital admissions per 100,000 population, compared to `r scot_emergency_adm1` in Scotland. - - - **`r latest_bed_days_loc1`** unscheduled acute specialty bed days per 100,000 population, compared to `r scot_bed_days1` in Scotland. - - - **`r latest_ae_att_loc1`** A&E attendances per 100,000 population, compared to `r scot_ae_att1` in Scotland. - - - **`r latest_dd_loc1`** delayed discharge bed days per 100,000 population aged over 65, compared to `r scot_dd1` in Scotland. - - - **`r latest_falls_loc1`** emergency hospital admissions from falls per 100,000 population aged over 65, compared to `r scot_falls1` in Scotland. - - - **`r latest_read_loc1`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. - - - **`r latest_ppa_loc$formatted_data[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$formatted_data[2]` in Scotland. +- **`r latest_emergency_adm_loc1`** emergency hospital admissions per 100,000 population, compared to `r scot_emergency_adm1` in Scotland. + +- **`r latest_bed_days_loc1`** unscheduled acute specialty bed days per 100,000 population, compared to `r scot_bed_days1` in Scotland. + +- **`r latest_ae_att_loc1`** A&E attendances per 100,000 population, compared to `r scot_ae_att1` in Scotland. + +- **`r latest_dd_loc1`** delayed discharge bed days per 100,000 population aged over 65, compared to `r scot_dd1` in Scotland. +- **`r latest_falls_loc1`** emergency hospital admissions from falls per 100,000 population aged over 65, compared to `r scot_falls1` in Scotland. + +- **`r latest_read_loc1`** emergency readmissions (28 day) per 1,000 discharges, compared to `r scot_read` in Scotland. + +- **`r latest_ppa_loc$formatted_data[2]`** potentially preventable hospital admissions per 100,000 population, compared to `r scot_ppa$formatted_data[2]` in Scotland. #####Pagebreak ### Emergency Admissions -Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. -####Figure `r x`: Emergency admissions by geographical area -\newline +####Figure `r x`: Emergency admissions by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} EAs_loc_ts @@ -72,12 +68,11 @@ EAs_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_ea_age` to `r max_ea_age` by age group. +Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_ea_age` to `r max_ea_age` by age group. -As presented in Figure `r x`, the highest emergency admissions rate for the `r LOCALITY` locality in `r max_ea_age` is `r latest_ea_max_age1` per 100,000 population for the `r age_group_max_ea` age group with a percentage `r max_word_change_ea` of `r max_rate_change_ea`% since `r min_ea_age`. The lowest emergency admissions rate for `r LOCALITY` in `r max_ea_age` is `r latest_ea_min_age1` per 100,000 population for the `r age_group_min_ea` age group with a percentage `r min_word_change_ea` of `r min_rate_change_ea`% since `r min_ea_age`. +As presented in Figure `r x`, the highest emergency admissions rate for the `r LOCALITY` locality in `r max_ea_age` is `r latest_ea_max_age1` per 100,000 population for the `r age_group_max_ea` age group with a percentage `r max_word_change_ea` of `r max_rate_change_ea`% since `r min_ea_age`. The lowest emergency admissions rate for `r LOCALITY` in `r max_ea_age` is `r latest_ea_min_age1` per 100,000 population for the `r age_group_min_ea` age group with a percentage `r min_word_change_ea` of `r min_rate_change_ea`% since `r min_ea_age`. -####Figure `r x`: Emergency admissions by age group -\newline +####Figure `r x`: Emergency admissions by age group \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} EAs_age_ts @@ -93,8 +88,7 @@ Figure `r x` presents the unscheduled bed days rate per 100,000 population in th As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. -####Figure `r x`: Unscheduled acute bed days by geographical area -\newline +####Figure `r x`: Unscheduled acute bed days by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} BDs_loc_ts @@ -102,12 +96,11 @@ BDs_loc_ts x <- x + 1 ``` -Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. +Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_ubd_age` to `r max_ubd_age` by age group. As presented in Figure `r x`, the highest unscheduled bed days rate for the `r LOCALITY` locality in `r max_ubd_age` is `r latest_ubd_max_age1` bed days per 100,000 population for the `r age_group_max_ubd` age group with a percentage `r max_word_change_ubd` of `r max_rate_change_ubd`% since `r min_ubd_age`. The lowest unscheduled bed days rate for `r LOCALITY` in `r max_ubd_age` is `r latest_ubd_min_age1` bed days per 100,000 population for the `r age_group_min_ubd` age group with a percentage `r min_word_change_ubd` of `r min_rate_change_ubd`% since `r min_ubd_age`. -####Figure `r x`: Unscheduled acute bed days by age group -\newline +####Figure `r x`: Unscheduled acute bed days by age group \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} BDs_age_ts @@ -115,17 +108,15 @@ BDs_age_ts x <- x + 1 ``` - ##### Page break ### A&E Attendances -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. -####Figure `r x`: A&E attendances by geographical area -\newline +####Figure `r x`: A&E attendances by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} AandE_loc_ts @@ -133,12 +124,11 @@ AandE_loc_ts x <- x + 1 ``` -Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. +Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area` by age group. As presented in Figure `r x`, the highest A&E attendance rate for the `r LOCALITY` locality in `r max_year_ae_age` is `r latest_ae_att_loc1_age` per 100,000 population for the `r age_group_max` age group with a percentage `r word_change_rate_ae_age` of `r percent_rate_change_ae_age`% since `r min_year_ae_age`. The lowest A&E attendance rate for `r LOCALITY` in `r max_year_ae_age` is `r latest_ae_att_loc1_age_min` per 100,000 population for the `r age_group_min` age group with a percentage `r word_change_rate_ae_age2` of `r percent_rate_change_ae_age2`% since `r min_year_ae_age`. -####Figure `r x`: A&E attendances by age group -\newline +####Figure `r x`: A&E attendances by age group \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} AandE_age_ts @@ -146,30 +136,27 @@ AandE_age_ts x <- x + 1 ``` - ##### Page break ### Emergency Readmissions (28 days) - -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. -####Figure `r x`: Emergency readmissions (28 days) by geographical area -\newline +####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} read_loc_ts x <- x + 1 ``` -Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. + +Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_age` to `r max_year_re_age` by age group. As presented in Figure `r x`, the highest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_max_age_data` per 1,000 discharges for the `r latest_re_max_age_group` age group with a percentage `r word_change_rate_re_age` of `r percent_rate_change_re_age`% since `r min_year_re_age`. The lowest emergency readmission (28 days) rate for the `r LOCALITY` locality in `r max_year_re_age` is `r latest_re_min_age_data` per 1,000 discharges for the `r latest_re_min_age_group` age group with a percentage `r word_change_rate_re_age_min` of `r percent_rate_change_re_age_min`% since `r min_year_re_age`. -####Figure `r x`: Emergency readmissions (28 days) by age group -\newline +####Figure `r x`: Emergency readmissions (28 days) by age group \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} read_age_ts @@ -177,17 +164,15 @@ read_age_ts x <- x + 1 ``` - ##### Page break ### Delayed Discharge Bed Days -Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. +Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. -As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd ` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. +As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. -####Figure `r x`: Delayed discharge bed days in population aged 65+ by geographical area -\newline +####Figure `r x`: Delayed discharge bed days in population aged 65+ by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} DD_loc_ts @@ -197,12 +182,11 @@ x <- x + 1 ### Emergency admissions from a fall -Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. +Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. -As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls ` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. +As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. -####Figure `r x`: Falls in population aged 65+ by geographical area -\newline +####Figure `r x`: Falls in population aged 65+ by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} Falls_loc_ts @@ -210,50 +194,44 @@ Falls_loc_ts x <- x + 1 ``` - ##### Page break ### Potentially Preventable Admissions (PPAs) -Information conditions included in PPAs is available in Appendix 3. In `r max_year_ppa_areas`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. +Information conditions included in PPAs is available in Appendix 3. In `r max_year_ppa_areas`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. +Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. -Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas ` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. -The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. - -####Figure `r x`: PPAs by geographical area -\newline +####Figure `r x`: PPAs by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} ppa_loc_ts x <- x + 1 ``` -\newline - +\newline ##### Page break ## Hospital Care (Mental Health Speciality) -###Summary -This section looks at mental health related unscheduled care indicators. +###Summary This section looks at mental health related unscheduled care indicators. **For the most recent time periods available, `r LOCALITY` had:** - - **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp$measure[2]` in Scotland^4^. - - **`r latest_bed_days_mh_loc1`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh1` in Scotland. +- **`r psych_hosp_latest`** psychiatric patient hospitalisations per 100,000, compared to `r scot_psych_hosp$measure[2]` in Scotland^4^. +- **`r latest_bed_days_mh_loc1`** unscheduled mental health specialty bed days per 100,000, compared to `r scot_bed_days_mh1` in Scotland. \newline ### Psychiatric patient hospitalisations + Figure `r x` presents the psychiatric patient hospitalisation 3-year aggregate rate per 100,000 population in the `r LOCALITY` locality from `r loc_psych_hosp$period_short[1]` to `r loc_psych_hosp$period_short[2]`. As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, a `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, a `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, a `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, a `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. -####Figure `r x`: Psychiatric patient hospitalisations by geographical area -\newline +####Figure `r x`: Psychiatric patient hospitalisations by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} psych_hosp_time_trend @@ -261,18 +239,15 @@ psych_hosp_time_trend x <- x + 1 ``` - ##### Page break ### Unscheduled Mental Health Specialty Bed Days -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. -As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas ` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` -and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. +As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. -####Figure `r x`: Unscheduled mental health specialty bed days by geographical area -\newline +####Figure `r x`: Unscheduled mental health specialty bed days by geographical area \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} BDMH_loc_ts @@ -280,13 +255,11 @@ BDMH_loc_ts x <- x + 1 ``` -Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. +Figure `r x` presents the unscheduled mental health bed days rate per 100,000 in the `r LOCALITY` locality from `r min_year_bd_mh_age` to `r max_year_bd_mh_age` by age group. As presented in Figure `r x`, the highest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_max_age1` per 100,000 population for the `r age_group_max_mh` age group with a percentage `r max_word_change_beds_mh` of `r max_rate_change_beds_mh`% since `r min_year_bd_mh_age`. The lowest unscheduled mental health bed days rate for the `r LOCALITY` locality in `r max_year_bd_mh_age` is `r latest_bd_mh_min_age1` per 100,000 population for the `r age_group_min_mh` age group with a percentage `r min_word_change_beds_mh` of `r min_rate_change_beds_mh`% since `r min_year_bd_mh_age1`. - -####Figure `r x`: Unscheduled mental health specialty bed days by age group -\newline +####Figure `r x`: Unscheduled mental health specialty bed days by age group \newline ```{r echo = FALSE, fig.width= 7.6, fig.height= 4, warning = F} BDMH_age_ts From 96923cdb2d343c34659d36053e86766e43c915cc Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Tue, 1 Oct 2024 14:06:38 +0100 Subject: [PATCH 33/38] drop_na issue --- Unscheduled Care/2. Unscheduled Care outputs.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 103cca7..c8f021f 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -1558,8 +1558,8 @@ ppa <- arrow::read_parquet(paste0(import_folder, "ppa_smr.parquet")) %>% # % PPAs in locality under and over 65 ppa_total <- ppa %>% rename(n = admissions) %>% - aggregate_usc_area_data()%>% - drop_na(year) + aggregate_usc_area_data() + ppa_65plus <- ppa %>% filter(age_group %in% c("65 - 74", "75+")) %>% From 17e015db1e9eaea776843f7c309359b36f589fc5 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Tue, 1 Oct 2024 14:36:54 +0100 Subject: [PATCH 34/38] Fix of conflicts --- Unscheduled Care/2. Unscheduled Care outputs.R | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index f4a9650..4022283 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -1571,14 +1571,8 @@ ppa <- arrow::read_parquet(paste0(import_folder, "ppa_smr.parquet")) %>% # % PPAs in locality under and over 65 ppa_total <- ppa %>% rename(n = admissions) %>% -<<<<<<< HEAD aggregate_usc_area_data() -======= - aggregate_usc_area_data() %>% - drop_na(year) ->>>>>>> de46a210b6bacab9b561a73d14eb2bb4891c79ba - ppa_65plus <- ppa %>% filter(age_group %in% c("65 - 74", "75+")) %>% rename(n = admissions) %>% From 7ddd769333ac19e9be01e5e637cbf353ae1ec1e7 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 2 Oct 2024 16:01:53 +0100 Subject: [PATCH 35/38] Add the `get_article` function --- .../Global Script.R | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Master RMarkdown Document & Render Code/Global Script.R b/Master RMarkdown Document & Render Code/Global Script.R index ab51b0b..a24d91f 100755 --- a/Master RMarkdown Document & Render Code/Global Script.R +++ b/Master RMarkdown Document & Render Code/Global Script.R @@ -43,7 +43,21 @@ format_number_for_text <- function(x) { format(x, big.mark = ",") } -## Theme for charts +# This will return the correct article depending on the (max 2-digit) number supplied +# e.g. +# 81.2 -> an +# 18 -> an +# 7.2 -> an +# To be used for "a xx increase" which could be "an xx increase" +get_article <- function(number) { + if (substr(number, 1, 1) == "8" || substr(number, 1, 2) == "18") { + return("an") + } else { + return("a") + } +} + +## Theme for charts ---- # This theme is similar to theme_phs() from phsstyles but adapted to locality profiles # Differences include smaller text (to ensure names of areas always fit regardless of length) # Code taken from phsstyles Github page From cd2f249ddb1e7fddc1959b096e153e35be478489 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 2 Oct 2024 16:41:29 +0100 Subject: [PATCH 36/38] Add `get_article()` to Community Care dynamic text --- .../Locality_Profiles_Master_Markdown.Rmd | 18 +++++++++--------- .../Unscheduled-Care-Testing-Markdown.Rmd | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd index 1282671..41575a7 100755 --- a/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd +++ b/Master RMarkdown Document & Render Code/Locality_Profiles_Master_Markdown.Rmd @@ -680,7 +680,7 @@ x <- x + 1 Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. -As presented in Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. +As presented in Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, `r get_article(percent_rate_change)` `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, `r get_article(hscp_rate_change)` `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, `r get_article(hb_rate_change)` `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, `r get_article(scot_rate_change)` `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. #### Figure `r x`: Emergency admissions by geographical area \newline @@ -710,7 +710,7 @@ x <- x + 1 Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. -As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. +As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, `r get_article(rate_change_ubd)` `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, `r get_article(hscp_rate_ubd)` `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, `r get_article(hb_rate_change_ubd)` `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, `r get_article(scot_rate_ubd)` `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. #### Figure `r x`: Unscheduled acute bed days by geographical area @@ -742,7 +742,7 @@ x <- x + 1 Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. -As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. +As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, `r get_article(percent_rate_change_ae_areas)` `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, `r get_article(percent_rate_change_ae_areas_hscp)` `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, `r get_article(hb_rate_change_ae)` `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, `r get_article(percent_rate_change_ae_areas_scot)` `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. #### Figure `r x`: A&E attendances by geographical area @@ -774,7 +774,7 @@ x <- x + 1 Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. -As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. +As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, `r get_article(percent_rate_change_re_area)` `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, `r get_article(percent_rate_change_re_area_hscp)` `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, `r get_article(hb_rate_change_read)` `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, `r get_article(percent_rate_change_re_area_scot)` `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. #### Figure `r x`: Emergency readmissions (28 days) by geographical area @@ -806,7 +806,7 @@ x <- x + 1 Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. -As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. +As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd` is `r latest_dd_loc1`, `r get_article(percent_rate_change_dd_loc)` `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, `r get_article(percent_rate_change_dd_hscp)` `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, `r get_article(hb_rate_change_dd)` `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, `r get_article(percent_rate_change_dd_scot)` `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. #### Figure `r x`: Delayed discharge bed days in the population aged 65+ by geographical area @@ -822,7 +822,7 @@ x <- x + 1 Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged 65 and over in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. -As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. +As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls` is `r latest_falls_loc1`, `r get_article(percent_rate_change_falls_loc)` `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, `r get_article(percent_rate_change_falls_hscp)` `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, `r get_article(hb_rate_change_falls)` `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, `r get_article(percent_rate_change_falls_scot)` `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. #### Figure `r x`: Falls in the population aged 65+ by geographical area @@ -840,7 +840,7 @@ x <- x + 1 Information on the conditions included in Potentially Preventable Admissions (PPA)s is available in Appendix 3. In `r max_fy`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. -Figure `r x` presents the PPA rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for PPAs in the `r LOCALITY` locality for `r max_year_ppa_areas` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. +Figure `r x` presents the PPA rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for PPAs in the `r LOCALITY` locality for `r max_year_ppa_areas` is `r latest_ppa_loc$formatted_data[2]`, `r get_article(ppa_diff)` `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, `r get_article(ppa_diff_hscp)` `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, `r get_article(diff_hb_ppa)` `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, `r get_article(diff_scot_ppa)` `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. #### Figure `r x`: Potentially Preventable Admissions (PPAs) by geographical area @@ -873,7 +873,7 @@ This section looks at mental health-related unscheduled care indicators. For the Figure `r x` presents the psychiatric patient hospitalisation 3-year aggregate rate per 100,000 population in the `r LOCALITY` locality from `r loc_psych_hosp$period_short[1]` to `r loc_psych_hosp$period_short[2]`. -As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, a `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, a `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, a `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, a `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. +As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, `r get_article(diff_loc_psych)` `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, `r get_article(diff_hscp_psych)` `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, `r get_article(diff_hb_psych)` `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, `r get_article(diff_scot_psych)` `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. #### Figure `r x`: Psychiatric patient hospitalisations by geographical area @@ -891,7 +891,7 @@ x <- x + 1 Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. -As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. +As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas` is `r latest_bed_days_mh_loc1`, `r get_article(loc_rate_change_beds_mh)` `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, `r get_article(hscp_rate_change_beds_mh)` `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, `r get_article(hb_rate_change_mh)` `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, `r get_article(scot_rate_change_beds_mh)` `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. #### Figure `r x`: Unscheduled mental health specialty bed days by geographical area diff --git a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd index 442f2fe..d508e89 100755 --- a/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd +++ b/Unscheduled Care/Unscheduled-Care-Testing-Markdown.Rmd @@ -58,7 +58,7 @@ This section includes acute hospital data, delayed discharge bed days and A&E at Figure `r x` presents the emergency admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ea` to `r max_year_ea`. -As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, a `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, a `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, a `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, a `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. +As presented Figure `r x`, the emergency admissions rate in the `r LOCALITY` locality for `r max_year_ea` is `r latest_emergency_adm_loc1`, `r get_article(percent_rate_change)` `r percent_rate_change`% `r word_change_rate` since `r min_year_ea`. The `r HSCP` HSCP rate is `r hscp_emergency_adm1`, `r get_article(hscp_rate_change)` `r hscp_rate_change`% `r word_change_hscp` since `r min_year_ea`. The `r HB` health board rate is `r hscp_emergency_adm1` in `r max_year_ea`, `r get_article(hb_rate_change)` `r hb_rate_change`% `r word_change_hb` since `r min_year_ea` and the Scotland rate is `r scot_emergency_adm1`, `r get_article(scot_rate_change)` `r scot_rate_change`% `r word_change_scot` since `r min_year_ea`. ####Figure `r x`: Emergency admissions by geographical area \newline @@ -86,7 +86,7 @@ x <- x + 1 Figure `r x` presents the unscheduled bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ubd` to `r max_year_ubd`. -As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, a `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, a `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, a `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, a `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. +As presented in Figure `r x`, the unscheduled bed days rate in the `r LOCALITY` locality for `r max_year_ubd` is `r latest_bed_days_loc1`, `r get_article(rate_change_ubd)` `r rate_change_ubd`% `r word_change_ubd` since `r min_year_ubd` and the `r HSCP` HSCP rate is `r hscp_bed_days1`, `r get_article(hscp_rate_ubd)` `r hscp_rate_ubd`% `r hscp_change_ubd` since `r min_year_ubd`. The `r HB` health board rate for `r max_year_ubd` is `r hb_bed_days1`, `r get_article(hb_rate_change_ubd)` `r hb_rate_change_ubd`% `r word_change_hb_ubd` since `r min_year_ubd` and the Scotland rate is `r scot_bed_days1`, `r get_article(scot_rate_ubd)` `r scot_rate_ubd`% `r scot_change_ubd` since `r min_year_ubd`. ####Figure `r x`: Unscheduled acute bed days by geographical area \newline @@ -114,7 +114,7 @@ x <- x + 1 Figure `r x` presents the A&E attendance rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ae_area` to `r max_year_ae_area`. -As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, a `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, a `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, a `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, a `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. +As presented in Figure `r x`, the A&E attendance rate per 100,000 in the `r LOCALITY` locality for `r max_year_ae_area` is `r latest_ae_att_loc1`, `r get_article(percent_rate_change_ae_areas)` `r percent_rate_change_ae_areas`% `r word_change_rate_ae_areas` since `r min_year_ae_area` and the `r HSCP` HSCP rate is `r hscp_ae_att1`, `r get_article(percent_rate_change_ae_areas_hscp)` `r percent_rate_change_ae_areas_hscp`% `r word_change_rate_ae_areas_hscp` since `r min_year_ae_area`. The `r HB` health board rate for `r max_year_ae_area` is `r hb_ae1`, `r get_article(hb_rate_change_ae)` `r hb_rate_change_ae`% `r word_change_hb_ae` since `r min_year_ae_area` and the Scotland rate is `r scot_ae_att1`, `r get_article(percent_rate_change_ae_areas_scot)` `r percent_rate_change_ae_areas_scot`% `r word_change_rate_ae_areas_scot` since `r min_year_ae_area`. ####Figure `r x`: A&E attendances by geographical area \newline @@ -142,7 +142,7 @@ x <- x + 1 Figure `r x` presents the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality from `r min_year_re_area` to `r max_year_re_area`. -As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, a `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, a `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, a `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, a `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. +As presented in Figure `r x`, the emergency readmission (28 days) rate per 1,000 discharges in the `r LOCALITY` locality for `r max_year_re_area` is `r latest_read_loc1`, `r get_article(percent_rate_change_re_area)` `r percent_rate_change_re_area`% `r word_change_rate_re_area` since `r min_year_re_area` and the `r HSCP` HSCP rate is `r hscp_read`, `r get_article(percent_rate_change_re_area_hscp)` `r percent_rate_change_re_area_hscp`% `r word_change_rate_re_area_hscp` since `r min_year_re_area`. The `r HB` health board rate for `r max_year_re_area` is `r hb_read1`, `r get_article(hb_rate_change_read)` `r hb_rate_change_read`% `r word_change_hb_read` since `r min_year_re_area` and the Scotland rate is `r scot_read`, `r get_article(percent_rate_change_re_area_scot)` `r percent_rate_change_re_area_scot`% `r word_change_rate_re_area_scot` since `r min_year_re_area`. ####Figure `r x`: Emergency readmissions (28 days) by geographical area \newline @@ -170,7 +170,7 @@ x <- x + 1 Figure `r x` presents the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_dd` to `r max_year_dd`. -As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd` is `r latest_dd_loc1`, a `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, a `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, a `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, a `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. +As presented in Figure `r x`, the number of delayed discharge bed days per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_dd` is `r latest_dd_loc1`, `r get_article(percent_rate_change_dd_loc)` `r percent_rate_change_dd_loc`% `r word_change_rate_dd_loc` since `r min_year_dd` and the `r HSCP` HSCP rate is `r hscp_dd1`, `r get_article(percent_rate_change_dd_hscp)` `r percent_rate_change_dd_hscp`% `r word_change_rate_dd_hscp` since `r min_year_dd`. The `r HB` health board rate for `r max_year_dd` is `r hb_dd1`, `r get_article(hb_rate_change_dd)` `r hb_rate_change_dd`% `r word_change_hb_dd` since `r min_year_dd` and the Scotland rate is `r scot_dd1`, `r get_article(percent_rate_change_dd_scot)` `r percent_rate_change_dd_scot`% `r word_change_rate_dd_scot` since `r min_year_dd`. ####Figure `r x`: Delayed discharge bed days in population aged 65+ by geographical area \newline @@ -184,7 +184,7 @@ x <- x + 1 Figure `r x` presents the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality from `r min_year_falls` to `r max_year_falls`. -As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls` is `r latest_falls_loc1`, a `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, a `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, a `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, a `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. +As presented in Figure `r x`, the emergency admissions from falls rate per 100,000 population aged over 65+ in the `r LOCALITY` locality for `r max_year_falls` is `r latest_falls_loc1`, `r get_article(percent_rate_change_falls_loc)` `r percent_rate_change_falls_loc`% `r word_change_rate_falls_loc` since `r min_year_falls` and the `r HSCP` HSCP rate is `r hscp_falls1`, `r get_article(percent_rate_change_falls_hscp)` `r percent_rate_change_falls_hscp`% `r word_change_rate_falls_hscp` since `r min_year_falls`. The `r HB` health board rate for `r max_year_falls` is `r hb_falls1`, `r get_article(hb_rate_change_falls)` `r hb_rate_change_falls`% `r word_change_hb_falls` since `r min_year_falls` and the Scotland rate is `r scot_falls1`, `r get_article(percent_rate_change_falls_scot)` `r percent_rate_change_falls_scot`% `r word_change_rate_falls_scot` since `r min_year_falls`. ####Figure `r x`: Falls in population aged 65+ by geographical area \newline @@ -200,7 +200,7 @@ x <- x + 1 Information conditions included in PPAs is available in Appendix 3. In `r max_year_ppa_areas`, **`r latest_ppa_65plus`%** of PPAs in `r LOCALITY` were amongst those aged 65 and over, and **`r latest_ppa_under65`%** were amongst those aged under 65. -Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas` is `r latest_ppa_loc$formatted_data[2]`, a `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, a `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, a `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, a `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. +Figure `r x` presents the potentially preventable admissions rate per 100,000 population in the `r LOCALITY` locality from `r min_year_ppa_areas` to `r max_year_ppa_areas`. The rate per 100,000 population for potentially preventable admissions in the `r LOCALITY` locality for `r max_year_ppa_areas` is `r latest_ppa_loc$formatted_data[2]`, `r get_article(ppa_diff)` `r ppa_diff`% `r ppa_word_change` since `r latest_ppa_loc$financial_year[1]` and the `r HSCP` HSCP rate is `r hscp_ppa$data[2]`, `r get_article(ppa_diff_hscp)` `r ppa_diff_hscp`% `r ppa_word_change_hscp` since `r latest_ppa_loc$financial_year[1]`. The `r HB` health board rate for `r hb_ppa$financial_year[2]` is `r hb_ppa$formatted_data[2]`, `r get_article(diff_hb_ppa)` `r diff_hb_ppa`% `r word_change_hb_ppa` since `r hb_ppa$financial_year[]` and the Scotland rate is `r scot_ppa$formatted_data[2]`, `r get_article(diff_scot_ppa)` `r diff_scot_ppa`% `r word_change_scot_ppa` since `r hb_ppa$financial_year[1]`. ####Figure `r x`: PPAs by geographical area \newline @@ -229,7 +229,7 @@ x <- x + 1 Figure `r x` presents the psychiatric patient hospitalisation 3-year aggregate rate per 100,000 population in the `r LOCALITY` locality from `r loc_psych_hosp$period_short[1]` to `r loc_psych_hosp$period_short[2]`. -As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, a `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, a `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, a `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, a `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. +As presented in Figure `r x`, the 3-year aggregate psychiatric patient hospitalisation rate per 100,000 population in the `r LOCALITY` locality for `r loc_psych_hosp$period_short[2]` is `r loc_psych_hosp$measure[2]`, `r get_article(diff_loc_psych)` `r diff_loc_psych`% `r word_change_loc_psych` since `r loc_psych_hosp$period_short[1]` and the `r HSCP` HSCP rate is `r hscp_psych_hosp$measure[2]`, `r get_article(diff_hscp_psych)` `r diff_hscp_psych`% `r word_change_hscp_psych` since `r loc_psych_hosp$period_short[1]`. The `r HB` health board the 3-year aggregate rate for `r loc_psych_hosp$period_short[2]` is `r hb_psych_hosp$measure[2]`, `r get_article(diff_hb_psych)` `r diff_hb_psych`% `r word_change_hb_psych` since `r loc_psych_hosp$period_short[1]` and the Scotland the 3-year aggregate rate is `r scot_psych_hosp$measure[2]`, `r get_article(diff_scot_psych)` `r diff_scot_psych`% `r word_change_scot_psych` since `r loc_psych_hosp$period_short[1]`. ####Figure `r x`: Psychiatric patient hospitalisations by geographical area \newline @@ -245,7 +245,7 @@ x <- x + 1 Figure `r x` presents the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality from `r min_year_bd_mh_areas` to `r max_year_bd_mh_areas`. -As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas` is `r latest_bed_days_mh_loc1`, a `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, a `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, a `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, a `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. +As presented in Figure `r x`, the unscheduled mental health bed days rate per 100,000 population in the `r LOCALITY` locality for `r max_year_bd_mh_areas` is `r latest_bed_days_mh_loc1`, `r get_article(loc_rate_change_beds_mh)` `r loc_rate_change_beds_mh`% `r loc_word_change_beds_mh` since `r min_year_bd_mh_areas` and the `r HSCP` HSCP rate is `r hscp_bed_days_mh1`, `r get_article(hscp_rate_change_beds_mh)` `r hscp_rate_change_beds_mh`% `r hscp_word_change_beds_mh` since `r min_year_bd_mh_areas`. The `r HB` health board rate for `r max_year_bd_mh_areas` is `r hb_mh_beddays1`, `r get_article(hb_rate_change_mh)` `r hb_rate_change_mh`% `r word_change_hb_mh` since `r min_year_bd_mh_areas` and the Scotland rate is `r scot_bed_days_mh1`, `r get_article(scot_rate_change_beds_mh)` `r scot_rate_change_beds_mh`% `r scot_word_change_beds_mh` since `r min_year_bd_mh_areas`. ####Figure `r x`: Unscheduled mental health specialty bed days by geographical area \newline From c2307a052d2bf403ec456f26479689d8004d2396 Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 16 Oct 2024 15:35:22 +0100 Subject: [PATCH 37/38] Fix part to filter that wasn't working --- Unscheduled Care/2. Unscheduled Care outputs.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index 4022283..be06618 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -913,13 +913,16 @@ max_year_ae_age <- max(ae_att_age$financial_year) latest_ae_att_max_age <- ae_att_age %>% filter( - year == max(year), + year == max(year) + ) %>% + filter( data == max(data) ) %>% mutate(formatted_data = format(data, big.mark = ",")) latest_ae_att_loc1_age <- latest_ae_att_max_age %>% pull(formatted_data) latest_ae_att_loc2_age <- latest_ae_att_max_age %>% pull(data) + age_group_max <- latest_ae_att_max_age %>% pull(age_group) first_ae_att_max_age <- ae_att_age %>% From ea55539b436b2014505c70eea3d81fa8db729d7c Mon Sep 17 00:00:00 2001 From: JosieSteele Date: Wed, 16 Oct 2024 15:42:46 +0100 Subject: [PATCH 38/38] Fix to another filter --- Unscheduled Care/2. Unscheduled Care outputs.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Unscheduled Care/2. Unscheduled Care outputs.R b/Unscheduled Care/2. Unscheduled Care outputs.R index be06618..5f11672 100755 --- a/Unscheduled Care/2. Unscheduled Care outputs.R +++ b/Unscheduled Care/2. Unscheduled Care outputs.R @@ -1360,7 +1360,8 @@ max_year_re_age <- max(readmissions_age$financial_year) latest_re_max_age <- readmissions_age %>% filter( - financial_year == max(financial_year), + financial_year == max(financial_year)) %>% + filter( data == max(data) ) @@ -1819,3 +1820,4 @@ word_change_scot_psych <- word_change_calc(scot_psych_hosp$measure[2], scot_psyc # "Readmissions 28" = readmissions, # "PPA" = ppa), # path = paste0(lp_path, "Publishing/SMR Data.xlsx")) +