Skip to contents

Introduction

HealthDataScotland uses a series of R6 objects to store and present statistics associated with GP practices and hospitals across Scotland. This vignette will outline the functionality of these objects and the motivation behind their design.

Health units

The object that acts as the lowest common denominator in HealthDataScotland is a health_unit. These objects store relevant statistics associated with a single health centre (GP or hospital). Currently HealthDataScotland has two class of health_unit() implemented; gp() and hospital() storing data associated with a single GP practice or hospital respectively.

GP

Data associated with a single GP practice is stored in a gp() health unit object. example_gp_unit() can be used to render an example object.

gp_unit <- example_gp_unit()
gp_unit
#> <gp>
#>   Inherits from: <health_unit>
#>   Public:
#>     .data: tbl_df, tbl, data.frame
#>     .metadata: tbl_df, tbl, data.frame
#>     address: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ...) 
#>     health_board: function () 
#>     ID: function () 
#>     initialize: function (.metadata, .data) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     popup_modal: function (ns) 
#>     server: function () 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     telephone: function () 
#>     title: function () 
#>     ui: function (ns) 
#>     validate: function () 
#>   Private:
#>     population_pyramid: function (...) 
#>     population_pyramid_data: function () 
#>     population_pyramid_info: function () 
#>     population_summary: function (...) 
#>     population_summary_info: function () 
#>     population_trend: function (...) 
#>     population_trend_data: function () 
#>     population_trend_info: function () 
#>     population_trend_y_range: function () 
#>     required_data_cols: function () 
#>     required_metadata_cols: function () 
#>     title_col: function ()

Data

GP health unit objects house a data.frame storing demography statistics and a data.frame storing metadata associated with the GP practice. These can be obtained using the public functions $data and $metadata.

gp_unit$data()
#> # A tibble: 9 × 23
#>     Date ID    HB    Sex   SexQF AllAges AllAgesQF Ages0to4 Ages0To4QF Ages5to14
#>    <dbl> <chr> <chr> <chr> <chr>   <dbl> <chr>        <dbl> <chr>          <dbl>
#> 1 2.02e7 10002 S080… Male  <NA>     4056 <NA>           186 <NA>             456
#> 2 2.02e7 10002 S080… Fema… <NA>     4195 <NA>           176 <NA>             397
#> 3 2.02e7 10002 S080… All   d        8251 <NA>           362 <NA>             853
#> 4 2.02e7 10002 S080… Male  <NA>     4065 <NA>           190 <NA>             456
#> 5 2.02e7 10002 S080… Fema… <NA>     4209 <NA>           171 <NA>             401
#> 6 2.02e7 10002 S080… All   d        8274 <NA>           361 <NA>             857
#> 7 2.02e7 10002 S080… Male  <NA>     4085 <NA>           186 <NA>             463
#> 8 2.02e7 10002 S080… Fema… <NA>     4216 <NA>           170 <NA>             407
#> 9 2.02e7 10002 S080… All   d        8301 <NA>           356 <NA>             870
#> # ℹ 13 more variables: Ages5To14QF <chr>, Ages15to24 <dbl>, Ages15To24QF <chr>,
#> #   Ages25to44 <dbl>, Ages25To44QF <chr>, Ages45to64 <dbl>, Ages45To64QF <chr>,
#> #   Ages65to74 <dbl>, Ages65To74QF <chr>, Ages75to84 <dbl>, Ages75To84QF <chr>,
#> #   Ages85plus <dbl>, Ages85PlusQF <chr>
gp_unit$metadata()
#> # A tibble: 1 × 16
#>   datasetID      ID    GPPracticeName PracticeListSize AddressLine1 AddressLine2
#>   <chr>          <chr> <chr>                     <dbl> <chr>        <chr>       
#> 1 b3b126d3-3b0c… 10002 Muirhead Medi…             8251 Muirhead Me… Liff Road   
#> # ℹ 10 more variables: AddressLine3 <chr>, AddressLine4 <chr>, Postcode <chr>,
#> #   TelephoneNumber <chr>, PracticeType <chr>, Dispensing <lgl>, HBName <chr>,
#> #   HSCP <chr>, DataZone <chr>, GPCluster <chr>

In addition, to the $metadata function returing a data.frame there are also relevant helper functions to pull out particular metadata associated with a GP practice.

gp_unit$ID()
#> [1] "10002"
gp_unit$title()
#> [1] "Muirhead Medical Centre"
gp_unit$health_board()
#> [1] "S08000030"
gp_unit$address()
#> [1] "Muirhead Medical Centre, Liff Road, Muirhead, DD2 5NH"

Plotting

Visualising data associated with a single GP practice can be achieved using the $plot function with an appropriate type argument. To see which plot types are available to use, the $plot_types function can be used.

gp_unit$plot_types()
#> [1] "population_pyramid" "population_trend"
gp_unit$plot(type = "population_pyramid")
Figure 1: This bar chart shows a population pyramid of the total number of GP registered patients (x-axis) across age category (y-axis) for each gender (colour).

Helper functions $plot_data and $plot_info can be used to create the data associated with each plot and character text describing each plot (alongside functionality related to the shiny application) respectively.

gp_unit$plot_data(type = "population_pyramid")
#> # A tibble: 24 × 4
#> # Groups:   Date [3]
#>        Date Age        Female  Male
#>       <dbl> <fct>       <dbl> <dbl>
#>  1 20231001 Ages0to4     -170   186
#>  2 20231001 Ages5to14    -407   463
#>  3 20231001 Ages15to24   -430   419
#>  4 20231001 Ages25to44   -975   952
#>  5 20231001 Ages45to64  -1259  1170
#>  6 20231001 Ages65to74   -539   494
#>  7 20231001 Ages75to84   -339   307
#>  8 20231001 Ages85plus    -97    94
#>  9 20240101 Ages0to4     -171   190
#> 10 20240101 Ages5to14    -401   456
#> # ℹ 14 more rows
gp_unit$plot_info(type = "population_pyramid")
#> [1] "This bar chart shows a population pyramid of the total number of\n        GP registered patients (x-axis) across age category\n        (y-axis) for each gender (colour)."

Summarising

Summarising data associated with a single GP practice can be achieved using the $summary function with an appropriate type argument. To see which summary types are available to use, the $summary_types function can be used.

gp_unit$summary_types()
#> [1] "population_summary"
gp_unit$summary(type = "population_summary")
#> # A tibble: 3 × 4
#>   Date         Male Female Total
#>   <date>      <dbl>  <dbl> <dbl>
#> 1 57386-05-03  4056   4195  8251
#> 2 57385-07-07  4065   4209  8274
#> 3 57360-08-07  4085   4216  8301

This summary can also be coerced into a datatable using the $datatable function.

The helper function $plot_info can be used to create the character text describing each summary table (alongside functionality related to the shiny application) respectively.

gp_unit$summary_info(type = "population_summary")
#> [1] "This summary table presents the number of registered patients for the\n        selected GP practice per gender and time point."

Hospital

Data associated with a single hospital is stored in a hospital() health unit object. example_hospital_unit() can be used to render an example object.

hospital_unit <- example_hospital_unit()

Data

Hospital health unit objects house a data.frame storing bed capacity data and a data.frame storing metadata associated with the hospital. These can be obtained using the public functions $data and $metadata.

hospital_unit$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>, …
hospital_unit$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>

In addition, to the $metadata function returing a data.frame there are also relevant helper functions to pull out particular metadata associated with a hospital.

hospital_unit$ID()
#> [1] "A101H"
hospital_unit$title()
#> [1] "Arran War Memorial Hospital"
hospital_unit$health_board()
#> [1] "S08000015"
hospital_unit$address()
#> [1] "Lamlash, Isle of Arran, KA278LF"

Plotting

Visualising data associated with a single hospital can be achieved using the $plot function with an appropriate type argument. To see which plot types are available to use, the $plot_types function can be used.

hospital_unit$plot_types()
#> [1] "specialty_line"
hospital_unit$plot(type = "specialty_line")
Figure 2: This line chart shows the number of available staffed beds and the number occupied (y-axis) across time (x-axis). Settings can be used to show data for different specialties (default is all specialities) and for different statistics (‘annual’ for the annual number of beds and ‘daily’ for the average daily number of beds).

Helper functions $plot_data and $plot_info can be used to create the data associated with each plot and character text describing each plot (alongside functionality related to the shiny application) respectively.

hospital_unit$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
hospital_unit$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)."

Summarising

Summarising data associated with a single hospital can be achieved using the $summary function with an appropriate type argument. To see which summary types are available to use, the $summary_types function can be used.

hospital_unit$summary_types()
#> [1] "specialty_summary"
hospital_unit$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>

This summary can also be coerced into a datatable using the $datatable function.

The helper function $plot_info can be used to create the character text describing each summary table (alongside functionality related to the shiny application) respectively.

hospital_unit$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"

Health unit grps

HealthDataScotland contains functionality that combines several GP practices or hospitals to create summary visualisations. This is achieved by using health_unitgrp() objects, which house multiple health units. Currently HealthDataScotland has two class of health_unitgrp() implemented; gp_grp() and hospital_grp(), which store data associated with a multiple GP practices or hospitals respectively.

GP

Data associated with multiple GP practices is stored in gp_grp() objects. example_gp_grp_unit() can be used to render an example object.

gp_grp_unit <- example_gp_grp_unit()
gp_grp_unit
#> <gp_grp>
#>   Inherits from: <health_unitgrp>
#>   Public:
#>     .data: list
#>     .id: gp
#>     addresses: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ns = NULL, ...) 
#>     download_handler: function () 
#>     health_boards: function () 
#>     health_unit: function (id) 
#>     ID: function () 
#>     IDs: function () 
#>     initialize: function (.data, .id) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     server: function () 
#>     subset: function (id) 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     telephones: function () 
#>     titles: function () 
#>     ui: function (...) 
#>     validate: function () 
#>   Private:
#>     bar_data: function (x, col, ...) 
#>     bar_echart: function (x) 
#>     dt_btn: function (ns) 
#>     gender_choices: function () 
#>     gp_bar: function (...) 
#>     gp_bar_data: function (gp = private[["unit_choices"]](), gender = private[["gender_choices"]]()) 
#>     gp_bar_info: function () 
#>     gp_data: function (gp, gender) 
#>     gp_trend: function (...) 
#>     gp_trend_data: function (gp = private[["unit_choices"]](), gender = private[["gender_choices"]]()) 
#>     gp_trend_info: function () 
#>     health_board_bar: function (...) 
#>     health_board_bar_data: function (health_board = private[["health_board_choices"]](), 
#>     health_board_bar_info: function () 
#>     health_board_choices: function () 
#>     health_board_data: function (health_board, gender) 
#>     health_board_trend: function (...) 
#>     health_board_trend_data: function (health_board = private[["health_board_choices"]](), 
#>     health_board_trend_info: function () 
#>     id_name_labels: function (x, name) 
#>     id_name_selection: function () 
#>     lookup: function (...) 
#>     lookup_info: function (...) 
#>     map_combine: function (func, nms = self[["IDs"]](), id = "ID", ...) 
#>     national_pyramid: function () 
#>     national_pyramid_data: function () 
#>     national_pyramid_info: function () 
#>     national_trend: function (...) 
#>     national_trend_data: function () 
#>     national_trend_info: function () 
#>     trend_data: function (x, ...) 
#>     trend_echart: function (x) 
#>     unit_choices: function ()

Data

gp_grp() objects contain a list of gp() health units. These can be accessed using the $data function.

gp_grp_unit$data()
#> [[1]]
#> <gp>
#>   Inherits from: <health_unit>
#>   Public:
#>     .data: tbl_df, tbl, data.frame
#>     .metadata: tbl_df, tbl, data.frame
#>     address: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ...) 
#>     health_board: function () 
#>     ID: function () 
#>     initialize: function (.metadata, .data) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     popup_modal: function (ns) 
#>     server: function () 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     telephone: function () 
#>     title: function () 
#>     ui: function (ns) 
#>     validate: function () 
#>   Private:
#>     population_pyramid: function (...) 
#>     population_pyramid_data: function () 
#>     population_pyramid_info: function () 
#>     population_summary: function (...) 
#>     population_summary_info: function () 
#>     population_trend: function (...) 
#>     population_trend_data: function () 
#>     population_trend_info: function () 
#>     population_trend_y_range: function () 
#>     required_data_cols: function () 
#>     required_metadata_cols: function () 
#>     title_col: function () 
#> 
#> [[2]]
#> <gp>
#>   Inherits from: <health_unit>
#>   Public:
#>     .data: tbl_df, tbl, data.frame
#>     .metadata: tbl_df, tbl, data.frame
#>     address: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ...) 
#>     health_board: function () 
#>     ID: function () 
#>     initialize: function (.metadata, .data) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     popup_modal: function (ns) 
#>     server: function () 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     telephone: function () 
#>     title: function () 
#>     ui: function (ns) 
#>     validate: function () 
#>   Private:
#>     population_pyramid: function (...) 
#>     population_pyramid_data: function () 
#>     population_pyramid_info: function () 
#>     population_summary: function (...) 
#>     population_summary_info: function () 
#>     population_trend: function (...) 
#>     population_trend_data: function () 
#>     population_trend_info: function () 
#>     population_trend_y_range: function () 
#>     required_data_cols: function () 
#>     required_metadata_cols: function () 
#>     title_col: function ()

Metadata for all gp() health units within the gp_grp object can be summarised using the $metadata function.

gp_grp_unit$metadata()
#> # A tibble: 2 × 16
#>   datasetID      ID    GPPracticeName PracticeListSize AddressLine1 AddressLine2
#>   <chr>          <chr> <chr>                     <dbl> <chr>        <chr>       
#> 1 b3b126d3-3b0c… 10002 Muirhead Medi…             8251 Muirhead Me… Liff Road   
#> 2 b3b126d3-3b0c… 10017 The Blue Prac…             7272 The Blue Pr… Crieff Medi…
#> # ℹ 10 more variables: AddressLine3 <chr>, AddressLine4 <chr>, Postcode <chr>,
#> #   TelephoneNumber <chr>, PracticeType <chr>, Dispensing <lgl>, HBName <chr>,
#> #   HSCP <chr>, DataZone <chr>, GPCluster <chr>

Additionally, selected metadata from the gp() health units can also be obtained using relevant getter functions.

gp_grp_unit$IDs()
#> [1] "10002" "10017"
gp_grp_unit$titles()
#> [1] "Muirhead Medical Centre" "The Blue Practice"

gp_grp() objects can also be subset to the selected GP practices using $subset with a set of character IDs.

gp_grp_unit$subset(id = "10017")
#> <gp_grp>
#>   Inherits from: <health_unitgrp>
#>   Public:
#>     .data: list
#>     .id: gp
#>     addresses: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ns = NULL, ...) 
#>     download_handler: function () 
#>     health_boards: function () 
#>     health_unit: function (id) 
#>     ID: function () 
#>     IDs: function () 
#>     initialize: function (.data, .id) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     server: function () 
#>     subset: function (id) 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     telephones: function () 
#>     titles: function () 
#>     ui: function (...) 
#>     validate: function () 
#>   Private:
#>     bar_data: function (x, col, ...) 
#>     bar_echart: function (x) 
#>     dt_btn: function (ns) 
#>     gender_choices: function () 
#>     gp_bar: function (...) 
#>     gp_bar_data: function (gp = private[["unit_choices"]](), gender = private[["gender_choices"]]()) 
#>     gp_bar_info: function () 
#>     gp_data: function (gp, gender) 
#>     gp_trend: function (...) 
#>     gp_trend_data: function (gp = private[["unit_choices"]](), gender = private[["gender_choices"]]()) 
#>     gp_trend_info: function () 
#>     health_board_bar: function (...) 
#>     health_board_bar_data: function (health_board = private[["health_board_choices"]](), 
#>     health_board_bar_info: function () 
#>     health_board_choices: function () 
#>     health_board_data: function (health_board, gender) 
#>     health_board_trend: function (...) 
#>     health_board_trend_data: function (health_board = private[["health_board_choices"]](), 
#>     health_board_trend_info: function () 
#>     id_name_labels: function (x, name) 
#>     id_name_selection: function () 
#>     lookup: function (...) 
#>     lookup_info: function (...) 
#>     map_combine: function (func, nms = self[["IDs"]](), id = "ID", ...) 
#>     national_pyramid: function () 
#>     national_pyramid_data: function () 
#>     national_pyramid_info: function () 
#>     national_trend: function (...) 
#>     national_trend_data: function () 
#>     national_trend_info: function () 
#>     trend_data: function (x, ...) 
#>     trend_echart: function (x) 
#>     unit_choices: function ()

This will return a gp_grp() object. However, a single gp object can be pulled out using $health_unit.

gp_grp_unit$health_unit(id = "10017")
#> <gp>
#>   Inherits from: <health_unit>
#>   Public:
#>     .data: tbl_df, tbl, data.frame
#>     .metadata: tbl_df, tbl, data.frame
#>     address: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ...) 
#>     health_board: function () 
#>     ID: function () 
#>     initialize: function (.metadata, .data) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     popup_modal: function (ns) 
#>     server: function () 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     telephone: function () 
#>     title: function () 
#>     ui: function (ns) 
#>     validate: function () 
#>   Private:
#>     population_pyramid: function (...) 
#>     population_pyramid_data: function () 
#>     population_pyramid_info: function () 
#>     population_summary: function (...) 
#>     population_summary_info: function () 
#>     population_trend: function (...) 
#>     population_trend_data: function () 
#>     population_trend_info: function () 
#>     population_trend_y_range: function () 
#>     required_data_cols: function () 
#>     required_metadata_cols: function () 
#>     title_col: function ()

Plotting

Visualising data assciated with multiple GP practices can be achieved using the $plot function with an appropriate type argument. To see which plot types are available to use, the $plot_types function can be used.

gp_grp_unit$plot_types()
#> [1] "national_trend"     "national_pyramid"   "health_board_trend"
#> [4] "health_board_bar"   "gp_trend"           "gp_bar"
gp_grp_unit$plot(type = "gp_bar")
Figure 3: This bar chart shows the total number of GP registered patients (y-axis) for each individal GP practice (colour) across age categories (x-axis). Settings can be used to show data for different GP practices and genders.

Helper functions $plot_data and $plot_info can be used to create the data associated with each plot and character text describing each plot (alongside functionality related to the shiny application) respectively.

gp_grp_unit$plot_data(type = "gp_bar")
#> # A tibble: 24 × 4
#> # Groups:   Date [3]
#>        Date Age        `10002 - Muirhead Medical Centre` 10017 - The Blue Prac…¹
#>       <dbl> <fct>                                  <dbl>                   <dbl>
#>  1 20231001 Ages0to4                                 186                     128
#>  2 20231001 Ages5to14                                463                     362
#>  3 20231001 Ages15to24                               419                     509
#>  4 20231001 Ages25to44                               952                     738
#>  5 20231001 Ages45to64                              1170                     976
#>  6 20231001 Ages65to74                               494                     422
#>  7 20231001 Ages75to84                               307                     298
#>  8 20231001 Ages85plus                                94                     107
#>  9 20240101 Ages0to4                                 190                     126
#> 10 20240101 Ages5to14                                456                     385
#> # ℹ 14 more rows
#> # ℹ abbreviated name: ¹​`10017 - The Blue Practice`
gp_grp_unit$plot_info(type = "gp_bar")
#> [1] "This bar chart shows the total number of GP registered patients\n        (y-axis) for each individal GP practice (colour) across\n        age categories (x-axis). Settings can be used to show data for\n        different GP practices and genders."

Summarising

Summarising data associated with multiple GP practices can be achieved using the $summary function with an appropriate type argument. To see which summary types are available to use, the $summary_types function can be used.

gp_grp_unit$summary_types()
#> [1] "lookup"
gp_grp_unit$summary(type = "lookup")
#>                     Title    ID
#> 1 Muirhead Medical Centre 10002
#> 2       The Blue Practice 10017
#>                                                                  Address
#> 1                  Muirhead Medical Centre, Liff Road, Muirhead, DD2 5NH
#> 2 The Blue Practice, Crieff Medical Centre, King Street, Crieff, PH7 3SA
#>           Telephone Health board
#> 1 01382   580   264    S08000030
#> 2 01764   652   283    S08000030

This summary can also be coerced into a datatable using the $datatable function.

The helper function $summary_info can be used to create the character text describing each summary table (alongside functionality related to the shiny application) respectively.

gp_grp_unit$summary_info(type = "lookup")
#> [1] "This lookup table presents data for all available GP practices\n      in the data set. This table can be searched, filtered and\n      the 'Plot' column allows the user to view statistics for a\n      selected GP practice."

Hospital

Data associated with multiple hospitals is stored in hospital_grp() objects. example_hospital_grp_unit() can be used to render an example object.

hospital_grp_unit <- example_hospital_grp_unit()
hospital_grp_unit
#> <hospital_grp>
#>   Inherits from: <health_unitgrp>
#>   Public:
#>     .data: list
#>     .id: hospital
#>     addresses: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ns = NULL, ...) 
#>     download_handler: function () 
#>     health_boards: function () 
#>     health_unit: function (id) 
#>     ID: function () 
#>     IDs: function () 
#>     initialize: function (.data, .id) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     server: function () 
#>     subset: function (id) 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     titles: function () 
#>     ui: function (...) 
#>     validate: function () 
#>   Private:
#>     bar_data: function (x, ...) 
#>     bar_echart: function (x, group = "HBName", x_axis = "", y_axis = "PercentageOccupancy") 
#>     dt_btn: function (ns) 
#>     health_board_bar: function (...) 
#>     health_board_bar_data: function (specialties = "All Specialties", health_boards = private[["health_board_choices"]]()) 
#>     health_board_bar_info: function () 
#>     health_board_choices: function () 
#>     health_board_data: function (specialties, health_boards) 
#>     health_board_trend: function (...) 
#>     health_board_trend_data: function (specialties = "All Specialties", health_boards = private[["health_board_choices"]]()) 
#>     health_board_trend_info: function () 
#>     hospital_bar: function (...) 
#>     hospital_bar_data: function (specialties = private[["specialty_choices"]](), hospitals = private[["unit_choices"]]()) 
#>     hospital_bar_info: function () 
#>     hospital_data: function (specialties, hospitals) 
#>     hospital_trend: function (...) 
#>     hospital_trend_data: function (specialties = "All Specialties", hospitals = private[["unit_choices"]]()) 
#>     hospital_trend_info: function () 
#>     id_name_labels: function (x, name) 
#>     id_name_selection: function () 
#>     lookup: function (...) 
#>     lookup_info: function (...) 
#>     map_combine: function (func, nms = self[["IDs"]](), id = "ID", ...) 
#>     national_trend: function (...) 
#>     national_trend_data: function (specialties = "All Specialties") 
#>     national_trend_info: function () 
#>     req_plot_cols: function () 
#>     specialty_choices: function () 
#>     summarise_percentage_occupancy: function (x, groups = colnames(x)) 
#>     trend_data: function (x, ...) 
#>     trend_echart: function (x) 
#>     unit_choices: function ()

Data

hospital_grp() objects contain a list of hospital() health units. These can be accessed using the $data function.

hospital_grp_unit$data()
#> [[1]]
#> <hospital>
#>   Inherits from: <health_unit>
#>   Public:
#>     .data: tbl_df, tbl, data.frame
#>     .metadata: tbl_df, tbl, data.frame
#>     address: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ...) 
#>     health_board: function () 
#>     ID: function () 
#>     initialize: function (.metadata, .data) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     popup_modal: function (ns) 
#>     server: function () 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     title: function () 
#>     ui: function (ns) 
#>     validate: function () 
#>   Private:
#>     annual_cols: function () 
#>     daily_cols: function () 
#>     required_data_cols: function () 
#>     required_metadata_cols: function () 
#>     specialty_choices: function () 
#>     specialty_line: function (...) 
#>     specialty_line_data: function (data_type = c("annual", "daily"), specialties = "All Specialties") 
#>     specialty_summary: function (data_type = c("annual", "daily"), specialties = private[["specialty_choices"]]()) 
#>     specialty_summary_info: function () 
#>     title_col: function () 
#> 
#> [[2]]
#> <hospital>
#>   Inherits from: <health_unit>
#>   Public:
#>     .data: tbl_df, tbl, data.frame
#>     .metadata: tbl_df, tbl, data.frame
#>     address: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ...) 
#>     health_board: function () 
#>     ID: function () 
#>     initialize: function (.metadata, .data) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     popup_modal: function (ns) 
#>     server: function () 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     title: function () 
#>     ui: function (ns) 
#>     validate: function () 
#>   Private:
#>     annual_cols: function () 
#>     daily_cols: function () 
#>     required_data_cols: function () 
#>     required_metadata_cols: function () 
#>     specialty_choices: function () 
#>     specialty_line: function (...) 
#>     specialty_line_data: function (data_type = c("annual", "daily"), specialties = "All Specialties") 
#>     specialty_summary: function (data_type = c("annual", "daily"), specialties = private[["specialty_choices"]]()) 
#>     specialty_summary_info: function () 
#>     title_col: function ()

Metadata for all hospital() health units within the hospital_grp object can be summarised using the $metadata function.

hospital_grp_unit$metadata()
#> # A tibble: 2 × 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>          
#> 2 c698f450-eeed-41a… A201H Ailsa Hospi… Dalmellingt… Ayr          <NA>          
#> # ℹ 10 more variables: AddressLine3 <chr>, AddressLine3QF <chr>,
#> #   AddressLine4 <chr>, AddressLine4QF <chr>, Postcode <chr>, HBName <chr>,
#> #   HSCP <chr>, CouncilArea <chr>, IntermediateZone <chr>, DataZone <chr>

Additionally, selected metadata from the hospital() health units can also be obtained using relevant getter functions.

hospital_grp_unit$IDs()
#> [1] "A101H" "A201H"
hospital_grp_unit$titles()
#> [1] "Arran War Memorial Hospital" "Ailsa Hospital"

hospital_grp() objects can also be subset to the selected hospitals using $subset with a set of character IDs.

hospital_grp_unit$subset(id = "A201H")
#> <hospital_grp>
#>   Inherits from: <health_unitgrp>
#>   Public:
#>     .data: list
#>     .id: hospital
#>     addresses: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ns = NULL, ...) 
#>     download_handler: function () 
#>     health_boards: function () 
#>     health_unit: function (id) 
#>     ID: function () 
#>     IDs: function () 
#>     initialize: function (.data, .id) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     server: function () 
#>     subset: function (id) 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     titles: function () 
#>     ui: function (...) 
#>     validate: function () 
#>   Private:
#>     bar_data: function (x, ...) 
#>     bar_echart: function (x, group = "HBName", x_axis = "", y_axis = "PercentageOccupancy") 
#>     dt_btn: function (ns) 
#>     health_board_bar: function (...) 
#>     health_board_bar_data: function (specialties = "All Specialties", health_boards = private[["health_board_choices"]]()) 
#>     health_board_bar_info: function () 
#>     health_board_choices: function () 
#>     health_board_data: function (specialties, health_boards) 
#>     health_board_trend: function (...) 
#>     health_board_trend_data: function (specialties = "All Specialties", health_boards = private[["health_board_choices"]]()) 
#>     health_board_trend_info: function () 
#>     hospital_bar: function (...) 
#>     hospital_bar_data: function (specialties = private[["specialty_choices"]](), hospitals = private[["unit_choices"]]()) 
#>     hospital_bar_info: function () 
#>     hospital_data: function (specialties, hospitals) 
#>     hospital_trend: function (...) 
#>     hospital_trend_data: function (specialties = "All Specialties", hospitals = private[["unit_choices"]]()) 
#>     hospital_trend_info: function () 
#>     id_name_labels: function (x, name) 
#>     id_name_selection: function () 
#>     lookup: function (...) 
#>     lookup_info: function (...) 
#>     map_combine: function (func, nms = self[["IDs"]](), id = "ID", ...) 
#>     national_trend: function (...) 
#>     national_trend_data: function (specialties = "All Specialties") 
#>     national_trend_info: function () 
#>     req_plot_cols: function () 
#>     specialty_choices: function () 
#>     summarise_percentage_occupancy: function (x, groups = colnames(x)) 
#>     trend_data: function (x, ...) 
#>     trend_echart: function (x) 
#>     unit_choices: function ()

This will return a hospital_grp() object. However, a single hospital object can be pulled out using $health_unit.

hospital_grp_unit$health_unit(id = "A201H")
#> <hospital>
#>   Inherits from: <health_unit>
#>   Public:
#>     .data: tbl_df, tbl, data.frame
#>     .metadata: tbl_df, tbl, data.frame
#>     address: function () 
#>     clone: function (deep = FALSE) 
#>     combine_data: function () 
#>     data: function () 
#>     datatable: function (type, ...) 
#>     health_board: function () 
#>     ID: function () 
#>     initialize: function (.metadata, .data) 
#>     metadata: function () 
#>     plot: function (type, ...) 
#>     plot_data: function (type, ...) 
#>     plot_info: function (type, ...) 
#>     plot_types: function () 
#>     popup_modal: function (ns) 
#>     server: function () 
#>     summary: function (type, ...) 
#>     summary_info: function (type, ...) 
#>     summary_types: function () 
#>     title: function () 
#>     ui: function (ns) 
#>     validate: function () 
#>   Private:
#>     annual_cols: function () 
#>     daily_cols: function () 
#>     required_data_cols: function () 
#>     required_metadata_cols: function () 
#>     specialty_choices: function () 
#>     specialty_line: function (...) 
#>     specialty_line_data: function (data_type = c("annual", "daily"), specialties = "All Specialties") 
#>     specialty_summary: function (data_type = c("annual", "daily"), specialties = private[["specialty_choices"]]()) 
#>     specialty_summary_info: function () 
#>     title_col: function ()

Plotting

Visualising data assciated with multiple hospitals can be achieved using the $plot function with an appropriate type argument. To see which plot types are available to use, the $plot_types function can be used.

hospital_grp_unit$plot_types()
#> [1] "national_trend"     "health_board_trend" "health_board_bar"  
#> [4] "hospital_trend"     "hospital_bar"
hospital_grp_unit$plot(type = "hospital_bar")
Figure 4: This bar chart shows the average hospital bed occupancy (y-axis) per hospital (x-axis) for each specialty (colour). Seetings can be used to show data for different specialties (default is all specialties) and hospitals.

Helper functions $plot_data and $plot_info can be used to create the data associated with each plot and character text describing each plot (alongside functionality related to the shiny application) respectively.

hospital_grp_unit$plot_data(type = "hospital_bar")
#> # A tibble: 4 × 8
#> # Groups:   FinancialYear [2]
#>   FinancialYear ID                 HBName `All Specialties` `Community Grouping`
#>   <chr>         <chr>              <chr>              <dbl>                <dbl>
#> 1 2022/23       A101H - Arran War… S0800…              77.4                 77.4
#> 2 2022/23       A201H - Ailsa Hos… S0800…              77.9                 NA  
#> 3 2023/24       A101H - Arran War… S0800…              68.5                 68.5
#> 4 2023/24       A201H - Ailsa Hos… S0800…              72.6                 NA  
#> # ℹ 3 more variables: `GP Other than Obstetrics` <dbl>,
#> #   `Mental Health Grouping` <dbl>, `Psychiatry of Old Age` <dbl>
hospital_grp_unit$plot_info(type = "hospital_bar")
#> [1] "This bar chart shows the average hospital bed occupancy (y-axis)\n        per hospital (x-axis) for each specialty (colour). Seetings can be\n        used to show data for different specialties (default is all\n        specialties) and hospitals."

Summarising

Summarising data associated with multiple hospitals can be achieved using the $summary function with an appropriate type argument. To see which summary types are available to use, the $summary_types function can be used.

hospital_grp_unit$summary_types()
#> [1] "lookup"
hospital_grp_unit$summary(type = "lookup")
#>                         Title    ID                          Address
#> 1 Arran War Memorial Hospital A101H  Lamlash, Isle of Arran, KA278LF
#> 2              Ailsa Hospital A201H Dalmellington Road, Ayr, KA6 6AB
#>   Health board
#> 1    S08000015
#> 2    S08000015

This summary can also be coerced into a datatable using the $datatable function.

The helper function $summary_info can be used to create the character text describing each summary table (alongside functionality related to the shiny application) respectively.

hospital_grp_unit$summary_info(type = "lookup")
#> [1] "This lookup table presents data for all available hospitals\n      in the data set. This table can be searched, filtered and\n      the 'Plot' column allows the user to view statistics for a\n      selected hospital."