Core R6 class for creating and managing disease surveillance systems. This class orchestrates database tables, tasks, and analyses for real-time epidemiological monitoring and public health surveillance.
Details
SurveillanceSystem_v9 provides infrastructure for:
Database table management with automated logging.
Task scheduling and parallel execution.
Data validation and schema enforcement.
Configuration and performance monitoring.
The surveillance system follows a structured approach:
Define database tables with
add_table().Configure surveillance tasks with
add_task().Execute tasks with
run_task()or external schedulers.
Public fields
tablesList of database tables managed by the surveillance system.
partitionedtablesList of partitioned database tables.
tasksList of surveillance tasks configured for execution.
nameCharacter string identifying the surveillance system instance.
implementation_versionCharacter string tracking the analytics code version.
Methods
SurveillanceSystem_v9$new()
Usage
SurveillanceSystem_v9$new(
name = "unspecified",
implementation_version = "unspecified"
)SurveillanceSystem_v9$add_table()
Add a table.
Usage
SurveillanceSystem_v9$add_table(
name_access,
name_grouping = NULL,
name_variant = NULL,
field_types,
keys,
indexes = NULL,
validator_field_types = csdb::validator_field_types_blank,
validator_field_contents = csdb::validator_field_contents_blank
)Arguments
name_accessFirst part of table name, corresponding to the database where it will be stored.
name_groupingSecond part of table name, corresponding to some sort of grouping.
name_variantFinal part of table name, corresponding to a distinguishing variant.
field_typesNamed character vector, where the names are the column names, and the values are the column types. Valid types are BOOLEAN, CHARACTER, INTEGER, DOUBLE, DATE, DATETIME.
keysCharacter vector, containing the column names that uniquely identify a row of data.
indexesNamed list, containing indexes.
validator_field_typesFunction corresponding to a validator for the field types.
validator_field_contentsFunction corresponding to a validator for the field contents.
Returns
No return value. This method is called for its side effect of adding a table to the surveillance system.
Examples
global$ss$add_table(
name_access = c("anon"),
name_grouping = "example_weather",
name_variant = "data",
field_types = c(
"granularity_time" = "TEXT",
"granularity_geo" = "TEXT",
"country_iso3" = "TEXT",
"location_code" = "TEXT",
"border" = "INTEGER",
"age" = "TEXT",
"sex" = "TEXT",
"isoyear" = "INTEGER",
"isoweek" = "INTEGER",
"isoyearweek" = "TEXT",
"season" = "TEXT",
"seasonweek" = "DOUBLE",
"calyear" = "INTEGER",
"calmonth" = "INTEGER",
"calyearmonth" = "TEXT",
"date" = "DATE",
"temp_max" = "DOUBLE",
"temp_min" = "DOUBLE",
"precip" = "DOUBLE"
),
keys = c(
"granularity_time",
"location_code",
"date",
"age",
"sex"
),
validator_field_types = csdb::validator_field_types_csfmt_rts_data_v1,
validator_field_contents = csdb::validator_field_contents_csfmt_rts_data_v1
)SurveillanceSystem_v9$add_partitionedtable()
Add a partitioned table to the surveillance system.
Usage
SurveillanceSystem_v9$add_partitionedtable(
name_access,
name_grouping = NULL,
name_variant = NULL,
name_partitions = "default",
column_name_partition = "partition",
value_generator_partition = NULL,
field_types,
keys,
indexes = NULL,
validator_field_types = csdb::validator_field_types_blank,
validator_field_contents = csdb::validator_field_contents_blank
)Arguments
name_accessFirst part of table name, corresponding to the database where it will be stored.
name_groupingSecond part of table name, corresponding to some sort of grouping.
name_variantFinal part of table name, corresponding to a distinguishing variant.
name_partitionsCharacter string specifying partition naming scheme.
column_name_partitionColumn name used for partitioning.
value_generator_partitionFunction to generate partition values.
field_typesNamed character vector of column names and types.
keysCharacter vector of column names that uniquely identify rows.
indexesNamed list containing index definitions.
validator_field_typesFunction to validate field types.
validator_field_contentsFunction to validate field contents.
SurveillanceSystem_v9$add_task()
Add a surveillance task to the system.
Usage
SurveillanceSystem_v9$add_task(
name_grouping = NULL,
name_action = NULL,
name_variant = NULL,
cores = 1,
permission = NULL,
plan_analysis_fn_name = NULL,
for_each_plan = NULL,
for_each_analysis = NULL,
universal_argset = NULL,
upsert_at_end_of_each_plan = FALSE,
insert_at_end_of_each_plan = FALSE,
action_fn_name,
data_selector_fn_name = NULL,
tables = NULL
)Arguments
name_groupingName of the task (grouping).
name_actionName of the task (action).
name_variantName of the task (variant).
coresNumber of CPU cores.
permissionA permission R6 instance.
plan_analysis_fn_nameThe name of a function that returns a named list
list(for_each_plan = list(), for_each_analysis = NULL).for_each_planA list, where each unit corresponds to one data extraction. You SHOULD use
plnr::expand_list.for_each_analysisA list, where each unit corresponds to one analysis within a plan (data extraction). You SHOULD use
plnr::expand_list.universal_argsetA list, where these argsets are applied to all analyses universally.
upsert_at_end_of_each_planWhether to upsert your results automatically at the end of each plan.
insert_at_end_of_each_planWhether to insert your results automatically at the end of each plan.
action_fn_nameThe name of the function called for each analysis with arguments
data,argset,schema.data_selector_fn_nameThe name of a function called to obtain the data for each analysis. The function MUST have the arguments
argset,schemaand MUST return a named list.tablesA named list that maps
cs9::config$schemasfor use inaction_fn_nameanddata_selector_fn_name.
SurveillanceSystem_v9$shortcut_get_argset()
Get argument set for a specific plan and analysis.
SurveillanceSystem_v9$shortcut_get_data()
Get data for a specific plan.
Examples
if (FALSE) { # \dontrun{
# Create surveillance system
ss <- SurveillanceSystem_v9$new(
name = "covid_surveillance",
implementation_version = "1.0"
)
# Add database table
ss$add_table(
name_access = "anon",
name_grouping = "covid",
name_variant = "cases",
field_types = c("date" = "DATE", "cases" = "INTEGER"),
keys = c("date")
)
# Add surveillance task
ss$add_task(
name_grouping = "covid",
name_action = "import",
name_variant = "daily_data",
action_fn_name = "import_covid_data",
data_selector_fn_name = "select_covid_sources"
)
# Run task
ss$run_task("covid_import_daily_data")
} # }
## ------------------------------------------------
## Method `SurveillanceSystem_v9$add_table()`
## ------------------------------------------------
if (FALSE) { # \dontrun{
global$ss$add_table(
name_access = c("anon"),
name_grouping = "example_weather",
name_variant = "data",
field_types = c(
"granularity_time" = "TEXT",
"granularity_geo" = "TEXT",
"country_iso3" = "TEXT",
"location_code" = "TEXT",
"border" = "INTEGER",
"age" = "TEXT",
"sex" = "TEXT",
"isoyear" = "INTEGER",
"isoweek" = "INTEGER",
"isoyearweek" = "TEXT",
"season" = "TEXT",
"seasonweek" = "DOUBLE",
"calyear" = "INTEGER",
"calmonth" = "INTEGER",
"calyearmonth" = "TEXT",
"date" = "DATE",
"temp_max" = "DOUBLE",
"temp_min" = "DOUBLE",
"precip" = "DOUBLE"
),
keys = c(
"granularity_time",
"location_code",
"date",
"age",
"sex"
),
validator_field_types = csdb::validator_field_types_csfmt_rts_data_v1,
validator_field_contents = csdb::validator_field_contents_csfmt_rts_data_v1
)
} # }
