Files
stack/tests/pfs/test_cpt_load.py
kert afec69c933 fix(pfs): CPT parser resolves guideline-reprint duplicates structurally; cpt_code_alt keeps the alternates (refs #687)
C9: some codes print twice with a real descriptor both times — a
guideline "Unlisted Service or Procedure" summary table, a "Qualifying
Circumstances for Anesthesia" cross-reference reprint, a section-level
variant of the same pattern — distinct from C8's placeholder rows
(already dropped, never real text). A title-string denylist was tried
and rejected: excluding "Unlisted Service" sections silently drops the
sole real entries for codes 90749/91299 in the 2022 edition, proving
title matching isn't a safe signal on its own.

_resolve_alternates (pfs/cpt_epub.py, run at edition level in
parse_epub after every chapter is parsed) scores every entry for a
duplicated code instead: +2 if the entry's section (or its nearest
ancestor with a TOC code range) has a range containing the code, +1 if
that section has any range at all, +1 if the entry carries elements or
a reference, -3 if any path component ends with "Guidelines". Highest
score wins as canonical (ties: first in document order); the rest
become CptAlternate(code, sec_id, reason) rows — kept, not dropped. A
code that only ever appears in a guideline section has one entry and
is untouched.

pfs.cpt_model.CptEdition gains `alternates: tuple[CptAlternate, ...] =
()`. pfs.codetables adds pfs.cpt_code_alt (CptCodeAltRow) and
write_cpt_edition writes it; the C8 one-row-per-code assertion now
passes on all four real editions (verified: zero duplicate codes in
2019/2021/2022/2024).
2026-09-09 18:34:14 -04:00

7.5 KiB