CODEX TASK 7
You are Cedric (Codex), worker #1, pass 7: Fable's re-gate of passes 4–5. Run it AFTER pass 6 is committed. Known-good fallback tag: demo-safe-1 (8d1dd5f, 135/135 on another PC). Do NOT break anything that works. Surgical fixes, a test that fails on the old code for each behavior change, commit per item with the per-command identity and trailers.
Fix:
1. Api Program.cs:~102: the pre-visit summary must use the SAME eligibility as risk/gold. Exclude entered-in-error/refuted/cancelled and future-dated facts. Test: a refuted newer Condition is not the headline.
2. SyncService.cs:~55: the watermark must not move past the earliest quarantined record in the batch. Set it to min(maxMapped, earliestFailed − 1 tick), or keep a replay list. Test: A ok, B fails, C ok → the next run re-reads B.
3. ClinicalMapping.cs:~52: persist FHIR status CODES via GetLiteral() (entered-in-error, not-done, on-hold) for every resource type. Drop the 'enteredinerror' special case. Add a migration/backfill if the stored values change. Tests.
4. LakehouseRunner.cs:~63 silver extraction: match the C# mapper:
- BP components require LOINC system + mmHg
- effective = effectiveDateTime OR effectivePeriod.start
- exclude preliminary/registered Observations (same rule as ToRiskPatient)
- Add a parity test: for every fixture patient, the gold latest A1c/BP equals what the operational risk engine uses.
5. SourceAdapters.cs:~95 OystehrFhirSource: reuse FhirSource's Bundle paging/Resources (OperationOutcome filtering, tolerant link parsing) instead of the second pager. Test with a link missing 'relation' plus an outcome entry.
6. ServiceDefaults Extensions.cs:~42: also redact url.full (strip the query string and patient path segments) on client spans. Test.
7. ClinicalMapping.cs:~115: remove the dead null-effective branches and state the undated-facts rule once, commented.
- NEVER IMPUTE (found by the Ottehr-track parity work, branch wt/WT-dc65/ottehr-track, docs/ottehr-track.md).
- Way 1 infers NEGATIVE ASCVD inputs when data is missing (e.g. treating no diabetes Condition as "not diabetic", no smoking observation as "non-smoker", no antihypertensive med as "not treated"), so it produces a score where the rule says "insufficient data".
- Fix in ClinicalMapping.ToRiskPatient / RiskEngine: an input is false only with explicit evidence of absence (e.g. a smoking-status Observation coded never/former smoker; a medication list present and complete). Otherwise null → "insufficient data", listing the missing inputs.
- Read docs/ottehr-track.md on that branch for the 3 patients and the exact differences. Add tests with those patients.
- After the fix, Way 1 and Way 2 must agree.
- Run the parity harness from the Ottehr branch (ehr-track/scripts/parity.ps1) if possible on this PC. If Windows Application Control blocks it, say BLOCKED.
Defer, and document under "Known limitations" in VERIFY.md with a one-line reason each: - the per-type fixture re-parse in FetchTypeAsync (FhirSource.cs:117) - the CaptureAsync SOURCE.md collision (FhirSource.cs:60) - the N+1 FindAsync/ChangeTracker growth (SyncService.cs:57)
DONE: dotnet build (0 warnings), dotnet test, npm test, npm run build:snapshot (regenerate), npm run e2e. Append "Pass 7 (Fable re-gate)" to VERIFY.md with the finding → commit → test table. Then git push origin HEAD.