Skip to contents

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


Method available_plots()

Get character vector of available plots for hospital grp

Usage

hospital$available_plots()


Method plot()

Plot hospital unit.

Usage

hospital$plot(type, ...)

Arguments

type

(character(1))
Character specifying plot type. See available_plots for 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.

Usage

hospital$plot_data(type, ...)

Arguments

type

(character(1))
Character specifying plot type. See available_plots for 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.

Usage

hospital$plot_info(type, ...)

Arguments

type

(character(1))
Character specifying plot type. See available_plots for options.

...

Passed to plot info functions.

Examples

x <- example_hospital_unit()
x[["plot_info"]](type = "specialty_line", data_type = "annual")


Method ui()

Create UI for hospital object.

Usage

hospital$ui(ns)

Arguments

ns

Namespace of shiny application page.


Method server()

Create server for hospital object.

Usage

hospital$server()


Method clone()

The objects of this class are cloneable with this method.

Usage

hospital$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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 annual 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)." 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", data_type = "annual") #> [1] "This line chart shows the annual 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)."