All checks were successful
CI / lint (push) Successful in 47s
CI / notebooks-smoke (push) Successful in 1m50s
Deploy / changes (push) Successful in 19s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Deploy / api (push) Has been skipped
Deploy / bcda (push) Has been skipped
Deploy / llm (push) Has been skipped
Deploy / mc (push) Has been skipped
Deploy / report (push) Successful in 14s
CI / test (push) Successful in 4m32s
Rational definitions in lean/Pay for PFS, the limiting charge, OPPS wage adjustment, ASP+6%, equipment cost, MPPR, the QPP year offset, and the REACH quality earn-back. Mathlib v4.34.0 checks them. pytest matches the Python pricers to the exported cases. IPPS and LEAD have no pricer here. MSSP and REACH settlements stay the published CMS tables.
167 lines
4.6 KiB
Python
167 lines
4.6 KiB
Python
"""Python calculations meet the Lean ceilings in ``lean/Pay``.
|
||
|
||
The committed ``cases.json`` is the output of ``lake exe pay-cases``.
|
||
Each case calls the production function on the same inputs.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import os
|
||
import shutil
|
||
import subprocess
|
||
from fractions import Fraction
|
||
from pathlib import Path
|
||
|
||
import polars as pl
|
||
import pytest
|
||
|
||
from opps.calcs.payment import payment as opps_payment
|
||
from pfs.calcs.payment import (
|
||
equipment_cost_per_use,
|
||
limiting_charge,
|
||
mppr_reduction,
|
||
)
|
||
from pfs.calcs.payment import (
|
||
payment as pfs_payment,
|
||
)
|
||
from qpp import QPP
|
||
|
||
ROOT = Path(__file__).resolve().parents[2]
|
||
PAY = ROOT / "lean" / "Pay"
|
||
CASES = json.loads((PAY / "cases.json").read_text())
|
||
BY_ID = {row["id"]: Fraction(row["num"], row["den"]) for row in CASES}
|
||
|
||
|
||
def _rat(value: float) -> Fraction:
|
||
return Fraction(value).limit_denominator(10**9)
|
||
|
||
|
||
def test_case_ids() -> None:
|
||
assert set(BY_ID) == {
|
||
"pfs-unit-gpci",
|
||
"limiting-100",
|
||
"opps-wage",
|
||
"opps-missing-wage",
|
||
"asp-100",
|
||
"reach-earn-back-85",
|
||
"qpp-2024",
|
||
"equipment-minute",
|
||
"mppr-second",
|
||
}
|
||
|
||
|
||
def test_pfs_unit_gpci() -> None:
|
||
rvu = pl.DataFrame(
|
||
{
|
||
"hcpcs": ["X"],
|
||
"work_rvu": [1.0],
|
||
"non_fac_pe_rvu": [2.0],
|
||
"mp_rvu": [3.0],
|
||
"mac": ["1"],
|
||
"locality": ["00"],
|
||
}
|
||
)
|
||
gpci = pl.DataFrame(
|
||
{
|
||
"mac": ["1"],
|
||
"locality": ["00"],
|
||
"work_gpci": [1.0],
|
||
"pe_gpci": [1.0],
|
||
"mp_gpci": [1.0],
|
||
}
|
||
)
|
||
got = pfs_payment(rvu, gpci, cf=10.0)["payment_amount"][0]
|
||
assert _rat(got) == BY_ID["pfs-unit-gpci"]
|
||
|
||
|
||
def test_limiting_charge() -> None:
|
||
assert _rat(limiting_charge(100.0)) == BY_ID["limiting-100"]
|
||
|
||
|
||
def test_opps_wage() -> None:
|
||
apc = pl.DataFrame(
|
||
{
|
||
"hcpcs": ["A", "B"],
|
||
"apc": ["1", "2"],
|
||
"relative_weight": [1.0, 1.0],
|
||
"payment_rate": [100.0, 80.0],
|
||
"status_indicator": ["J1", "J1"],
|
||
"cbsa": ["10180", "99999"],
|
||
}
|
||
)
|
||
wage = pl.DataFrame({"cbsa": ["10180"], "wage_index": [1.05]})
|
||
result = opps_payment(apc, wage, labor_share=0.60)
|
||
adjusted = {
|
||
row["hcpcs"]: row["adjusted_payment"] for row in result.iter_rows(named=True)
|
||
}
|
||
assert _rat(adjusted["A"]) == BY_ID["opps-wage"]
|
||
assert _rat(adjusted["B"]) == BY_ID["opps-missing-wage"]
|
||
|
||
|
||
def test_asp_limit_inside_skin_sub() -> None:
|
||
"""The express skin-sub step sets the limit to ASP × 1.06, rounded to cents."""
|
||
from opps.express.payment import skin_sub_impact
|
||
|
||
claims = pl.DataFrame({"hcpcs": ["Q"], "payment_rate": [0.0], "units": [1.0]})
|
||
asp = pl.DataFrame({"hcpcs_code": ["Q"], "asp_per_unit": [100.0]})
|
||
result = skin_sub_impact(claims, asp)
|
||
assert _rat(result["old_payment"][0]) == BY_ID["asp-100"]
|
||
|
||
|
||
def test_reach_earn_back_matches_the_published_example() -> None:
|
||
"""85% quality × the 2% withhold = 1.7% of benchmark."""
|
||
assert BY_ID["reach-earn-back-85"] == Fraction(85, 100) * Fraction(2, 100)
|
||
|
||
|
||
def test_qpp_payment_year() -> None:
|
||
assert QPP[2024].payment_year == BY_ID["qpp-2024"]
|
||
|
||
|
||
def test_equipment_cost_per_minute() -> None:
|
||
equipment = pl.DataFrame(
|
||
{
|
||
"hcpcs": ["X"],
|
||
"unit_price": [1000.0],
|
||
"useful_life": [5.0],
|
||
"minutes_per_year": [10000.0],
|
||
"maintenance_factor": [0.0],
|
||
}
|
||
)
|
||
got = equipment_cost_per_use(equipment)["cost_per_minute"][0]
|
||
assert _rat(got) == BY_ID["equipment-minute"]
|
||
|
||
|
||
def test_mppr_second_rank() -> None:
|
||
claims = pl.DataFrame(
|
||
{
|
||
"hcpcs": ["A", "B"],
|
||
"session_id": ["s", "s"],
|
||
"non_fac_pe_rvu": [4.0, 9.0],
|
||
}
|
||
)
|
||
result = mppr_reduction(claims, reduction_pct=0.50)
|
||
second = result.filter(pl.col("hcpcs") == "A")["pe_rvu_adjusted"][0]
|
||
assert _rat(second) == BY_ID["mppr-second"]
|
||
|
||
|
||
def test_committed_cases_match_the_lean_executable() -> None:
|
||
lake = shutil.which("lake")
|
||
if lake is None:
|
||
candidate = Path.home() / ".elan" / "bin" / "lake"
|
||
lake = str(candidate) if candidate.is_file() else None
|
||
if lake is None:
|
||
pytest.skip("lake is not installed")
|
||
env = os.environ.copy()
|
||
elan_bin = str(Path.home() / ".elan" / "bin")
|
||
env["PATH"] = elan_bin + os.pathsep + env.get("PATH", "")
|
||
proc = subprocess.run(
|
||
[lake, "exe", "pay-cases"],
|
||
cwd=PAY,
|
||
check=True,
|
||
capture_output=True,
|
||
text=True,
|
||
env=env,
|
||
)
|
||
assert json.loads(proc.stdout) == CASES
|