From b7d15d910c07be9dc84dabfcd8e8331c230ad352 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Fri, 24 Jul 2026 13:42:57 +0530 Subject: [PATCH 1/2] Add documentation for Items Transferred to Consumption and Entered-in-Error Locations query --- ...ion_and_entered_in_error_locations_ssmm.md | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md diff --git a/Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md b/Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md new file mode 100644 index 0000000..b6f1883 --- /dev/null +++ b/Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md @@ -0,0 +1,63 @@ + +# Items Transferred to Consumption and Entered-in-Error Locations + +> Summary of stock transferred into a curated set of consumption / entered in error destination locations, with value + +## Purpose + +Summarises supply deliveries at SSMM whose **destination** is one of a curated list of "consumption" or "entered in error" facility locations. Groups by day, origin, destination, and both delivery statuses, reporting total quantity and total purchase-price value moved. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `created_date` | DATE / range | Metabase date filter (typically bound to `sd.created_date`) | `'2026-07-01'` | +| `location` | TEXT (multi) | Filter by one or more origin location names | `'Pharmacy', 'Main Store'` | + +--- + +## Query + +```sql +SELECT + DATE(sd.created_date) AS created_date, + fl_origin.name AS origin_location, + fl_destination.name AS destination_location, + sd.status, + delivery_order.status, + SUM(sd.supplied_item_quantity) AS total_quantity, + SUM(p.purchase_price * sd.supplied_item_quantity) AS total_purchase_price +FROM emr_supplydelivery sd +JOIN emr_deliveryorder delivery_order + ON sd.order_id = delivery_order.id +JOIN emr_facilitylocation fl_destination + ON delivery_order.destination_id = fl_destination.id +JOIN emr_facilitylocation fl_origin + ON delivery_order.origin_id = fl_origin.id +JOIN emr_inventoryitem ii + ON sd.supplied_inventory_item_id = ii.id +JOIN emr_product p + ON ii.product_id = p.id +WHERE fl_destination.id IN ( + 264, 32, 280, 266, 36, 638, 279, 278, 265, 481, 27, 298, + 17, 273, 639, 275, 238, 270, 276, 274, 277, 297, 641 +) + AND fl_destination.deleted = FALSE + AND fl_origin.deleted = FALSE + AND sd.status IN ('completed', 'in_progress') + AND delivery_order.status IN ('completed', 'pending') + AND fl_destination.status = 'active' + AND fl_origin.status = 'active' + --[[AND {{created_date}}]] + --[[AND fl_origin.name IN ({{location}})]] +GROUP BY DATE(sd.created_date), fl_origin.name, fl_destination.name, sd.status, delivery_order.status +ORDER BY DATE(sd.created_date) DESC, total_purchase_price DESC; +``` + +## Notes +- **Metabase filters:** + - `[[AND {{created_date}}]]` is a field filter — bind it to `sd.created_date`. + - `[[AND fl_origin.name IN ({{location}})]]` — multi-select filter on origin location name. +- Results are ordered by most recent date first, then by highest purchase value within each day. + +*Last updated: 2026-07-24* From a215b13dd3358668e2f1898b9be75755cfcb3d77 Mon Sep 17 00:00:00 2001 From: Sona Sara Shibu Date: Fri, 24 Jul 2026 14:11:51 +0530 Subject: [PATCH 2/2] Update items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md --- ...rred_to_consumption_and_entered_in_error_locations_ssmm.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md b/Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md index b6f1883..b761ad4 100644 --- a/Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md +++ b/Care/Inventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md @@ -23,8 +23,8 @@ SELECT DATE(sd.created_date) AS created_date, fl_origin.name AS origin_location, fl_destination.name AS destination_location, - sd.status, - delivery_order.status, + sd.status AS supply_delivery_status, + delivery_order.status AS delivery_order_status, SUM(sd.supplied_item_quantity) AS total_quantity, SUM(p.purchase_price * sd.supplied_item_quantity) AS total_purchase_price FROM emr_supplydelivery sd