diff --git a/src/prisma/project.py b/src/prisma/project.py index 03dcf0b..73e0983 100644 --- a/src/prisma/project.py +++ b/src/prisma/project.py @@ -369,6 +369,205 @@ Included by default; excluded only with code: """ +_LEAD_SUSPECTING = """\ +Suspecting is in scope as both a code uplift and a care change. Each is a +hypothesized status transition, such as not High Needs to High Needs, an +absent HCC becoming present, or a quality denominator without a numerator +gaining one. A code uplift makes an existing status visible to the math. +Care changes the underlying state. Record how far each can move the score, +including when demographic reweighting shrinks the coding payoff. +""" + +_LEAD_CRITERIA_HISTORY = """\ +# LEAD history — inclusion criteria + +Strand 1. For each target in the LEAD registry, find where the component +came from, what assumption it rests on, what evidence supported it when it +was adopted and what has appeared since, and how it changed through MA, +MSSP, Pioneer, NGACO, and REACH on the way to LEAD. + +Include primary CMS methodology, the papers those methods cite, and +critiques of the same component. Exclude a record that names no registry +target and no predecessor of one. +""" + +_LEAD_EXTRACTION_HISTORY = """\ +# Extraction — lead-history + +- **target_id** — registry id this row is about +- **origin** — where the component came from +- **assumptions** — the assumption it rests on +- **supporting_evidence** — evidence at adoption and since +- **critiques** — published critiques of the component +- **changes_to_lead** — how it changed on the way to LEAD +- **status_in_lead** — adopted / modified / dropped +- **page_refs** — page or section locators +""" + +_LEAD_REASONS_HISTORY = """\ +# Exclusion reasons — lead-history + +- `off-topic` — names no registry target and no predecessor of one. +- `editorial` — editorial, commentary, or letter with no historical claim. +- `not-english` — no English text. +- `unavailable-fulltext` — full text cannot be retrieved. +""" + +_LEAD_CRITERIA_LIMITS = f"""\ +# LEAD limits — inclusion criteria + +Strand 2. For each registry target, the mathematical and empirical limits +on predictive accuracy, how far an ACO's actions can move the scored +result, bias across subgroups, and incentive distortion. + +{_LEAD_SUSPECTING} +Include a limit when it states a bound, a formula, or a number that can +be checked. Exclude commentary that names no limit. +""" + +_LEAD_EXTRACTION_LIMITS = """\ +# Extraction — lead-limits + +- **target_id** — registry id the limit applies to +- **limit_type** — accuracy / movability / fairness / incentive +- **statement** — the limit in one or two sentences +- **formula** — formula or bound, when the source gives one +- **empirical_value** — number the source reports, with its unit +- **computable_expression** — expression that can run on public data +- **page_refs** — page or section locators +""" + +_LEAD_REASONS_LIMITS = """\ +# Exclusion reasons — lead-limits + +- `off-topic` — not a limit on a registry target. +- `no-limit` — on topic but states no bound, formula, or checkable number. +- `editorial` — editorial, commentary, or letter. +- `not-english` — no English text. +- `unavailable-fulltext` — full text cannot be retrieved. +""" + +_LEAD_CRITERIA_SCAN = """\ +# LEAD environment scan — inclusion criteria + +Strand 3, from 2023 onward. What surrounds LEAD: adjacent policy, how the +industry identifies High Needs patients, public data sources and their +grain, current methods for risk and prognosis, and open-model candidates +with their licenses. + +Include a dated item the chassis would have to notice. Exclude undated +background with no consequence for the model. +""" + +_LEAD_EXTRACTION_SCAN = """\ +# Extraction — lead-scan + +- **item_type** — policy / method / data / model / industry +- **item_date** — date or year of the item +- **summary** — what the item says, in a few sentences +- **target_ids** — registry ids it bears on, if any +- **aacods** — AACODS appraisal notes +- **chassis_meaning** — what the chassis should do because of this item +""" + +_LEAD_REASONS_SCAN = """\ +# Exclusion reasons — lead-scan + +- `off-topic` — not about the environment LEAD is built in. +- `undated` — no date, and no way to place it in 2023 or later. +- `editorial` — color with no fact the chassis can use. +- `not-english` — no English text. +- `unavailable-fulltext` — full text cannot be retrieved. +""" + +_LEAD_CRITERIA_PRECURSORS = f"""\ +# LEAD precursors — inclusion criteria + +Strand 4, a prognostic-factor review. The population is Medicare +beneficiaries, or comparable older, disabled, or ESRD adults, in claims +or EHR cohorts. An index factor is measured before the outcome. The +outcome is a registry target or a named proxy, and the lead time is +recorded. Eligible designs are cohort, case-control, prediction-model +development or validation, and quasi-experimental. Grain may be the +beneficiary, the provider, the ACO, or an area. + +A cross-sectional study with no temporal order is excluded. + +{_LEAD_SUSPECTING} +""" + +_LEAD_EXTRACTION_PRECURSORS = """\ +# Extraction — lead-precursors + +- **design** — study design as reported +- **data_source** — claims, EHR, registry, or survey named by the paper +- **population** — who was studied +- **n** — sample size +- **setting** — care setting +- **country** — country of the data +- **years** — years the data cover +- **factor_definition** — how the precursor was defined +- **outcome_target_id** — registry id of the outcome, or of its proxy +- **proxy_closeness** — how close a proxy is to the registry target +- **lead_time** — time from factor to outcome +- **grain** — beneficiary / provider / ACO / area +- **effect_measure** — measure the paper reports +- **effect_value** — point estimate +- **effect_ci** — confidence interval or other uncertainty +- **adjusted_for** — covariates the estimate adjusts for +- **c_statistic** — discrimination, when reported +- **calibration** — calibration, when reported +- **risk_of_bias** — bias appraisal, with the tool named +- **observable_public** — whether public data can supply the factor +- **observable_claims** — whether claims can supply the factor +""" + +_LEAD_REASONS_PRECURSORS = """\ +# Exclusion reasons — lead-precursors + +- `off-topic` — not a precursor of a registry target. +- `wrong-population` — not Medicare or a comparable older, disabled, or ESRD cohort. +- `cross-sectional-no-time-order` — cross-sectional study with no temporal order. +- `editorial` — editorial, commentary, or letter with no study result. +- `not-english` — no English text. +- `unavailable-fulltext` — full text cannot be retrieved. +- `wrong-outcome` — outcome is not a registry target and not a named proxy. +""" + +_LEAD_CRITERIA_EXTERNAL = """\ +# LEAD external forces — inclusion criteria + +Strand 5. How forces outside the ACO move LEAD's inputs and scores: labor +markets and prices, legislation and rulemaking, tax and coverage policy, +and market structure. + +Include a series or a dated event when the record states a mechanism that +reaches a registry target. Exclude a series with no stated path into the +score. +""" + +_LEAD_EXTRACTION_EXTERNAL = """\ +# Extraction — lead-external + +- **series_or_event** — name of the series or the dated event +- **dates** — period or date the record covers +- **geography** — geography the figure applies to +- **source** — agency or publication the figure comes from +- **mechanism** — how this force reaches a LEAD input or score +- **magnitude** — size of the move, with its unit +""" + +_LEAD_REASONS_EXTERNAL = """\ +# Exclusion reasons — lead-external + +- `off-topic` — no path into a LEAD input or score. +- `no-mechanism` — a series or event with no stated mechanism. +- `editorial` — commentary with no series and no dated event. +- `not-english` — no English text. +- `unavailable-fulltext` — full text cannot be retrieved. +""" + + STARTERS = { "skin-subs": ( _STARTER_CRITERIA_SKIN_SUBS, @@ -380,6 +579,31 @@ STARTERS = { _STARTER_EXTRACTION_PALLIATIVE_RFI, _STARTER_REASONS_PALLIATIVE_RFI, ), + "lead-history": ( + _LEAD_CRITERIA_HISTORY, + _LEAD_EXTRACTION_HISTORY, + _LEAD_REASONS_HISTORY, + ), + "lead-limits": ( + _LEAD_CRITERIA_LIMITS, + _LEAD_EXTRACTION_LIMITS, + _LEAD_REASONS_LIMITS, + ), + "lead-scan": ( + _LEAD_CRITERIA_SCAN, + _LEAD_EXTRACTION_SCAN, + _LEAD_REASONS_SCAN, + ), + "lead-precursors": ( + _LEAD_CRITERIA_PRECURSORS, + _LEAD_EXTRACTION_PRECURSORS, + _LEAD_REASONS_PRECURSORS, + ), + "lead-external": ( + _LEAD_CRITERIA_EXTERNAL, + _LEAD_EXTRACTION_EXTERNAL, + _LEAD_REASONS_EXTERNAL, + ), } diff --git a/tests/prisma/test_lead_starters.py b/tests/prisma/test_lead_starters.py new file mode 100644 index 0000000..7cea83c --- /dev/null +++ b/tests/prisma/test_lead_starters.py @@ -0,0 +1,111 @@ +"""The five LEAD review projects init from starter criteria.""" + +from __future__ import annotations + +import pytest + +from prisma.project import init +from prisma.tools import parse_extraction_fields +from zot.db import Db +from zot.schema import create_db + +FIELDS = { + "lead-history": ( + "target_id", + "origin", + "assumptions", + "supporting_evidence", + "critiques", + "changes_to_lead", + "status_in_lead", + "page_refs", + ), + "lead-limits": ( + "target_id", + "limit_type", + "statement", + "formula", + "empirical_value", + "computable_expression", + "page_refs", + ), + "lead-scan": ( + "item_type", + "item_date", + "summary", + "target_ids", + "aacods", + "chassis_meaning", + ), + "lead-precursors": ( + "design", + "data_source", + "population", + "n", + "setting", + "country", + "years", + "factor_definition", + "outcome_target_id", + "proxy_closeness", + "lead_time", + "grain", + "effect_measure", + "effect_value", + "effect_ci", + "adjusted_for", + "c_statistic", + "calibration", + "risk_of_bias", + "observable_public", + "observable_claims", + ), + "lead-external": ( + "series_or_event", + "dates", + "geography", + "source", + "mechanism", + "magnitude", + ), +} + +ENUMS = { + "lead-history": {"status_in_lead": ["adopted", "modified", "dropped"]}, + "lead-limits": {"limit_type": ["accuracy", "movability", "fairness", "incentive"]}, + "lead-scan": {"item_type": ["policy", "method", "data", "model", "industry"]}, + "lead-precursors": {"grain": ["beneficiary", "provider", "ACO", "area"]}, +} + + +def _db(tmp_path) -> str: + path = str(tmp_path / "z.sqlite") + con = create_db(path) + con.close() + return path + + +def test_each_lead_starter_inits(tmp_path): + with Db(_db(tmp_path)) as db: + for name, fields in FIELDS.items(): + project = init(db, name) + assert project.name == name + props = parse_extraction_fields(project.extraction_template) + assert set(props) == set(fields) + for field, members in ENUMS.get(name, {}).items(): + assert props[field]["enum"] == [*members, ""] + with pytest.raises(ValueError): + init(db, "nope") + + +def test_criteria_pin_suspecting_and_temporal_order(tmp_path): + with Db(_db(tmp_path)) as db: + limits = init(db, "lead-limits") + precursors = init(db, "lead-precursors") + for project in (limits, precursors): + assert "code uplift" in project.criteria + assert "care" in project.criteria + assert "status" in project.criteria + assert "cross-sectional" in precursors.criteria + assert "temporal order" in precursors.criteria + assert "cross-sectional-no-time-order" in precursors.reasons