Skip to content

Add IP Patient Due Report documentation with SQL query and parameters - #169

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

sonzsara wants to merge 2 commits into
mainfrom
ENG-1147

Conversation

@sonzsara

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:02

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.

🟡 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

Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:06

@github-actions github-actions Bot 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.

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_error or deleted filtering 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 = 21 is explained.
  • The + INTERVAL '5 hours 30 minutes' IST offset in first_discharged is 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

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.

🔵 Needs a closer look

Missing soft-delete checks can include invalid inpatient debts and obsolete identifiers, while filtering rounded balances incorrectly excludes small positive amounts owed.

5 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 30, 2026 07:57

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.

🟢 Approval recommended

There are no active review issues for the SSMM inpatient patient-due report documentation.

No open issues 🎉

5 resolved since last review

Review effort: Balanced

@github-actions github-actions Bot 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.

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:

  1. There is no entered_in_error or deleted = FALSE exclusion on accounts, charge items or encounters, so mistaken records can show up as dues.
  2. There is no facility scoping, which matters for an _ssmm query.

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'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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