Skip to content

PLAN REVIEW 9 FULL

PLAN REVIEW: attack this plan BEFORE it's built. You are one of three independent senior reviewers (Fable / Astra / Carbon). Andrew Jones presents this proof of concept tomorrow at noon in an interview with Innovare: a 4-person healthcare team migrating Allscripts → Ottehr (open-source EHR front end on the Oystehr headless FHIR backend) → their own in-house EMR. The hiring manager is a data-first .NET/Azure person. It must be correct, honest and defensible.

Context, already built and verified (222/222 tests, tag demo-safe-3): - A .NET 10 API + EF Core (SQL Server/Sqlite) - A DuckDB lakehouse (bronze/silver/gold) and a Vue 3 + Vuetify UI - Aspire - A local HAPI FHIR server - An Oystehr adapter (env-gated) - Risk rules (A1c, BP, flu gap, ASCVD with never-impute), with Way 1 / Way 2 parity of 56 flags across 12 synthetic patients - Synthetic data only

THE PLAN UNDER REVIEW (docs/CODEX-TASK-9.md) follows verbatim below.

Answer concisely, with numbered findings. Each finding: severity (Critical/High/Medium/Low), the plan section, the problem, and the concrete fix. Cover: 1. Migration CORRECTNESS: FHIR as the canonical interchange; idempotency (PUT by id); version handling; references between resources (Patient refs, contained resources); ordering and dependencies; resumability via checkpoints; partial failure; duplicate and merge risks; ID mapping (source id → target id) and provenance. 2. RECONCILIATION: are counts + checksums + risk-flag parity sufficient proof? What would a real clinical migration also verify (referential integrity, code-system fidelity, effective dates/time zones, status semantics)? 3. "Does not migrate programmatically": is the list complete and honest (auth/users, audit logs, Zambdas, consent, documents/attachments, scheduling, billing)? 4. How EF migrations, cdktn and Aspire genuinely contribute vs. overclaiming. Anything a skeptical data-first hiring manager would poke holes in. 5. Scope risk for a ~1-2 hour build. What to CUT so the core path is bulletproof (fixtures → in-house EMR → reconcile → flags identical; idempotent; resumable). 6. Security/privacy: Oystehr writes stay dry-run by default; no secrets; synthetic only. End with a verdict: PROCEED / PROCEED-WITH-FIXES (list them) / STOP.

===== docs/CODEX-TASK-9.md ===== You are Cedric (Codex), worker #1, pass 9: MIGRATION proof of concept. Run AFTER pass 8 is committed, and follow Andrew's style guide (docs/ANDREW-STYLE-GUIDE.md). Fallback tag: demo-safe-3.

Story (Innovare's real roadmap from the interview notes): Allscripts → Ottehr/Oystehr → their own in-house EMR. Andrew wants to show what can be migrated PROGRAMMATICALLY between: 1. our solution 2. the Oystehr solution 3. an eventual in-house EMR

and how EF Core, cdktn and Aspire make that repeatable. Synthetic data only.

Build

  1. IFhirSink, the counterpart to IFhirSource. Implementations:
  2. LocalEhrFhirSink (the HAPI in Aspire): transaction Bundles with PUT by id, so it's idempotent
  3. OystehrFhirSink: env-gated, dry-run by default; writes only with --apply AND OYSTEHR_SEED_CONFIRM=I_OWN_THIS_PROJECT; NEVER run apply yourself
  4. InHouseEmrSink: writes into a NEW EF Core model InHouseEmrDbContext (its own schema emr, with its own migrations) that represents "Innovare's own EMR". Model it the way a team would: Patient, Encounter, Allergy, Immunization, Observation, Condition, Medication, IntakeAnswer, plus a SourceSystem / SourceId / SourceVersion provenance on every row.
  5. FhirDemo.Cli migrate --from <fixtures|operational|localehr|oystehr> --to <localehr|oystehr|inhouse> [--dry-run] [--resume]
  6. Export: FHIR from the source. For operational, rebuild FHIR from the stored RawJson. Prove it round-trips.
  7. Transform: a mapping hook (identity for FHIR→FHIR; FHIR→in-house entities via a mapper that reuses ClinicalMapping).
  8. Load: batch in chunks with a checkpoint table (migration_run, migration_checkpoint) so it's resumable. It must be idempotent: a second run means 0 changes.
  9. Reconciliation report:
    • counts by resource type, source vs target
    • per-record checksum of the clinically relevant fields
    • missing/extra ids
    • AND risk-flag parity: run the RiskEngine over source vs target data, and the flags must be identical, per patient
    • Written to docs/migration-report-*.md and JSON.
  10. A "what does NOT migrate programmatically" section: users/credentials/auth, audit logs, Zambda code (it becomes in-house services), UI customizations, integrations config, binary attachments if any. Each one gets its plan.
  11. Aspire: add an emr-db resource (SQL Server, or the Sqlite fallback) for the in-house EMR, plus a config switch Source:Mode / Sink:Mode, so the same app points at LocalEhr, Oystehr or InHouse with configuration only.
  12. cdktn: add the in-house EMR's target infrastructure to the synth-only Azure stack (Azure SQL database emr, a Container App for the EMR API). Document how cutover works as code: plan, apply (human), migrate, reconcile, switch traffic.
  13. UI: a "Migration" page (and in the snapshot) showing the three-hop path with the latest reconciliation numbers and flag parity. Plain-language plus technical toggles. Add a short demo-script beat to the README.
  14. Tests:
  15. fixtures → inhouse → reconcile: 0 diffs, flags identical
  16. a second run makes 0 changes
  17. resume after a simulated crash mid-batch
  18. operational → FHIR round-trip equality
  19. dry-run makes no writes
  20. the Oystehr sink refuses without confirm (fake HTTP)

docs/MIGRATION.md (Andrew reads this): a plain explanation, the 3-hop diagram, how EF migrations / cdktn / Aspire each make it repeatable, the cutover runbook, risks, and a "what I'd say if asked" section.

DONE: dotnet build (0 warnings), dotnet test, npm test, npm run build:snapshot, npm run e2e, plus a real migrate --from fixtures --to inhouse run twice and a migrate --from fixtures --to localehr run, with the reconciliation reports. Paste the REAL outputs into VERIFY.md under "Pass 9 (migration)". Commit per item with the per-command identity and trailers. Push.