Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Runnable EncodeBox examples against the sample Sentinel CDM database.
cd /path/to/encodebox pixi install -e dev pixi run db-up
python examples/simple_example.py
Register connector
import encodebox as eb eb.register_connector("connectors/postgres_local_sentinel/connector.yml")
Connect → Database
db = eb.connect( "postgres", host="localhost", port=5433, database="encodebox_sample", username="postgres", password="postgres", connector="postgres_local_sentinel", )
Query
diabetes = ( db.diagnosis .matching("E11", code_type="10", match="starts_with") ) df = diabetes.to_df()
# Diagnoses db.diagnosis.matching("E11", code_type="10", match="starts_with") # Procedures db.procedure.matching("45378", code_type="C4", match="exactly") # Medications (dispensing) db.medication.matching("00002-7510", code_type="ND", match="starts_with") # Multiple code sets (UNION → code_set) db.diagnosis.matching( [["E11"], ["I10"]], code_type="10", match=["starts_with", "exactly"], )
index = ( db.diagnosis .matching("E11", code_type="10", match="starts_with") .occurring(at_least=2, gap_days=30) .with_index_date() .first_per_patient() )
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()) df = cohort.to_df()