fix(pfs): CPT parser drops resequenced placeholder rows (refs #687)
A resequenced code prints twice in the AMA book: a bare pointer at its
old numeric position ("Code is out of numerical sequence. See
NNNNN-NNNNN") and its real entry, with descriptor/elements/tail, at its
new print-order position. finalize_entry now recognizes the pointer
row by its own text and emits nothing for it (C8), so only the real
entry survives — a downstream loader can now assert one pfs.cpt_code
row per (edition_year, code) without the pointer creating a spurious
duplicate.
This commit is contained in:
@@ -81,6 +81,11 @@ _TOC_HEADING_RE = re.compile(r"^h([1-5])a?-toc$")
|
||||
_TOC_RANGE_RE = re.compile(r"\(([^()]*)\)\s*$")
|
||||
_APPENDIX_LETTER_RE = re.compile(r"[Aa]ppendix_?([A-Z])(?:[_.]|$)")
|
||||
|
||||
# C8 (task 3): a resequenced code's placeholder row at its old numeric
|
||||
# position ("Code is out of numerical sequence. See 99490-99491") —
|
||||
# never a real code entry, see finalize_entry.
|
||||
_RESEQUENCED_PLACEHOLDER_RE = re.compile(r"out of numerical sequence", re.IGNORECASE)
|
||||
|
||||
_LIST_APPENDICES = {"D", "E", "F", "G", "K", "N", "P", "T"}
|
||||
|
||||
|
||||
@@ -370,6 +375,17 @@ def _group(
|
||||
parts = [p for p in (stem, elements_joined, tail) if p]
|
||||
descriptor = joiner.join(parts).strip()
|
||||
|
||||
if _RESEQUENCED_PLACEHOLDER_RE.search(descriptor):
|
||||
# A resequenced code prints twice: once as a bare pointer at
|
||||
# its old numeric position ("Code is out of numerical
|
||||
# sequence. See NNNNN-NNNNN") and once with its real entry
|
||||
# at its new print-order position. The pointer row carries
|
||||
# no descriptor/section of its own worth keeping — C8 (task
|
||||
# 3) — so it must never become a pfs.cpt_code row; only the
|
||||
# real entry (elsewhere, under its real section) survives.
|
||||
entry = None
|
||||
return
|
||||
|
||||
for ref_text in entry["refs"]:
|
||||
low = ref_text.lower()
|
||||
if "cpt changes" in low:
|
||||
|
||||
@@ -47,6 +47,14 @@
|
||||
</table>
|
||||
|
||||
<div class="h1" id="sec_3">Other Sample Services</div>
|
||||
<table class="table1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="td-w1"><div class="table-para"><span class="red"><b>55000</b></span></div></td>
|
||||
<td class="td"><div class="table-para1">Code is out of numerical sequence. See 55010-55019</div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="h2" id="sec_4">Empty Category Services</div>
|
||||
<div class="noindent">Guideline text with no code rows, to test that a section with zero codes still gets a path.</div>
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ def parsed():
|
||||
"sections": {s.sec_id: s for s in sections},
|
||||
"sections_list": sections,
|
||||
"codes": {c.code: c for c in codes},
|
||||
"codes_list": codes,
|
||||
"instructions": instructions,
|
||||
"references": references,
|
||||
}
|
||||
@@ -290,6 +291,23 @@ class TestInstructions:
|
||||
assert "55555" in not_with[0].targets
|
||||
|
||||
|
||||
class TestResequencedPlaceholder:
|
||||
"""C8 (task 3): a resequenced code prints twice — a bare pointer row
|
||||
at its old numeric position ("Code is out of numerical sequence.
|
||||
See 55010-55019") plus its real entry (with elements/tail/refs)
|
||||
under its real section. Only the real entry may survive."""
|
||||
|
||||
def test_placeholder_row_is_not_emitted(self, parsed):
|
||||
matches = [c for c in parsed["codes_list"] if c.code == "55000"]
|
||||
assert len(matches) == 1
|
||||
|
||||
def test_surviving_row_is_the_real_entry_under_its_real_section(self, parsed):
|
||||
code = parsed["codes"]["55000"]
|
||||
assert code.sec_id == "sec_2"
|
||||
assert code.elements # only the real entry has elements/tail
|
||||
assert "out of numerical sequence" not in code.descriptor.lower()
|
||||
|
||||
|
||||
class TestReferences:
|
||||
def test_cpt_changes_years(self, parsed):
|
||||
refs = [
|
||||
|
||||
Reference in New Issue
Block a user