Skip to content

Commit

Permalink
Updated england secondary care metrics to latest data
Browse files Browse the repository at this point in the history
  • Loading branch information
jennajt committed Sep 3, 2024
1 parent 7ef51f4 commit 017c10d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 35 deletions.
Binary file modified R/sysdata.rda
Binary file not shown.
37 changes: 21 additions & 16 deletions data-raw/england-critical-general-acute-beds.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ df <-
tibble(
id = query_urls |>
slice(which(
query_urls$id == "nhs_critical_general_acute_beds_april_22"):which(query_urls$id == "nhs_critical_general_acute_beds_july_23")
) |>
query_urls$id == "nhs_critical_general_acute_beds_april_22"
):which(query_urls$id == "nhs_critical_general_acute_beds_july_23")) |>
filter(!(date %in% c("April 2023"))) |>
pull(id),

sheet = rep(2, 15),
range = c(rep("D26:V163", 7), rep("D26:AB163", 8)),
date = c(
Expand Down Expand Up @@ -172,14 +171,14 @@ scrape_data_after_aug23 <- function(id, sheet, range, date) {
select(
nhs_trust22_code = 1,
general_acute_beds_available = 3,
general_acute_beds_occupied =7,
general_acute_beds_occupied = 7,
general_acute_beds_occupancy_rate = 8,
adult_general_acute_beds_available = 10,
adult_general_acute_beds_occupied =14,
adult_general_acute_beds_occupied = 14,
adult_general_acute_beds_occupancy_rate = 15,
paediatric_general_acute_beds_available =17,
paediatric_general_acute_beds_available = 17,
paediatric_general_acute_beds_occupied = 21,
paediatric_general_acute_beds_occupancy_rate =22,
paediatric_general_acute_beds_occupancy_rate = 22,
adult_critical_care_beds_available = 24,
adult_critical_care_beds_occupied = 25,
adult_critical_care_occupancy_rate = 26,
Expand All @@ -188,10 +187,10 @@ scrape_data_after_aug23 <- function(id, sheet, range, date) {
paediatric_intensive_cared_occupancy_rate = 29,
neonatal_intensive_care_bed_avaialble = 30,
neonatal_intensive_care_bed_occupied = 31,
neonatal_intensive_care_occupancy_rate =32
neonatal_intensive_care_occupancy_rate = 32
) |>
mutate(date = date) |>
relocate(date, .after = nhs_trust22_code) |>
mutate(date = date) |>
relocate(date, .after = nhs_trust22_code) |>
mutate_at(vars(3:20), as.double)


Expand All @@ -205,17 +204,22 @@ df <-
tibble(
id = query_urls |>
filter(str_detect(id, "^nhs_critical_general_acute_beds")) |>
filter(date %in% c("August 2023", "September 2023", "October 2023", "November 2023", "December 2023")) |>
filter(date %in% c(
"August 2023", "September 2023", "October 2023", "November 2023", "December 2023",
"January 2024", "February 2024", "March 2024"
)) |>
pull(id),
sheet = rep(2, 5),
range = rep("C69:AH204",5),
sheet = rep(2, 8),
range = rep("C69:AH204", 8),
date = c(
"August 2023",
"September 2023",
"October 2023",
"November 2023",
"December 2023"

"December 2023",
"January 2024",
"February 2024",
"March 2024"
)
)

Expand All @@ -226,7 +230,8 @@ england_critical_general_acute_beds <-
bind_rows(
england_critical_general_acute_beds_april23,
england_critical_general_acute_beds_afteraug23
)
) |>
drop_na(nhs_trust22_code)


# Save output to data/ folder
Expand Down
60 changes: 42 additions & 18 deletions data-raw/england-hospital-discharge-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ england_trust_criteria_to_reside_before_may23 <-
fill(do_not_meet_criteria_to_reside)

# Save output to data/ folder
#usethis::use_data(england_trust_criteria_to_reside, overwrite = TRUE)
# usethis::use_data(england_trust_criteria_to_reside, overwrite = TRUE)

# - Number discharged
trust_discharged_patients_before_may23 <-
Expand All @@ -128,7 +128,7 @@ england_trust_discharged_patients_before_may23 <-
ungroup()

# Save output to data/ folder
#usethis::use_data(england_trust_discharged_patients, overwrite = TRUE)
# usethis::use_data(england_trust_discharged_patients, overwrite = TRUE)

# ---- ICB level data ----
# Older 'h' codes are provided in the data that need replacing with newer ICB
Expand Down Expand Up @@ -173,7 +173,7 @@ england_icb_criteria_to_reside_before_may23 <- icb_criteria_to_reside_before_may
select(-icb22_code_h)

# Save output to data/ folder
#usethis::use_data(england_icb_criteria_to_reside, overwrite = TRUE)
# usethis::use_data(england_icb_criteria_to_reside, overwrite = TRUE)

# - Number discharged
icb_discharged_patients_before_may23 <-
Expand Down Expand Up @@ -267,12 +267,24 @@ trust_df <-
filter(str_detect(id, "^nhs_hospital_discharge")) |>
slice(15:n()) |> # filter from June '23 onwards
pull(id),
sheet = rep("Table 2", 7),
number_of_areas = c(120, 119,119,119,119,119,119),
range = c("C59:CP179","C59:CS178","C59:CS178", "C58:CP177", "C58:CS177","C58:CP177","C58:CS177" ),
date_start = c( "2023-06-01", "2023-07-01", "2023-08-01", "2023-09-01", "2023-10-01", "2023-11-01", "2023-12-01"),
date_end = c("2023-06-30", "2023-07-31", "2023-08-31", "2023-09-30", "2023-10-31", "2023-11-30", "2023-12-31"),
days = c( 30, 31, 31, 30, 31, 30, 31)
sheet = rep("Table 2", 14),
number_of_areas = c(120, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119),
range = c(
"C59:CP179", "C59:CS178", "C59:CS178", "C58:CP177", "C58:CS177", "C58:CP177",
"C58:CS177", "C58:CS177", "C58:CM177", "C58:CS177", "C58:CP177", "C58:CS177",
"C58:CP177", "C58:CS177"
),
date_start = c(
"2023-06-01", "2023-07-01", "2023-08-01", "2023-09-01", "2023-10-01",
"2023-11-01", "2023-12-01", "2024-01-01", "2024-02-01", "2024-03-01",
"2024-04-01", "2024-05-01", "2024-06-01", "2024-07-01"
),
date_end = c(
"2023-06-30", "2023-07-31", "2023-08-31", "2023-09-30", "2023-10-31",
"2023-11-30", "2023-12-31", "2024-01-31", "2024-02-29", "2024-03-31",
"2024-04-30", "2024-05-31", "2024-06-30", "2024-07-31"
),
days = c(30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31)
)

# Build df after May'23
Expand All @@ -289,7 +301,7 @@ trust_criteria_to_reside_after_may23 <-


# Join the data before may'23 with after may'23
england_trust_criteria_to_reside <-
england_trust_criteria_to_reside <-
bind_rows(
england_trust_criteria_to_reside_before_may23,
trust_criteria_to_reside_after_may23
Expand Down Expand Up @@ -332,12 +344,24 @@ icb_df <-
filter(str_detect(id, "^nhs_hospital_discharge")) |>
slice(15:n()) |> # Filter for after May'23
pull(id),
sheet = rep("Table 2", 7),
number_of_areas = c(42, 42, 42, 41, 41, 41, 41),
range = c("C15:CP57", "C15:CS57", "C15:CS57", "C15:CP56", "C15:CS56", "C15:CP56", "C15:CS56" ),
date_start = c( "2023-06-01", "2023-07-01", "2023-08-01", "2023-09-01", "2023-10-01", "2023-11-01", "2023-12-01"),
date_end = c("2023-06-30", "2023-07-31", "2023-08-31", "2023-09-30", "2023-10-31", "2023-11-30", "2023-12-31"),
days = c( 30, 31, 31, 30, 31, 30, 31)
sheet = rep("Table 2", 14),
number_of_areas = c(42, 42, 42, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41),
range = c(
"C15:CP57", "C15:CS57", "C15:CS57", "C15:CP56", "C15:CS56", "C15:CP56", "C15:CS56",
"C15:CS56", "C15:CM56", "C15:CS56", "C15:CP56", "C15:CS56",
"C15:CP56", "C15:CS56"
),
date_start = c(
"2023-06-01", "2023-07-01", "2023-08-01", "2023-09-01", "2023-10-01",
"2023-11-01", "2023-12-01", "2024-01-01", "2024-02-01", "2024-03-01",
"2024-04-01", "2024-05-01", "2024-06-01", "2024-07-01"
),
date_end = c(
"2023-06-30", "2023-07-31", "2023-08-31", "2023-09-30", "2023-10-31",
"2023-11-30", "2023-12-31", "2024-01-31", "2024-02-29", "2024-03-31",
"2024-04-30", "2024-05-31", "2024-06-30", "2024-07-31"
),
days = c(30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31)
)

# Build dataframe with all months
Expand All @@ -359,7 +383,7 @@ england_icb_criteria_to_reside_after_may23 <- icb_criteria_to_reside_after_may23
select(-icb22_code_h)

# Join the data before may'23 with after may'23
england_icb_criteria_to_reside <-
england_icb_criteria_to_reside <-
bind_rows(
england_icb_criteria_to_reside_before_may23,
england_icb_criteria_to_reside_after_may23
Expand All @@ -381,7 +405,7 @@ icb_discharged_patients_after_may23 <-
select(-icb22_code_h)

# Join the data before may'23 with after may'23
england_icb_discharged_patients <-
england_icb_discharged_patients <-
bind_rows(
england_icb_discharged_patients_before_may23,
icb_discharged_patients_after_may23
Expand Down
12 changes: 11 additions & 1 deletion data-raw/query-urls.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ query_urls <-
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_october_23", "October 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/11/202310-October-2023-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_november_23", "November 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/12/202311-November-2023-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_december_23", "December 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/01/202312-December-2023-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_january_24", "January 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/03/202401-January-2024-sitrep-data-FINAL-v2.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_february_24", "February 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/03/202402-February-2024-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_march_24", "March 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/04/202403-March-2024-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Disability", "england_disability_2021", "2021", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts038.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk",
"Health Index", "england_health_index_2021", "June 2021", "OGLv3", "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexscoresengland/current/healthindexscoresengland.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexscoresengland",
"Health Index underlying indicators", "england_health_index_2021_indicators", "June 2021", "OGLv3", "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexunderlyingdataengland/current/healthindexunderlyingdataenglandcanscreenfix.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexunderlyingdataengland",
Expand All @@ -79,13 +82,20 @@ query_urls <-
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_march_23", "March 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/04/Daily-discharge-sitrep-monthly-data-webfile-March2023-1.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_april_23", "April 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/06/Daily-discharge-sitrep-monthly-data-webfile-April2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_may_23", "May 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/06/Daily-discharge-sitrep-monthly-data-webfile-May2023-1.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_june_23", "June 2023", "OGLv3","https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/10/Daily-discharge-sitrep-monthly-data-webfile-June2023-revised.xlsx" , "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_june_23", "June 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/10/Daily-discharge-sitrep-monthly-data-webfile-June2023-revised.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_july_23", "July 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/10/Daily-discharge-sitrep-monthly-data-webfile-July2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_august_23", "August 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/10/Daily-discharge-sitrep-monthly-data-webfile-August2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_september_23", "September 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/10/Daily-discharge-sitrep-monthly-data-webfile-September2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_october_23", "October 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/11/Daily-discharge-sitrep-monthly-data-webfile-October2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_november_23", "November 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/12/Daily-discharge-sitrep-monthly-data-webfile-November2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_december_23", "December 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/01/Daily-discharge-sitrep-monthly-data-webfile-December2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_january_24", "January 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/02/Daily-discharge-sitrep-monthly-data-webfile-January2024.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_february_24", "February 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/03/Daily-discharge-sitrep-monthly-data-webfile-February2024.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_march_24", "March 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/04/Daily-discharge-sitrep-monthly-data-webfile-March2024.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_april_24", "April 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/05/Daily-discharge-sitrep-monthly-data-webfile-April2024.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_may_24", "May 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/07/Daily-discharge-sitrep-monthly-data-webfile-May2024-revised.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_june_24", "June 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/08/Daily-discharge-sitrep-monthly-data-webfile-June2024-revised.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_july_24", "July 2024", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/08/Daily-discharge-sitrep-monthly-data-webfile-July2024.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Legal partnership status", "legal_partnership_status_2021", "2021", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts002.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk",
"Mental Health Services Monthly Statistics, Performance", "mental_health_monthly", "April 2024", "OGLv3", "https://files.digital.nhs.uk/0F/A8A88A/MHSDS%20Time_Series_data_Apr_2016_Apr_2024.zip", "https://digital.nhs.uk/data-and-information/publications/statistical/mental-health-services-monthly-statistics/performance-april-2024",
"Psychological Therapies (IAPT)", "nhs_iapt_22_23", "January 2022-23", "OGLv3", "https://files.digital.nhs.uk/89/B4C209/iapt_time_series_Jan_22_Jan_23_key_measures.zip", "https://digital.nhs.uk/data-and-information/publications/statistical/psychological-therapies-report-on-the-use-of-iapt-services",
Expand Down
Binary file modified data/england_critical_general_acute_beds.rda
Binary file not shown.
Binary file modified data/england_icb_criteria_to_reside.rda
Binary file not shown.
Binary file modified data/england_icb_discharged_patients.rda
Binary file not shown.
Binary file modified data/england_trust_criteria_to_reside.rda
Binary file not shown.
Binary file modified data/england_trust_discharged_patients.rda
Binary file not shown.

0 comments on commit 017c10d

Please sign in to comment.