Repository navigation
Conversation
There was a problem hiding this comment.
Analytics SQL Review — Reception counter closing report with IP/OP split (SSMM)
Ticket (ENG-1237): a per-staff invoiced vs. collected summary, split into IP and OP, with an optional date.
Verdict: not safe to publish yet. The staff filter is fully commented out in both CTEs, so the report aggregates all staff and does not deliver the "selected staff member" the ticket asks for. The Notes section describes the filter as mandatory, which contradicts the SQL. There is also a question about whether draft invoices should count.
Looks fine:
deleted = FALSEis applied on both tables.entered_in_errorandcancelledinvoices are excluded.- Payments are limited to active, complete ones.
- The IP/OP grain is right: one row per class, plus Total.
- The LEFT JOINs to the account and encounter are intended, and the Notes explain the no-encounter → OP fallback.
- The lint report is clean.
Generated by Analytics SQL Reviewer for #174 · auto · 19.6 AIC · ⊞ 5.3K
| LEFT JOIN emr_encounter ae ON ae.id = a.primary_encounter_id | ||
| JOIN users_user u ON u.id = i.updated_by_id | ||
| WHERE i.deleted = FALSE | ||
| AND i.status NOT IN ('cancelled', 'entered_in_error') |
There was a problem hiding this comment.
Question about intent: NOT IN ('cancelled','entered_in_error') leaves draft invoices in invoiced_gross (the Notes say so too). A counter closing report normally counts only issued/finalized invoices, so drafts would inflate "invoiced" against "collected". Please confirm drafts should count, or switch to an explicit allow-list such as i.status IN ('issued','balanced'). Check the status values in care/emr/resources/base.py or the invoice model before using them.
No description provided.