test(pfs): lock in NPRM Addendum B data-quality handling; deterministic discovery (refs #592)
This commit is contained in:
@@ -65,7 +65,8 @@ def _discover_addendum_b() -> Path:
|
||||
"JOIN items i ON i.id = a.item_id "
|
||||
"JOIN item_tags it ON it.item_id = i.id "
|
||||
"JOIN tags t ON t.id = it.tag_id "
|
||||
"WHERE t.name = ?",
|
||||
"WHERE t.name = ? "
|
||||
"ORDER BY a.id",
|
||||
(_ADDENDUM_B_TAG,),
|
||||
)
|
||||
.fetchall()
|
||||
|
||||
@@ -30,3 +30,63 @@ def test_load_rvu_proposed_loads_and_reloads(tmp_path, monkeypatch):
|
||||
assert row == ("99213", 1.3, "CMS-1832-P")
|
||||
nprm.load_rvu_proposed(con) # idempotent delete-and-reload
|
||||
assert con.execute("SELECT count(*) FROM pfs.rvu_proposed").fetchone()[0] == 2
|
||||
|
||||
|
||||
def _dirty_fixture(tmp_path):
|
||||
"""Real-file quirks: padded cells, "NA" markers, a footnote row.
|
||||
|
||||
Mirrors what the actual CY2026 Addendum B workbook contains — this
|
||||
combination broke silently on the real file (see task-5-report.md)
|
||||
and was fixed via manual smoke-testing rather than a fixture test,
|
||||
so these rows lock the fix in.
|
||||
"""
|
||||
p = tmp_path / "CY2026_NPRM_Addendum_B_dirty.csv"
|
||||
p.write_text(
|
||||
"HCPCS,MOD,DESCRIPTION,STATUS CODE,WORK RVU,"
|
||||
"NON-FAC PE RVU,FAC PE RVU,MP RVU\n"
|
||||
" 99213 , ,Office visit est,A, 1.30 , 1.50 , 0.55 , 0.10 \n"
|
||||
"99214,,Office visit NA test,A,NA,NA,NA,NA\n"
|
||||
"1 CPT codes and descriptors only are copyright 2025 American "
|
||||
"Medical Association. All Rights Reserved.,,,,,,,\n"
|
||||
)
|
||||
return p
|
||||
|
||||
|
||||
def test_load_rvu_proposed_strips_padding(tmp_path, monkeypatch):
|
||||
"""Whitespace-padded HCPCS/numeric cells load clean, not null."""
|
||||
path = _dirty_fixture(tmp_path)
|
||||
monkeypatch.setattr(nprm, "_discover_addendum_b", lambda: path)
|
||||
con = duckdb.connect()
|
||||
nprm.load_rvu_proposed(con)
|
||||
row = con.execute(
|
||||
"SELECT hcpcs, description, work_rvu, nonfac_pe_rvu, fac_pe_rvu, mp_rvu "
|
||||
"FROM pfs.rvu_proposed WHERE hcpcs='99213'"
|
||||
).fetchone()
|
||||
assert row == ("99213", "Office visit est", 1.3, 1.5, 0.55, 0.1)
|
||||
|
||||
|
||||
def test_load_rvu_proposed_na_marker_becomes_null(tmp_path, monkeypatch):
|
||||
""" "NA" in a numeric cell loads as SQL NULL, not a cast error."""
|
||||
path = _dirty_fixture(tmp_path)
|
||||
monkeypatch.setattr(nprm, "_discover_addendum_b", lambda: path)
|
||||
con = duckdb.connect()
|
||||
nprm.load_rvu_proposed(con)
|
||||
row = con.execute(
|
||||
"SELECT work_rvu, nonfac_pe_rvu, fac_pe_rvu, mp_rvu "
|
||||
"FROM pfs.rvu_proposed WHERE hcpcs='99214'"
|
||||
).fetchone()
|
||||
assert row == (None, None, None, None)
|
||||
|
||||
|
||||
def test_load_rvu_proposed_drops_footnote_rows(tmp_path, monkeypatch):
|
||||
"""A footnote row (first cell = long sentence) is not a HCPCS code."""
|
||||
path = _dirty_fixture(tmp_path)
|
||||
monkeypatch.setattr(nprm, "_discover_addendum_b", lambda: path)
|
||||
con = duckdb.connect()
|
||||
out = nprm.load_rvu_proposed(con)
|
||||
assert out["rows"] == 2 # only 99213 and 99214 — footnote row excluded
|
||||
assert con.execute("SELECT count(*) FROM pfs.rvu_proposed").fetchone()[0] == 2
|
||||
footnote = con.execute(
|
||||
"SELECT count(*) FROM pfs.rvu_proposed WHERE hcpcs LIKE '1 CPT%'"
|
||||
).fetchone()[0]
|
||||
assert footnote == 0
|
||||
|
||||
Reference in New Issue
Block a user