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 30s
Notebooks Integration / notebooks-integration (push) Failing after 11m25s
Renovate / renovate (push) Successful in 1m40s
LLM Golden / llm-golden (push) Successful in 38m12s
Zotero Sync / zotero-sync (push) Successful in 2m58s
Package Supply Chain / pkg-supply-chain (push) Successful in 1m17s
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.
525 lines
18 KiB
Python
525 lines
18 KiB
Python
"""The IPPS operating federal rate uses the published standardized amounts."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import duckdb
|
|
import polars as pl
|
|
import pytest
|
|
|
|
from ipps.calcs.payment import (
|
|
OUTLIER_BURN_MARGINAL,
|
|
OUTLIER_MARGINAL,
|
|
capital_claim,
|
|
capital_dollars,
|
|
capital_federal,
|
|
claim_payment,
|
|
operating_claim,
|
|
operating_dollars,
|
|
operating_federal,
|
|
operating_payment,
|
|
outlier_payment,
|
|
)
|
|
from ipps.rules import wage_index_table
|
|
from ipps.table import OperatingPayment
|
|
|
|
# FY2026 CMS-1833-F full update (quality data and a meaningful EHR user),
|
|
# as loaded from Tables 1A, 1B, and 1D. MS-DRG 470 weight is Table 5.
|
|
_FY2026_GT1 = (4456.72, 2295.89)
|
|
_FY2026_LE1 = (4186.62, 2565.99)
|
|
_FY2026_CAPITAL = 524.15
|
|
_DRG_470 = 1.9289
|
|
|
|
# FY2014 names the same full-update hospital full_update rather than quality_ehr.
|
|
_FY2014_GT1 = (3737.71, 1632.57)
|
|
_FY2014_LE1 = (3329.57, 2040.71)
|
|
|
|
_REPLICA = Path(__file__).resolve().parents[2] / "data" / "replica" / "aco.ro.duckdb"
|
|
|
|
|
|
def _drg() -> pl.DataFrame:
|
|
return pl.DataFrame(
|
|
{
|
|
"ms_drg": ["470", "470"],
|
|
"relative_weight": [_DRG_470, _DRG_470],
|
|
"fiscal_year": [2026, 2014],
|
|
}
|
|
)
|
|
|
|
|
|
def _wage() -> pl.DataFrame:
|
|
return pl.DataFrame(
|
|
{
|
|
"cbsa": ["11111", "22222", "33333", "11111"],
|
|
"state": ["AL", "WY", "AK", "AL"],
|
|
"wage_index": [1.2, 0.9, None, 1.2],
|
|
"year": [2026, 2026, 2026, 2014],
|
|
}
|
|
)
|
|
|
|
|
|
def _amounts() -> pl.DataFrame:
|
|
rows = [
|
|
(2026, "1A", "quality_ehr_labor", _FY2026_GT1[0]),
|
|
(2026, "1A", "quality_ehr_nonlabor", _FY2026_GT1[1]),
|
|
(2026, "1B", "quality_ehr_labor", _FY2026_LE1[0]),
|
|
(2026, "1B", "quality_ehr_nonlabor", _FY2026_LE1[1]),
|
|
(2026, "1A", "no_quality_no_ehr_labor", 4313.38),
|
|
(2026, "1D", "national_rate", _FY2026_CAPITAL),
|
|
(2026, "1E", "standard_federal_rate_full_update", 50824.51),
|
|
(2014, "1A", "full_update_labor", _FY2014_GT1[0]),
|
|
(2014, "1A", "full_update_nonlabor", _FY2014_GT1[1]),
|
|
(2014, "1B", "full_update_labor", _FY2014_LE1[0]),
|
|
(2014, "1B", "full_update_nonlabor", _FY2014_LE1[1]),
|
|
(2014, "1D", "national_rate", 429.31),
|
|
(2014, "1D", "puerto_rico_rate", 209.82),
|
|
]
|
|
return pl.DataFrame(
|
|
{
|
|
"fiscal_year": [row[0] for row in rows],
|
|
"table_code": [row[1] for row in rows],
|
|
"component": [row[2] for row in rows],
|
|
"amount": [row[3] for row in rows],
|
|
}
|
|
)
|
|
|
|
|
|
def _priced() -> pl.DataFrame:
|
|
return operating_payment(_drg(), _wage(), _amounts())
|
|
|
|
|
|
class TestOperatingDollars:
|
|
def test_wage_index_above_one_uses_table_1a(self) -> None:
|
|
assert wage_index_table(1.2) == "1A"
|
|
assert operating_dollars(_DRG_470, *_FY2026_GT1, 1.2) == 14744.42
|
|
|
|
def test_wage_index_at_or_below_one_uses_table_1b(self) -> None:
|
|
assert wage_index_table(1.0) == "1B"
|
|
assert wage_index_table(0.9) == "1B"
|
|
assert operating_dollars(_DRG_470, *_FY2026_LE1, 0.9) == 12217.55
|
|
# At wage index 1 the two splits add to the same national amount.
|
|
assert operating_dollars(_DRG_470, *_FY2026_GT1, 1.0) == 13025.11
|
|
assert operating_dollars(_DRG_470, *_FY2026_LE1, 1.0) == 13025.11
|
|
|
|
def test_capital_is_the_national_rate_times_the_weight(self) -> None:
|
|
assert capital_dollars(_DRG_470, _FY2026_CAPITAL) == 1011.03
|
|
|
|
|
|
class TestOperatingPayment:
|
|
def test_output_matches_the_table_contract(self) -> None:
|
|
assert set(_priced().columns) == set(OperatingPayment.column_names())
|
|
|
|
def test_high_wage_index_uses_the_table_1a_dollars(self) -> None:
|
|
row = _priced().filter(
|
|
(pl.col("fiscal_year") == 2026) & (pl.col("cbsa") == "11111")
|
|
)
|
|
assert row["labor"][0] == _FY2026_GT1[0]
|
|
assert row["nonlabor"][0] == _FY2026_GT1[1]
|
|
assert row["operating_payment"][0] == 14744.42
|
|
assert row["capital_payment"][0] == 1011.03
|
|
|
|
def test_low_wage_index_uses_the_table_1b_dollars(self) -> None:
|
|
row = _priced().filter(pl.col("cbsa") == "22222")
|
|
assert row["labor"][0] == _FY2026_LE1[0]
|
|
assert row["nonlabor"][0] == _FY2026_LE1[1]
|
|
assert row["operating_payment"][0] == 12217.55
|
|
|
|
def test_a_blank_wage_index_is_filled_with_one(self) -> None:
|
|
row = _priced().filter(pl.col("cbsa") == "33333")
|
|
assert row["wage_index"][0] == 1.0
|
|
assert row["labor"][0] == _FY2026_LE1[0]
|
|
assert row["operating_payment"][0] == 13025.11
|
|
|
|
def test_fy2014_full_update_name_is_the_full_update(self) -> None:
|
|
row = _priced().filter(pl.col("fiscal_year") == 2014)
|
|
assert row["labor"][0] == _FY2014_GT1[0]
|
|
assert row["operating_payment"][0] == operating_dollars(
|
|
_DRG_470, *_FY2014_GT1, 1.2
|
|
)
|
|
# Puerto Rico's capital rate is not the national rate.
|
|
assert row["capital_rate"][0] == 429.31
|
|
|
|
def test_quality_ehr_wins_when_a_year_also_has_the_old_name(self) -> None:
|
|
amounts = pl.concat(
|
|
[
|
|
_amounts(),
|
|
pl.DataFrame(
|
|
{
|
|
"fiscal_year": [2026, 2026],
|
|
"table_code": ["1A", "1A"],
|
|
"component": ["full_update_labor", "full_update_nonlabor"],
|
|
"amount": [1.0, 1.0],
|
|
}
|
|
),
|
|
]
|
|
)
|
|
priced = operating_payment(_drg(), _wage(), amounts)
|
|
row = priced.filter(
|
|
(pl.col("fiscal_year") == 2026) & (pl.col("cbsa") == "11111")
|
|
)
|
|
assert row["labor"][0] == _FY2026_GT1[0]
|
|
|
|
|
|
class TestClaim:
|
|
"""The claim applies published factors. The federal rate is unchanged."""
|
|
|
|
def test_zero_adjustments_match_the_federal_rate(self) -> None:
|
|
assert operating_claim(_DRG_470, *_FY2026_GT1, 1.2) == operating_dollars(
|
|
_DRG_470, *_FY2026_GT1, 1.2
|
|
)
|
|
assert operating_claim(_DRG_470, *_FY2026_GT1, 1.2) == 14744.42
|
|
assert operating_claim(_DRG_470, *_FY2026_LE1, 0.9) == 12217.55
|
|
assert operating_claim(_DRG_470, *_FY2026_LE1, 1.0) == 13025.11
|
|
assert operating_claim(_DRG_470, *_FY2026_LE1, None) == 13025.11
|
|
assert capital_claim(_DRG_470, _FY2026_CAPITAL) == capital_dollars(
|
|
_DRG_470, _FY2026_CAPITAL
|
|
)
|
|
assert capital_claim(_DRG_470, _FY2026_CAPITAL) == 1011.03
|
|
assert round(capital_federal(_DRG_470, _FY2026_CAPITAL, gaf=1), 2) == 1011.03
|
|
|
|
def test_cola_multiplies_only_the_nonlabor_portion(self) -> None:
|
|
plain = operating_federal(_DRG_470, *_FY2026_LE1, 0.9049, cola=1)
|
|
adjusted = operating_federal(_DRG_470, *_FY2026_LE1, 0.9049, cola=1.25)
|
|
assert adjusted - plain == pytest.approx(
|
|
_DRG_470 * _FY2026_LE1[1] * 0.25, rel=0, abs=1e-9
|
|
)
|
|
|
|
def test_fy2026_provider_010001_drg_470(self) -> None:
|
|
# Impact-file factors. WI 0.9049 selects Table 1B. Operating DSH
|
|
# is the printed 0.0298, not that number times 0.25.
|
|
operating = operating_claim(
|
|
_DRG_470,
|
|
*_FY2026_LE1,
|
|
0.9049,
|
|
cola=1,
|
|
operating_ime=0.0655,
|
|
operating_dsh=0.0298,
|
|
ucp_per_claim=1400.27,
|
|
)
|
|
capital = capital_claim(
|
|
_DRG_470,
|
|
_FY2026_CAPITAL,
|
|
gaf=0.933856364,
|
|
capital_ime=0.05496,
|
|
capital_dsh=0.05731,
|
|
)
|
|
assert operating == 14825.50
|
|
assert capital == 1050.16
|
|
assert round(operating + capital, 2) == 15875.66
|
|
doubled = operating_claim(
|
|
_DRG_470,
|
|
*_FY2026_LE1,
|
|
0.9049,
|
|
cola=1,
|
|
operating_ime=0.0655,
|
|
operating_dsh=0.0298 * 0.25,
|
|
ucp_per_claim=1400.27,
|
|
)
|
|
assert doubled == 14551.55
|
|
assert doubled != operating
|
|
|
|
def test_a_missing_uncompensated_care_addon_contributes_nothing(self) -> None:
|
|
assert operating_claim(
|
|
_DRG_470, *_FY2026_LE1, 1.0, ucp_per_claim=None
|
|
) == operating_claim(_DRG_470, *_FY2026_LE1, 1.0, ucp_per_claim=0)
|
|
|
|
def test_outlier_needs_charges_and_a_published_threshold(self) -> None:
|
|
kwargs = dict(
|
|
operating_ccr=0.25,
|
|
capital_ccr=0.25,
|
|
operating_paid=30.0,
|
|
capital_paid=20.0,
|
|
wage_index=1.0,
|
|
labor_share=0.5,
|
|
nonlabor_share=0.5,
|
|
)
|
|
assert outlier_payment(None, fixed_loss=100, **kwargs) is None
|
|
assert outlier_payment(1000, fixed_loss=None, **kwargs) is None
|
|
assert outlier_payment(1000, fixed_loss=100, **kwargs) == 280.0
|
|
assert (
|
|
outlier_payment(
|
|
1000, fixed_loss=100, marginal=OUTLIER_BURN_MARGINAL, **kwargs
|
|
)
|
|
== 315.0
|
|
)
|
|
assert outlier_payment(10, fixed_loss=100, **kwargs) == 0.0
|
|
assert OUTLIER_MARGINAL == 0.8
|
|
|
|
def test_mac_shares_that_do_not_sum_to_one_are_used_as_printed(self) -> None:
|
|
# FY2026 MAC shares are 0.66 and 0.324, not 0.66 and 0.34.
|
|
used = outlier_payment(
|
|
1000,
|
|
operating_ccr=0.25,
|
|
capital_ccr=0.25,
|
|
operating_paid=0,
|
|
capital_paid=0,
|
|
fixed_loss=100,
|
|
wage_index=1,
|
|
cola=1,
|
|
gaf=1,
|
|
labor_share=0.66,
|
|
nonlabor_share=0.324,
|
|
)
|
|
corrected = outlier_payment(
|
|
1000,
|
|
operating_ccr=0.25,
|
|
capital_ccr=0.25,
|
|
operating_paid=0,
|
|
capital_paid=0,
|
|
fixed_loss=100,
|
|
wage_index=1,
|
|
cola=1,
|
|
gaf=1,
|
|
labor_share=0.66,
|
|
nonlabor_share=0.34,
|
|
)
|
|
assert used is not None and corrected is not None
|
|
assert used != corrected
|
|
|
|
def test_a_ccr_above_the_published_ceiling_is_not_repriced(self) -> None:
|
|
assert (
|
|
outlier_payment(
|
|
1000,
|
|
operating_ccr=1.3,
|
|
capital_ccr=0.01,
|
|
operating_paid=0,
|
|
capital_paid=0,
|
|
fixed_loss=100,
|
|
wage_index=1,
|
|
labor_share=0.5,
|
|
nonlabor_share=0.5,
|
|
operating_ccr_ceiling=1.263,
|
|
)
|
|
is None
|
|
)
|
|
|
|
def test_claim_payment_uses_the_impact_file_for_a_named_provider(self) -> None:
|
|
claims = pl.DataFrame(
|
|
{
|
|
"ms_drg": ["470", "470"],
|
|
"fiscal_year": [2026, 2026],
|
|
"provider": ["010001", None],
|
|
"wage_index": [1.2, 1.2],
|
|
"cola": [9.0, 1.0],
|
|
"gaf": [9.0, 1.0],
|
|
"charges": [None, None],
|
|
}
|
|
)
|
|
providers = pl.DataFrame(
|
|
{
|
|
"fiscal_year": [2026],
|
|
"provider": ["010001"],
|
|
"payment_wage_index": [0.9049],
|
|
"cola": [1.0],
|
|
"operating_ime": [0.0655],
|
|
"operating_dsh": [0.0298],
|
|
"ucp_per_claim": [1400.27],
|
|
"capital_ime": [0.05496],
|
|
"capital_dsh": [0.05731],
|
|
"gaf": [0.933856364],
|
|
"operating_ccr": [0.187],
|
|
"capital_ccr": [0.013],
|
|
}
|
|
)
|
|
factors = pl.DataFrame(
|
|
{
|
|
"fiscal_year": [2026, 2026, 2026, 2026],
|
|
"factor": [
|
|
"fixed_loss_threshold",
|
|
"labor_share_le1",
|
|
"nonlabor_share_le1",
|
|
"cola",
|
|
],
|
|
"area": ["", "", "", "anchorage"],
|
|
"amount": [40397.0, 0.62, 0.34, 1.22],
|
|
}
|
|
)
|
|
priced = claim_payment(
|
|
claims,
|
|
_drg().filter(pl.col("fiscal_year") == 2026),
|
|
_amounts(),
|
|
providers,
|
|
factors,
|
|
)
|
|
named = priced.filter(pl.col("provider") == "010001")
|
|
assert named["wage_index"][0] == 0.9049
|
|
assert named["labor"][0] == _FY2026_LE1[0]
|
|
assert named["cola"][0] == 1.0
|
|
assert named["gaf"][0] == 0.933856364
|
|
assert named["operating_payment"][0] == 14825.50
|
|
assert named["capital_payment"][0] == 1050.16
|
|
assert named["outlier_payment"][0] is None
|
|
assert named["payment"][0] == 15875.66
|
|
area = priced.filter(pl.col("provider").is_null())
|
|
assert area["wage_index"][0] == 1.2
|
|
assert area["labor"][0] == _FY2026_GT1[0]
|
|
assert area["operating_payment"][0] == 14744.42
|
|
assert area["capital_payment"][0] == 1011.03
|
|
assert area["operating_ime"][0] is None
|
|
assert area["payment"][0] == round(14744.42 + 1011.03, 2)
|
|
|
|
def test_provider_numbers_match_the_stored_ccn(self) -> None:
|
|
claims = pl.DataFrame(
|
|
{"ms_drg": ["470"], "fiscal_year": [2026], "provider": ["10001"]}
|
|
)
|
|
providers = pl.DataFrame(
|
|
{
|
|
"fiscal_year": [2026],
|
|
"provider": ["010001"],
|
|
"payment_wage_index": [0.9049],
|
|
"cola": [1.0],
|
|
"gaf": [1.0],
|
|
}
|
|
)
|
|
factors = pl.DataFrame(
|
|
schema={
|
|
"fiscal_year": pl.Int64,
|
|
"factor": pl.Utf8,
|
|
"area": pl.Utf8,
|
|
"amount": pl.Float64,
|
|
}
|
|
)
|
|
priced = claim_payment(claims, _drg(), _amounts(), providers, factors)
|
|
assert priced["provider"][0] == "010001"
|
|
assert priced["wage_index"][0] == 0.9049
|
|
|
|
def test_a_missing_drg_does_not_invent_a_payment(self) -> None:
|
|
claims = pl.DataFrame(
|
|
{"ms_drg": ["999"], "fiscal_year": [2026], "provider": [None]}
|
|
)
|
|
providers = pl.DataFrame(
|
|
{
|
|
"fiscal_year": [2026],
|
|
"provider": ["010001"],
|
|
"payment_wage_index": [1.0],
|
|
}
|
|
)
|
|
factors = pl.DataFrame(
|
|
{
|
|
"fiscal_year": [2026],
|
|
"factor": ["fixed_loss_threshold"],
|
|
"area": [""],
|
|
"amount": [40397.0],
|
|
}
|
|
)
|
|
priced = claim_payment(claims, _drg(), _amounts(), providers, factors)
|
|
assert priced["payment"][0] is None
|
|
|
|
|
|
class TestPipe:
|
|
def test_step_writes_the_operating_payment_table(self) -> None:
|
|
from ipps.pipe import STEPS
|
|
|
|
assert STEPS[0][2] is OperatingPayment
|
|
|
|
def test_registry_runs_one_expression(self) -> None:
|
|
from aco.pipe import registry
|
|
|
|
assert len(registry["ipps"]) == 1
|
|
assert registry["ipps"].names() == ["ipps.operating_payment"]
|
|
|
|
|
|
@pytest.mark.skipif(not _REPLICA.is_file(), reason="aco replica is not present")
|
|
class TestLoadedTables:
|
|
def test_every_loaded_year_reconciles_at_wage_index_one(self) -> None:
|
|
from rec.engine import reconcile
|
|
from rec.pricers.ipps import IppsPricer
|
|
|
|
con = duckdb.connect(str(_REPLICA), read_only=True)
|
|
try:
|
|
pricer = IppsPricer()
|
|
years = pricer.years_available(con)
|
|
assert years == list(range(2014, 2028))
|
|
for year in years:
|
|
result = reconcile(pricer, con, year)
|
|
assert result.matched_rows > 700, year
|
|
assert result.exact_matches == result.matched_rows, year
|
|
assert result.ground_truth_only == 0
|
|
assert result.calculated_only == 0
|
|
finally:
|
|
con.close()
|
|
|
|
def test_fy2026_drg_470_on_a_real_cbsa(self) -> None:
|
|
con = duckdb.connect(str(_REPLICA), read_only=True)
|
|
try:
|
|
drg = con.execute(
|
|
"""
|
|
SELECT ms_drg, relative_weight, fiscal_year
|
|
FROM ipps.drg_weight
|
|
WHERE fiscal_year = 2026 AND ms_drg = '470'
|
|
"""
|
|
).pl()
|
|
wage = con.execute(
|
|
"""
|
|
SELECT cbsa, state, wage_index, year
|
|
FROM opps.wage_index
|
|
WHERE year = 2026 AND cbsa = '10180' AND wage_index IS NOT NULL
|
|
"""
|
|
).pl()
|
|
amounts = con.execute(
|
|
"""
|
|
SELECT fiscal_year, table_code, component, amount
|
|
FROM ipps.standardized_amount
|
|
WHERE fiscal_year = 2026
|
|
"""
|
|
).pl()
|
|
finally:
|
|
con.close()
|
|
assert wage.height >= 1
|
|
priced = operating_payment(drg, wage, amounts)
|
|
index = float(wage["wage_index"][0])
|
|
band = _FY2026_GT1 if index > 1 else _FY2026_LE1
|
|
row = priced.filter(pl.col("state") == wage["state"][0])
|
|
assert row["operating_payment"][0] == operating_dollars(_DRG_470, *band, index)
|
|
assert row["capital_payment"][0] == capital_dollars(_DRG_470, _FY2026_CAPITAL)
|
|
|
|
def test_fy2026_provider_010001_drg_470_matches_the_impact_file(self) -> None:
|
|
con = duckdb.connect(str(_REPLICA), read_only=True)
|
|
try:
|
|
claims = pl.DataFrame(
|
|
{
|
|
"ms_drg": ["470"],
|
|
"fiscal_year": [2026],
|
|
"provider": ["010001"],
|
|
"charges": [None],
|
|
}
|
|
)
|
|
drg = con.execute(
|
|
"""
|
|
SELECT ms_drg, relative_weight, fiscal_year
|
|
FROM ipps.drg_weight
|
|
WHERE fiscal_year = 2026 AND ms_drg = '470'
|
|
"""
|
|
).pl()
|
|
amounts = con.execute(
|
|
"""
|
|
SELECT fiscal_year, table_code, component, amount
|
|
FROM ipps.standardized_amount
|
|
WHERE fiscal_year = 2026
|
|
"""
|
|
).pl()
|
|
providers = con.execute(
|
|
"""
|
|
SELECT *
|
|
FROM ipps.provider_factor
|
|
WHERE fiscal_year = 2026 AND provider = '010001'
|
|
"""
|
|
).pl()
|
|
factors = con.execute(
|
|
"""
|
|
SELECT fiscal_year, factor, area, amount
|
|
FROM ipps.national_factor
|
|
WHERE fiscal_year = 2026
|
|
"""
|
|
).pl()
|
|
finally:
|
|
con.close()
|
|
priced = claim_payment(claims, drg, amounts, providers, factors)
|
|
assert priced["operating_payment"][0] == 14825.50
|
|
assert priced["capital_payment"][0] == 1050.16
|
|
assert priced["outlier_payment"][0] is None
|
|
assert priced["payment"][0] == 15875.66
|
|
assert priced["wage_index"][0] == 0.9049
|
|
assert float(providers["ucp_per_claim"][0]) == 1400.27
|