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.
- Local open-source FHIR server in Aspire (option B, works tonight with no accounts).
- 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 resourceehr-fhir. - 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). - REFUSE any non-loopback target unless
--target oystehris used AND the env varOYSTEHR_SEED_CONFIRM=I_OWN_THIS_PROJECTis set (option A, below). - Add
LocalEhrFhirSource : IFhirSource. It pulls from the local server over real FHIR REST:_lastUpdatedincremental- paging through Bundle next links
- OperationOutcome entries skipped (pass 4 rule)
- Selected with
Source:Mode=LocalEhr. AppHost wires the URL from theehr-fhirresource. - The Ottehr resources (Patient, QuestionnaireResponse for intake) must flow through Track B. Map the QuestionnaireResponse intake answers into a simple
intake_answerstable/entity plus an API field on the patient summary ("Intake (Ottehr)"). Test with the verbatim fixture. - Option A readiness (real Oystehr, used only if Andrew creates an account).
OystehrFhirSourcestays env-gated (OYSTEHR_CLIENT_ID, OYSTEHR_CLIENT_SECRET, OYSTEHR_PROJECT_ID).ehr seed --target oystehruses the same bundles against the Oystehr FHIR API, only withOYSTEHR_SEED_CONFIRM=I_OWN_THIS_PROJECT, and prints the planned writes first (dry-run by default;--applyto write).- NEVER run
--applyyourself. No real calls without credentials. - Unit tests use a fake HTTP handler: token request shape, project header, base URL, and refusal without confirm.
- UI:
- 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/dashboardsourceModefield. - The patient chart shows the "Intake (Ottehr)" section when present.
- The snapshot includes this.
- Snapshot: regenerate. The Ottehr patients appear in the patient list, labeled "Ottehr sample".
- 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.