new-site/data/hc_campaigns
justin 1acae2f20c healthcare: fix 4 bugs in segment-assignment + free-check email
Found during a bug-review pass of the one-email-per-provider work:

1. assign_all overwrite bug: an email on MULTIPLE rows (shared practice inbox /
   multiple NPIs -- 2,592 such emails, 299 with mixed status) was assigned by
   the LAST row, so a less-urgent row could clobber an urgent one (overdue ->
   free check). Now keeps the most-urgent (lowest-priority) assignment.

2. warm_segment double-import + wrong-row render: all of an email's rows passed
   the candidate filter, so it could be imported twice (over-counting the slice)
   and attribs_for could render a sibling row's blank due-date in the overdue
   email. Now requires row_matches(seg) for the specific row AND dedupes by
   email (one row per email).

3. free-check email rendered broken text ('last updated on  -- about  years
   ago', 'Last updated  . ~ yrs ago') for any provider whose NPPES date isn't
   cached yet (the free check goes to everyone, and the fill is gradual). Wrapped
   the example sentence + official-record card in listmonk {{ if
   .nppes_last_updated }}...{{ else }}...{{ end }}; added a date-free else
   branch. altbody keeps the conditionals (listmonk evaluates body+altbody), and
   the test/preview renderer gained a minimal {{ if/else/end }} evaluator so
   previews match real sends. Verified both branches render with zero unfilled
   tokens.

4. cross-cron double-send: pw-hc-campaign (warmup file) and pw-hc-nppes (63k
   file) share state but tracked imports per-segment; 312 emails overlap both
   files, so a provider could get an urgent email from one cron AND the free
   check from the other. Added load_all_imported() global guard (union of all
   segment state) so each provider gets exactly one healthcare email overall.

All verified: assignment regression test (10 cases) + new dup-email/guard checks
pass; all 6 templates render clean.
2026-06-20 16:14:44 -05:00
..
hc_clia_renewal.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_compliance_bundle.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_npi_reactivation.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_nppes_outdated.html healthcare: fix 4 bugs in segment-assignment + free-check email 2026-06-20 16:14:44 -05:00
hc_oig_screening.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_revalidation_due_soon.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_revalidation_overdue.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_revalidation_overdue_personal.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_revalidation_personal.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00
hc_revalidation_turnover.html healthcare emails: remove prices, fix click tracking, de-risk claims 2026-06-20 09:37:02 -05:00