docs(spec): CMS legal epidemiology platform — the code-family book and its one-page analysis app

This commit is contained in:
kert
2026-11-12 11:08:02 -05:00
parent 85663894f3
commit a364fbc943

View File

@@ -0,0 +1,339 @@
# CMS legal epidemiology platform: the code-family book and its analysis app
Date: 2026-11-12. Status: draft for review. The user handed the design
to me ("you should draft the design"), so the choices not stated by the
user are marked **my call**. Builds on
`2026-11-11-code-family-dossier-design.md` (the dossier) and
`2026-09-09-code-family-longitudinal-design.md` §P50 (the exposure
calendar, outcome series and event study).
## Intent
**The driver (user):** a legal epidemiology platform focused on CMS
regulation, aimed at quality and payment for health care value.
The user's two deliverables:
1. **The book.** One dossier for *every* code family, not only primary
care. The 2026-11-11 spec defines what a dossier holds and the order
families are covered. Scope is under "The book's scope" below.
2. **The app.** A one-page web app to inspect and manage everything known
about a code or family. It abstracts away the Zotero plumbing and keeps
the functions the work needs. It exposes no more and no less than
necessary.
**The point (user):** an analytical tool that uses mixed quantitative and
qualitative methods to synthesize evidence for three things:
- predictions;
- crafting new strategy and policy;
- informing future submissions to public comment periods.
### Who uses it, and when (my call)
One analyst, the user, behind SSO. Three recurring moments:
- **A rule drops** (proposed or final). Which families and measures did it
touch? What changed? What will CMS likely finalize, and who will say what?
- **A comment period is open.** Build a submission from cited evidence and
the record of past fights.
- **A strategy or policy question.** What has CMS law done to primary care,
care management or home-based care, and what happened after? This goes
across families.
## The legal-epidemiology frame, made concrete
Legal epidemiology studies law as a cause of health and health care
outcomes. Its working methods map directly onto this stack:
| Legal-epi method | What it is here |
|---|---|
| **The law** | Cited text: FR paragraph, CFR section, statute section, CMS manual section, CPT descriptor (paraphrased, licensed). |
| **Jurisdiction** | A CMS payment system or program. The PFS comes first; QPP/MIPS and MSSP follow; OPPS, home health, hospice and ESRD come later. |
| **Unit of observation** | A *policy object*: a code family (now), a quality measure, or a program provision (phase 2). Every object gets a dossier with the same anatomy. |
| **Policy surveillance** | A *codebook* of legal variables, coded per object per year. Each value is cited, with extractor and review status. |
| **Exposure** | A dated change in a coded variable. This generalizes `pfs.code_exposure`. |
| **Outcomes** | Utilization (`pfs.utilization`), payment and spending, workforce (`bls.*`), billing share by specialty, the primary-care share of spending; quality performance in phase 2. |
| **Evaluation** | Event study and difference-in-differences around exposures (`pfs.event_study`, with controls from `control_codes`). |
| **Mechanism and politics** | Comments, stances, commenter identities, money and power stakes, CMS rationale (the dossier spec). |
| **Quality control** | Codebook versions; double coding (model vs analyst) with the agreement rate reported; a review queue. |
### Starter codebook (my call; the builder finalizes the definitions)
These variables are coded per object per year:
- payable status;
- work, PE and MP RVUs, and the national payment, proposed vs final;
- conversion factor;
- descriptor time and its typical-time basis;
- who may bill (practitioner types);
- supervision level;
- place of service;
- telehealth eligibility (permanent, provisional, or temporary/PHE);
- frequency or time limits;
- documentation requirements;
- beneficiary cost sharing and consent;
- add-on and modifier linkage (e.g. G2211, B1/B2);
- APM/MSSP linkage (in the primary-care service definition used for assignment);
- quality-measure linkage.
Each variable has four parts:
- a definition;
- its allowed values;
- a coding rule;
- a source precedence: final rule, then CFR, then manual, then proposed rule.
### Value lens
Every object carries one or more *value domains*:
- primary care;
- care management and coordination;
- behavioral health integration;
- home-based care;
- telehealth and virtual care;
- APM linkage;
- quality reporting;
- bundling and global packages;
- prevention.
Domains order the book's contents and drive the cross-object analyses.
Value-oriented outcome series start with:
- the primary-care share of PFS allowed charges, using the MSSP primary-care code set already in `cms_provider_attribution._primary_care_hcpcs_codes`;
- care-management uptake;
- home-visit volume.
Rates per 1,000 beneficiaries need an enrollment denominator, which is a source to add.
## The book's scope (my call)
`pfs.code_family` holds 8,662 derived families, and 7,858 of them are
single codes. One analyst cannot hand-curate and review all of them, so
the book has two tiers.
**Reviewed dossiers**
- Covers phases 1–2: primary care and home-based care, then bundling and value-based care.
- Membership is hand-curated.
- Every row passes the review queue.
**Machine-built dossiers**
- Covers everything else.
- Built from derived families. Single-code families fold into their CPT heading or subsection family, so the unit is a meaningful group, not one code.
- Built unattended in nightly batches at the lowest GPU priority.
- Clearly labeled "machine-built, not reviewed", with gaps stated.
- Promoted to Reviewed when a family is curated.
**Code scope**
- Codes the PFS has ever paid (status A/R/T in any year) come first.
- Non-PFS HCPCS (drugs, DMEPOS, ambulance, lab) join when their payment systems join as jurisdictions.
The book is read on screen: the Contents view plus the dossiers. A
compiled PDF/EPUB/DOCX is not built (2026-11-11 non-goal). An export can
come later; it would need a leak check for licensed AMA text.
## The app: one page
### Shape (my call)
- **Left rail:** a search box plus the book's table of contents.
- **Main pane:** the selected object, one tab per view.
- **Right drawer:** the evidence and sources behind whatever is selected.
The whole state lives in the URL (`#/family/HOME-VISITS/timeline?code=99343`). Every view can therefore be linked, chat answers link straight into it, and the back button works.
### Views: exactly these nine
1. **Contents (the book).**
- Shows every object with its phase, value domains, coverage (which dossier sections are filled, and the stated gaps), last rule activity, and an "open comment period" flag. Filter and sort.
- Actions: open an object; propose a new family, which goes to curation.
2. **Dossier.**
- The 2026-11-11 page: header, summary, timeline, valuation rounds, payment table, stakeholders, governance context, sources, gaps.
- Read-only, apart from *flag this*, which sends the row to the review queue.
3. **Surveillance grid.**
- Legal variables down, years across. Each cell holds the coded value and its citation; cells that changed are marked; clicking a cell opens the cited paragraph.
- Actions: code or correct a cell (an analyst coding); export CSV plus the codebook.
4. **Evaluate.**
- Pick an exposure from the calendar and an outcome series. The event study runs with controls and shows a chart, the effect with its interval, and the caveats (censoring, missing post-period years).
- Actions: save the result as a finding.
5. **Politics.**
- Events across, stakeholders (organization type × specialty) down.
- Each cell shows our counted stance, CMS's own summary beside it (never merged), the expected stance from stakes, and a mark where actual and expected disagree. A money and power stakes panel sits alongside.
- Actions: correct an identity or a stance.
6. **Predict.**
- For each pending proposal that touches the object, the view shows:
- base rates (how often CMS finalizes as proposed for comparable items, and how often it accepts the RUC recommendation);
- expected stances;
- this object's record of past predictions, scored.
- Actions: record a prediction. It is timestamped before the final rule and scored automatically when the final rule lands.
7. **Synthesize and draft.**
- *Findings*: claims, each linked to quantitative and qualitative evidence rows and shown as a mixed-methods *joint display* (numbers beside the coded text that explains them).
- *Positions*: what we would argue, built from findings.
- *Drafts*: a comment workspace for an open docket. It starts from an outline built from positions; the local model drafts only from cited rows; the draft must pass the citation check, an American-English check and a full-text-on-file check; export to Markdown or DOCX.
- The app never submits a comment.
8. **Sources (the library, without Zotero).**
- Every source the object cites or could cite, with its status: full text on file, wanted, paywalled, or citation only.
- Open a source in the existing viewer (`/ui/pdf`) at the cited page or paragraph.
- Add a source by pasting a URL, DOI, FR citation, docket id or comment id. The app fetches it, files it and links it to the object.
- Add notes and qualitative codes (the theme vocabulary plus the analyst's own) to a source or a passage.
9. **Review queue.**
- Holds model-extracted rows that are low-confidence or not yet reviewed: stances, identities, origin rows, valuation rounds, coded cells.
- Actions: accept, correct or reject.
- It shows the agreement rate per extractor (model vs analyst); this is the double-coding QC.
### No more, no less: what the app hides and what it shows
**Hidden:** Zotero item keys, collections, tag namespaces (`sup:`, `code:`, `family:`, `reg-docket:` …), sync jobs, storage paths, bib/DuckDB table names, run ledgers, model hosts and chunk indexes.
**Shown:** objects, sources (as citations with a status), notes, qualitative codes, corrections, membership curation, predictions, findings, positions, drafts and exports.
**How the Zotero functions we use map to app actions:**
| Zotero function | App action |
|---|---|
| add item | **Add source** |
| attach a PDF | automatic on fetch; upload a file |
| tag | link a source to an object, or add a qualitative code |
| note | **Note** |
| collection | an object's source list (derived, never managed by hand) |
| wanted / unavailable lists | the source's status |
| search | the left-rail search |
**Not exposed:** citation styles, groups, manual collections, item-type editing, merge and dedupe (these stay pipeline jobs), and sync scheduling.
### Writes (my call)
- **App writes go to a separate analyst store**, `data/analyst/analyst.sqlite` (WAL mode). They never go to `aco.duckdb` (single-writer lock, nightly pipelines) and never to Zotero's SQLite (container lock).
- **Pipelines read the analyst store.** The nightly zotero-sync carries new sources, notes and links into Zotero through the existing path, scoped by tag.
- **Corrections never overwrite extracted rows.** A correction is a row of its own: target row, field, value, reason, timestamp. The app displays the analyst value when one exists and shows the extracted value beside it.
- **Family membership stays reviewed code.** `src/pfs/curated.yaml` is the baseline; app edits are overrides in the analyst store, applied after the YAML; `stack pfs families --export-curated` writes them back to YAML for a commit.
### Actions that need host work (my call)
Some actions cannot run inside the web service:
- adding a source (fetch tools and API keys live on the host);
- proposing a family or changing membership (GPU extraction, DuckDB writes, replica publish);
- re-running a dossier after a correction.
These become **jobs**. The app writes a job row to the analyst store. A
host-side worker, run as a systemd user service, claims and runs it: on
the host, with the host's keys, on the shared GPU lanes at the lowest
priority, publishing the replica when it finishes. The app shows each
job's state: queued, running, done, or failed with its log line. No
action needs a shell.
## Prediction
This extends the 2026-11-11 design.
**Targets:**
1. CMS's action on a proposal: finalized as proposed, modified, or not finalized; and, for RUC recommendations, accepted or refined.
2. Each stakeholder's stance.
**Phase 1** shows base rates plus explicit rules (stakes → expected stance), each with its evidence.
**Every prediction is pre-registered.** It is stored, with the evidence it used, before the final rule. When the final rule's rows land it is scored (accuracy and Brier score), and the running calibration record is shown.
**Later:** a fitted, explainable model (logistic regression with named features) once the primary-care fan-out supplies enough events.
## Comment submissions
- **Open-docket tracker:** each regulations.gov docket, its close date, and the objects the proposed rule touches (from lineage on that rule's item).
- **Drafting rules** (user rules carried over from the palliative comment):
- American English;
- every source relied on has full text on file;
- every number and every factual claim carries a citation and passes the citation check (my call);
- argument and ask sentences may stand uncited, but the draft marks them as argument, so the check can tell them apart from unsupported facts;
- no individual commenter is named.
- **What a draft may cite:** dossier rows, FR paragraphs, comments, and studies in the library, including the systematic-review records (screening decisions and extraction). Those records live only in Zotero today; the builder brings them into bib so the app can cite them.
- **Whose voice (my call):** positions and drafts are the user's own analysis, built only from public data. No employer positions or material (ACO/HarmonyCares/WNOT/Wakely) is stored. "Our past submissions" are the comments the user marks as theirs in the app, by comment id; there is no lookup by name.
- **No near deadline, so drafting is not urgent:**
- The CY2027 PFS final rule (FR Doc 2026-22743, 91 FR 70992) is a plain final rule. Its DATES section gives only the January 1, 2027 effective date, so it has no comment period. The palliative draft (#650) has no venue there.
- The next PFS venue is the CY2028 proposed rule, expected around July 2027. The drafting view must be ready before it.
- The open-docket tracker surfaces any earlier CMS request for information that touches a tracked object. The #650 draft stays on file as a seed source.
## Cross-object analyses (the atlas)
These are standing, cited views across the book, each defined by a stored query:
- RUC acceptance rate by year and family;
- CMS finalize-as-proposed rate;
- stance alignment by organization type and specialty;
- payment trends of value domains against the rest;
- the primary-care share of spending;
- prediction calibration across objects.
They are the "mapping study" layer of legal epidemiology.
## Build order: slices, each with its own plan (my call)
- **S0, now.** Plan A continues: Tasks 7–13 (data, stakes, payment table, assembly and citecheck), 15 (chat) and 16 (golden test). **Task 14's standalone page is folded into S1**, so there is one page rather than two.
- **S1. App shell, Contents, Dossier and Sources (read-only).**
- Covers HOME-VISITS, with URL state, behind SSO, in the existing llm service.
- Acceptance is Plan A's golden home-visit dossier rendered in the app.
- **S2. Review queue, analyst store, job worker and corrections.** Sources management: add source, notes, qualitative codes. This is the Zotero abstraction.
- **S3. Surveillance grid and codebook.** A legal-variable extractor (rules first, local model second), `pfs.code_exposure` generalized to any coded variable, CSV and codebook export.
- **S4. Evaluate (event study in the app) plus the atlas.**
- **S5. Predict (pre-registration and scoring) plus the full Politics view.**
- **S6. Synthesize and draft (comment workspace) plus the open-docket tracker.** It must be ready before the CY2028 PFS proposed rule (around July 2027). It moves earlier if the tracker finds a nearer CMS comment window on a tracked object.
- **S7. Fan-out, the book.** It starts once S2's review queue exists and runs alongside S3–S6.
- Order: the rest of primary care and home-based care in the dossier spec's order, then bundling and value-based care, then the machine-built rest.
- Reviewed families each get curated membership, a pipeline run and a review-queue pass.
- Quality measures (the QPP/MIPS inventory by year, benchmarks, MSSP quality standard) and program provisions join as object types during the bundling/VBC phase, with public sources added then.
- **Plan B backfills keep running in parallel** (pre-CY2018 dockets, pre-CY2002 rules, pre-2015 RVU files). Gap notes shrink as they land.
## Goals
- Every code family has a dossier. Contents shows coverage and gaps honestly.
- For any object, one page answers six questions:
- what CMS law says;
- how it changed and why;
- what happened after;
- who fought over it and why;
- what is likely next;
- what we should say.
- Every statement and number is cited. Predictions carry a scored record.
- The analyst never has to open Zotero, a notebook or a shell to do the work above.
## Non-goals
- Multi-user collaboration, roles or permissions beyond SSO.
- Replacing Zotero as the library of record; it stays, behind the scenes.
- Submitting comments; the app exports, and the user submits.
- Publishing anything outside the stack.
- Real-time updates. Data refreshes with the nightly pipeline or on demand.
## Anti-goals: failure even if it works
- Plumbing in the UI: item keys, tag namespaces, table names.
- Numbers without the legal text behind them; a dashboard rather than evidence.
- Uncited or invented claims; editorial tone; profiling private individuals.
- Blurring proposed and final values, or CMS's summary with our own counts.
- Predictions with no scored record, or scored after the fact.
- Analyst edits silently replacing extracted data.
## Constraints
All existing repo rules apply:
- main only;
- local LLMs only;
- public data only (no ACO/HarmonyCares/WNOT/Wakely material);
- never spoof a browser UA for FR/eCFR;
- hoard old copies of every source;
- behind SSO;
- licensed AMA text paraphrased (≤ 240 characters, cited by edition and page);
- NLM/UMLS data never published;
- GPU budget shared with tagging and chat; extraction stays resumable.
### Tech (my call)
- **Where it is served:** the existing llm FastAPI service at `/ui/app`.
- **Front end:** one HTML file plus vanilla ES modules and vendored libraries only, with no build step, matching `/ui/search` and `/ui/pdf`.
- **API:** a JSON API under `/api/policy/…` that reads the DuckDB replica (read-only), bib and the analyst store, plus a small write API for analyst actions.
## Left to the builder
- Final codebook definitions per object type.
- Legal-variable extraction methods.
- The chart library (vendored), following the dataviz guidance.
- API shapes.
- Review-queue prioritization.
- The enrollment denominator source.
- The prediction scoring details beyond accuracy and Brier score.
- Which public QPP/MSSP sources come first when measures join.