๐Ÿ›ค๏ธ Anesthesia Data Model โ€” A Save in Motion (flow board)

Follow one real action through every layer. This is the "vertical" that ties the spine, the chart, and the billing bridge together.

๐ŸŽฏ Scenario: an anesthesiologist documents an ultrasound-guided popliteal nerve block, left leg in the Procedures tab and clicks Save.
โ‘ 
UI โ€” gi-webpackages/anesthesia ยท procedures-panel
Fills the peripheral_block SynForm โ€” laterality=Left, block=popliteal, ultrasound โœ“ โ€” and clicks Save. Descriptors are a hardcoded TS mirror; the values become a ProcedureRecord (layoutKey + formData{โ€ฆ}).
โ–ผ
โ‘ก
HTTP โ€” EdgeAFD โ†’ SWA gi-web
AnesthesiaService.saveProcedure()  โ†’  PUT /api/anesthesia/cases/{id}/procedures. Same-origin through Azure Front Door; bearer token attached.
โ–ผ
โ‘ข
clinical-apiAnesthesiaProxyController
Just forwards to aims-api (AimsApi:BaseUrl) โ€” no anesthesia logic here. Re-injects the identity (Authorization, or X-Dev-ApiKey+X-User-Id) so the RLS org survives the hop.
โ–ผ
โ‘ฃ
aims-api โ€” controllerAnesthesiaCaseController
SaveProcedure โ†’ GetOrCreateByCaseIdAsync(caseId) resolves the spine row (anesthesia_cases) โ€” creating it on first touch (1:1 with cases).
โ–ผ
โ‘ค
aims-api โ€” repo (Dapper)AnesthesiaCaseRepository
Opens NpgsqlConnection โ†’ SET app.organization_id (RLS) โ†’ upserts anesthesia_procedures: form_data JSONB (SNAPSHOT) + promoted laterality / block_name / ultrasound_guided (PROJECTION, via SynFormValueMapper) so billing never parses JSON.
โ–ผ
โ‘ฅ
the bridgeAnesthesiaProcedureBillingBridge
OnProcedureSavedAsync โ€” deterministic, no LLM. popliteal = named-nerve โ†’ CPT 64445 (mod -59). ultrasound โœ“ โ†’ adds a 76942 found-money flag. UpsertBlockBySourceProcedureAsync โ†’ anesthesia_regional_blocks (idempotent). try/catch โ€” best-effort.
โ–ผ
โ‘ฆ
PostgreSQLRLS by organization_id
Rows committed inside the org session context. 200 OK returns to the UI โ€” even if โ‘ฅ threw (a billing hiccup never blocks the clinical save).

๐Ÿ“ฆ What's in the DB now (3 rows, 1 save)

anesthesia_procedures  id=42, anesthesia_case_id=7, procedure_type=peripheral_block,
  laterality=Left, block_name=popliteal, ultrasound_guided=true, form_data={โ€ฆ}
anesthesia_regional_blocks  source_procedure_id=42, cpt_code=64445,
  modifier=-59, laterality=Left  โ† the billable line
anesthesia_field_avoidance_flags  type=us_guided_block,
  notes="us_block:42"  โ†’ drives 76942 imaging on the charge ticket

๐Ÿ” Read ยท idempotency ยท live data

Read path = same hops in reverse. GET โ€ฆ/procedures โ†’ proxy โ†’ aims-api โ†’ repo โ†’ JSON back. Nothing PHI is cached client-side.
Idempotent + reversible. Re-Save updates the same block (partial-unique on source_procedure_id). Delete the procedure โ†’ block cascades away (ON DELETE CASCADE) and the 76942 flag is removed.
โš ๏ธ Live vitals are NOT this path. They stream over SignalR /hubs/intraop (aims-api), a separate channel from REST.

Source: AnesthesiaService (packages/anesthesia), AnesthesiaProxyController (clinical-api), AnesthesiaCaseController + AnesthesiaCaseRepository + AnesthesiaProcedureBillingBridge + SynFormValueMapper (aims-api). Verified against source 2026-06-30.