Skip to contents

Mirrors python/omop_etl/build_omop_cdm.py table-for-table. Both read the same PCORnet-format source directory, share the same schema and concept-resolution logic, and generate 100% deterministic surrogate keys and OHDSI v5.4 tables.

Usage

etl_pcornet(
  source_dir,
  db_path = "omop_cdm.duckdb",
  central_vocab = NULL,
  site_id = NULL,
  site_anon = NULL,
  site_name = NULL,
  disambiguate_patids = FALSE,
  auto_resources = FALSE,
  memory_limit = NULL,
  threads = NULL,
  temp_dir = NULL,
  source_format = NULL,
  strict_source = FALSE,
  key_check = c("warn", "raise", "ignore"),
  key_check_callback = NULL,
  date_audit_callback = NULL,
  use_enrollment = "auto",
  enrollment_type_concept_id = 0L,
  data_cutoff = "auto",
  mode = c("full", "append"),
  since = NULL
)

Arguments

source_dir

Directory containing PCORnet-format CSVs (demographic.csv, encounter.csv, diagnosis.csv, procedures.csv, lab_result_cm.csv, prescribing.csv, provider.csv, optionally vital.csv, facility.csv, and optionally death.csv), matched case-insensitively. Any table whose source file isn't found is skipped.

db_path

Path to the DuckDB database file (schema + vocabulary must already exist).

central_vocab

Optional path to an existing central vocabulary DuckDB database to attach in read-only mode with zero-copy views.

site_id

Optional numeric site identifier (e.g. 1 to 5).

site_anon

Optional publication pseudonym (e.g. "Site A").

site_name

Optional institutional name or internal descriptor (e.g. "Hospital System A").

disambiguate_patids

Logical. If TRUE, formats person_source_value as src.PATID || '-' || site_id and derives surrogate keys via pcornet_id(src.PATID || '-' || site_id).

auto_resources

Logical. If TRUE, size DuckDB to the host with configure_resources() (75% of available RAM, best spill volume, cores - 1) before loading; memory_limit, threads and temp_dir still win over the detected values.

memory_limit

Optional DuckDB memory_limit, e.g. "16GB".

threads

Optional DuckDB worker thread count.

temp_dir

Optional DuckDB disk-spill directory.

source_format

"csv", "parquet" or NULL (either); restricts which source files are read when checking the source contract (see check_source()). Only used when strict_source = TRUE.

strict_source

Logical. If TRUE, run check_source() first and stop with a source_contract_error when a required source table or column is missing.

key_check

"warn" (default), "raise" or "ignore": at the end of the build, compare distinct source ids with distinct surrogate keys via check_etl_keys() and report any encounters/patients that would be merged.

key_check_callback

Optional function called with the list returned by check_etl_keys().

date_audit_callback

Optional function called with the list of per-source-table date-fallback and undated-drop counts.

use_enrollment

"auto" (default), TRUE or FALSE. Build observation_period from the PCORnet ENROLLMENT file when the source has one (load_enrollment_spans()); people without an enrolment record keep the event-span period. TRUE fails if no usable ENROLLMENT file exists.

enrollment_type_concept_id

period_type_concept_id for enrolment-derived periods (default 0).

data_cutoff

"auto" (default), an ISO date or NULL (today): caps observation_period ends. "auto" uses the latest event dated before today, so events filled with the build date do not set period ends.

mode

"full" (default) or "append": add only newly arrived rows to an existing database. Patients, providers and encounters already present are skipped (matched on source values), events dated before since are skipped, surrogate keys continue from the current maximum, care sites / locations are left alone, and observation_period and the eras are rebuilt. Encounters are selected by admit date. Mirror of Python etl_pcornet(mode = "append").

since

With mode = "append": ISO date; only events on/after it are loaded.

Value

Invisibly, db_path.