Skip to main content
EncodeBox has three ways to write the same query. Prefer the highest level that fits; drop down only when you need to.

Setup

With connector=, you get a Database. Domains are attributes: db.diagnosis, db.procedure, db.medication, db.enrollment, …

EventFrame — finding events

An EventFrame is a lazy list of clinical events (one row ≈ one code on one date for one patient). You chain verbs; nothing hits the database until .to_df().

Typical index-date chain

“Patients with at least two E11* diagnoses on different days, with at least 30 days between some consecutive visits; use the start of the first such pair as their index date.”

EventFrame verbs

Gap semantics

gap_days=30 means: look at ordered distinct dates and require some neighboring pair to be ≥30 days apart.
Legacy filter_event(..., gap=30) used span (max−min). New gap_days uses consecutive gaps. They do not select the same patients.

Cohort — defining a study population

A Cohort starts from an entry EventFrame (people + index date), then requires or excludes criteria. Each step is a set operation on patient_id. .attrition() counts how many people remain after each step.

Cohort building blocks

Built-in criteria

Windows are always (days_before, days_after) relative to the cohort entry index date. Example: window=(-365, 0) = the year ending on the index day.

Table / Column — custom predicates

Use column expressions when EventFrame verbs cannot say what you mean. Prefer EventFrame for matching / occurrence / ranking.

Inspect anything

Legacy API

query_event / filter_event still import but warn. Their gap rule is span, not consecutive days — see Migration.