diff --git a/Care/Accounting/billed_paid_chargeitem_report_pallium.md b/Care/Accounting/billed_paid_chargeitem_report_pallium.md new file mode 100644 index 0000000..a373042 --- /dev/null +++ b/Care/Accounting/billed_paid_chargeitem_report_pallium.md @@ -0,0 +1,54 @@ + +# Billed / Paid Charge Item Report - Pallium + +> List of charge items currently in `billed` or `paid` status with patient, item, modifier and pricing details + +## Purpose + + Shows every charge item that has been billed or paid, along with the patient (and their Pallium ID), the charge item title and quantity, total price, when it was last modified and by whom. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `DATE` | DATE / range | Metabase date filter (typically bound to `ci.modified_date`) | `'2026-05-28'` | +| `chargeitem` | TEXT (multi) | Filter by one or more charge item titles | `'Consultation', 'X-Ray'` | + +--- + +## Query + +```sql +SELECT + p.name AS patient_name, + pi.value AS ssmm_id, + ci.modified_date, + ci.status, + ci.title, + ci.quantity, + TRIM(modified_user.first_name || ' ' || COALESCE(modified_user.last_name, '')) AS modified_by, + ci.total_price +FROM emr_chargeitem ci +JOIN emr_patient p ON ci.patient_id = p.id +LEFT JOIN emr_patientidentifier pi ON p.id = pi.patient_id AND pi.config_id = 4 +LEFT JOIN users_user modified_user ON ci.updated_by_id = modified_user.id +WHERE ci.status IN ('billed', 'paid') + --[[AND {{DATE}}]] + --[[AND ci.title IN ({{chargeitem}})]] +ORDER BY ci.modified_date DESC; +``` + + +## Notes + +- **Hardcoded values:** + - `pi.config_id = 4` — the identifier config representing the Pallium ID. Update if the config ID changes. +- **Metabase filters:** + - `[[AND {{DATE}}]]` is a field filter — bind it to `ci.modified_date` (or `ci.created_date`) in the Metabase variable settings. + - `[[AND ci.title IN ({{chargeitem}})]]` accepts a multi-select list of charge item titles. +- **Ordering** — most recently modified first. + +*Last updated: 2026-05-28* + +```` + diff --git a/Care/Encounter/bed_occupancy_ssmm.md b/Care/Encounter/bed_occupancy_ssmm.md index 49b8c25..b82d4c7 100644 --- a/Care/Encounter/bed_occupancy_ssmm.md +++ b/Care/Encounter/bed_occupancy_ssmm.md @@ -30,20 +30,19 @@ WITH all_beds AS ( AND fl.status = 'active' AND fl.form = 'bd' AND fl.root_location_id != 300 + AND fl.parent_id NOT IN (19, 44) ), - occupied_beds AS ( SELECT DISTINCT ON (e.patient_id) - fle.location_id AS bed_id + ab.bed_id FROM emr_facilitylocationencounter fle - INNER JOIN emr_encounter e ON fle.encounter_id = e.id - INNER JOIN all_beds ab ON fle.location_id = ab.bed_id + JOIN emr_encounter e ON fle.encounter_id = e.id + JOIN all_beds ab ON ab.bed_id = fle.location_id WHERE fle.deleted = FALSE --AND DATE(fle.start_datetime) <= {{report_date}} --AND (fle.end_datetime IS NULL OR DATE(fle.end_datetime) > {{report_date}}) ORDER BY e.patient_id, fle.start_datetime DESC ), - bed_stats AS ( SELECT ab.level1_name, @@ -60,10 +59,10 @@ SELECT * FROM ( SELECT 'Total' AS level1_name, 'Total' AS floor, - SUM(total_bed_count) AS total_bed_count, - SUM(occupied_bed_count) AS occupied_bed_count + SUM(total_bed_count), + SUM(occupied_bed_count) FROM bed_stats -) AS final_result +) final_result ORDER BY CASE WHEN floor = 'Total' THEN 1 ELSE 0 END, floor, level1_name; ``` @@ -73,6 +72,7 @@ ORDER BY CASE WHEN floor = 'Total' THEN 1 ELSE 0 END, floor, level1_name; - **`occupied_beds` CTE** — for each patient, the latest bed assignment. - **Hardcoded values:** - `fl.root_location_id != 300` — excludes the fake beds root. Update if the fake-beds root ID changes. + - `fl.parent_id NOT IN (19, 44)` — excludes specific parent locations (In this case OT and casualty). Update these IDs if the excluded wards change. - `fl.form = 'bd'` — only bed-type facility locations. - `fl.status = 'active'` — only currently active beds count toward totals. - **`report_date` filter** — when provided, treats a bed as occupied if `start_datetime <= report_date` and (`end_datetime IS NULL` OR `end_datetime > report_date`).