-
Notifications
You must be signed in to change notification settings - Fork 1
Add Doctor Performance Report Documentation #119
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
6
commits into
main
Choose a base branch
from
ENG-615
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1a63778
Add Doctor Performance Report documentation for SSMM
sonzsara 7108b2e
Fix formatting in Doctor Performance Report documentation
sonzsara 391a890
Update column alias for doctor in Doctor Performance Report query
sonzsara 309485b
Refactor SQL query in Doctor Performance Report to improve calculatio…
sonzsara e7405bd
Update doctor_performance_report_ssmm.md
sonzsara 4ed3745
Refactor SQL query in Doctor Performance Report to simplify discount …
sonzsara 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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,72 @@ | ||
|
|
||
| # Doctor Performance Report - SSMM | ||
|
|
||
| > Per-doctor / category / issue-date charge item summary with quantity, gross price, and net amount | ||
|
|
||
| ## Purpose | ||
|
|
||
| Summarises billed / paid charge items at SSMM grouped by resource category, invoice issue date, and the performer (doctor). For each group it reports the total quantity, total gross price, and a net `amount` calculated as `total_price + discount − CGST − SGST - IGST` | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | Example | | ||
| |-----------|------|-------------|---------| | ||
| | `start_date` | DATE | Inclusive lower bound on the IST-adjusted invoice issue date | `'2026-06-01'` | | ||
| | `end_date` | DATE | Inclusive upper bound on the IST-adjusted invoice issue date (filter is `< end_date + 1 day`) | `'2026-06-30'` | | ||
| | `doctor` | TEXT | Filter by full doctor name (exact match on `prefix + first_name + last_name`) | `'Dr. John Doe'` | | ||
| | `category` | TEXT (multi) | Filter by one or more resource category titles | `'Consultation', 'Procedure'` | | ||
|
|
||
| --- | ||
|
|
||
| ## Query | ||
|
|
||
| ```sql | ||
| SELECT | ||
| emr_resourcecategory.title AS category, | ||
| emr_invoice.issue_date - INTERVAL '5 hours 30 minutes' AS issue_date, | ||
| TRIM(COALESCE(u.prefix || ' ', '') || u.first_name || ' ' || u.last_name) AS requested, | ||
| SUM(emr_chargeitem.quantity) AS total_quantity, | ||
|
Comment on lines
+26
to
+28
|
||
| SUM(emr_chargeitem.total_price) AS total_price, | ||
| SUM( | ||
| emr_chargeitem.total_price | ||
| + COALESCE(price_components.discount_amount, 0) | ||
| - COALESCE(price_components.cgst_amount, 0) | ||
| - COALESCE(price_components.sgst_amount, 0) | ||
| - COALESCE(price_components.igst_amount, 0) | ||
| ) AS amount | ||
| FROM emr_chargeitem | ||
| JOIN emr_chargeitemdefinition | ||
| ON emr_chargeitem.charge_item_definition_id = emr_chargeitemdefinition.id | ||
| JOIN emr_resourcecategory | ||
| ON emr_chargeitemdefinition.category_id = emr_resourcecategory.id | ||
| LEFT JOIN users_user u | ||
| ON emr_chargeitem.performer_actor_id = u.id | ||
| JOIN emr_invoice | ||
| ON emr_chargeitem.paid_invoice_id = emr_invoice.id | ||
| LEFT JOIN LATERAL ( | ||
|
sonzsara marked this conversation as resolved.
|
||
| SELECT | ||
| SUM((elem ->> 'amount')::numeric) FILTER (WHERE elem ->> 'monetary_component_type' = 'discount') AS discount_amount, | ||
| SUM((elem ->> 'amount')::numeric) FILTER (WHERE elem ->> 'monetary_component_type' = 'tax' AND elem -> 'code' ->> 'code' = 'cgst') AS cgst_amount, | ||
| SUM((elem ->> 'amount')::numeric) FILTER (WHERE elem ->> 'monetary_component_type' = 'tax' AND elem -> 'code' ->> 'code' = 'sgst') AS sgst_amount, | ||
| SUM((elem ->> 'amount')::numeric) FILTER (WHERE elem ->> 'monetary_component_type' = 'tax' AND elem -> 'code' ->> 'code' = 'igst') AS igst_amount | ||
| FROM jsonb_array_elements(emr_chargeitem.total_price_components) AS elem | ||
| ) price_components ON TRUE | ||
| WHERE emr_chargeitem.status IN ('paid','billed') | ||
| AND emr_invoice.status IN ('issued','balanced') | ||
| --[[AND emr_invoice.issue_date >= {{start_date}} + INTERVAL '5 hours 30 minutes']] | ||
| --[[AND emr_invoice.issue_date < {{end_date}} + INTERVAL '1 day' + INTERVAL '5 hours 30 minutes']] | ||
| --[[AND TRIM(COALESCE(u.prefix || ' ', '') || u.first_name || ' ' || u.last_name) = {{doctor}}]] | ||
|
|
||
| --[[AND emr_resourcecategory.title IN ({{category}})]] | ||
| GROUP BY | ||
| emr_resourcecategory.title, | ||
| emr_invoice.issue_date, | ||
| TRIM(COALESCE(u.prefix || ' ', '') || u.first_name || ' ' || u.last_name) | ||
|
|
||
| ORDER BY total_price DESC; | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - **`amount` formula:** `total_price + discount − CGST − SGST - IGST`. The discount is *added back* (it is stored as a negative-style component), and the CGST/SGST tax portions are subtracted to isolate the net revenue contribution. | ||
| - Results are ordered by `total_price DESC` so the highest-revenue groups surface first. | ||
|
|
||
| *Last updated: 2026-06-29* | ||
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.