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`). diff --git a/Care/Operations/patients_referred_to_secondary_unit_for_comfort_devices_kc.md b/Care/Operations/patients_referred_to_secondary_unit_for_comfort_devices_kc.md new file mode 100644 index 0000000..e7708e7 --- /dev/null +++ b/Care/Operations/patients_referred_to_secondary_unit_for_comfort_devices_kc.md @@ -0,0 +1,47 @@ + +# Patients Referred to Secondary Unit for Comfort Devices - KC + +> Count of active (non-cancelled, non-rejected) resource requests in the `comfort_devices` category — i.e. patients referred to a secondary unit for comfort devices + +## Purpose + +Operational metric for KC showing how many comfort-device resource requests have been raised by a facility (and optionally a specific staff member) in a given period. A "resource request" here represents a referral / request for comfort device support (e.g. air bed, wheelchair, walker) from one facility to another. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT (UUID) | Filter by originating facility's external ID | `'a1b2c3d4-...'` | +| `created_date` | DATE / range | Metabase date filter (typically bound to `emr_resourcerequest.created_date`) | `'2026-06-01'` | +| `staff_name` | TEXT | Filter by the creating user's full name (`prefix + first + last`, trimmed) | `'Dr Asha Menon'` | + +--- + +## Query + +```sql +SELECT + COUNT(*) +FROM + emr_resourcerequest + JOIN facility_facility ON emr_resourcerequest.origin_facility_id = facility_facility.id + JOIN users_user ON emr_resourcerequest.created_by_id = users_user.id +WHERE + emr_resourcerequest.category IN ('comfort_devices', 'COMFORT_DEVICES') + AND emr_resourcerequest.status NOT IN ('cancelled', 'rejected') + --[[AND facility_facility.external_id::text = {{facility_id}}]] + --[[AND {{created_date}}]] + --[[AND TRIM(COALESCE(users_user.prefix || ' ', '') || users_user.first_name || ' ' || COALESCE(users_user.last_name, '')) = {{staff_name}}]] +``` + + +## Notes + +- **Metabase filters:** + - `[[AND {{created_date}}]]` is a field filter — bind it to `emr_resourcerequest.created_date` in the Metabase variable settings. + - `{{facility_id}}` and `{{staff_name}}` are exact-match text filters. + +*Last updated: 2026-06-01* + +```` + diff --git a/Care/Operations/patients_referred_to_secondary_unit_for_patientcare_kc.md b/Care/Operations/patients_referred_to_secondary_unit_for_patientcare_kc.md new file mode 100644 index 0000000..49dff3f --- /dev/null +++ b/Care/Operations/patients_referred_to_secondary_unit_for_patientcare_kc.md @@ -0,0 +1,48 @@ + +# Patients Referred to Secondary Unit for Patient Care - KC + +> Count of active (non-cancelled, non-rejected) resource requests in the `patient_care` category — i.e. patients referred to a secondary unit for patient care + +## Purpose + +Operational metric for KC showing how many patient-care resource requests have been raised by a facility (and optionally a specific staff member) in a given period. A "resource request" here represents a referral / request for patient-care services from one facility to another. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `facility_id` | TEXT (UUID) | Filter by originating facility's external ID | `'a1b2c3d4-...'` | +| `created_date` | DATE / range | Metabase date filter (typically bound to `emr_resourcerequest.created_date`) | `'2026-06-01'` | +| `staff_name` | TEXT | Filter by the creating user's full name (`prefix + first + last`, trimmed) | `'Dr Asha Menon'` | + +--- + +## Query + +```sql +SELECT + COUNT(*) +FROM + emr_resourcerequest + JOIN facility_facility ON emr_resourcerequest.origin_facility_id = facility_facility.id + JOIN users_user ON emr_resourcerequest.created_by_id = users_user.id +WHERE + emr_resourcerequest.category IN ('patient_care', 'PATIENT_CARE') + AND emr_resourcerequest.status NOT IN ('cancelled', 'rejected') + --[[AND facility_facility.external_id::text = {{facility_id}}]] + --[[AND {{created_date}}]] + --[[AND TRIM(COALESCE(users_user.prefix || ' ', '') || users_user.first_name || ' ' || COALESCE(users_user.last_name, '')) = {{staff_name}}]] +``` + + +## Notes + +- **Metabase filters:** + - `[[AND {{created_date}}]]` is a field filter — bind it to `emr_resourcerequest.created_date` in the Metabase variable settings. + - `{{facility_id}}` and `{{staff_name}}` are exact-match text filters. + + +*Last updated: 2026-06-01* + +```` +