Skip to contents

R6 class storing health statistics for a single GP practice.

R6 class storing health statistics for a single GP practice.

Details

This R6 class is designed to store population demography data for a single GP practice. This class can be used to plot summary statistics and create shiny UI/server objects.

Methods

Inherited methods


Method telephone()

Get telephone number of GP practice.

Usage

gp$telephone()


Method available_plots()

Get character vector of available plots for gp unit. Options are either "population_pyramid" plot or "population_trend" plot.

Usage

gp$available_plots()


Method plot()

Plot gp unit.

Usage

gp$plot(type, ...)

Arguments

type

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

...

Passed to plot functions.

Examples

x <- example_gp_unit()
x[["plot"]](type = "population_pyramid")


Method plot_data()

Generate plot data for gp unit.

Usage

gp$plot_data(type, ...)

Arguments

type

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

...

Passed to plot data functions.

Examples

x <- example_gp_unit()
x[["plot_data"]](type = "population_pyramid")


Method plot_info()

Get plot info for gp unit.

Usage

gp$plot_info(type, ...)

Arguments

type

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

...

Passed to plot info functions.

Examples

x <- example_gp_unit()
x[["plot_info"]](type = "population_pyramid")


Method ui()

Create UI for general practice object.

Usage

gp$ui(ns)

Arguments

ns

Namespace of shiny application page.


Method server()

Create server for general practice object.

Usage

gp$server()


Method clone()

The objects of this class are cloneable with this method.

Usage

gp$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
meta <- HealthDataScotland::example_gp_metadata |>
  rename("ID" = "PracticeCode", "HBName" = "HB") |>
  filter(.data[["ID"]] == "10002")
data <- HealthDataScotland::example_gp_data |>
  select(-"datasetID", -"HSCP") |>
  rename("ID" = "PracticeCode") |>
  filter(.data[["ID"]] == "10002")
x <- gp[["new"]](meta, data)
x[["ID"]]()
#> [1] "10002"
x[["title"]]()
#> [1] "Muirhead Medical Centre"
x[["address"]]()
#> [1] "Muirhead Medical Centre, Liff Road, Muirhead, DD2 5NH"
x[["telephone"]]()
#> [1] "01382   580   264"
x[["health_board"]]()
#> [1] "S08000030"
x[["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>
x[["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>
x[["plot"]](type = "population_pyramid")
x[["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 x[["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)." if (FALSE) { # \dontrun{ x[["ui"]]() x[["server"]]() } # } ## ------------------------------------------------ ## Method `gp$plot` ## ------------------------------------------------ x <- example_gp_unit() x[["plot"]](type = "population_pyramid")
## ------------------------------------------------ ## Method `gp$plot_data` ## ------------------------------------------------ x <- example_gp_unit() x[["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 ## ------------------------------------------------ ## Method `gp$plot_info` ## ------------------------------------------------ x <- example_gp_unit() x[["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)."