|
| 1 | + |
| 2 | +# Patients with Billable Charge Item and Encounter/Appointment Details - SSMM |
| 3 | + |
| 4 | +> Patient-level list of encounters linked to appointments that have billable charge items |
| 5 | +
|
| 6 | +## Purpose |
| 7 | + |
| 8 | +Returns encounter records at SSMM where the linked appointment (`emr_tokenbooking`) has a charge item in `billable` status. The result includes patient details, SSMM identifier, encounter and appointment statuses, charge item status/value, and encounter date. |
| 9 | + |
| 10 | +## Parameters |
| 11 | + |
| 12 | +| Parameter | Type | Description | Example | |
| 13 | +|-----------|------|-------------|---------| |
| 14 | +| `date_filter` | DATE / range | Metabase date filter (typically bound to `emr_encounter.created_date`) | `'2026-08-01'` | |
| 15 | +| `encounter_class` | TEXT | Filter by encounter class (exact match on `emr_encounter.encounter_class`) | `'amb'` | |
| 16 | +| `encounter_status` | TEXT | Filter by encounter status (exact match on `emr_encounter.status`) | `'in-progress'` | |
| 17 | +| `ssmm_id` | TEXT | Filter by patient SSMM identifier value (exact match on `emr_patientidentifier.value`) | `'SSMM-100245'` | |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Query |
| 22 | + |
| 23 | +```sql |
| 24 | +SELECT |
| 25 | + emr_patient.name AS patient_name, |
| 26 | + emr_patientidentifier.value AS ssmm_id, |
| 27 | + emr_encounter.status AS encounter_status, |
| 28 | + emr_encounter.encounter_class AS encounter_class, |
| 29 | + emr_tokenbooking.status AS appointment_status, |
| 30 | + emr_chargeitem.status AS charge_item_status, |
| 31 | + emr_chargeitem.total_price AS total_price, |
| 32 | + emr_encounter.created_date AS encounter_date |
| 33 | +FROM emr_encounter |
| 34 | +JOIN emr_patient |
| 35 | + ON emr_patient.id = emr_encounter.patient_id |
| 36 | +LEFT JOIN emr_patientidentifier |
| 37 | + ON emr_patientidentifier.patient_id = emr_patient.id |
| 38 | + AND emr_patientidentifier.config_id = 21 |
| 39 | +JOIN emr_tokenbooking |
| 40 | + ON emr_tokenbooking.associated_encounter_id = emr_encounter.id |
| 41 | +JOIN emr_chargeitem |
| 42 | + ON emr_chargeitem.id = emr_tokenbooking.charge_item_id |
| 43 | +WHERE emr_chargeitem.status = 'billable' |
| 44 | + AND emr_chargeitem.total_price > 0 |
| 45 | + --[[AND {{date_filter}}]] |
| 46 | + --[[AND {{encounter_class}}]] |
| 47 | + --[[AND {{encounter_status}}]] |
| 48 | + --[[AND emr_patientidentifier.value = {{ssmm_id}}]] |
| 49 | +ORDER BY emr_encounter.created_date DESC, emr_patient.name; |
| 50 | +``` |
| 51 | + |
| 52 | +## Notes |
| 53 | + |
| 54 | +- **Core cohort:** Only rows where `emr_chargeitem.status = 'billable'` and `total_price > 0` are included. |
| 55 | +- **Identifier mapping:** `config_id = 21` is hardcoded for SSMM patient identifier configuration; update if this mapping changes. |
| 56 | + |
| 57 | +*Last updated: 2026-08-13* |
0 commit comments