From db9ad9f02c259f2b7fad195a39433033e3b4506e Mon Sep 17 00:00:00 2001 From: sonzsara Date: Tue, 30 Jun 2026 11:23:37 +0530 Subject: [PATCH 1/2] Documentation on inventory report --- Care/Inventory/inventory_report_pallium.md | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Care/Inventory/inventory_report_pallium.md diff --git a/Care/Inventory/inventory_report_pallium.md b/Care/Inventory/inventory_report_pallium.md new file mode 100644 index 0000000..3b065f1 --- /dev/null +++ b/Care/Inventory/inventory_report_pallium.md @@ -0,0 +1,47 @@ + +# Inventory Report + +> Per-location, per-batch inventory snapshot with purchase value and expiry flagging + +## Purpose + +Returns a full inventory snapshot with one row per inventory item . Each row shows the stock count, batch number, expiration date, unit purchase price, total purchase value (`stock_count × purchase_price`), and an `expiry_flag` that buckets each batch as **Expired**, **Critical (≤1 month)**, **Warning (≤3 months)**, or normal. + +--- + +## Query + +```sql +SELECT + fl.name AS location_name, + pk.name AS stock_name, + TO_CHAR(p.expiration_date, 'DD/MM/YYYY') AS expiration_date, + p.purchase_price, + ii.net_content * p.purchase_price AS total_purchase, + p.batch ->> 'lot_number' AS batch_number, + CASE + WHEN p.expiration_date <= CURRENT_DATE THEN 'Expired' + WHEN p.expiration_date <= CURRENT_DATE + INTERVAL '1 month' THEN 'Critical - Expires in 1 month' + WHEN p.expiration_date <= CURRENT_DATE + INTERVAL '3 months' THEN 'Warning - Expires in 3 months' + ELSE '' + END AS expiry_flag, + ii.net_content AS stock_count +FROM emr_productknowledge pk +JOIN emr_product p + ON p.product_knowledge_id = pk.id +JOIN emr_inventoryitem ii + ON ii.product_id = p.id +JOIN emr_facilitylocation fl + ON ii.location_id = fl.id +WHERE fl.deleted = FALSE +ORDER BY + fl.name, + pk.name, + expiration_date; +``` + + +## Notes +- Results are ordered by location, then stock name, then expiration date (earliest first) so each location's near-expiry items surface first within its group. + +*Last updated: 2026-06-29* From c2783f57ffb522ade2fc71f1c6cfa7ecc387fa11 Mon Sep 17 00:00:00 2001 From: Sona Sara Shibu Date: Tue, 30 Jun 2026 12:24:12 +0530 Subject: [PATCH 2/2] Update inventory_report_pallium.md --- Care/Inventory/inventory_report_pallium.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Care/Inventory/inventory_report_pallium.md b/Care/Inventory/inventory_report_pallium.md index 3b065f1..09c6198 100644 --- a/Care/Inventory/inventory_report_pallium.md +++ b/Care/Inventory/inventory_report_pallium.md @@ -42,6 +42,6 @@ ORDER BY ## Notes -- Results are ordered by location, then stock name, then expiration date (earliest first) so each location's near-expiry items surface first within its group. +- Results are ordered by location, then stock name. *Last updated: 2026-06-29*