fix(pfs): stance R67a — valuation accepts any family mention, coding accepts a family code and coding|revised|descriptor
Some checks failed
CI / lint (push) Successful in 45s
CI / notebooks-smoke (push) Successful in 1m59s
Deploy / changes (push) Successful in 22s
CI / test (push) Failing after 3m58s
Infra CI / zotero (push) Successful in 27s
Infra CI / notebooks (push) Successful in 1m44s
Infra CI / docs (push) Successful in 1m30s
Deploy / notebooks (push) Has been cancelled
Deploy / report (push) Has been cancelled
Deploy / zotero (push) Has been cancelled
Deploy / docs (push) Has been cancelled
Deploy / api (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Infra CI / api (push) Has been cancelled
Infra CI / llm (push) Has been cancelled
Infra CI / mc (push) Has been cancelled
Infra CI / bcda (push) Has started running

Golden (in-sample, multi 32b): cell 0.83, recall 13/27, direction 10/13.
This commit is contained in:
kert
2026-11-12 16:09:00 -05:00
parent dfaaf43890
commit e1913ac89b
2 changed files with 83 additions and 13 deletions

View File

@@ -506,9 +506,9 @@ def _any(words: Sequence[str]) -> re.Pattern[str]:
def event_subjects(family: Any, events: Sequence[EventChoice]) -> dict[str, Subject]:
"""The relevance ``Subject`` of each event of *family*, by its slug (R65).
R67: the window must name the event's subject keyword AND this family --
one of its codes (ranges expanded), the code or alias of a link offered
among *events*, or a pair phrase; for valuation, one of its codes."""
R67/R67a: the window must name the event's subject AND this family -- one
of its codes (ranges expanded), the code or alias of a link offered among
*events*, or a pair phrase. A family code is also a coding subject."""
codes = code_pattern(family.codes)
phrases = (
_any([re.escape(x) for x in family.pair_phrases])
@@ -527,7 +527,6 @@ def event_subjects(family: Any, events: Sequence[EventChoice]) -> dict[str, Subj
codes,
phrases,
)
by_code = Subject(_NEVER, codes)
out: dict[str, Subject] = {}
for e in events:
slug = e.event_key.rsplit(":", 1)[-1]
@@ -536,7 +535,7 @@ def event_subjects(family: Any, events: Sequence[EventChoice]) -> dict[str, Subj
_any(
["RVU", "valuation", "value", "percentile", r"\btime\b", "payment"]
),
family=by_code,
family=named,
)
elif slug == "coding":
sub = Subject(
@@ -548,8 +547,12 @@ def event_subjects(family: Any, events: Sequence[EventChoice]) -> dict[str, Subj
r"\bMDM\b",
"medical decision",
r"\btime\b",
"coding",
"revised",
"descriptor",
]
),
codes,
family=named,
)
elif slug == "telehealth":

View File

@@ -1024,18 +1024,28 @@ def test_event_subjects_by_slug():
sub = event_subjects(FAM, SUBJ_EVENTS)
v, c, t, g, o = (sub[e.event_key] for e in SUBJ_EVENTS)
# R67: the event's subject keyword AND this family; valuation needs a code
# R67: the event's subject keyword AND this family
assert v.named_in("the work RVU of 99342 is low")
assert v.named_in("payment for 99341-99343 falls") # a range names 99342
assert not v.named_in("the work RVU is low") # no family code
assert not v.named_in("the work RVU is low") # no family mention
assert not v.named_in("see 99341-99343") # no subject keyword
assert not v.named_in("home visit codes are undervalued") # a phrase, no code
# R67a: valuation's family mention may be a pair phrase
assert v.named_in("home visit codes are undervalued")
assert v.named_in("the RVU of GXXX3") # or an offered link's alias
assert not v.named_in("nothing relevant at all")
assert c.named_in("codes 99339-99341 were deleted")
assert c.named_in("domiciliary care visit codes merge") # keyword and phrase
assert c.named_in("MDM for home or residence visits") and not c.named_in("MDM")
assert not c.named_in("codes were deleted") and not c.named_in("see 99342")
assert not c.named_in("codes were deleted") # no family mention
assert c.named_in("GXXX3 time counts") # the link alias names the family
# R67a: a family code is a coding subject too; coding|revised|descriptor are
# coding keywords
assert c.named_in("see 99342") and c.named_in("see 99341-99343")
assert not c.named_in("see GXXX3") # a link code is not a coding subject
assert c.named_in("these coding changes for home visit codes")
assert c.named_in("the revised home or residence visit descriptors")
assert c.named_in("descriptor of the home visit codes")
assert not c.named_in("these coding changes help")
assert t.named_in("audio-only home visit codes") and t.named_in("telehealth 99341")
assert t.named_in("telehealth for GXXX3")
assert not t.named_in("we support telehealth after the PHE")
@@ -1061,9 +1071,10 @@ def test_event_subjects_by_slug():
def test_window_must_name_this_family_and_the_subject():
"""R67, from the CY2023 live rows: a general telehealth endorsement and a
valuation complaint that names only "home visit codes" are dropped; a
telehealth ask about the family's codes one sentence away is kept."""
"""R67, from the CY2023 live rows: a general telehealth endorsement is
dropped; a valuation complaint that names only "home visit codes" is kept
(R67a); a telehealth ask about the family's codes one sentence away is
kept."""
from pfs.stance import event_subjects
sub = event_subjects(FAM, SUBJ_EVENTS)
@@ -1081,7 +1092,8 @@ def test_window_must_name_this_family_and_the_subject():
"practices would incur a seven percent decrease in revenue next year."
)
q2 = "By combining these two code sets and not increasing the value"
assert _rows([pos(val, "oppose", "r", q2)], phrase_only, sub) == []
kept2 = _rows([pos(val, "oppose", "r", q2)], phrase_only, sub)
assert [(r.event_key, r.stance) for r in kept2] == [(val, "oppose")]
ask = (
"Telehealth flexibilities matter to our patients. We recommend that all "
"codes listed above be retained through the end of the year. This includes "
@@ -1092,6 +1104,61 @@ def test_window_must_name_this_family_and_the_subject():
assert [(r.event_key, r.stance) for r in kept] == [(tele, "modify")]
#: CY2023 comment KUAPZ8ER (BJC HealthCare), as posted on CMS-2022-0113
KUAPZ8ER_CODING = (
"Changes to beneficiary attribution protocols due to revised coding policies "
"CMS proposes updates to beneficiary attribution criteria, including updating "
"the roster of primary care service CPTs to include new prolonged services codes "
"for SNF and \u201chome\u201d settings (Gxxx2 and Gxxx3), chronic pain management "
"(Gyyy1 and Gyyy2) and revising billing protocols for those \u201chome\u201d services "
"(99341\u201499350) to identify and include primary care services provided in "
"assisted living facilities, group homes, custodial care facilities, and "
"residential substance use treatment facilities. BJC strongly supports this "
"proposal both because it will likely increase our assigned beneficiary "
"population, but also because these coding changes will help bring transparency "
"to the services provided in those settings. Under current coding and billing "
"conventions, \u201chome\u201d services are all lumped together and thus difficult to"
)
#: CY2023 comment 8U6AFHTJ (AMA RUC), as posted on CMS-2022-0113
RUC_TEMPLATE = (
"VI. Evaluation and Management (E/M) Visits [FR section II.F.] The RUC commends "
"the Agency for accepting the work RVU recommendations for the hospital inpatient "
"or observation codes, nursing facility codes, home or residence visit codes, "
"emergency department visits and prolonged services codes. This was the result "
"of significant collaboration by an AMA-convened workgroup that brought together "
"more than 30 specialty societies involved in surveying these services."
)
def test_r67a_coding_by_family_code_and_valuation_by_phrase():
"""R67a, real CY2023 text: KUAPZ8ER's coding support names 99341\u201499350
and "coding changes" (no R65 coding keyword); the RUC's valuation support
names the family only as "home or residence visit codes". Both are kept."""
from pfs.stance import event_subjects
sub = event_subjects(FAM, SUBJ_EVENTS)
val, coding = SUBJ_EVENTS[0].event_key, SUBJ_EVENTS[1].event_key
q = (
"BJC strongly supports this proposal both because it will likely increase "
"our assigned beneficiary population"
)
kept = _rows([pos(coding, "support", "r", q)], KUAPZ8ER_CODING, sub)
assert [(r.event_key, r.stance) for r in kept] == [(coding, "support")]
# the window, not only the quote, carries the family code and the keyword
assert not sub[coding].named_in(q)
q2 = (
"The RUC commends the Agency for accepting the work RVU recommendations for "
"the hospital inpatient or observation codes, nursing facility codes, home or "
"residence visit codes"
)
kept2 = _rows([pos(val, "support", "r", q2)], RUC_TEMPLATE, sub)
assert [(r.event_key, r.stance) for r in kept2] == [(val, "support")]
# the same sentence without the family names no family
other_fam = RUC_TEMPLATE.replace("home or residence visit codes, ", "")
q3 = q2.replace(", home or residence visit codes", "")
assert _rows([pos(val, "support", "r", q3)], other_fam, sub) == []
def test_holding_sentence():
from pfs.stance import _holding_sentence