Skip to content

CODEX TASK 4

You are Cedric (Codex), worker #1, pass 4: council review fixes. Seats run at 28663e7: Fable (native), Gronktayvius red team, Susie (front end + infra), Jenny (chunked, may add more). Clahadore chaired. These are the ACCEPTED findings; fix them all. Keep changes surgical. Commit per group with the per-command identity (git -c user.name="Andrew Jones" -c user.email="andrewjonesdev1@gmail.com" commit) and the Co-Authored-By trailers for Cedric (Codex) and Claude Opus 5.5. Add or adjust a test for every behavior change. Tests must FAIL on the old code.

A. Data / clinical correctness

  1. LakehouseRunner.cs:~126 / LakehouseReports.cs:41: gold_outreach.warning_count is a HUGEINT, which serializes as a BigInteger object. CAST the aggregates to INTEGER/BIGINT in SQL. Also convert any BigInteger / decimal values to JSON numbers when building report rows. Test: the JSON contains a number.
  2. ClinicalMapping.cs:~106 ToRiskPatient: stop hard-coding BpTreated=null.
  3. Derive BpTreated from active/recent MedicationRequest RxNorm codes in a small, explicit antihypertensive allowlist (e.g. amlodipine, lisinopril, losartan, hydrochlorothiazide, metoprolol, atenolol; use the RxNorm codes actually present in the fixtures, and comment the list's origin). It is null only when there is NO medication data.
  4. Derive diabetes status from Condition SNOMED (44054006 and its descendants present in the fixtures; prediabetes 15777000 is NOT diabetes).
  5. Race: ONLY from the explicit US Core race extension (http://hl7.org/fhir/us/core/StructureDefinition/us-core-race, ombCategory 2106-3 White / 2054-5 Black or African American). Never inferred. Otherwise keep "insufficient: race".
  6. Add a test that at least one fixture patient now gets an ASCVD percentage, with its inputs cited.
  7. SyncService.cs:66 IsNewer: when both versionIds are empty or equal-but-empty, compare lastUpdated. Test with no versionId plus a newer lastUpdated, which must update.
  8. FhirSource.cs:215 ValidateCohort: skip OperationOutcome entries (and any search.mode=outcome). Don't throw. Log them to quarantine/learnings. Test.
  9. SyncService.cs:43: dedupe quarantine on (ResourceType, FhirId, VersionId). Re-running must not grow the count. Test.
  10. Api Program.cs:~175 ClinicalRows: project out RawJson where it's unused, and map rows once before the per-patient loop.
  11. Lakehouse effective timestamps: emit UTC ISO-8601 with a Z (or the original offset) consistently with Track B. Test.
  12. ClinicalMapping.Coding: pick the code system in a fixed priority per resource type (Observation: LOINC first; Immunization: CVX; Medication: RxNorm; Condition/Allergy: SNOMED) instead of FirstOrDefault across all of them. Test with SNOMED before LOINC on an A1c.

B. Security

  1. appsettings.json: Demo:ReadOnly defaults to TRUE; appsettings.Development.json sets it false.
  2. On startup, refuse to bind a non-loopback address unless Auth:Enabled=true OR Demo:PublicSynthetic=true (explicit). Log why.
  3. Add FallbackPolicy when auth is enabled.
  4. Deploy stack: REMOVE the allUsers run.invoker binding. Cloud Run stays private; the public demo is the static Pages site. Keep the budget, and add a note that budgets don't cap spend.
  5. AppHost: remove WithExternalHttpEndpoints(). The API stays loopback.
  6. /api/sync: require Content-Type: application/json (an empty JSON body is fine), so a cross-site form POST can't trigger it. Update the web client and tests.
  7. Allergy display validation: reject UnicodeCategory Control, Format, Surrogate and PrivateUse (bidi overrides, zero-width). Test with U+202E.
  8. CLI Program.cs:53: on auth/provision paths, print the exception type plus a scrubbed message, never ToString().
  9. bi/metabase/get-driver.ps1: download to a temp path, verify the SHA-256, then move; delete on mismatch. AppHost mounts ONLY lakehouse.duckdb read-only into Metabase, not the whole data dir.

C. Infra / CI

  1. Deploy stack backend: follow fleet-infra's pattern. GcsBackend with a placeholder bucket, then AddOverride("terraform.backend.gcs.bucket", null), with the bucket supplied by -backend-config. A distinct prefix per stack (fhir-demo/gcp, fhir-demo/cf). Billing account and Cloudflare account id become TerraformVariables with NO defaults, set via *.auto.tfvars (gitignored) or env. Update DEPLOY.md.
  2. Azure skeleton: Service Bus public_network_access_enabled=false; Container App ingress internal with Demo__ReadOnly=true. Synth only.
  3. CI (both .github/workflows/ci.yml and azure-pipelines.yml):
    • run npm test and npm run e2e
    • synth infra/FhirDemo.Deploy
    • a read-only smoke: Demo__ReadOnly=true, expect 403 on POST /api/sync and 200 on the CDS POST
    • fail the build on dotnet list package --vulnerable and npm audit --audit-level=high
    • fix the health loop so a dead /health fails the step

D. Front end

  1. Reports race: add a version guard plus a test (out-of-order resolution, the older one doesn't win).
  2. web/src/api.ts:23: replace the corrupted U+FFFD with "1-200". Grep the whole repo for U+FFFD and mojibake sequences and fix any you find.
  3. Static hosting CSP:
    • Add web/public/_headers (Cloudflare Pages): Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; object-src 'none'; base-uri 'self'; frame-ancestors 'none', plus nosniff and referrer-policy.
    • Apply the SAME style-src allowance to the API's CSP when it serves web/dist (Vuetify injects its theme style element).
    • Verify in the Playwright e2e that no CSP violation fires: listen for securitypolicyviolation and assert zero.
  4. Mobile polish: in the CDS cards, collapse the cited FHIR ids behind a "Sources (n)" <details> toggle. On narrow screens, make the clinical tables readable (hide the Code column below 600px, or use Vuetify's mobile breakpoint).

DONE: dotnet build (0 warnings), dotnet test, npm test, npm run build:snapshot (regenerate the snapshot), npm run e2e (refresh the screenshots), and synth for both infra projects. Paste the REAL outputs into docs/VERIFY.md under "Pass 4 (council fixes)" with a table: finding → commit → test name. Windows Application Control blocks = BLOCKED, never "passed". Then git push origin HEAD.