From adebeec811cbac9e430b41e3aef56c5dffca2802 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Mon, 4 May 2026 14:57:30 +0530 Subject: [PATCH 1/6] Add documentation for Scan Revenue and Scan Count queries at SSMM --- Care/Accouting/revenue_scan_ssmm.md | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Care/Accouting/revenue_scan_ssmm.md diff --git a/Care/Accouting/revenue_scan_ssmm.md b/Care/Accouting/revenue_scan_ssmm.md new file mode 100644 index 0000000..7bd8225 --- /dev/null +++ b/Care/Accouting/revenue_scan_ssmm.md @@ -0,0 +1,45 @@ + +# Scan Revenue - SSMM + +> Total revenue from scans charge items linked to issued/balanced invoices + +## Purpose + +Returns the total scan/imaging revenue at SSMM by summing `total_price` of charge items whose `charge_item_definition` belongs to one of the scan resource categories (`category_id IN (32, 57)`) and which are linked to a settled invoice. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `DATE` | DATE | Filter by date range (typically `inv.created_date` or `ci.created_date`) | `inv.created_date BETWEEN '2026-05-01' AND '2026-05-04'` | + +--- + +## Query + +```sql +SELECT + COALESCE(SUM(ci.total_price), 0) AS total_revenue_today +FROM emr_chargeitem ci +JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id +JOIN emr_resourcecategory rc ON cid.category_id = rc.id +JOIN emr_invoice inv ON ci.paid_invoice_id = inv.id +WHERE rc.id IN (32, 57) + AND ci.deleted = FALSE + AND ci.status IN ('paid', 'billed') + AND inv.deleted = FALSE + AND inv.status IN ('issued', 'balanced') + --[[AND {{DATE}}]] +; +``` + + +## Notes + +- Hardcoded to `rc.id IN (32, 57)` — the scan / imaging resource categories. Update if these IDs change or new scan categories are added. +- `COALESCE(SUM(...), 0)` ensures the result is `0` instead of `NULL` when no rows match. +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards; remove the brackets when running outside Metabase. + +*Last updated: 2026-05-04* + +```` From 46e3673db4a0dd62ee0fa4d71e76cbf605df2440 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Mon, 4 May 2026 15:07:59 +0530 Subject: [PATCH 2/6] Add documentation for Scan Count and revenue query at SSMM --- Care/Accouting/revenue_scam_ssmm.md | 45 +++++++++++++++++++++++++++++ Care/Encounter/count_of_scan.md | 43 +++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Care/Accouting/revenue_scam_ssmm.md create mode 100644 Care/Encounter/count_of_scan.md diff --git a/Care/Accouting/revenue_scam_ssmm.md b/Care/Accouting/revenue_scam_ssmm.md new file mode 100644 index 0000000..7bd8225 --- /dev/null +++ b/Care/Accouting/revenue_scam_ssmm.md @@ -0,0 +1,45 @@ + +# Scan Revenue - SSMM + +> Total revenue from scans charge items linked to issued/balanced invoices + +## Purpose + +Returns the total scan/imaging revenue at SSMM by summing `total_price` of charge items whose `charge_item_definition` belongs to one of the scan resource categories (`category_id IN (32, 57)`) and which are linked to a settled invoice. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `DATE` | DATE | Filter by date range (typically `inv.created_date` or `ci.created_date`) | `inv.created_date BETWEEN '2026-05-01' AND '2026-05-04'` | + +--- + +## Query + +```sql +SELECT + COALESCE(SUM(ci.total_price), 0) AS total_revenue_today +FROM emr_chargeitem ci +JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id +JOIN emr_resourcecategory rc ON cid.category_id = rc.id +JOIN emr_invoice inv ON ci.paid_invoice_id = inv.id +WHERE rc.id IN (32, 57) + AND ci.deleted = FALSE + AND ci.status IN ('paid', 'billed') + AND inv.deleted = FALSE + AND inv.status IN ('issued', 'balanced') + --[[AND {{DATE}}]] +; +``` + + +## Notes + +- Hardcoded to `rc.id IN (32, 57)` — the scan / imaging resource categories. Update if these IDs change or new scan categories are added. +- `COALESCE(SUM(...), 0)` ensures the result is `0` instead of `NULL` when no rows match. +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards; remove the brackets when running outside Metabase. + +*Last updated: 2026-05-04* + +```` diff --git a/Care/Encounter/count_of_scan.md b/Care/Encounter/count_of_scan.md new file mode 100644 index 0000000..edb52ea --- /dev/null +++ b/Care/Encounter/count_of_scan.md @@ -0,0 +1,43 @@ + +# Scan Count - SSMM + +> Total count of scans charge items (in the scan resource categories) + +## Purpose + +Returns the total number of scans (e.g. ultrasound, CT, MRI etc.) at SSMM by counting charge items whose `charge_item_definition` belongs to one of the scan resource categories (`category_id IN (32, 57)`) + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `DATE` | DATE | Filter by date range (typically `ci.created_date`) | `ci.created_date BETWEEN '2026-05-01' AND '2026-05-04'` | + +--- + +## Query + +```sql +SELECT + COUNT(ci.id) AS total_tests_today +FROM emr_chargeitem ci +JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id +JOIN emr_resourcecategory rc ON cid.category_id = rc.id +WHERE rc.id IN (32, 57) + AND ci.status IN ('paid', 'billed', 'billable') + AND ci.deleted = FALSE + --[[AND {{DATE}}]] +; +``` + + + +## Notes + +- Hardcoded to `rc.id IN (32, 57)` — the scan / imaging resource categories. Update if these category IDs change or new scan categories are added. +- Only active (`ci.deleted = FALSE`) charge items are included. +- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. + +*Last updated: 2026-05-04* + +```` From 3f0a0711e8b39592ed511d937926ae9951fe3df2 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Mon, 4 May 2026 15:22:18 +0530 Subject: [PATCH 3/6] Remove Scan Revenue documentation for SSMM --- Care/Accouting/revenue_scam_ssmm.md | 45 ----------------------------- 1 file changed, 45 deletions(-) delete mode 100644 Care/Accouting/revenue_scam_ssmm.md diff --git a/Care/Accouting/revenue_scam_ssmm.md b/Care/Accouting/revenue_scam_ssmm.md deleted file mode 100644 index 7bd8225..0000000 --- a/Care/Accouting/revenue_scam_ssmm.md +++ /dev/null @@ -1,45 +0,0 @@ - -# Scan Revenue - SSMM - -> Total revenue from scans charge items linked to issued/balanced invoices - -## Purpose - -Returns the total scan/imaging revenue at SSMM by summing `total_price` of charge items whose `charge_item_definition` belongs to one of the scan resource categories (`category_id IN (32, 57)`) and which are linked to a settled invoice. - -## Parameters - -| Parameter | Type | Description | Example | -|-----------|------|-------------|---------| -| `DATE` | DATE | Filter by date range (typically `inv.created_date` or `ci.created_date`) | `inv.created_date BETWEEN '2026-05-01' AND '2026-05-04'` | - ---- - -## Query - -```sql -SELECT - COALESCE(SUM(ci.total_price), 0) AS total_revenue_today -FROM emr_chargeitem ci -JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id -JOIN emr_resourcecategory rc ON cid.category_id = rc.id -JOIN emr_invoice inv ON ci.paid_invoice_id = inv.id -WHERE rc.id IN (32, 57) - AND ci.deleted = FALSE - AND ci.status IN ('paid', 'billed') - AND inv.deleted = FALSE - AND inv.status IN ('issued', 'balanced') - --[[AND {{DATE}}]] -; -``` - - -## Notes - -- Hardcoded to `rc.id IN (32, 57)` — the scan / imaging resource categories. Update if these IDs change or new scan categories are added. -- `COALESCE(SUM(...), 0)` ensures the result is `0` instead of `NULL` when no rows match. -- Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards; remove the brackets when running outside Metabase. - -*Last updated: 2026-05-04* - -```` From 03806122b0d785ea372176bfb4cfa2725657904f Mon Sep 17 00:00:00 2001 From: sonzsara Date: Mon, 4 May 2026 16:19:40 +0530 Subject: [PATCH 4/6] rename Accounting --- Care/{Accouting => Accounting}/.gitkeep | 0 Care/{Accouting => Accounting}/revenue_scan_ssmm.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Care/{Accouting => Accounting}/.gitkeep (100%) rename Care/{Accouting => Accounting}/revenue_scan_ssmm.md (100%) diff --git a/Care/Accouting/.gitkeep b/Care/Accounting/.gitkeep similarity index 100% rename from Care/Accouting/.gitkeep rename to Care/Accounting/.gitkeep diff --git a/Care/Accouting/revenue_scan_ssmm.md b/Care/Accounting/revenue_scan_ssmm.md similarity index 100% rename from Care/Accouting/revenue_scan_ssmm.md rename to Care/Accounting/revenue_scan_ssmm.md From 948e05d94c3ea6756b373925e3bbf91485bc99d6 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Fri, 8 May 2026 13:32:19 +0530 Subject: [PATCH 5/6] Updated aliases in revenue and scan count documentation --- Care/Accounting/revenue_scan_ssmm.md | 2 +- Care/Encounter/count_of_scan.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Care/Accounting/revenue_scan_ssmm.md b/Care/Accounting/revenue_scan_ssmm.md index 7bd8225..9af5888 100644 --- a/Care/Accounting/revenue_scan_ssmm.md +++ b/Care/Accounting/revenue_scan_ssmm.md @@ -19,7 +19,7 @@ Returns the total scan/imaging revenue at SSMM by summing `total_price` of charg ```sql SELECT - COALESCE(SUM(ci.total_price), 0) AS total_revenue_today + COALESCE(SUM(ci.total_price), 0) AS total_revenue FROM emr_chargeitem ci JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id JOIN emr_resourcecategory rc ON cid.category_id = rc.id diff --git a/Care/Encounter/count_of_scan.md b/Care/Encounter/count_of_scan.md index edb52ea..c494a9b 100644 --- a/Care/Encounter/count_of_scan.md +++ b/Care/Encounter/count_of_scan.md @@ -19,7 +19,7 @@ Returns the total number of scans (e.g. ultrasound, CT, MRI etc.) at SSMM by cou ```sql SELECT - COUNT(ci.id) AS total_tests_today + COUNT(ci.id) AS total_tests FROM emr_chargeitem ci JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id JOIN emr_resourcecategory rc ON cid.category_id = rc.id From 582da0e5dbe27e32bdab9017bca95244cea2a3b5 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Wed, 20 May 2026 12:55:58 +0530 Subject: [PATCH 6/6] Updated SQL queries in revenue and scan count documentation to use category_id directly and remove unnecessary joins --- Care/Accounting/revenue_scan_ssmm.md | 6 ++---- Care/Encounter/count_of_scan.md | 7 ++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Care/Accounting/revenue_scan_ssmm.md b/Care/Accounting/revenue_scan_ssmm.md index 9af5888..554b801 100644 --- a/Care/Accounting/revenue_scan_ssmm.md +++ b/Care/Accounting/revenue_scan_ssmm.md @@ -22,10 +22,8 @@ SELECT COALESCE(SUM(ci.total_price), 0) AS total_revenue FROM emr_chargeitem ci JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id -JOIN emr_resourcecategory rc ON cid.category_id = rc.id JOIN emr_invoice inv ON ci.paid_invoice_id = inv.id -WHERE rc.id IN (32, 57) - AND ci.deleted = FALSE +WHERE cid.category_id IN (32,57) AND ci.status IN ('paid', 'billed') AND inv.deleted = FALSE AND inv.status IN ('issued', 'balanced') @@ -36,7 +34,7 @@ WHERE rc.id IN (32, 57) ## Notes -- Hardcoded to `rc.id IN (32, 57)` — the scan / imaging resource categories. Update if these IDs change or new scan categories are added. +- Hardcoded to `cid.category_id IN (32, 57)` — the scan / imaging resource categories. Update if these IDs change or new scan categories are added. - `COALESCE(SUM(...), 0)` ensures the result is `0` instead of `NULL` when no rows match. - Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards; remove the brackets when running outside Metabase. diff --git a/Care/Encounter/count_of_scan.md b/Care/Encounter/count_of_scan.md index c494a9b..8336238 100644 --- a/Care/Encounter/count_of_scan.md +++ b/Care/Encounter/count_of_scan.md @@ -22,10 +22,8 @@ SELECT COUNT(ci.id) AS total_tests FROM emr_chargeitem ci JOIN emr_chargeitemdefinition cid ON ci.charge_item_definition_id = cid.id -JOIN emr_resourcecategory rc ON cid.category_id = rc.id -WHERE rc.id IN (32, 57) +WHERE cid.category_id IN (32,57) AND ci.status IN ('paid', 'billed', 'billable') - AND ci.deleted = FALSE --[[AND {{DATE}}]] ; ``` @@ -34,8 +32,7 @@ WHERE rc.id IN (32, 57) ## Notes -- Hardcoded to `rc.id IN (32, 57)` — the scan / imaging resource categories. Update if these category IDs change or new scan categories are added. -- Only active (`ci.deleted = FALSE`) charge items are included. +- Hardcoded to `cid.category_id IN (32, 57)` — the scan / imaging resource categories. Update if these category IDs change or new scan categories are added. - Metabase-specific filters (`[[...]]`) allow dynamic filtering in dashboards. *Last updated: 2026-05-04*