- Analytics use case(s): Characterization
- Study type: Clinical Application
- Tags: -
- Study lead: -
- Study lead forums tag: -
- Study start date: -
- Study end date: -
- Protocol: -
- Publications: -
- Results explorer: -
Can-BUILD is a Strategus study that produces incidence rates: how often each outcome of interest occurs per 100 person-years, in each calendar year.
All cohorts are defined in ATLAS and downloaded by
scriptsForStudyDesigner/DownloadAssets.R into inst/. There is no hand-written
cohort SQL in the study.
| Cohort | ID | ATLAS id | Role |
|---|---|---|---|
| Fiscal year cohort with 365 days prior observation | 1 | 1798688 | target |
| Fiscal year cohort with 1095 days prior observation | 2 | 1798701 | target |
| Dummy outcome | 3 | 1797622 | outcome (placeholder) |
Targets are the two fiscal-year cohorts: anyone with observation on 1 April of each calendar year, with the fiscal year running to the following 31 March. They differ only in how much prior observation they require (365 vs 1095 days).
Outcomes are the events being counted. Cohort 3 is a dummy outcome used to exercise the pipeline until the real outcome cohorts are defined; see Placeholders.
Analysis is done with the HADES Characterization package (v4 settings API):
| Module | What it contributes |
|---|---|
| CohortGenerator | Builds the cohorts |
| CohortDiagnostics | Checks the cohorts (inclusion rules, orphan concepts, incidence rate, ...) |
| Characterization | Baseline characteristics of each target, the incidence rates (c_incidence_summary) and a point-prevalence design |
The specification runs two designs side by side, each across 12 study periods (an unrestricted period plus 11 fiscal years from 2016/17 to 2026/27):
| Design | Washout | Time at risk |
|---|---|---|
| Incidence rate | 99999 days (one event per person) | day 1 to day 365 after cohort start |
| Point prevalence | 0 days | day 0 to day 1 after cohort start |
There is no population-level estimation and no patient-level prediction in this study, so CohortMethod, SelfControlledCaseSeries and PatientLevelPrediction are not used.
ExecuteAnalyses.R Run the study (edit the INPUTS section)
ShareResults.R Zip the results for the study coordinator
config.yml Study name, folders, results database
inst/analysisSpecifications.json Generated by CreateStrategusAnalysisSpecifications.R
inst/Cohorts.csv The ATLAS cohorts in the study (the outcome cohorts)
inst/cohorts/<id>.json Circe definitions for the outcome cohorts
inst/sql/sql_server/<id>.sql SQL definitions for the ATLAS cohorts
scriptsForStudyDesigner/ Study design: cohorts, analysis specification
scriptsForStudyCoordinator/ Results database, results model, Shiny app
template_docs/ Generic documentation for this study template
If you are running this study at your site, follow PARTICIPANT-GUIDE.md. In short:
# 1. environment (once)
renv::restore() # then restart R
# NEVER renv::snapshot() - see renv/README.md
# 2. edit the INPUTS block at the top of ExecuteAnalyses.R for your database
# (keep the password out of it - use keyring or .Renviron)
# 3. run
source("ExecuteAnalyses.R")Settings are edited directly in the INPUTS block at the top of
ExecuteAnalyses.R - the same pattern as
StrategusStudyRepoTemplate.
There is no separate settings file to learn.
##=========== START OF INPUTS ==========
cdmDatabaseSchema <- "my_cdm" # clinical tables AND vocabulary
workDatabaseSchema <- "my_scratch" # must be writable
cohortTableName <- "can_build_cohort"
resultsFolder <- "results"
workFolder <- "strategusInternals"
databaseName <- "MY_SITE"
minCellCount <- 5
connectionDetails <- DatabaseConnector::createConnectionDetails(
dbms = "postgresql",
server = Sys.getenv("OHDSI_SERVER", "db.example.org/cdm"),
user = Sys.getenv("OHDSI_USER", "my_user"),
password = Sys.getenv("OHDSI_PASSWORD"),
pathToDriver = Sys.getenv("DATABASECONNECTOR_JAR_FOLDER")
)
##=========== END OF INPUTS ==========Never write it in ExecuteAnalyses.R - that file is committed. Use either:
-
OS keychain (recommended):
keyring::key_set("ohdsi")once, thenpassword = keyring::key_get("ohdsi") -
.Renviron, which git ignores:OHDSI_PASSWORD="your password" OHDSI_SERVER="db.example.org/cdm" OHDSI_USER="my_user"
R reads
.Renvirononly at startup - restart R after editing it.
Work down the INPUTS block and confirm each of these:
| Check | How |
|---|---|
| Java 17+ | export JAVA_HOME=/path/to/jdk-17, then restart R |
| JDBC driver | DatabaseConnector::downloadJdbcDrivers("postgresql"), or set pathToDriver |
| Credentials load | Sys.getenv("OHDSI_PASSWORD") returns your password |
| Connection works | uncomment the connect() / disconnect() pair in the INPUTS block and run it |
| CDM readable | SELECT COUNT(*) FROM <cdmDatabaseSchema>.person returns a number |
| Vocabulary present | concept is in the same schema as person |
| Work schema writable | your user has CREATE there |
If any of those fail, fix it before running the study - each one produces its own clear error at that step.
-
Install R 4.6.2 and restore the package versions pinned in
renv.lock:renv::restore()
Restart R afterwards.
renv.lockis frozen before any site execution. Sites restore it as it is; a change to the lock goes through a pull request tomainbefore sites run, never during a site run.Read renv/README.md before
renv::snapshot(). The lock file pins HADES packages the study scripts neverlibrary()directly - CohortDiagnostics, OhdsiShinyAppBuilder, OhdsiShinyModules, OhdsiReportGenerator - because the results app and the report generator need them at run time.StudyPackages.Rin the project root lists them so a snapshot keeps them; without it, a snapshot would drop them. -
Install Java 17 or newer and point
JAVA_HOMEat it. The pinned DatabaseConnector 8.0.0 fails on Java 8 (NoSuchMethodError: java.nio.ByteBuffer.clear()). -
Edit the INPUTS block at the top of
ExecuteAnalyses.R: schemas, folders and connection details. Put the password inkeyringor.Renviron, not in the file. The check list under Configuration covers each value. -
Create the analysis specification (only needed after a design change):
source("scriptsForStudyDesigner/CreateStrategusAnalysisSpecifications.R")This writes
inst/analysisSpecifications.json. -
Run the study:
source("ExecuteAnalyses.R")Results are written to
results/<databaseName>/.
The scripts expect to be run from the project root, because config.yml uses
getwd() as the project folder.
On the local OHDSI Lab (a 4 GB Docker VM) the run takes about 17 minutes:
about 5.5 minutes of cohort diagnostics and 10.5 minutes of characterization.
Stop the WebAPI and Atlas containers (docker stop ohdsi-lab-webapi ohdsi-lab-atlas3) while it runs if Postgres is short of memory, and start them
again afterwards.
The primary output is
results/<databaseName>/CharacterizationModule/c_incidence_summary.csv: one row
per target cohort, outcome, age group and gender, with persons at risk, person
days, events and incidence_rate_p_100py.
Characterization numbers the target cohorts internally (10, 20, ...), so join
back to c_target_settings.csv to get the calendar year:
path <- "results/SYNTHEA10K/CharacterizationModule"
incidence <- readr::read_csv(file.path(path, "c_incidence_summary.csv"))
targets <- readr::read_csv(file.path(path, "c_target_settings.csv"))
outcomes <- readr::read_csv(file.path(path, "c_outcome_def.csv"))
overall <- incidence |>
dplyr::filter(is.na(age_group_id), is.na(gender_name)) |> # not a stratum
dplyr::left_join(
targets |> dplyr::select(characterization_target_id, target_id),
by = "characterization_target_id"
) |>
dplyr::left_join(
outcomes |> dplyr::select(outcome_id, outcome_cohort_definition_id),
by = "outcome_id"
) |>
dplyr::select(
year = target_id,
outcome = outcome_cohort_definition_id,
persons_at_risk,
person_days,
outcomes,
incidence_rate_p_100py
)ExecuteAnalyses.R is pre-filled with the local OHDSI Lab settings:
PostgreSQL 127.0.0.1:5432, database postgres, user postgres, password mypass
CDM cdm_vocab, work schema can_build
The lab keeps the clinical schema (cdm) and the vocabulary (vocab) apart,
while HADES analyses expect both in the CDM schema. cdm_vocab is a view layer
that presents them as one. It is created once with:
CREATE SCHEMA IF NOT EXISTS cdm_vocab;
DO $$
DECLARE r record;
BEGIN
FOR r IN SELECT table_name FROM information_schema.tables
WHERE table_schema = 'vocab' AND table_type = 'BASE TABLE' LOOP
EXECUTE format('CREATE OR REPLACE VIEW cdm_vocab.%I AS SELECT * FROM vocab.%I',
r.table_name, r.table_name);
END LOOP;
FOR r IN SELECT table_name FROM information_schema.tables
WHERE table_schema = 'cdm' AND table_type = 'BASE TABLE' LOOP
IF NOT EXISTS (SELECT 1 FROM information_schema.views
WHERE table_schema = 'cdm_vocab' AND table_name = r.table_name) THEN
EXECUTE format('CREATE OR REPLACE VIEW cdm_vocab.%I AS SELECT * FROM cdm.%I',
r.table_name, r.table_name);
END IF;
END LOOP;
END $$;If your site has a normal OMOP CDM with the vocabulary tables inside it, set
cdmDatabaseSchema in ExecuteAnalyses.R to that schema instead.
Cohort 3 is a dummy outcome (ATLAS 1797622). To swap in the real outcome
cohorts:
- Define them in ATLAS.
- Add them to the
cohortsToDownloadtable inscriptsForStudyDesigner/DownloadAssets.Rand run that script. It rewritesinst/Cohorts.csv,inst/cohorts/andinst/sql/sql_server/. - Point
outcomesinCreateStrategusAnalysisSpecifications.Rat the new cohort IDs and re-create the analysis specification.
The script stops if an outcome ID is not in inst/Cohorts.csv, so a mismatch is
caught immediately.