CODEX TASK 8
You are Cedric (Codex), worker #1, pass 8: MAKE IT READ LIKE ANDREW WROTE IT. Run AFTER pass 7 is committed. Known-good fallback tag: demo-safe-1.
Andrew: "make sure it's all written how I would write it from looking at USPTO, or if there are changes explain them to me and why."
READ docs/ANDREW-STYLE-GUIDE.md fully. It was extracted from his USPTO repos, with evidence. Apply it to src/, tests/, tools/ and web/.
BEHAVIOR MUST NOT CHANGE. This is a pure restyle and refactor. The full test suite, snapshot and e2e must stay green after every commit. If a rule would change behavior, don't apply it; record it instead.
Apply (Andrew's style)¶
- Layout: layered folders matching his:
Services/,Data/,Helpers/,Models/(withModels/Entities/),Enums/, each with anInterfaces/subfolder where he'd have one. One type per file. Every service/helper/settings class gets anI-interface and is injected by interface. - C# conventions:
- file-scoped namespaces
ImplicitUsingsOFF with explicit usings- Allman braces
varfor locals; target-typednew()- private fields
_camelCase+ readonly - block-bodied methods (no expression-bodied members)
- no records, no primary constructors (convert them; keep value semantics where tests depend on them, e.g. implement equality explicitly or keep a record ONLY if equality is relied on, and note it)
- Async: every Task method ends in
Asyncand takesCancellationToken cancellationToken = defaultas its last parameter, threaded through every layer. - DI: one registration chain. In .NET 10 that's an extension method like
services.AddFhirDemoServices(configuration), one fluent.AddScoped<I, T>()chain, called from Program.cs. This mirrors his single Startup chain. - Options: settings classes bound by section name, injected via
IOptionsMonitor<T>, with.CurrentValuecopied into an interface-typed field (his pattern). - DTOs:
*Request/*Responsewith{ get; init; } = string.Empty;. Enums use explicit values. - EF: keep code-first migrations. The operational context implements
IUnitOfWork(SaveChangesAsync); services depend onIUnitOfWork. Prefer data annotations where he would; keep Fluent API only where annotations can't express it, and note each case. DO NOT change the database schema. If a change would alter the model snapshot, don't make it; record it. - Errors: guard clauses with
throw new ArgumentNullException(nameof(x)). The boundary catches, logs a structured template, and returns a friendly message. Lower layers log andthrow;. - Logging: injected
ILogger<T>with structured templates ("Sync finished {inserted} {updated}"). Do NOT add Serilog or App Insights packages tonight; record it as a difference. - Comments: few comments, no XML docs, no regions. Remove AI-sounding comment chatter; keep only the comments that explain a non-obvious clinical/FHIR rule or a security decision.
- Tests: convert xUnit to NUnit + Moq + AutoFixture + Bogus the way he does it:
[TestFixture],[Category("Unit Tests")](or "Integration Tests")<Type>Testsclasses- PascalCase behavior method names with an
Asyncsuffix on async tests Assert.Thatgrouped withAssert.Multiple
The same test COUNT or more, all passing. This is the riskiest item: convert mechanically, one file per commit, and run the suite after each.
- Vue (web/): he used Vuetify 3 + axios calls. Add a small services/ layer (patientService, reportService, syncService) used by the components, and break the single App.vue into views/components the way he'd organize them. Keep Vuetify 3. Keep TypeScript. 2-space indentation.
Keep modern (do NOT copy dated 2022 patterns); EXPLAIN each in docs/STYLE-DECISIONS.md¶
The guide's section 5 lists these. At minimum:
- ASP.NET Core minimal API endpoints instead of Azure Functions (the job description asks for ASP.NET Core REST APIs). Group endpoints in static *Endpoints classes that call services, so it still reads like his layered style.
- <script setup> Composition API instead of the Options API (current Vue 3 guidance, better TypeScript). If you judge Options API both feasible and safe within the time, you may switch; either way, explain.
- System.Text.Json, not Newtonsoft.
- Async EF methods everywhere (his code had sync .Any() / .First() in async flows).
- No secrets or keys in the bundle or settings (his USPTO had function keys in the front end).
- Thread-safe collections (his Parallel.ForEach adding to a List<T> was a race).
- Polly-style retries never retry 4xx.
- Keeping xUnit IF converting to NUnit can't be done safely in time (then explain).
DATA-FIRST view (the hiring manager, James, is a "data guy": "data first, models, forms and data structures, .NET")¶
Add, without changing behavior:
1. docs/DATA-MODEL.md:
- (a) a Mermaid ER diagram of the operational EF model (entities, keys, relationships, the key indexes), generated from the actual DbContext/entities, not hand-drawn guesses
- (b) the lakehouse bronze → silver → gold tables, with columns and grain
- (c) a mapping table for each clinical type: FHIR resource + element path → EF entity.property → SQL column → API Response DTO field → Vue form/table field. Include the code system used (LOINC/SNOMED/CVX/RxNorm) and the status/eligibility rules.
- (d) a data dictionary for the gold tables (column, type, meaning, source rule)
2. A "Data model" page in the Vue app (and in the snapshot):
- shows that same FHIR → entity → table → API → form chain for AllergyIntolerance (the form he'll see) and Observation (labs/BP)
- a rendered ER diagram (pre-render the Mermaid to SVG at build time, or draw simple SVG; no runtime CDN)
- links to the data dictionary
- Put it in the nav as "Data model". On the Overview, add a one-line pointer: "Start here if you think data-first."
3. e2e: visit the Data model page on mobile and assert the allergy mapping row renders.
4. EMPHASIS (Andrew): show HOW THE MODELS COME FROM THE DATA. Data first, model second:
- (a) Data profiling: a CLI command profile plus a generated docs/DATA-PROFILE.md and JSON, computed from the REAL committed fixtures. For each resource type: record counts, and for each element path the fill rate (% present), distinct values / code systems seen, date ranges and units seen (e.g. Observation.valueQuantity.unit by LOINC code), plus status distributions. Example: "AllergyIntolerance.code: 100% SNOMED", "Observation 4548-4 (A1c): N results across M patients, unit %".
- (b) Derivation write-up per entity: "This data → this decision → this model". For each EF entity and gold table, which profiled fields became properties, which were left out and why (e.g. a low fill rate, or not needed by any screen or rule), the chosen types/lengths (justified by the observed max lengths and formats), the keys (FHIR id + versionId), and the indexes (justified by the actual query patterns in the API/risk engine).
- (c) The "Data model" page leads with this: Data profile → Decisions → EF model → Table → API → Form, with the profile numbers shown next to each model field.
- (d) A test asserts that the profile numbers in the doc and page are produced by the profile command from the fixtures (no hand-typed stats).
5. LINEAGE: data → models → predictions → tables, three ways (Andrew: "how the models from the data are translated into the predictions and the tables and duckdb or oystehr").
For EACH risk flag (A1c range, A1c trend, repeated elevated BP, flu care gap, ASCVD), document and show the chain:
- Source data: FHIR resource + element path + code (e.g. Observation, LOINC 4548-4, valueQuantity %), with the profile stats from item 4
- → Model: the EF entity/property and the RiskPatient input it feeds
- → Prediction logic: the exact rule/formula in RiskEngine (file:line), its thresholds, and its eligibility rules (status, as_of, never impute)
- → Way 1 operational: SQL Server/Sqlite tables read, the API endpoint, and the CDS card output
- → Track A lakehouse (DuckDB): bronze → silver table/columns → gold_risk_flags / gold_outreach columns, plus the SQL that computes it (file:line), which feeds Metabase
- → Way 2 Oystehr: the Zambda rule in branch wt/WT-dc65/ottehr-track (ehr-track/risk/... file:line) reading the same FHIR elements via the Oystehr FHIR API. Read it with git show origin/wt/WT-dc65/ottehr-track:<path>; don't edit it.
Output:
- (a) docs/LINEAGE.md with one Mermaid flow per flag plus a table
- (b) a "Lineage" section on the Data model page: pick a flag, and see the three-way chain with the actual values for one synthetic patient (e.g. Adalberto's A1c 6.21% → flag), proving that all three paths produce the same flag
- (c) a test asserting that the Way 1 operational flag and the Track A gold flag agree for every fixture patient. Way 2 parity is covered by the Ottehr branch's parity harness; link it.
- "The model at every layer" (MVC inside MVC) (Andrew: "models when you think of MVC, where the V has its own MVC with frameworks like Angular, and then C"). Show ONE AllergyIntolerance and ONE A1c Observation as the model at each tier, with the real code (file:line) and the actual value for one synthetic patient:
- FHIR JSON (the source data)
- SQL table row (and the DuckDB silver/gold row)
- EF entity class (back-end Model)
- Domain/risk model (RiskPatient input)
- API Response DTO (the back end's "View" = the JSON contract)
- The back-end Controller (endpoint + service) that maps 3 → 5
- Front-end TS interface (the front end's Model)
- Vue service/component (the front end's Controller)
- Vuetify template plus the form model (the front end's View)
Also the reverse path for "Add allergy": form model → Request DTO → validation → FHIR AllergyIntolerance outbox.
- Put this in docs/DATA-MODEL.md as a stacked diagram + table.
- Add it as a "Model at every layer" tab on the Data model page.
- Keep the vocabulary plain: Model / View / Controller per tier.
- Architecture framing: present it as a C4 Component-level diagram (inside the API container and inside the Vue container) plus a layered-architecture view. Show:
- the boundaries where the model is translated (FHIR ↔ entity ↔ domain ↔ DTO ↔ TS ↔ form)
- which component owns each translation
- why each boundary exists: persistence vs domain vs contract vs UI state, versioning the API contract independently of the DB schema, and keeping FHIR out of the UI
- Also emit the same Component view in Structurizr DSL as docs/architecture/components.dsl, so Forge Studio's C4 page can include it when its branch is merged.
docs/STYLE-DECISIONS.md (Andrew reads this)¶
- Plain language. A table with columns: Area | How Andrew writes it (USPTO evidence) | What the demo does now | Same or Different | Why.
- Then a short "What I'd say if asked" line for each Different row, so he can defend it in the interview.
DONE¶
After all commits, the following all pass:
- dotnet build (0 warnings)
- dotnet test (count >= the pass-7 count)
- npm test
- npm run build:snapshot
- npm run e2e
The snapshot JSON must be byte-identical to pass 7 (behavior didn't change) or the differences must be explained. Paste the real outputs into VERIFY.md under "Pass 8 (Andrew's style)". Push.