Files
stack/tests/pfs/test_cite.py

226 lines
6.9 KiB
Python

"""pfs.cite — one citation per dossier fact (dossier task 13)."""
from __future__ import annotations
import pytest
from pfs.cite import (
KINDS,
Cite,
book_cite,
comment_cite,
dataset_cite,
fr_page_cite,
fr_para_cite,
guidance_cite,
reference_cite,
rule_label,
rvu_cite,
ssa_section_url,
)
from pfs.codetables import GuidanceRow
PETM = "https://www.federalregister.gov/documents/2022/11/18/2022-23873/medicare-and-medicaid-programs-cy-2023-payment-policies-under-the-physician-fee-schedule-and-other"
def test_kinds():
assert KINDS == (
"fr_para",
"fr_page",
"comment",
"cms_file",
"cpt_book",
"iom",
"cfr",
"mln",
"statute",
"study",
"rvu_file",
"dataset",
)
def test_rule_label_moved_verbatim():
assert (
rule_label("Medicare Program; CY 2015 PFS Final Rule", "2014-11-13", 1251)
== "CY2015 PFS final ¶1251"
)
assert (
rule_label(
"CY 2021 PFS", "2020-12-28", 1578, vol="85", page=84639, kind="final"
)
== "CY2021 PFS final 85 FR 84639 ¶1578"
)
def test_fr_para_cite(home_fixture):
_con, store, _fam, _ask = home_fixture
c = fr_para_cite(store, "PETM225D", 1672)
assert c == Cite(
kind="fr_para",
label="CY2023 PFS final 87 FR 69608 ¶1672",
url=f"{PETM}#p-1672",
item_key="PETM225D",
p_id=1672,
page=69608,
locator="87 FR 69608",
)
def test_fr_para_cite_unresolved_keeps_a_locator(home_fixture):
_con, store, _fam, _ask = home_fixture
c = fr_para_cite(store, "PETM225D", 99999) # no such paragraph
assert c.url == ""
assert c.label == "CY2023 PFS final ¶99999"
assert c.locator == "PETM225D ¶99999"
c = fr_para_cite(store, "NOSUCH", 3) # no such item
assert (c.url, c.label, c.locator) == ("", "NOSUCH ¶3", "NOSUCH ¶3")
def test_fr_page_cite(home_fixture):
_con, store, _fam, _ask = home_fixture
c = fr_page_cite(store, "54GTKR5G", 66361, table="Table 14")
assert c.label == "CY2008 PFS final 72 FR 66361 Table 14"
assert c.url.endswith("#page-66361")
assert (c.kind, c.item_key, c.page, c.locator) == (
"fr_page",
"54GTKR5G",
66361,
"72 FR 66361",
)
assert (
fr_page_cite(store, "54GTKR5G", 66361).label == "CY2008 PFS final 72 FR 66361"
)
bad = fr_page_cite(store, "54GTKR5G", 1) # outside the rule's pages
assert bad.url == "" and bad.locator == "72 FR 1"
none = fr_page_cite(store, "NOSUCH", 5)
assert (none.url, none.label) == ("", "NOSUCH p. 5")
def test_comment_cite():
c = comment_cite("CMS-2022-0113-0001")
assert c.label == "Comment CMS-2022-0113-0001"
assert c.url == "https://www.regulations.gov/comment/CMS-2022-0113-0001"
assert c.kind == "comment"
def test_rvu_cite():
assert rvu_cite(2023).label == "PFS CY2023 RVU file"
assert rvu_cite(2023).url.startswith("https://www.cms.gov/")
assert rvu_cite(2023).kind == "rvu_file"
def test_rvu_cite_names_the_years_own_file():
"""M4: each year's own release page (CMS's links, read 2026-11-13), not
one landing page for every year; CY2027's final values on file come from
the final rule's Addendum B, and a proposed value from the NPRM's."""
from pfs.cite import RVU_FILES_URL
assert rvu_cite(2023).url.endswith("/pfs-relative-value-files/rvu23a")
assert rvu_cite(2015).url.endswith("/pfs-relative-value-files-items/rvu15a")
assert rvu_cite(2026).url == (
"https://www.cms.gov/medicare/payment/fee-schedules/physician/"
"pfs-relative-value-files/rvu26a"
)
final27 = rvu_cite(2027)
assert final27.label == "CY2027 final rule Addendum B"
assert final27.url == (
"https://www.cms.gov/files/zip/"
"cy-2027-pfs-final-rule-addenda-updated-11-05-2026.zip"
)
prop27 = rvu_cite(2027, proposed=True)
assert prop27.label == "CY2027 proposed rule Addendum B"
assert prop27.url.endswith("cy-2027-pfs-proposed-rule-addenda.zip")
assert rvu_cite(2026, proposed=True).url.endswith(
"cy-2026-pfs-proposed-rule-addenda.zip"
)
# a year with no known page keeps the landing page
assert rvu_cite(2009).url == RVU_FILES_URL
assert rvu_cite(2030, proposed=True).label == "CY2030 proposed rule Addendum B"
def test_book_cite():
c = book_cite("3ANRT854", "CPT Changes 2023", "49")
assert (c.kind, c.label, c.item_key, c.url) == (
"cpt_book",
"CPT Changes 2023 p. 49",
"3ANRT854",
"",
)
assert c.locator == "CPT Changes 2023 p. 49"
assert book_cite("K", "CPT 2024", "p. 29").label == "CPT 2024 p. 29"
assert (
book_cite("F7", "Panel summary", "tab 10, PDF p. 4").label
== "Panel summary, tab 10, PDF p. 4"
)
def test_dataset_cite():
c = dataset_cite("K1", "PSPS CY2022", "https://data.cms.gov/x")
assert c == Cite(
"dataset", "PSPS CY2022", "https://data.cms.gov/x", "K1", 0, 0, "PSPS CY2022"
)
def test_guidance_cite():
cfr = guidance_cite(
GuidanceRow(
"F", "99341", "cfr", "42 CFR 425.400(c)", "", "PETM225D", 3607, 69823
)
)
assert cfr.kind == "cfr"
assert cfr.label == "42 CFR 425.400(c)"
assert (
cfr.url == "https://www.ecfr.gov/current/title-42/section-425.400#p-425.400(c)"
)
assert (cfr.item_key, cfr.p_id, cfr.locator) == (
"PETM225D",
3607,
"42 CFR 425.400(c)",
)
iom = guidance_cite(
GuidanceRow(
"F", "99341", "iom", "100-04 ch.26", "IOMKEY", "PETM225D", 3607, 0, 4
)
)
assert (iom.kind, iom.url, iom.item_key, iom.page) == ("iom", "", "IOMKEY", 4)
junk = guidance_cite(GuidanceRow("F", "x", "cfr", "not a cite", "", "", 0, 0))
assert junk.url == "" and junk.locator == "not a cite"
@pytest.mark.parametrize(
"ref,url",
[
(
"section 1834(m) of the Act",
"https://www.ssa.gov/OP_Home/ssact/title18/1834.htm",
),
(
"section 1899(c) of the Act",
"https://www.ssa.gov/OP_Home/ssact/title18/1899.htm",
),
(
"section 1866E of the Social Security Act",
"https://www.ssa.gov/OP_Home/ssact/title18/1866E.htm",
),
("section 5501(a) of the Affordable Care Act", ""),
("42 CFR 410.78", ""),
("section 1902 of the Act", ""),
],
)
def test_ssa_section_url(ref, url):
assert ssa_section_url(ref) == url
def test_cite_round_trips_through_a_dict():
c = comment_cite("X-1")
assert Cite(**c.__dict__) == c
def test_reference_cite_keeps_given_url():
assert reference_cite("iom", "100-04 ch.26", url="u").url == "u"
assert reference_cite("iom", "100-04 ch.26").url == ""
assert reference_cite("cfr", "42 CFR 410.78", url="u").url.startswith(
"https://www.ecfr.gov/"
)