Some checks failed
CI / lint (push) Failing after 44s
CI / notebooks-smoke (push) Successful in 1m48s
Deploy / changes (push) Successful in 18s
Infra CI / notebooks (push) Successful in 55s
Infra CI / zotero (push) Successful in 23s
CI / test (push) Successful in 4m23s
Infra CI / docs (push) Successful in 22s
Infra CI / api (push) Successful in 1m10s
Infra CI / bcda (push) Successful in 1m46s
Infra CI / llm (push) Successful in 52s
Infra CI / mc (push) Successful in 20s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Deploy / api (push) Successful in 2m0s
Lean Pay / pay (push) Successful in 3m26s
Deploy / bcda (push) Successful in 1m59s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m19s
Deploy / report (push) Successful in 15s
Comment Pull / comment-pull (push) Failing after 29s
Notebooks Integration / notebooks-integration (push) Failing after 12m24s
Renovate / renovate (push) Successful in 2m31s
LLM Golden / llm-golden (push) Successful in 29m52s
Zotero Sync / zotero-sync (push) Successful in 3m3s
Package Supply Chain / pkg-supply-chain (push) Successful in 1m35s
Operating payment is the federal rate with COLA on the nonlabor portion, times (1 + operating IME + operating DSH), plus the uncompensated-care add-on. The impact-file operating DSH is already the empirically justified factor and is not multiplied by 0.25. Capital payment is the Table 1D national rate times the hospital GAF, times (1 + capital IME + capital DSH). The impact file is the final-rule model, not the quarterly Provider Specific File. An outlier is the 42 CFR 412.84 marginal factor on the excess of charge-based cost over that claim payment and the wage- or GAF-adjusted fixed-loss share. No charges, or no published fixed-loss threshold, produces no outlier. The national wage-index-1 federal-rate identity is unchanged.
218 lines
5.9 KiB
Python
218 lines
5.9 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",
|
||
"ipps-operating-cola-one",
|
||
"ipps-operating-claim",
|
||
"ipps-capital-gaf-one",
|
||
"ipps-capital-claim",
|
||
"ipps-outlier",
|
||
}
|
||
|
||
|
||
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_ipps_claim_matches_the_ceiling() -> None:
|
||
from ipps.calcs.payment import (
|
||
OUTLIER_MARGINAL,
|
||
capital_claim,
|
||
operating_claim,
|
||
outlier_payment,
|
||
)
|
||
|
||
assert _rat(operating_claim(2, 10, 5, 1)) == BY_ID["ipps-operating-cola-one"]
|
||
assert (
|
||
_rat(
|
||
operating_claim(
|
||
2,
|
||
10,
|
||
5,
|
||
1,
|
||
cola=1,
|
||
operating_ime=0.125,
|
||
operating_dsh=0.125,
|
||
ucp_per_claim=1,
|
||
)
|
||
)
|
||
== BY_ID["ipps-operating-claim"]
|
||
)
|
||
assert _rat(capital_claim(2, 10)) == BY_ID["ipps-capital-gaf-one"]
|
||
assert (
|
||
_rat(capital_claim(2, 10, gaf=1, capital_ime=0.25, capital_dsh=0))
|
||
== BY_ID["ipps-capital-claim"]
|
||
)
|
||
got = outlier_payment(
|
||
1000,
|
||
operating_ccr=0.25,
|
||
capital_ccr=0.25,
|
||
operating_paid=30,
|
||
capital_paid=20,
|
||
fixed_loss=100,
|
||
wage_index=1,
|
||
cola=1,
|
||
gaf=1,
|
||
labor_share=0.5,
|
||
nonlabor_share=0.5,
|
||
marginal=OUTLIER_MARGINAL,
|
||
)
|
||
assert _rat(got) == BY_ID["ipps-outlier"]
|
||
|
||
|
||
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
|