CODEX TASK 12
You are Cedric on gpt-6-astra (high reasoning), worker #1, pass 12: "6 pages to a 5-minute read" doctor summary. Run AFTER pass 9 in branch wt/WT-dc65/fhir-demo. It is held to the same pass-11 quality bar: NUnit + Moq, Stryker on the summary builder, contract tests, and a new column E in QUALITY-MATRIX.md. Follow docs/ANDREW-STYLE-GUIDE.md. Synthetic data only. Commit and push each item yourself as its check passes; never stop to ask for a review chair.
Why: Innovare's clinicians get about 6 pages of data per patient and need a summary a doctor can read in 5 minutes. Andrew: "Either we need a programmatic in-house solution or a model that can be used for medical data." Research brief: fhir-pipeline-demo-docs/HIPAA-AI-SUMMARIZATION.md (the orchestrator will paste the relevant parts into docs/AI-SUMMARY.md).
1. Deterministic executive summary (the default, no LLM)¶
IExecutiveSummaryBuilder builds the summary from the operational store / FHIR. It extends the existing pre-visit summary; do not duplicate it (one implementation per behavior).
Sections, in this order: 1. Active problems 2. Current meds, plus changes in the last 90 days 3. Allergies 4. Abnormal and trending labs (A1c trend, repeated BP), with dates and units 5. Immunization gaps 6. Last 3 encounters 7. Risk flags (same RiskEngine)
Rules:
- Citations: every line carries ResourceType/id/_history/version citations.
- Length: hard budget of at most 250 words, and at most 7 bullets per section.
- Overflow: anything cut is counted, e.g. "+4 older labs, see chart".
- Never impute. Missing data is shown as missing.
- entered-in-error is excluded.
Endpoint: GET /api/patients/{id}/executive-summary (read-only), plus snapshot JSON.
UI: Vue card "Executive summary (5-minute read)" on the patient page: - Every line links to its source resource view. - The card shows the source-document page count vs the summary word count (e.g. "6 pages to 212 words").
1b. CONSOLIDATE THE NOTES TOO (Andrew, 2026-11-13: "the executive summary is for consolidating the information and notes for the doctors")¶
The summary must cover the free-text notes (DocumentReference text, encounter notes, Questionnaire free text) as well as the structured data. Release 1 is QUOTE-ONLY (plan v2, step 16).
INoteExcerptSelector, default implementationDeterministicNoteExcerptSelector(no model):- Pick verbatim sentences from each note using section headers (Assessment/Plan/HPI/Impression), clinical keywords tied to the patient's active problems, meds and abnormal labs, and the negation/temporality cues ("ruled out", "denies", "stopped", "mother/father").
- Each excerpt is an EXACT substring with a pinned citation (
DocumentReference/id/_history/version+ offsets + SHA-256). - Notes block placement: a "From the notes" block sits under the structured sections. It holds at most 6 excerpts per patient, ordered most recent first and grouped by note, each with a link to its source.
- Ledger: "N notes reviewed, M excerpts shown, K passages not shown".
- Sensitive classes (confidentiality PSY/SUD/R/V or unknown) are never excerpted; they're shown only as "restricted note, open with authorization".
- The MedGemma selector plugs in behind the same interface: pass 13 spike, flag
Ai:NoteSelector=MedGemma, default off. Tests run with the deterministic selector. - Fixtures:
- Add synthetic clinical notes to at least 6 of the 12 synthetic patients (data/fixtures, clearly marked SYNTHETIC). Include negation traps, family history, stopped meds and a prompt-injection line, so the demo shows the excerpts staying correct.
- Tests: every excerpt is verbatim, the injection line is never excerpted as an instruction, and restricted notes are never shown.
- Demo story: "6 pages → 1 screen" shows the structured facts plus the consolidated note excerpts, each a tap away from its source.
1c. EXAMPLES THEY CAN SEE (Andrew: "i want it to be able to have examples they can see")¶
Add a public "Examples" page to the Vue app. It must work in static snapshot mode on a phone, because it is the page Andrew shows at the table.
- For each of the 6 note-bearing synthetic patients, a BEFORE / AFTER view:
- BEFORE: the full raw record as a clinician would get it (every note in full + every resource, rendered as readable "pages", with a page count, e.g. "6 pages").
- AFTER: the one-screen executive summary (structured facts + consolidated note excerpts).
- Every summary line links to the exact spot in the BEFORE view, highlighted.
- Show reading time: the estimated time for BEFORE vs AFTER.
- "How it handles the hard cases" gallery (one card each, showing the source sentence and what the summary did):
- a negation trap ("CT ruled out pulmonary embolism"): never shown as PE
- family history ("mother had breast cancer"): attributed to family
- a stopped medication ("metformin stopped in March"): not listed as current
- a prompt-injection line in a note: shown inert, never followed
- a restricted psychotherapy/substance-use note: withheld with "restricted"
- missing data: "not in structured data", never guessed
- All examples are SYNTHETIC and labeled so.
- Add the page to the snapshot export, the nav, the e2e tests (390px + 1280px) and screenshots docs/screenshots/examples-*.png.
1d. MOCK REPORTS, ONE SCENARIO PER USE CASE (Andrew: "of mock reports consolidating, showcasing each usecase")¶
Build a synthetic "packet" of mock clinical REPORTS for each use case. They are realistic in format, clearly SYNTHETIC, and stored as FHIR DocumentReference + DiagnosticReport/Observation with the report text attached. The Examples page shows each packet (BEFORE) consolidated into the one-screen summary (AFTER).
| Use case | Mock reports in the packet (about 6 pages total) |
|---|---|
| Pre-visit, chronic care (diabetes + BP) | PCP progress note, lab panel report (A1c trend, BMP, lipids), home-BP log, pharmacy fill history |
| Post-discharge follow-up | hospital discharge summary, ED triage note, imaging report (CT angiogram ruling out PE), new-med list |
| Specialist referral consolidation | cardiology consult letter, echo report, stress-test report, referral question from the PCP |
| Medication reconciliation | outside med list, pharmacy history, PCP med list with conflicts (stopped metformin, duplicate statin) |
| Preventive care gaps | immunization record, screening history (colonoscopy, mammogram due), an annual wellness questionnaire (Ottehr intake) |
| Multi-source new patient (Allscripts → Ottehr) | a C-CDA-style transfer summary + an HL7 v2 ORU lab result + an Ottehr intake QuestionnaireResponse, consolidated into one view. This shows the migration story clinically. |
For each scenario: - the summary card shows which reports fed which line (citation chips) - the reading time BEFORE vs AFTER - the hard-case handling that applies (negation, family history, stopped meds, injection, restricted notes)
Every packet goes through the SAME pipeline (Tier 1 facts + quote-only note excerpts). Nothing is special-cased for the demo; add a test proving it. Add golden-file tests per scenario and screenshots docs/screenshots/usecase-*.png at 390px and 1280px.
1e. EACH USE CASE SHOWN THREE WAYS (Andrew: "programatic medgemma and baa")¶
On the Examples page, each use-case packet has three tabs side by side:
1. Programmatic: Tier 1 facts + deterministic quote-only note excerpts. This is the release-1 default.
2. MedGemma (in-tenant): MedGemma 4B's output on the same packet, both quote-mode excerpts AND a paraphrase, after FactGuard. Every rejected line is visibly marked "rejected by fact check" with the reason.
3. BAA tier (simulated): OpenAI gpt-oss:20b running locally, labeled "SIMULATED BAA ENDPOINT, local, synthetic data only". The scrubbed payload it received is shown, the gateway checks that passed are listed, and the output after FactGuard is shown. If the model refuses (e.g. because of the injection line), show the refusal honestly as the result.
Rules for the tabs: - The model outputs are PRE-COMPUTED by pass 13 on the 4090, stored as committed snapshot JSON with model id, revision/digest, prompt hash, timestamp and FactGuard verdicts. The static phone demo makes NO live model calls. - Every tab carries a footer: "Release 1 ships Programmatic + quote-only. Model tiers shown for comparison on synthetic data." - Diff highlight: show what each tier added, dropped or got wrong compared with the programmatic baseline. - If pass 13's outputs aren't available yet, show "model comparison pending". The UI must not break, and fake text must never stand in for real model output.
2. Optional LLM narrative layer (OFF by default; interface + guard only)¶
INarrativeRewriterwith two implementations:NoOpRewriteris the default and returns the deterministic text.BaaGatedRewriteris a stub. It refuses unless configAi:Provideris set ANDAi:BaaConfirmed=true. Docs name Azure OpenAI / Foundry under BAA.- Never call a real model. Tests use a fake.
FactGuard: after any rewrite, every number, date, code and drug name in the output must appear in the deterministic facts. Otherwise reject the rewrite and fall back to the deterministic text. Tests:- a fake rewriter that invents a lab value is rejected
- one that drops a flag is rejected
- one that only rephrases is accepted
- Prompt-injection test: free-text note content ("ignore previous instructions...") never reaches the output as an instruction. Notes are treated as data and quoted.
3. Docs: docs/AI-SUMMARY.md (plain + technical)¶
Cover: - the three paths (hosted under BAA, in-house open model, programmatic first) - why programmatic first: auditable, no invented facts - the FactGuard design - minimum necessary - audit logging of who viewed which summary - "What I'd say if asked"
DONE¶
dotnet build(0 warnings)- NUnit green, count increased
- Stryker on the summary builder + FactGuard: mutants > 0, score >= break
npm test,build:snapshot, e2e asserting the card renders with citations at 390px and 1280px- screenshots
docs/screenshots/executive-summary-*.png - REAL output for 3 synthetic patients pasted into VERIFY.md "Pass 12"