From a45219cac9b4d87e296b648ce10647ab57c7ba05 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Mon, 29 Jun 2026 17:20:29 +0530 Subject: [PATCH] Add internal stock transfer report documentation --- .../internal_stock_transfer_report_pallium.md | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Care/Operations/internal_stock_transfer_report_pallium.md diff --git a/Care/Operations/internal_stock_transfer_report_pallium.md b/Care/Operations/internal_stock_transfer_report_pallium.md new file mode 100644 index 0000000..6116dd5 --- /dev/null +++ b/Care/Operations/internal_stock_transfer_report_pallium.md @@ -0,0 +1,54 @@ + +# Internal Stock Transfer Report + +> Line-level report of internal stock transfers between facility locations with batch, expiry, and quantity + +## Purpose + +Lists supply deliveries at Pallium that move stock **between two facility locations** (origin → destination). Each row shows the supply date, origin and destination locations, the product (with batch / lot number and expiry), and the quantity transferred. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `date` | DATE / range | Metabase date filter (typically bound to `sd.created_date`) | `'2026-06-01'` | +| `stock_name` | TEXT | Filter by product / stock name (exact match on `emr_productknowledge.name`) | `'Paracetamol'` | + +--- + +## Query + +```sql +SELECT + DATE(sd.created_date) AS supply_date, + fl_origin.name AS origin_location, + fl_dest.name AS destination_location, + p.batch ->> 'lot_number' AS lot_number, + p.expiration_date, + pk.name AS product_name, + sd.supplied_item_quantity AS quantity_delivered +FROM emr_supplydelivery sd +JOIN emr_inventoryitem ii + ON sd.supplied_inventory_item_id = ii.id +JOIN emr_product p + ON ii.product_id = p.id +JOIN emr_productknowledge pk + ON p.product_knowledge_id = pk.id +JOIN emr_deliveryorder d + ON sd.order_id = d.id +JOIN emr_facilitylocation fl_origin + ON d.origin_id = fl_origin.id +JOIN emr_facilitylocation fl_dest + ON d.destination_id = fl_dest.id +WHERE sd.status NOT IN ('entered_in_error','abandoned') + --[[AND {{date}}]] + --[[AND pk.name = {{stock_name}}]] +ORDER BY supply_date DESC; +``` + +## Notes + +- **Internal transfer scope:** Joining `emr_deliveryorder` on both `origin_id` and `destination_id` to `emr_facilitylocation` (via `fl_origin` and `fl_dest`) means only deliveries that have both a source and destination facility location are returned — i.e. internal transfers. +- Results are ordered by most recent `supply_date` first. + +*Last updated: 2026-06-29*