-
Notifications
You must be signed in to change notification settings - Fork 1
Add documentation for Items Transferred to Consumption and Entered-in-Error Locations query #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sonzsara
wants to merge
2
commits into
main
Choose a base branch
from
ENG-802
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...ventory/items_transferred_to_consumption_and_entered_in_error_locations_ssmm.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 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 | ||
| 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* | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.