Skip to contents

The base population is visit_occurrence restricted to visit_concept_ids (default inpatient 9201 and emergency-to-inpatient 262). Each step is a SQL predicate over alias v (a visit_occurrence row) and p (person); steps apply cumulatively, so the attrition table, the final cohort and the diagram can never disagree. The unit of analysis is the index visit (persons counts distinct people).

Usage

cohort_flow(
  con,
  visit_concept_ids = c(9201L, 262L),
  anchor = c("admission", "discharge"),
  follow_up_days = NULL,
  one_visit_per_person = FALSE
)

Arguments

con

DuckDB DBI connection with an OMOP CDM.

visit_concept_ids

Index visit concept ids.

anchor

"admission" (visit_start_date) or "discharge" (visit_end_date).

follow_up_days

If set, the pre-flight verifies every row can be followed that long (or died first).

one_visit_per_person

Keep only each person's first index visit.

Value

A list of functions (add_step, run, to_markdown, to_mermaid, to_latex, to_graphviz) and a state environment holding cohort, attrition and checks after run().

Details

flow <- cohort_flow(con, anchor = "admission", follow_up_days = 30)
flow$add_step("Adults", "EXTRACT(year FROM v.visit_start_date) - p.year_of_birth >= 18")
res <- flow$run()
res$attrition; res$checks; flow$to_mermaid(); flow$to_graphviz()