R6 class storing health statistics for a single hospital.
R6 class storing health statistics for a single hospital.
Details
This R6 class is designed to store bed occupancy statistics for a single hospital location. This class can be used to plot summary statistics and create shiny UI/server objects.
Super class
HealthDataScotland::health_unit -> hospital
Methods
Inherited methods
HealthDataScotland::health_unit$ID()HealthDataScotland::health_unit$address()HealthDataScotland::health_unit$combine_data()HealthDataScotland::health_unit$data()HealthDataScotland::health_unit$datatable()HealthDataScotland::health_unit$health_board()HealthDataScotland::health_unit$initialize()HealthDataScotland::health_unit$metadata()HealthDataScotland::health_unit$popup_modal()HealthDataScotland::health_unit$title()HealthDataScotland::health_unit$validate()
Method plot()
Plot hospital unit.
Arguments
type(character(1))
Character specifying plot type. Seeplot_typesfor options....Passed to plot functions.
Examples
x <- example_hospital_unit()
x[["plot"]](type = "specialty_line", data_type = "annual")Method plot_data()
Generate plot data for hospital unit.
Arguments
type(character(1))
Character specifying plot type. Seeplot_typesfor options....Passed to plot data functions.
Examples
x <- example_hospital_unit()
x[["plot_data"]](type = "specialty_line", data_type = "annual")Method plot_info()
Get plot info for hospital unit.
Arguments
type(character(1))
Character specifying plot type. Seeplot_typesfor options....Passed to plot info functions.
Examples
x <- example_hospital_unit()
x[["plot_info"]](type = "specialty_line")Method summary()
Summarise hospital data.
Arguments
type(character(1))
Character specifying summary type. Seesummary_typesfor options....Passed to method.
Examples
x <- example_hospital_unit()
x[["summary"]](type = "specialty_summary")Method summary_info()
Get summary info for hospital unit.
Arguments
type(character(1))
Character specifying summary type. Seesummary_typesfor options....Passed to summary info functions.
Examples
x <- example_hospital_unit()
x[["summary_info"]](type = "specialty_summary")Examples
library(dplyr)
meta <- HealthDataScotland::example_hospital_metadata |>
rename("ID" = "HospitalCode", "HBName" = "HealthBoard") |>
filter(.data[["ID"]] == "A101H")
data <- HealthDataScotland::example_hospital_data |>
rename("ID" = "Location") |>
filter(.data[["ID"]] == "A101H")
x <- hospital[["new"]](meta, data)
x[["ID"]]()
#> [1] "A101H"
x[["title"]]()
#> [1] "Arran War Memorial Hospital"
x[["address"]]()
#> [1] "Lamlash, Isle of Arran, KA278LF"
x[["health_board"]]()
#> [1] "S08000015"
x[["metadata"]]()
#> # A tibble: 1 × 16
#> datasetID ID HospitalName AddressLine1 AddressLine2 AddressLine2QF
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 c698f450-eeed-41a… A101H Arran War M… Lamlash Isle of Arr… NA
#> # ℹ 10 more variables: AddressLine3 <chr>, AddressLine3QF <chr>,
#> # AddressLine4 <chr>, AddressLine4QF <chr>, Postcode <chr>, HBName <chr>,
#> # HSCP <chr>, CouncilArea <chr>, IntermediateZone <chr>, DataZone <chr>
x[["data"]]()
#> # A tibble: 21 × 23
#> datasetID FinancialYear FinancialYearQF HB HBQF ID LocationQF
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 2 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 3 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 4 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 5 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 6 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 7 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 8 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 9 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> 10 d719af13-5fb3-430… 2022/23 NA S080… NA A101H NA
#> # ℹ 11 more rows
#> # ℹ 16 more variables: Specialty <chr>, SpecialtyQF <chr>, SpecialtyName <chr>,
#> # SpecialtyNameQF <chr>, SpecialtyGrouping <chr>, SpecialtyGroupingQF <chr>,
#> # AverageAvailableStaffedBeds <dbl>, AverageAvailableStaffedBedsQF <chr>,
#> # PercentageOccupancy <dbl>, PercentageOccupancyQF <chr>,
#> # AllStaffedBeds <dbl>, AllStaffedBedsQF <chr>, AverageOccupiedBeds <dbl>,
#> # AverageOccupiedBedsQF <chr>, TotalOccupiedBeds <dbl>, …
x[["plot"]](type = "specialty_line")
x[["plot_data"]](type = "specialty_line")
#> # A tibble: 4 × 7
#> ID FinancialYear HospitalName SpecialtyName PercentageOccupancy name value
#> <chr> <chr> <chr> <chr> <dbl> <chr> <dbl>
#> 1 A101H 2022/23 Arran War M… All Specialt… 77.4 Annu… 3263
#> 2 A101H 2022/23 Arran War M… All Specialt… 77.4 Annu… 2526
#> 3 A101H 2023/24 Arran War M… All Specialt… 68.5 Annu… 3631
#> 4 A101H 2023/24 Arran War M… All Specialt… 68.5 Annu… 2488
x[["plot_info"]](type = "specialty_line")
#> [1] "This line chart shows the number of\n available staffed beds and the number occupied (y-axis)\n across time (x-axis). Settings can be used to show data for\n different specialties (default is all specialities) and\n for different statistics ('annual' for the annual number of\n beds and 'daily' for the average daily number of beds)."
x[["summary"]](type = "specialty_summary")
#> # A tibble: 21 × 8
#> `Financial Year` Specialty Annual percentage oc…¹ Annual number of ava…²
#> <chr> <chr> <dbl> <dbl>
#> 1 2022/23 General Medic… NA 0
#> 2 2022/23 Cardiology NA 0
#> 3 2022/23 Geriatric Med… NA 0
#> 4 2022/23 General Surge… NA 0
#> 5 2022/23 Trauma and Or… NA 0
#> 6 2022/23 GP Other than… 77.4 3263
#> 7 2022/23 All Acute Spe… NA 0
#> 8 2022/23 All Specialti… 77.4 3263
#> 9 2022/23 Community Gro… 77.4 3263
#> 10 2022/23 Medical Group… NA 0
#> # ℹ 11 more rows
#> # ℹ abbreviated names: ¹`Annual percentage occupancy`,
#> # ²`Annual number of available staffed beds`
#> # ℹ 4 more variables: `Annual number of occupied beds` <dbl>,
#> # `Daily percentage occupancy` <dbl>,
#> # `Daily average number of available staffed beds` <dbl>,
#> # `Daily average number of occupied beds` <dbl>
x[["summary_info"]](type = "specialty_summary")
#> [1] "This summary table presents the annual and daily average number of available staffed beds,\n the number of annual and daily average beds occupied, and the percentage occupancy for\n the selected hospital"
if (FALSE) { # \dontrun{
x[["ui"]]()
x[["server"]]()
} # }
## ------------------------------------------------
## Method `hospital$plot`
## ------------------------------------------------
x <- example_hospital_unit()
x[["plot"]](type = "specialty_line", data_type = "annual")
## ------------------------------------------------
## Method `hospital$plot_data`
## ------------------------------------------------
x <- example_hospital_unit()
x[["plot_data"]](type = "specialty_line", data_type = "annual")
#> # A tibble: 4 × 7
#> ID FinancialYear HospitalName SpecialtyName PercentageOccupancy name value
#> <chr> <chr> <chr> <chr> <dbl> <chr> <dbl>
#> 1 A101H 2022/23 Arran War M… All Specialt… 77.4 Annu… 3263
#> 2 A101H 2022/23 Arran War M… All Specialt… 77.4 Annu… 2526
#> 3 A101H 2023/24 Arran War M… All Specialt… 68.5 Annu… 3631
#> 4 A101H 2023/24 Arran War M… All Specialt… 68.5 Annu… 2488
## ------------------------------------------------
## Method `hospital$plot_info`
## ------------------------------------------------
x <- example_hospital_unit()
x[["plot_info"]](type = "specialty_line")
#> [1] "This line chart shows the number of\n available staffed beds and the number occupied (y-axis)\n across time (x-axis). Settings can be used to show data for\n different specialties (default is all specialities) and\n for different statistics ('annual' for the annual number of\n beds and 'daily' for the average daily number of beds)."
## ------------------------------------------------
## Method `hospital$summary`
## ------------------------------------------------
x <- example_hospital_unit()
x[["summary"]](type = "specialty_summary")
#> # A tibble: 21 × 8
#> `Financial Year` Specialty Annual percentage oc…¹ Annual number of ava…²
#> <chr> <chr> <dbl> <dbl>
#> 1 2022/23 General Medic… NA 0
#> 2 2022/23 Cardiology NA 0
#> 3 2022/23 Geriatric Med… NA 0
#> 4 2022/23 General Surge… NA 0
#> 5 2022/23 Trauma and Or… NA 0
#> 6 2022/23 GP Other than… 77.4 3263
#> 7 2022/23 All Acute Spe… NA 0
#> 8 2022/23 All Specialti… 77.4 3263
#> 9 2022/23 Community Gro… 77.4 3263
#> 10 2022/23 Medical Group… NA 0
#> # ℹ 11 more rows
#> # ℹ abbreviated names: ¹`Annual percentage occupancy`,
#> # ²`Annual number of available staffed beds`
#> # ℹ 4 more variables: `Annual number of occupied beds` <dbl>,
#> # `Daily percentage occupancy` <dbl>,
#> # `Daily average number of available staffed beds` <dbl>,
#> # `Daily average number of occupied beds` <dbl>
## ------------------------------------------------
## Method `hospital$summary_info`
## ------------------------------------------------
x <- example_hospital_unit()
x[["summary_info"]](type = "specialty_summary")
#> [1] "This summary table presents the annual and daily average number of available staffed beds,\n the number of annual and daily average beds occupied, and the percentage occupancy for\n the selected hospital"