CODEX TASK 6

You are Cedric (Codex), worker #1, pass 6: the "built on the open-source EHR" track. Andrew asked for a version that is actually built on Ottehr/Oystehr. Keep the existing work intact; this adds to it. Commit per item with the per-command identity and trailers. Every behavior change needs a test.

Background: - Ottehr = MassLight's open-source EHR front end (github.com/masslight/ottehr). - Oystehr = the headless FHIR R4B/R5 backend Ottehr runs on. Auth: M2M POST https://auth.zapehr.com/oauth/token with audience https://api.zapehr.com, plus the header x-oystehr-project-id. - Verify the FHIR base URL and the exact API paths against docs.oystehr.com BEFORE coding. Write what you verified (URL + date) into docs/LEARNINGS.md.

  1. Local open-source FHIR server in Aspire (option B, works tonight with no accounts).
  2. Add a HAPI FHIR JPA server container to the AppHost: pinned image hapiproject/hapi:<pinned tag>, R4, in-memory/H2, loopback only, no external endpoint. Name the resource ehr-fhir.
  3. Add the CLI command FhirDemo.Cli ehr seed --target local. It loads the committed Synthea fixtures AND the verbatim Ottehr fixtures (data/fixtures/ottehr/*) into that LOCAL server as transaction Bundles (PUT with ids, so seeding is idempotent).
  4. REFUSE any non-loopback target unless --target oystehr is used AND the env var OYSTEHR_SEED_CONFIRM=I_OWN_THIS_PROJECT is set (option A, below).
  5. Add LocalEhrFhirSource : IFhirSource. It pulls from the local server over real FHIR REST:
    • _lastUpdated incremental
    • paging through Bundle next links
    • OperationOutcome entries skipped (pass 4 rule)
  6. Selected with Source:Mode=LocalEhr. AppHost wires the URL from the ehr-fhir resource.
  7. The Ottehr resources (Patient, QuestionnaireResponse for intake) must flow through Track B. Map the QuestionnaireResponse intake answers into a simple intake_answers table/entity plus an API field on the patient summary ("Intake (Ottehr)"). Test with the verbatim fixture.
  8. Option A readiness (real Oystehr, used only if Andrew creates an account).
  9. OystehrFhirSource stays env-gated (OYSTEHR_CLIENT_ID, OYSTEHR_CLIENT_SECRET, OYSTEHR_PROJECT_ID).
  10. ehr seed --target oystehr uses the same bundles against the Oystehr FHIR API, only with OYSTEHR_SEED_CONFIRM=I_OWN_THIS_PROJECT, and prints the planned writes first (dry-run by default; --apply to write).
  11. NEVER run --apply yourself. No real calls without credentials.
  12. Unit tests use a fake HTTP handler: token request shape, project header, base URL, and refusal without confirm.
  13. UI:
  14. The Compare page gets a third card, "Built on the open-source EHR": Ottehr (open-source front end) → Oystehr (headless FHIR backend) → our sync → our app. It shows which source the current data came from (Fixture / LocalEhr / Oystehr) via a /api/dashboard sourceMode field.
  15. The patient chart shows the "Intake (Ottehr)" section when present.
  16. The snapshot includes this.
  17. Snapshot: regenerate. The Ottehr patients appear in the patient list, labeled "Ottehr sample".
  18. README demo script: add a 30-second "open-source EHR" beat, with honest wording: "locally hosted open-source FHIR server standing in for Oystehr; the same adapter points at a real Oystehr project with one setting."

DONE: dotnet build, dotnet test, npm test, npm run build:snapshot, npm run e2e (Docker is available on this PC). Plus an AppHost run that shows ehr-fhir healthy, ehr seed --target local counts, and a Source:Mode=LocalEhr sync run twice (the second run all unchanged). Paste the REAL outputs into docs/VERIFY.md "Pass 6 (open-source EHR)". Then git push origin HEAD.