Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved query defects can include soft-deleted records, omit small positive debts, select outdated patient identifiers, and cause optional filters to fail due to missing alias configuration.
5 open issues
What changed in this PR
Adds two SSMM reports to the SQL query catalog: an inpatient account-due report for unpaid-bill follow-up and a stock-movement report for inventory tracing.
Changes:
- Adds account-to-encounter mapping, first discharge time, rounded financial amounts, and tags.
- Adds supply-delivery history with batch, quantity, purchase value, and movement details.
- Documents parameters, optional filter clauses, and interpretation notes for both queries.
| File | Description |
|---|---|
Care/Inventory/stock_movement_ssmm.md |
Documents stock-movement history and filtering options. |
Care/Accounting/ip_patient_due_report_ssmm.md |
Documents inpatient account balances, encounter details, and filtering options. |
Review effort: Balanced
There was a problem hiding this comment.
Analytics SQL Review — IP patient due report (SSMM)
Ticket (ENG-1147, "Build report on IP dues"): the description and comments are empty. I'm assuming the ask is a list of inpatient accounts with an outstanding balance. This PR plausibly delivers that. I can't check the grain, filters or facility scope against the ticket. Please add the requirements to the ticket.
Numbers: not yet safe to publish.
- Facility scope: there is no facility predicate, so the report spans all facilities (Critical).
- Status filters: there is no
entered_in_errorordeletedfiltering on accounts or encounters (same comment). - Fan-out: it is handled by
DISTINCT ON (a.id), which picks one encounter per account. Mention this in Notes.
Docs:
- Parameters and Notes are present, and
config_id = 21is explained. - The
+ INTERVAL '5 hours 30 minutes'IST offset infirst_dischargedis a hardcoded assumption and should go in Notes. - The parse lint is clean.
- The file location and name are correct.
Generated by Analytics SQL Reviewer for #169 · auto · 20 AIC · ⊞ 5.1K
There was a problem hiding this comment.
Analytics SQL Review — IP patient due report (SSMM)
Ticket (ENG-1147): list every account with money due that is linked to an inpatient encounter, via paid/billed charge items or primary_encounter_id.
Delivery: The query matches the ask. The acc_enc union covers both link paths, it filters to imp encounters, and DISTINCT ON (a.id) gives one row per account, so the money columns are not fanned out. The lint report shows no parse or template findings. The Purpose, Parameters and Notes sections match the SQL, and config_id = 21 is documented.
Not yet safe to publish. There are two correctness gaps, both in the inline comments:
- There is no
entered_in_errorordeleted = FALSEexclusion on accounts, charge items or encounters, so mistaken records can show up as dues. - There is no facility scoping, which matters for an
_ssmmquery.
I couldn't run the SQL, and I haven't checked the status strings against the care models. Please confirm them before applying the fixes.
Generated by Analytics SQL Reviewer for #169 · auto · 21.3 AIC · ⊞ 5.1K
| JOIN emr_encounter e ON e.id = ae.encounter_id | ||
| LEFT JOIN first_discharged fd ON fd.encounter_id = e.id | ||
| WHERE ROUND(a.total_balance) > 0 | ||
| AND e.encounter_class = 'imp' |
There was a problem hiding this comment.
Validity filters missing (wrong-number risk). None of emr_account, emr_chargeitem, or the joined emr_encounter e is checked for entered_in_error or deleted = FALSE. An account or encounter created by mistake that still carries a balance will show up as "money due". Per the skill's inversion 1, please exclude them. Check the exact status strings in care/emr/models first.
WHERE ROUND(a.total_balance) > 0
AND a.deleted = FALSE AND a.status <> 'entered_in_error'
AND e.deleted = FALSE AND e.status <> 'entered_in_error'
AND e.encounter_class = 'imp'Add c.deleted = FALSE and c.status IN ('paid','billed') in acc_enc; the status filter is already there. Also confirm whether inactive/closed accounts should count as "still has money due".
| WHERE tc.id = ANY(a.tags) AND NOT tc.deleted) AS account_tags, | ||
| (SELECT STRING_AGG(tc.display, ', ') FROM emr_tagconfig tc | ||
| WHERE tc.id = ANY(p.instance_tags) AND NOT tc.deleted) AS patient_tags | ||
| FROM emr_account a |
There was a problem hiding this comment.
No facility scoping. The file is _ssmm, but nothing restricts a.facility_id / e.facility_id. If the database holds more than one facility, this returns dues across all of them. Either add the SSMM facility filter and document its ID in Notes, or state in Notes that the DB is single-tenant. The ticket doesn't say which facility is meant, so please confirm the intended scope.


No description provided.