-
Notifications
You must be signed in to change notification settings - Fork 1
Add payment reconciliation summary documentation for SSMM #111
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
3
commits into
main
Choose a base branch
from
ENG-532
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.
+72
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
72 changes: 72 additions & 0 deletions
72
Care/Accounting/payment_reconciliation_summary_by_method_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,72 @@ | ||
|
|
||
| # Payment Reconciliation Summary by Method - SSMM | ||
|
|
||
| > Payment reconciliation summary with amounts split across payment methods | ||
|
|
||
| ## Purpose | ||
|
|
||
| Aggregates active payment reconciliation records per invoice / patient / payment event and pivots the `amount` across the different payment methods (cash, credit card, debit card, cheque, DD, debit, etc.). | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | Example | | ||
| |-----------|------|-------------|---------| | ||
| | `date` | DATE | Filter by reconciliation modified date | `'2026-06-09'` | | ||
| | `ssmm_id` | TEXT | Filter by patient SSMM ID (exact match on `emr_patientidentifier.value`) | `'SSMM-1023'` | | ||
|
|
||
| --- | ||
|
|
||
| ## Query | ||
|
|
||
| ```sql | ||
| SELECT | ||
| emr_invoice.number AS invoice_number, | ||
| emr_patient.name AS patient_name, | ||
| pi.value AS ssmm_id, | ||
| emr_paymentreconciliation.payment_datetime, | ||
| emr_paymentreconciliation.status, | ||
| emr_paymentreconciliation.kind, | ||
| emr_paymentreconciliation.issuer_type, | ||
| emr_paymentreconciliation.reconciliation_type, | ||
| TRIM(COALESCE(users_user.prefix || ' ', '') || users_user.first_name || ' ' || users_user.last_name) AS updated_by, | ||
| SUM(CASE WHEN emr_paymentreconciliation.method = 'cash' THEN emr_paymentreconciliation.amount ELSE 0 END) AS cash, | ||
|
abhimanyurajeesh marked this conversation as resolved.
|
||
| SUM(CASE WHEN emr_paymentreconciliation.method = 'ccca' THEN emr_paymentreconciliation.amount ELSE 0 END) AS ccca, | ||
| SUM(CASE WHEN emr_paymentreconciliation.method = 'cdac' THEN emr_paymentreconciliation.amount ELSE 0 END) AS cdac, | ||
| SUM(CASE WHEN emr_paymentreconciliation.method = 'chck' THEN emr_paymentreconciliation.amount ELSE 0 END) AS chck, | ||
| SUM(CASE WHEN emr_paymentreconciliation.method = 'ddpo' THEN emr_paymentreconciliation.amount ELSE 0 END) AS ddpo, | ||
| SUM(CASE WHEN emr_paymentreconciliation.method = 'debc' THEN emr_paymentreconciliation.amount ELSE 0 END) AS debc | ||
| FROM emr_paymentreconciliation | ||
| JOIN users_user ON emr_paymentreconciliation.updated_by_id = users_user.id | ||
| LEFT JOIN emr_invoice ON emr_paymentreconciliation.target_invoice_id = emr_invoice.id | ||
|
sonzsara marked this conversation as resolved.
|
||
| JOIN emr_account ON emr_paymentreconciliation.account_id = emr_account.id | ||
| JOIN emr_patient ON emr_account.patient_id = emr_patient.id | ||
| LEFT JOIN emr_patientidentifier pi | ||
| ON emr_patient.id = pi.patient_id | ||
| AND pi.config_id = 21 | ||
| WHERE emr_paymentreconciliation.status = 'active' | ||
| --[[AND DATE(emr_paymentreconciliation.modified_date) = {{date}}]] | ||
| --[[AND pi.value = {{ssmm_id}}]] | ||
| GROUP BY | ||
| emr_invoice.number, | ||
| emr_patient.name, | ||
| pi.value, | ||
| emr_paymentreconciliation.payment_datetime, | ||
| emr_paymentreconciliation.status, | ||
| emr_paymentreconciliation.kind, | ||
| emr_paymentreconciliation.issuer_type, | ||
| emr_paymentreconciliation.reconciliation_type, | ||
| updated_by | ||
| ORDER BY emr_paymentreconciliation.payment_datetime DESC; | ||
| ``` | ||
|
|
||
|
|
||
| ## Notes | ||
|
|
||
| - Only reconciliations with `status = 'active'` are included. | ||
| - The patient identifier join is hardcoded to `pi.config_id = 21` which corresponds to the SSMM ID configuration — update this if the config ID changes. | ||
| - **Metabase filters:** | ||
| - `[[AND DATE(emr_paymentreconciliation.modified_date) = {{date}}]]` filters by the reconciliation's modified date. | ||
| - `[[AND pi.value = {{ssmm_id}}]]` is an exact-match text filter on the SSMM patient ID. | ||
| - Results are ordered by most recent `payment_datetime` first. | ||
|
|
||
| *Last updated: 2026-06-09* | ||
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.