93 lines
3.5 KiB
Python
93 lines
3.5 KiB
Python
"""Tests for pfs.nprm — NPRM Addendum B loader → pfs.rvu_proposed (#592)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import duckdb
|
|
|
|
from pfs import nprm
|
|
|
|
|
|
def _fixture(tmp_path):
|
|
p = tmp_path / "CY2026_NPRM_Addendum_B.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.3,1.5,0.55,0.1\n"
|
|
"0001A,,Admin covid,X,0.0,0.0,0.0,0.0\n"
|
|
)
|
|
return p
|
|
|
|
|
|
def test_load_rvu_proposed_loads_and_reloads(tmp_path, monkeypatch):
|
|
path = _fixture(tmp_path)
|
|
monkeypatch.setattr(nprm, "_discover_addendum_b", lambda: path)
|
|
con = duckdb.connect()
|
|
out = nprm.load_rvu_proposed(con)
|
|
assert out["rows"] == 2
|
|
row = con.execute(
|
|
"SELECT hcpcs, work_rvu, cms_rule_id FROM pfs.rvu_proposed WHERE hcpcs='99213'"
|
|
).fetchone()
|
|
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
|