> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encodebox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# EventFrame

> EventFrame verbs for matching, occurrence, gaps, and index dates.

An **EventFrame** is a lazy list of clinical events. Chain verbs; nothing hits the database until `.to_df()`.

```python theme={null}
index = (
    db.diagnosis
    .matching("E11", code_type="10", match="starts_with")
    .occurring(at_least=2, gap_days=30)
    .with_index_date()
    .first_per_patient()
)
```

## Verbs

| Verb                                           | Meaning                                     |
| ---------------------------------------------- | ------------------------------------------- |
| `matching(codes, code_type=…, match=…)`        | Filter by code / type / match mode          |
| `in_position("primary")`                       | Primary / secondary diagnosis               |
| `occurring(at_least=…, at_most=…, gap_days=…)` | Patient-level occurrence + consecutive gaps |
| `with_index_date()`                            | Add `index_date`                            |
| `first_per_patient()` / `last_per_patient()`   | One row per patient                         |
| `between(...)` / `in_years(...)`               | Calendar filters                            |
| `with_age(...)` / `with_followup(...)`         | Attach derived columns                      |
| `union(other)`                                 | Stack event streams                         |
| `label("name")`                                | Name a step for repr / attrition            |
| `to_sql()` / `to_df()` / `explain()`           | Inspect / run                               |

## Match aliases

`starts_with` / `start with`, `exactly` / `exactly match`, `contain`, `end with`.

## Gap semantics

`gap_days` uses consecutive distinct-date gaps (`lead()`), not span. See [Which API?](/which-api).

## Related

* [Cohort](/api/cohort)
* [Query patterns](/query-patterns)
* [Cheat sheet](/cheatsheet)
