Conversation
There was a problem hiding this comment.
Pull request overview
Adds SSMM-facing documentation for an inventory SQL query that computes per-product stock balances and valuation for a single location at a selected snapshot date, split across incoming, outgoing (normal vs error/consumption destinations), and dispensed quantities.
Changes:
- Introduces a new markdown document describing the “Total Stock Value with Location Split” query (purpose, parameters, SQL, notes).
- Includes a full SQL statement that aggregates incoming supplies, outgoing transfers (normal/error buckets), and medication dispenses into a net stock and total value output.
Suppressed comments (1)
Care/Inventory/total_stock_value_with_location_split_ssmm.md:125
dispensesis FULL OUTER JOINed onincoming.id, which can leave dispense counts in a separate row when the product is present only inoutgoing_*joins. Use the coalesced key from all prior joins to keep per-product rows merged.
) dispenses ON dispenses.id = incoming.id
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
Care/Inventory/total_stock_value_with_location_split_ssmm.md:139
- Notes line has a few avoidable grammar issues ("hard coded", "id's") and inconsistent hyphenation ("entered in error" vs "entered-in-error"). This reads more clearly as "hardcoded destination IDs" and consistent hyphenation.
- The hard coded destination id's refer to the entered in error and consumption locations, update if needed
Care/Inventory/total_stock_value_with_location_split_ssmm.md:16
- Parameter description uses "id" in prose; elsewhere in docs this is typically written as "ID" (e.g., "location ID") for readability/consistency.
This issue also appears on line 139 of the same file.
| `location_id` | INTEGER | Facility location id to compute stock for | `239` |
Care/Inventory/total_stock_value_with_location_split_ssmm.md:98
- The long destination_id list is duplicated in both
outgoing_normal(NOT IN) andoutgoing_error(IN). Keeping these in sync is error-prone; consider factoring the IDs into a single CTE (or a temp table/view) and referencing it from both clauses (e.g.,destination_id IN (SELECT id FROM error_destinations)andNOT IN (...)).
WHERE esd.status IN ('completed', 'in_progress')
AND esd.deleted = FALSE AND edo.deleted = FALSE
AND DATE(esd.created_date) <= {{selected_date}}
AND origin_id = {{location_id}}
AND destination_id NOT IN (264, 270, 280, 274, 273, 275, 276, 266, 279, 36, 265, 278, 297, 238, 298, 27, 481, 17, 32, 277)
GROUP BY ep.id
No description provided.