> ## 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.

# Cheat sheet

> Short reference for EventFrame verbs, Cohort criteria, and code types.

## Default path

```python theme={null}
import encodebox as eb

eb.register_connector("path/to/connector.yml")
db = eb.connect("postgres", ..., connector="name")

index = (
    db.diagnosis
    .matching("E11", code_type="10", match="starts_with")
    .occurring(at_least=2, gap_days=30)
    .with_index_date()
    .first_per_patient()
)

other = db.diagnosis.matching("E10", code_type="10").occurring(at_least=2)
cohort = (
    eb.Cohort("study", database=db)
    .entry(index, index="first")
    .include(db.demographic.age_at_index(18, 89))
    .include(db.enrollment.covering_index(days_before=365))
    .include(other, window=(-365, 0))
    .exclude(db.diagnosis.matching("C", match="starts_with"), window=(-365, 0))
)
df = cohort.to_df()
```

| Need               | Type                                | Meaning                         |
| ------------------ | ----------------------------------- | ------------------------------- |
| Event query        | **EventFrame**                      | Which events / who has an index |
| Study + attrition  | **Cohort**                          | Who stays after require/exclude |
| Code-in-window     | `db.diagnosis.matching` + `window=` | Coded EventFrame criterion      |
| EventFrame-as-rule | `include(frame, window=)`           | Reuse a full event definition   |
| Odd predicate      | **Table**                           | Column boolean filters          |

## EventFrame verbs

| Verb                | Meaning                                                                    |
| ------------------- | -------------------------------------------------------------------------- |
| `matching`          | Filter by code / code\_type / match mode                                   |
| `occurring`         | Patient must have enough distinct-date events (+ optional consecutive gap) |
| `with_index_date`   | Add `index_date` column                                                    |
| `first_per_patient` | One row per patient                                                        |
| `in_position`       | Primary / secondary diagnosis                                              |
| `to_sql` / `to_df`  | Inspect / run                                                              |

## Cohort criteria

| Criterion                                               | Meaning                                         |
| ------------------------------------------------------- | ----------------------------------------------- |
| `db.demographic.age_at_index(lo, hi)`                   | Age at index                                    |
| `db.enrollment.covering_index(days_before, days_after)` | Continuous enrollment around index              |
| `db.demographic.sex(...)` / `.race(...)`                | Sex / race at index                             |
| `db.death.recorded(window=…)`                           | Death (needs a `death` domain in the connector) |
| `include(frame, window=)`                               | Any EventFrame as patient set                   |

`window=(-365, 0)` → from 365 days before index through index day.

## Domains / code types

| Domain        | Code types                          |
| ------------- | ----------------------------------- |
| `diagnosis`   | `10` ICD-10, `09` ICD-9             |
| `procedure`   | `C4` CPT, `HC` HCPCS, `09`/`10` PCS |
| `medication`  | `ND` NDC (`db.dispensing` alias)    |
| `measurement` | `LC` LOINC                          |

Glossary: [Which API?](/which-api) · Legacy: [Migration](/migration)
