354 lines
9.0 KiB
Python
354 lines
9.0 KiB
Python
"""Tests for pfs.table — Pydantic SQLTable models for CMS PFS data files.
|
|
|
|
Covers:
|
|
- Re-exports from pfs.table.__init__
|
|
- Each model's __schema__, __tablename__, qualified_name(), column_names()
|
|
- Default instantiation (all None) and sample-data instantiation
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from pfs.table import (
|
|
AddendumA,
|
|
AddendumB,
|
|
AddendumC,
|
|
AddendumD,
|
|
AddendumE,
|
|
CarrierLocality,
|
|
ClinicalLabor,
|
|
Gpci,
|
|
MedicalEquipment,
|
|
MedicalSupply,
|
|
PhysicianWorkTime,
|
|
Rvu,
|
|
)
|
|
from pfs.table.zip_carrier import ZipCarrierLocality
|
|
|
|
# ── Re-export smoke test ─────────────────────────────────────────
|
|
|
|
|
|
class TestReExports:
|
|
"""pfs.table.__init__ re-exports all 12 model classes."""
|
|
|
|
def test_all_classes_importable(self):
|
|
# If any of these were missing, the import block above would
|
|
# already fail, but be explicit.
|
|
classes = [
|
|
AddendumA,
|
|
AddendumB,
|
|
AddendumC,
|
|
AddendumD,
|
|
AddendumE,
|
|
CarrierLocality,
|
|
ClinicalLabor,
|
|
Gpci,
|
|
MedicalEquipment,
|
|
MedicalSupply,
|
|
PhysicianWorkTime,
|
|
Rvu,
|
|
]
|
|
for cls in classes:
|
|
assert cls.__schema__ == "pfs"
|
|
|
|
|
|
# ── Parametrized table-model tests ──────────────────────────────
|
|
|
|
_TABLE_SPECS = [
|
|
(
|
|
AddendumA,
|
|
"addendum_a",
|
|
[
|
|
"hcpcs",
|
|
"mod",
|
|
"description",
|
|
"status",
|
|
"current_work_rvu",
|
|
"proposed_work_rvu",
|
|
"current_nf_pe_rvu",
|
|
"proposed_nf_pe_rvu",
|
|
"current_f_pe_rvu",
|
|
"proposed_f_pe_rvu",
|
|
"current_mp_rvu",
|
|
"proposed_mp_rvu",
|
|
"current_nf_total",
|
|
"proposed_nf_total",
|
|
"current_f_total",
|
|
"proposed_f_total",
|
|
"year",
|
|
],
|
|
{"hcpcs": "99213", "mod": "26", "year": 2026},
|
|
),
|
|
(
|
|
AddendumB,
|
|
"addendum_b",
|
|
[
|
|
"hcpcs",
|
|
"mod",
|
|
"description",
|
|
"status",
|
|
"work_rvu",
|
|
"non_fac_pe_rvu",
|
|
"fac_pe_rvu",
|
|
"mp_rvu",
|
|
"non_fac_total",
|
|
"fac_total",
|
|
"global_period",
|
|
"pctc_ind",
|
|
"mult_proc",
|
|
"bilat_surg",
|
|
"asst_surg",
|
|
"co_surg",
|
|
"team_surg",
|
|
"endo_base",
|
|
"conv_factor",
|
|
"year",
|
|
],
|
|
{"hcpcs": "99213", "work_rvu": 1.3, "year": 2026},
|
|
),
|
|
(
|
|
AddendumC,
|
|
"addendum_c",
|
|
[
|
|
"hcpcs",
|
|
"mod",
|
|
"description",
|
|
"status",
|
|
"work_rvu",
|
|
"non_fac_pe_rvu",
|
|
"fac_pe_rvu",
|
|
"mp_rvu",
|
|
"global_period",
|
|
"year",
|
|
],
|
|
{"hcpcs": "0001U", "year": 2025},
|
|
),
|
|
(
|
|
AddendumD,
|
|
"addendum_d",
|
|
[
|
|
"mac",
|
|
"locality",
|
|
"locality_name",
|
|
"state",
|
|
"work_gpci",
|
|
"pe_gpci",
|
|
"mp_gpci",
|
|
"year",
|
|
],
|
|
{"mac": "10112", "locality": "01", "state": "NY", "year": 2026},
|
|
),
|
|
(
|
|
AddendumE,
|
|
"addendum_e",
|
|
[
|
|
"hcpcs",
|
|
"mod",
|
|
"description",
|
|
"status",
|
|
"mppr_category",
|
|
"year",
|
|
],
|
|
{"hcpcs": "76000", "mppr_category": "1", "year": 2026},
|
|
),
|
|
(
|
|
CarrierLocality,
|
|
"carrier_locality",
|
|
[
|
|
"mac",
|
|
"locality",
|
|
"hcpcs",
|
|
"mod",
|
|
"non_fac_fee",
|
|
"fac_fee",
|
|
"non_fac_limiting_charge",
|
|
"fac_limiting_charge",
|
|
"year",
|
|
],
|
|
{"mac": "10112", "hcpcs": "99213", "non_fac_fee": 109.04},
|
|
),
|
|
(
|
|
MedicalEquipment,
|
|
"medical_equipment",
|
|
[
|
|
"hcpcs",
|
|
"equipment_code",
|
|
"equipment_description",
|
|
"nf_minutes",
|
|
"f_minutes",
|
|
"unit_price",
|
|
"useful_life",
|
|
"minutes_per_year",
|
|
"maintenance_factor",
|
|
"year",
|
|
],
|
|
{"hcpcs": "99213", "equipment_code": "EQ168", "unit_price": 5000.0},
|
|
),
|
|
(
|
|
Gpci,
|
|
"gpci",
|
|
[
|
|
"mac",
|
|
"locality",
|
|
"locality_name",
|
|
"state",
|
|
"work_gpci",
|
|
"pe_gpci",
|
|
"mp_gpci",
|
|
"year",
|
|
],
|
|
{"mac": "10112", "locality": "01", "work_gpci": 1.094, "year": 2026},
|
|
),
|
|
(
|
|
ClinicalLabor,
|
|
"clinical_labor",
|
|
[
|
|
"hcpcs",
|
|
"activity_code",
|
|
"activity_description",
|
|
"nf_minutes",
|
|
"f_minutes",
|
|
"rate_per_minute",
|
|
"staff_type",
|
|
"pre_service",
|
|
"service_period",
|
|
"post_service",
|
|
"year",
|
|
],
|
|
{"hcpcs": "99213", "activity_code": "L037D", "nf_minutes": 5.0},
|
|
),
|
|
(
|
|
Rvu,
|
|
"rvu",
|
|
[
|
|
"hcpcs",
|
|
"mod",
|
|
"description",
|
|
"status_code",
|
|
"not_used_for_medicare",
|
|
"work_rvu",
|
|
"non_fac_pe_rvu",
|
|
"fac_pe_rvu",
|
|
"mp_rvu",
|
|
"non_fac_total",
|
|
"fac_total",
|
|
"pctc_ind",
|
|
"glob_days",
|
|
"pre_op",
|
|
"intra_op",
|
|
"post_op",
|
|
"mult_proc",
|
|
"bilat_surg",
|
|
"asst_surg",
|
|
"co_surg",
|
|
"team_surg",
|
|
"endo_base",
|
|
"conv_factor",
|
|
"physician_supervision",
|
|
"calc_flag",
|
|
"diag_imaging_family",
|
|
"non_fac_pe_used_for_opps",
|
|
"fac_pe_used_for_opps",
|
|
"mp_used_for_opps",
|
|
"year",
|
|
"quarter",
|
|
],
|
|
{
|
|
"hcpcs": "99213",
|
|
"work_rvu": 1.3,
|
|
"year": 2026,
|
|
"quarter": "A",
|
|
},
|
|
),
|
|
(
|
|
MedicalSupply,
|
|
"medical_supply",
|
|
[
|
|
"hcpcs",
|
|
"supply_code",
|
|
"supply_description",
|
|
"nf_quantity",
|
|
"f_quantity",
|
|
"unit_price",
|
|
"year",
|
|
],
|
|
{"hcpcs": "99213", "supply_code": "SA048", "unit_price": 0.12},
|
|
),
|
|
(
|
|
PhysicianWorkTime,
|
|
"physician_work_time",
|
|
[
|
|
"hcpcs",
|
|
"description",
|
|
"global_period",
|
|
"work_rvu",
|
|
"pre_eval_time",
|
|
"pre_positioning_time",
|
|
"pre_scrub_dress_wait",
|
|
"intra_service_time",
|
|
"post_immediate_time",
|
|
"post_critical_care",
|
|
"post_other_hospital",
|
|
"post_discharge_mgmt",
|
|
"post_office_visits",
|
|
"total_time",
|
|
"year",
|
|
],
|
|
{"hcpcs": "99213", "intra_service_time": 15.0, "total_time": 23.0},
|
|
),
|
|
(
|
|
ZipCarrierLocality,
|
|
"zip_carrier_locality",
|
|
[
|
|
"state",
|
|
"zip_code",
|
|
"carrier",
|
|
"locality",
|
|
"rural_indicator",
|
|
"plus_four_flag",
|
|
"part_b_indicator",
|
|
"year",
|
|
"quarter",
|
|
],
|
|
{"state": "NY", "zip_code": "10001", "carrier": "56202", "year": 2026},
|
|
),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"model_cls, tablename, expected_columns, sample_data",
|
|
_TABLE_SPECS,
|
|
ids=[spec[0].__name__ for spec in _TABLE_SPECS],
|
|
)
|
|
class TestTableModels:
|
|
"""Shared tests applied to every PFS table model."""
|
|
|
|
def test_schema_is_pfs(self, model_cls, tablename, expected_columns, sample_data):
|
|
assert model_cls.__schema__ == "pfs"
|
|
|
|
def test_tablename(self, model_cls, tablename, expected_columns, sample_data):
|
|
assert model_cls.__tablename__ == tablename
|
|
|
|
def test_qualified_name(self, model_cls, tablename, expected_columns, sample_data):
|
|
assert model_cls.qualified_name() == f"pfs.{tablename}"
|
|
|
|
def test_column_names(self, model_cls, tablename, expected_columns, sample_data):
|
|
assert model_cls.column_names() == expected_columns
|
|
|
|
def test_default_instantiation(
|
|
self, model_cls, tablename, expected_columns, sample_data
|
|
):
|
|
"""All fields default to None — empty constructor works."""
|
|
instance = model_cls()
|
|
for col in expected_columns:
|
|
assert getattr(instance, col) is None
|
|
|
|
def test_sample_instantiation(
|
|
self, model_cls, tablename, expected_columns, sample_data
|
|
):
|
|
"""Construct with sample data and verify values round-trip."""
|
|
instance = model_cls(**sample_data)
|
|
for key, value in sample_data.items():
|
|
assert getattr(instance, key) == value
|