Skip to content

Add report for invoices with duplicate discounts on charge items - #163

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

sonzsara wants to merge 2 commits into
mainfrom
ENG-1068

Conversation

@sonzsara

Copy link
Copy Markdown
Contributor

No description provided.

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

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 account report is under-filtered, and deployment-specific constants and PR scope need clarification.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds two SSMM accounting reports for duplicate invoice discounts and accounts without encounters.

Changes:

  • Detects invoices containing charge items with multiple discounts.
  • Reports accounts lacking primary encounters.
File Description
Care/​Accounting/​invoices_with_duplicate_discounts_on_chargeitems_ssmm.md Adds duplicate-discount invoice report.
Care/​Accounting/​accounts_with_no_encounter_linked_ssmm.md Adds unlinked-account balance report.

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

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

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

🔵 Needs a closer look

The hardcoded SSMM facility UUID must be documented in the Notes section.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

@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 — SSMM report of invoices with duplicate charge-item discounts

Ticket: The PR isn't linked to a verifiable JIRA ticket. The branch is ENG-1068, but the lookup failed (HTTP 404, then 401 on the scoped endpoint). That means either the ticket is inaccessible to the bot or the ID is wrong, so I couldn't review requirement fidelity. If the ticket is real, please make sure it's visible to the integration.

SQL: It parses cleanly (lint report has no findings). The EXISTS with GROUP BY eci.id HAVING COUNT(*) > 1 does count discount components per charge item correctly, and there is no fan-out because of DISTINCT. Open questions:

  • Cancelled and entered_in_error invoices aren't excluded (inline comment).
  • The link hardcodes one facility while the query is unscoped (inline comment).

Docs: The Notes section is missing the hardcoded host and facility ID, and it doesn't explain what counts as a "discount" component. Copilot already raised the Notes point.

Verdict: Not yet safe to publish until the status filter and facility scoping are settled.

Generated by Analytics SQL Reviewer for #163 · auto · 12.3 AIC · ⊞ 14.3K


```sql
SELECT DISTINCT
i.number AS invoice_number,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The link hardcodes a single facility UUID, but the query has no facility filter. If the DB holds more than one facility, invoices from the others get a link pointing at the wrong facility. Either join emr_facility and build the link from the invoice's own facility (i.facility_id), or add an explicit facility filter. Then document the host and UUID in Notes (Copilot raised the Notes point too, so I'm not repeating it).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

At head 5d3cfb1 the facility-UUID link column is gone, so the wrong-facility link problem and the Notes point no longer apply. Resolving. The query still has no facility predicate, which I've noted in the summary.

Generated by Analytics SQL Reviewer for #163 · auto · 20.2 AIC · ⊞ 14.3K

'https://care-public.ssmmhospital.com/facility/9bef54be-70b1-4210-adb5-37a0183ee5f9/billing/invoices/'
|| i.external_id::text AS invoice_link,
i.created_date AS invoice_date
FROM emr_invoice i

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only deleted = FALSE is filtered. Invoices with status of cancelled / entered_in_error still show up, so they will be flagged as duplicate-discount problems even though they no longer count. Please confirm intent. If they shouldn't count, add e.g. AND i.status NOT IN ('cancelled', 'entered_in_error'). I couldn't check the ticket, so I'm assuming the report is about live invoices. Verify the exact status values against care/emr/models/invoice.py first.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 05:44

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

🟢 Approval recommended

The query correctly groups discounts per charge item, with only a minor documentation-format issue.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Low severity Remove empty Parameters section from query template

Care/​Accounting/​invoices_with_duplicate_discounts_on_chargeitems_ssmm.md:15

The repository template says to delete the Parameters section when a query has no parameters (TEMPLATE.md:15). Keeping a placeholder row here diverges from that documented format; remove this section and retain only the divider before the query.

@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 — invoices with duplicate discounts on charge items (SSMM)

Ticket: none found. JIRA returned 404 for ENG-1068 (the branch name), possibly an access problem with the token. I can't check requirement fidelity, so I'm assuming the report is meant to cover live invoices only.

Fixed since last round: the hardcoded facility URL and UUID column has been removed. I replied to that thread and resolved it.

Still open:

  • The i.status exclusion thread (cancelled / entered_in_error) is not addressed. The query still filters only on deleted = FALSE, so voided invoices will be reported as duplicate-discount problems. The same goes for charge items: emr_chargeitem has a status, and the report probably shouldn't count entered_in_error rows. Please confirm the exact values in care/emr/models/.

New:

  • The file is named _ssmm, but no facility predicate is in the SQL. If the database holds more than one facility, other facilities' invoices will leak in. Add a facility filter (for example i.facility_id = <ssmm id>), or drop the suffix if the report is meant to span all facilities. Any hardcoded ID needs a line in Notes.
  • The Notes should describe the "duplicate discount" definition (more than one monetary_component_type = 'discount' component on a single charge item), and the output columns table is missing.

The parse is clean (lint report: 0 findings). The EXISTS with GROUP BY ... HAVING avoids fan-out, so DISTINCT is redundant but harmless. The numbers aren't safe to publish until the status and facility scoping are settled.

Generated by Analytics SQL Reviewer for #163 · auto · 20.2 AIC · ⊞ 14.3K

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