Skip to content

Documentation on Total Stock Value with Location Split - #146

Open
sonzsara wants to merge 2 commits into
mainfrom
ENG-909
Open

Documentation on Total Stock Value with Location Split#146
sonzsara wants to merge 2 commits into
mainfrom
ENG-909

Conversation

@sonzsara

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • dispenses is FULL OUTER JOINed on incoming.id, which can leave dispense counts in a separate row when the product is present only in outgoing_* 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.

Comment thread Care/Inventory/total_stock_value_with_location_split_ssmm.md Outdated
Comment thread Care/Inventory/total_stock_value_with_location_split_ssmm.md

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and outgoing_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) and NOT 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants