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

# Walkthrough

> End-to-end Sentinel CDM walkthrough with the sample PostgreSQL database.

End-to-end example using FDA Sentinel CDM with the sample PostgreSQL database.

```text theme={null}
Your Python code
  → register connector + connect
  → EventFrame / Cohort
  → IR → SQLAlchemy SQL
  → PostgreSQL sample (diagnosis / procedure / dispensing / …)
```

## Step-by-step

<Steps>
  <Step title="Register connector">
    ```python theme={null}
    import encodebox as eb

    eb.register_connector("connectors/postgres_local_sentinel/connector.yml")
    ```
  </Step>

  <Step title="Connect (returns Database)">
    ```python theme={null}
    db = eb.connect(
        "postgres",
        host="localhost",
        port=5433,
        database="encodebox_sample",
        username="postgres",
        password="postgres",
        connector="postgres_local_sentinel",
    )
    ```

    Start the sample DB with `pixi run db-up` (port 5433).
  </Step>

  <Step title="Query events">
    ```python theme={null}
    diabetes = (
        db.diagnosis
        .matching("E11", code_type="10", match="starts_with")
    )

    df = diabetes.to_df()
    print(diabetes.to_sql())
    ```

    Confirmed cases (≥2 distinct dates, ≥30 consecutive-day gap) with index at first qualifying pair:

    ```python theme={null}
    index = (
        diabetes
        .occurring(at_least=2, gap_days=30)
        .with_index_date()
        .first_per_patient()
    )
    df_index = index.to_df()
    ```
  </Step>

  <Step title="Build a cohort">
    ```python theme={null}
    cohort = (
        eb.Cohort("t2dm", database=db)
        .entry(index, index="first")
        .include(db.demographic.age_at_index(18, 89))
        .include(db.enrollment.covering_index(days_before=365, days_after=0))
        .exclude(db.diagnosis.matching("C", match="starts_with"), window=(-365, 0))
    )

    print(cohort.attrition())
    final = cohort.to_df()
    ```
  </Step>
</Steps>

## Inspect SQL

Every EventFrame and Cohort exposes `.to_sql()` and `.explain()` so you can audit generated SQL before execution.

## Next

* [Query patterns](/query-patterns)
* [Connectors](/connectors)
* [Data model](/data-model)
