Skip to contents

The DiseasyObservables module is responsible for interfacing with the available diseasystores and provide disease data to the models. The module primarily acts as a convenience wrapper around the diseasystores. The observables and stratifications will therefore depend on the data made available by the diseasystores.

See vignette("diseasy-observables")

Value

A new instance of the DiseasyBaseModule

R6 class.

See also

Super class

diseasy::DiseasyBaseModule -> DiseasyObservables

Active bindings

diseasystore

(character)
The set diseasystore to get DiseasyObservables for. Read-only.

start_date

(Date)
The start date of the study period. Read-only.

end_date

(Date)
The end date of the study period. Read-only.

last_queryable_date

(Date)
The latest date that can be queried. Read-only.

ds

(Diseasystore*)
The currently loaded diseasystore which provides the features. Read-only.

available_observables

(character)
The currently available observables in the loaded diseasystore. Read-only.

available_stratifications

(character)
The currently available stratifications in the loaded diseasystore. Read-only.

slice_ts

(Date)
The timestamp to slice database on. Read-only.

conn

(DBIConnection)
The connection to the database on. Read-only.

Methods

Inherited methods


Method new()

Creates a new instance of the DiseasyObservables R6 class.

Usage

DiseasyObservables$new(
  diseasystore = NULL,
  start_date = NULL,
  end_date = NULL,
  last_queryable_date = NULL,
  conn = NULL,
  slice_ts = NULL,
  ...
)

Arguments

diseasystore

(character)
A character string that controls which feature store to get data from.

start_date

(Date)
Study period start (default values for get_observation).

end_date

(Date)
Study period end (default values for get_observation).

last_queryable_date

(Date)
Enforce a limit on data that can be pulled (not after this date).

conn

(DBIConnection)
A database connection object (inherits from DBIConnection)

slice_ts

(Date or character)
Date to slice the database on. See SCDB::get_table()

...

Parameters sent to DiseasyBaseModule R6 constructor.

Returns

A new instance of the DiseasyBaseModule R6 class.


Method set_diseasystore()

Set the case definition to get DiseasyObservables for.

Usage

DiseasyObservables$set_diseasystore(diseasystore, verbose = NULL)

Arguments

diseasystore

(character)
Text label of the disease to get DiseasyObservables for.
Must match case definition implemented in diseasystore package.

verbose

Should the diseasystore use verbose outputs?


Method set_last_queryable_date()

Enforce a limit on data that can be pulled.

Usage

DiseasyObservables$set_last_queryable_date(last_queryable_date)

Arguments

last_queryable_date

(Date)
DiseasyObservables module will not return data after this date.


Method set_study_period()

Set the (default) time period to get observations from.

Usage

DiseasyObservables$set_study_period(start_date, end_date)

Arguments

start_date

(Date)
Start date to get DiseasyObservables for (including).

end_date

(Date)
End date to get DiseasyObservables for (including).


Method set_slice_ts()

Set the slice_ts to get data for

Usage

DiseasyObservables$set_slice_ts(slice_ts)

Arguments

slice_ts

(Date or character)
Date to slice the database on


Method get_observation()

Retrieve an "observable" in the data set corresponding to the set diseasystore.
By default, the internal values for start_date and end_date are used to return data, but these can be overwritten.
The results are cached for faster retrieval at subsequent calls.

Usage

DiseasyObservables$get_observation(
  observable,
  stratification = NULL,
  start_date = self %.% start_date,
  end_date = self %.% end_date
)

Arguments

observable

(character)
The requested observable. Should follow the pattern 'n_*'.

stratification

(list(quosures))
Default NULL. If given, expressions in stratification evaluated to give the stratification level.
Use rlang::quos(...) to specify stratification.

start_date

(Date)
Start date to get DiseasyObservables for (including).

end_date

(Date)
End date to get DiseasyObservables for (including).

Returns

If the observable is found, the function returns the corresponding data at the stratification level.
Otherwise, the function fails and lists the available DiseasyObservables from the diseasystore.


Method describe()

Prints a human readable report of the internal state of the module.

Usage

DiseasyObservables$describe()


Method finalize()

Handles the clean-up of the class

Usage

DiseasyObservables$finalize()


Method clone()

The objects of this class are cloneable with this method.

Usage

DiseasyObservables$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

  # Create observables module using the Google COVID-19 data
  obs <- DiseasyObservables$new(diseasystore = "Google COVID-19",
                                conn = DBI::dbConnect(RSQLite::SQLite()))

  # See available observables
  print(obs$available_observables)
#> [1] "n_population" "n_hospital"   "n_deaths"     "n_positive"   "n_icu"       
#> [6] "n_ventilator"
  print(obs$available_stratifications)
#> [1] "age_group"       "country_id"      "country"         "region_id"      
#> [5] "region"          "subregion_id"    "subregion"       "min_temperature"
#> [9] "max_temperature"

  # Get data for one observable
  if (FALSE) {
  obs$get_observation("n_hospital",
                      start_date = as.Date("2020-03-01"),
                      end_date = as.Date("2020-03-05"))
  }
  rm(obs)