← The Machine Room · Case File 003 — EHR Behavioral Bench run · --:--:-- GST · Sheet 1 of 7
CASE FILE · EHR BEHAVIORAL · HEALTH / COMPLIANCE DWG NO. AH-CS-003

A spoken therapy session becomes a signed, tamper-evident record. Built for the strictest privacy rule in American healthcare.

A compliance-first transcription prototype for a New York behavioral-health firm: record, diarize, review, hold-to-sign — every event hash-chained, and substance-use records physically segregated from everything else. Synthetic data; no clinician has used it yet. That is stated on every sheet, not hidden in one.

CONSENT → RECORD → DIARIZE → SIGN → SEAL
13 EVENT TYPES → ONE SHA-256 HASH CHAIN
AUDIO PURGED ≤30 D · TRANSCRIPT KEPT 6 Y

DESIGNED FOR 42 CFR PART 2 — NOT CERTIFIED;
NO ATTORNEY REVIEW YET. STATED, NOT HIDDEN.
3
PHYSICALLY SEPARATE DATA STORES — SUD RECORDS
NEVER SHARE A DATABASE WITH THE REST OF THE CHART
ADR-011  VERIFIED
Drawn byAbu Huraira Mukhtar
RoleArchitect & Lead Engineer · Solo
Build window2026-04 → 2026-05 · 6 WK
Regime42 CFR PART 2 + HIPAA + NY
ClientWithheld · NY Behavioral Health
StatusPrototype · Synthetic data only
Source33,800 LOC · 16 Packages
Sheet1 of 7
SHEET 2 OF 7 · ABSTRACTGENERAL NOTES APPLY

01 · The session is sacred; the record must be too

Fifty minutes of someone's worst week is spoken aloud in a small room. This machine has one job: make the record of it accurate, signed, and impossible to alter silently.

The clinician records in the browser; audio goes to object storage on a presigned URL — the bytes never transit the application server. Deepgram Nova-3 fetches it directly and returns a diarized draft, or the pipeline fails loud: an unlabeled transcript is a defect here, not a degraded mode. The clinician reviews, reassigns a mislabeled speaker, then presses and holds to sign. The transcript locks, and every one of thirteen domain events along the way lands in an append-only, SHA-256 hash-chained audit log.

Deliberately, the machine writes no clinical note. New York's S.8484 permits administrative AI and forbids the therapist kind, so Phase 1 ships the boring, legal thing: a verbatim, speaker-labeled transcript. The clinician stays the author; the machine is the stenographer and the notary.

GENERAL NOTES
1 · 16 PACKAGES · HEXAGONAL PORTS & ADAPTERS · STRICT TS
2 · 505 TESTS · 16/16 LINT · 30/30 TYPECHECK VERIFIED
3 · WCAG 2.1 AA — AXE, GOLDEN PATH VERIFIED
4 · 4 RUN MODES — IN-MEMORY → REAL R2 / DEEPGRAM / ACCESS
5 · AI NOTE-DRAFTING — EXCLUDED BY DESIGN · NY S.8484
SHEET 3 OF 7 · FIELD NOTESTHE BEFORE-STATE

02 · The chart is written from memory, at 11 p.m.

Somewhere in New York tonight, a counselor is typing up a two-o'clock session at the kitchen table — the third note of the evening, all of it from memory.

Nothing was recorded; nothing could be. So the legal record of care is a reconstruction: what she remembers, hours later, filtered through two more sessions and dinner. The client's own brief put the wedge in four words — clinicians hate writing notes — and the sector has a name for the symptom: pajama-time charting, the after-hours documentation load that burns clinicians out.

The loop in FIG. 1 is the before-state this machine was drawn against. Note what stalls it: not slowness — fidelity. The chart is a memory of a memory, and it is the document a court, an auditor, or the next clinician will treat as what happened.

OBSERVED
RECORDING OF SESSION — NONE
NOTE WRITTEN — HOURS LATE, FROM MEMORY
BURDEN — SECTOR-WIDE; UNMEASURED HERE, NO PILOT YET CLAIMED
SESSION · 50 MIN · 2 PM MEMORY · DECAYING 11 PM · KITCHEN TABLE THE CHART · FILED NEXT DAY A MEMORY OF A MEMORY — AND TOMORROW ADDS THREE MORE
FIG. 1 — THE MANUAL CHARTING LOOP, AS DESCRIBED IN THE CLIENT BRIEFSCALE — ONE SESSION : ONE RECONSTRUCTED NOTE
SHEET 4 OF 7 · SECTION A-ACUT THROUGH THE TRUST MACHINERY

03 · Three stores, one chain, no shortcuts

CONSENT · AI-USE V1 988 HANDOFF · RE-CONSENT ON EDIT RECORD · IN-BROWSER R2 PRESIGNED — BYTES NEVER TRANSIT THE SERVER DEEPGRAM · NOVA-3 FETCHES DIARIZE=TRUE DIARIZED DRAFT NO LABELS → FAIL LOUD HOLD-TO-SIGN SEALED RECORD SIG REF · LOCKED PART 2? CLASSIFICATION PER PATIENT UNKNOWN → PART 2 · FAIL-SAFE PART2_DB NON_PART2_DB SHARED_DB · META + 2 R2 BUCKETS · 1 PER CLASS APPEND-ONLY AUDIT CHAIN — SHA-256(SEQ ‖ PREV ‖ ENTRY) 13 EVENT TYPES EVERY EVENT LANDS HERE, ATOMIC WITH ITS WRITE READ CROSS-CHECK — STORE VS FLAG MISMATCH FIRES AUDIT.TAMPER_SIGNAL
FIG. 2 — SECTION A-A · THE SEALED-SESSION MACHINEEVERY BEAT IS A DOMAIN EVENT ON THE BUS
STATION 1 · CONSENT.CAPTURED

1Consent, before anything listens

Nothing records until the patient signs a standalone, versioned AI-use consent — plain English, the vendors named, a 988 crisis-line handoff, and the promise that nothing said trains an AI. Editing the document bumps its version and forces re-consent. The consent is a gate, not a checkbox.

STATION 2 · RECORD → DIARIZE

2Audio that avoids the server

The browser records opus/webm and uploads on a presigned URL — audio bytes never transit the application server. Deepgram Nova-3 fetches straight from storage and returns speaker-labeled segments, or the use case fails loud: in a two-person room, a transcript that can't say who spoke is a defect, not a degraded mode.

STATION 3 · THREE PHYSICAL STORES

3Segregation you can point at

Federal law (42 CFR Part 2) makes substance-use records stricter than the rest of the chart. Most EHRs enforce that with a flag column. Here every record routes physically — part2_db, non_part2_db, shared_db, plus two audio buckets — and an unclassified patient defaults to Part 2, fail-safe. A wiring mistake becomes a 500 error, not a leak.

STATION 4 · THE CHAIN CHECKS ITSELF

4An audit log that can't be quietly edited

All thirteen event types append to a hash chain — each entry's SHA-256 covers the sequence, the previous hash, and its own canonical form — with a meta-chain in shared_db anchoring both stores. The dashed arc is the consequence loop: every repository read re-asserts that store and flag agree, and a mismatch fires audit.tamper_signal into the same chain it protects.

STATION 5 · CLINICIAN.SIGNED → LOCKED

5Hold to sign, sealed for six years

After review — reassign a speaker, fix a segment, every edit hash-chained per transcript — the clinician presses and holds. The transcript locks with a signature reference and becomes the record; export is an AES-128 password-encrypted PDF on a 15-minute link. The audio is purged within thirty days. The transcript is what remains, and it can prove it hasn't changed.

DETAIL B · SEE FIG. 2, STORES

Physical beds, not a flag column

The industry default for Part 2 is logical segregation — one database, a flag, query-layer discipline. This firm is SUD-primary: over half its patients are Part 2-protected, so the flag would guard the majority of every table.

Chose physical segregation — three databases, two buckets, a routing audit log — because a boundary engineers cross constantly should be architectural: a connection-string mistake yields an error, not a disclosure, and an auditor is shown storage, not query code. Cost: ~3× the milestone, no cross-DB transactions (event-bus sagas instead), doubled backup complexity. Revisit when the SUD share drops below 25% or saga load outgrows the audit-readability win. ADR-011
DETAIL C · SEE FIG. 2, PORTS

The compliance bill, deferred by an adapter

The governing tension: the strictest regulation in US healthcare versus a prototype that must prove itself before real money. HIPAA-grade infrastructure and BAAs cost more than an unvalidated idea is worth.

Chose hexagonal ports-and-adapters on free tiers with synthetic data, because the production cutover — AWS Transcribe Medical, RDS, Cognito under BAA — becomes a new adapter file plus one composition-root line, not a rewrite. Cost: indirection everywhere; sixteen packages for one module. Already paid off once: the STT vendor swap in REV A touched zero domain code. Revisit when vendors stop changing — which is to say, never. ADR-009 · PROJECT BRIEF §4
SHEET 5 OF 7 · REVISION HISTORYALL ENTRIES TRACEABLE

04 · What broke, by revision

Real drawings carry a revision table because real machines break. This one broke in instructive places.

Every row traces to an ADR or the repo's own status log. The pattern: in a compliance system, the fix is never a patch — it is a rule written down so the same class of mistake becomes impossible.

REV
DATE
WHAT BROKE
THE FIX
TRACE
A
2026-04-20
VENDORGroq Whisper was the planned STT primary — and its endpoint returns no speaker labels. The module boundary reads: an un-diarized transcript is a defect, not a degraded mode.
SWAP AT THE PORTDeepgram Nova-3 with diarize=true became primary. The port boundary made it one adapter and one composition-root line; zero domain code moved. The WER benchmark was demoted to a pre-pilot gate — recorded, not forgotten.
ADR-009
B
2026-04-24
EXPORTThe first encrypted-PDF export crashed in browser verification — pdfkit's .afm font files ENOENT'd under the bundler. Same pass: the primary button in forms defaulted to type="button" and silently swallowed submissions.
CODIFY, DON'T PATCHWebpack externals for the transitively-required package; and the button default became a written convention (ADR-010) so no future form dies silently. Both fixes verified in the same session: the PDF opened only with its password.
STATUS M11 · ADR-010
C
2026-04-30
PRIVACYSupervisors needed to see what exactly changed in an edited transcript — but putting before/after text into the audit log would route patient words to every firm-wide auditor.
POINTERS, NOT CONTENTChange history moved to a resource-level table that inherits the transcript's own access control, with a hash chain per transcript. The audit log stays pointer-only; its threat model survives the feature.
ADR-014 · ADR-003
D
2026-05-05
TOPOLOGYOne database held both record classes; a non_part2_flag was the only wall — exactly the boundary an engineer under deadline pressure crosses without noticing.
MAKE THE MISTAKE IMPOSSIBLEThree stores and two buckets landed across M14a–c. The flag survived its own demotion — kept as a second, independent check: every read asserts store and flag agree, and a mismatch fires audit.tamper_signal.
ADR-011 · M14A–C

Two things a skeptic would find, answered before the interview: the Cloudflare Access adapter parses identity headers but JWT signature verification is stubbed — a marked production TODO, tolerable only because no real patient data exists to protect yet. And there is no PII redaction anywhere: the transcript is stored verbatim by design, defended by segregation, access control and the chain — not by masking. Both are written in the repo's known-issues file, not discovered by an auditor.

VERIFICATION
505 TESTS — CONTRACT-RUN PER ADAPTER, IN-MEMORY + DRIZZLE VERIFIED
E2E GOLDEN PATH ~40 S + AXE WCAG 2.1 AA
JWT VERIFY — STUBBED · STATED, NOT HIDDEN
SHEET 6 OF 7 · APPROVAL PLATEPROVENANCE ON EVERY NUMBER

05 · Proof of mechanism, not of outcome

3+2Physically separate databases plus two audio buckets — the Part 2 boundary is storage topology, not query disciplineVERIFIED
13 → 1Domain event types flowing into one append-only SHA-256 hash chain; every entry's hash covers the one before itVERIFIED
505Tests green across eleven packages — contract harnesses run once per adapter, so the fakes and the real thing obey the same lawVERIFIED
§2.12(e)Segregation built to the federal SUD-records rule — designed for, not certified; counsel review is scoped, not doneDESIGNED FOR
≤30 dAudio lifetime after sign-off, swept by cron with legal-hold override; the six-year record is the transcript, not the recordingVERIFIED · MECHANISM
<$1Total API spend for a ten-session synthetic pilot — storage inside free tiers by an order of magnitudeVERIFIED
SPECIMEN — THE SEALED TRANSCRIPT, DRAWN FROM THE REAL REVIEW SURFACE · 66-SECOND TWO-VOICE BENCH RECORDING, DIARIZED BY DEEPGRAM INTO 5 SEGMENTS VERIFIED 2026-04-24
LENGTH 01:06 LANGUAGE EN-US MODEL DEEPGRAM:NOVA-3 SEGMENTS 5 STATUS FINALIZED
S·00
00:00
S·01
00:14
S·00 ↺
00:31
S·01
00:44
S·00
00:58
▣ SIGNED & ON RECORD — LOCKED SIGNATURE REF 019DB194-2CD… · EVERY EDIT HASH-CHAINED
SEGMENT TEXT DRAWN AS BARS BY POLICY — NO TRANSCRIPT LINE, EVEN A SYNTHETIC ONE, LEAVES THE SYSTEM · THE ↺ TAG IS THE REAL REASSIGN-SPEAKER AFFORDANCE

What these numbers are not: a clinical result. No clinician has used this system on a real session. The first supervised pilot is a future Phase 2 gate, so no time-savings figure appears anywhere on these sheets — a number like that would be invented, and in healthcare an invented number is disqualifying. What the numbers are: proof that the trust machinery a pilot cannot retrofit — consent, segregation, the chain, the seal — already works, to production engineering gates.

Discuss a compliance-first build →
SHEET 7 OF 7 · CLOSE-OUTPLAIN VOICE

06 · What the drawing doesn't show

A compliance dossier that claimed compliance would be lying twice, so here is the plain state of it.

This system is designed for 42 CFR Part 2; it is not compliant with it. The §2.32 redisclosure notice that must ride on every export exists as a typed constant and is not yet attached to the PDF — the repo flags it [CRITICAL] in its own known-issues file, and real-PHI mode stays off until it ships. The consent and court-order machinery of §2.31, §2.35 and §2.65 is drawn (M15–M17), not built. No healthcare-privacy attorney has reviewed any of it; that review is scoped as one end-of-project bundle before any pilot. One module of a planned twenty-one exists.

The hardest part of the build was refusing the demo that sells. AI-drafted clinical notes were the obvious wow — and New York's S.8484 red zone, and a trust debt no startup in this domain survives. So Phase 1 shipped the stenographer and the notary instead, and hardened consent, audit and retention before any model gets to infer anything. That is the judgment this case file is actually selling: under real regulatory constraint, build the boring, provable thing first — and write every gap down before someone else finds it.

UNRESOLVED
§2.32 NOTICE ON EXPORTS — CRITICAL · NOT ATTACHED
§2.31 / §2.35 / §2.65 — DRAWN, NOT BUILT · M15–M17
ATTORNEY REVIEW — PENDING · END-OF-PROJECT BUNDLE
FIRST CLINICIAN PILOT — PHASE 2 GATE · NOT HELD
DRAWN & BUILT BY
ABU HURAIRA MUKHTAR · SOLO · 2026-04 → 2026-05
A. H. M.
SHEET 7 OF 7
END OF CASE FILE 003
THE DRAWING OFFICE · AFTER HOURS

The strictest room in your business deserves this kind of drawing.

Bring the process nobody is allowed to get wrong — patient records, money movement, audit trails. The first conversation costs nothing, and the discretion you just read is permanent.

Start a conversation → ← Back to the machine room
NEXT CASE FILE · 004 Financial Modelling OS → SHEET 1 OF —