Skip to content

Documentation on accounts with no encounters linked - #162

Open
sonzsara wants to merge 1 commit into
mainfrom
ENG-1064
Open

sonzsara wants to merge 1 commit into
mainfrom
ENG-1064

Conversation

@sonzsara

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 11:03

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.

Copilot review overview

🟡 Changes recommended

The query does not enforce the documented outstanding-balance scope, and its hardcoded identifier configuration is undocumented.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Documents an SSMM report for patient accounts without a linked primary encounter.

Changes:

  • Adds report purpose, SQL query, parameters, and usage notes.
  • Includes patient, account, balance, status, and SSMM identifier fields.
File Description
Care/​Accounting/​accounts_with_no_encounter_linked_ssmm.md Adds the account-without-encounter report documentation and SQL.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

LEFT JOIN emr_patientidentifier pi
ON emr_patient.id = pi.patient_id
AND pi.config_id = 21
WHERE emr_account.primary_encounter_id IS NULL
Comment on lines +39 to +41
- **No encounter filter:** `emr_account.primary_encounter_id IS NULL` returns only accounts not linked to any primary encounter.
- **Due amount:** `total_balance` is rounded to the nearest whole number and cast to integer.
- Results are sorted by highest due amount first.

@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 — Accounts with no encounter linked (SSMM)

Ticket: not linked. JIRA returned no ticket for branch ENG-1064 (404 at the base URL, 401 at the scoped endpoint). Either the ticket ID is wrong, the ticket isn't visible to the bot, or the token has expired. I couldn't check requirement fidelity: metric, grain, facility scope and whether "outstanding" means > 0. Please confirm against ENG-1064 by hand.

SQL: the query parses cleanly (lint found nothing) but I wouldn't publish it yet. It has no facility filter, no entered_in_error exclusion and no deleted filter. See the inline comment. This is the main issue.

Already raised by another reviewer, so I'm not repeating them: the zero and negative balances vs the "outstanding balance" wording, and the undocumented config_id = 21. I agree with both. For the second, the Notes should say what identifier config 21 is (SSMM ID) and when to update it.

Doc and hygiene: the folder, filename and Last updated are fine, and the Parameters table is consistent with a query that has no parameters.

Verdict: not safe to publish as is. The numbers can include other facilities' accounts and void accounts.

Generated by Analytics SQL Reviewer for #162 · auto · 19.2 AIC · ⊞ 14.3K

LEFT JOIN emr_patientidentifier pi
ON emr_patient.id = pi.patient_id
AND pi.config_id = 21
WHERE emr_account.primary_encounter_id IS NULL

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical — no facility scope, no status/deleted filter. emr_account has a facility FK, but nothing here restricts the query to the SSMM facility. The _ssmm suffix is only a filename; the query returns accounts from every facility on the deployment, and the pi.config_id = 21 join only affects the ID column, not the rows. There is also no entered_in_error exclusion (accounts created by mistake still count toward "due amount") and no deleted = FALSE. Please confirm the field names against care/emr/models/account.py and add something like:

WHERE emr_account.primary_encounter_id IS NULL
  AND emr_account.facility_id = <SSMM facility id>   -- document in Notes
  AND emr_account.status <> 'entered_in_error'
  AND emr_account.deleted = FALSE
  AND emr_patient.deleted = FALSE

Also, emr_patientidentifier is optional here (LEFT JOIN, good). If a patient can have more than one identifier row for config 21, they'd be duplicated. Worth confirming that's unique per patient.

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