# Diabetic ketoacidosis (DKA)

Source: saved session `01a154bf-cfa0-743b-9ef2-78cd8a7b7cd3`, October 19, 2026.

The original physiology write-up and follow-up control instructions are preserved verbatim below. Desktop paths and verification claims refer to that original session, not this import. Educational material only; not a clinical protocol. Medical statements and cited consensus thresholds have not been independently verified during import. The original limitations include assumed full respiratory compensation, potassium discussed only in the caption, and the fluid-deficit beaker interpretation. Clinical review is required before teaching or patient-care use.

---

I built the DKA figure: an interactive bench machine where each part stands for one piece of the physiology, driven by a small numerical model. Both pages open with no console errors. The line-end check showed no stray lines in either theme, at rest, in full DKA and partway through treatment. Hover and treatment both work in the browser, and I checked the desktop, phone and close-up views.

Files are in `~/Desktop/02_projects/anatomy-dka/`:
- `dka.html` and `dka-light.html`: the dark and light versions of the figure.
- `build.mjs`: the model plus the drawing code. Rebuild with `node build.mjs` (add `--light` for the light page, or `--table` to print the numbers).
- `preview-dark.png` and `preview-light.png`: snapshots at full DKA.

## What each part stands for

| Part | Meaning |
|---|---|
| Hopper with two valves on one bar | The liver: one valve releases glucose, the other ketoacids |
| Syringe holding the bar up | Insulin, keeping both valves shut |
| Springs pushing the bar down | Glucagon, cortisol and adrenaline, which push the valves open |
| Left column | Blood glucose. Above 180 mg/dL it spills over a lip into the beaker (urine), taking water with it |
| Right column, piston (the highlighted part) | Bicarbonate below the piston, ketone acids above it. Each acid uses up one bicarbonate, so the piston drops as the anion gap (the readout's AG) grows |
| Bellows on springs | The lungs, breathing out CO₂. They breathe deeper and faster as acid builds (Kussmaul breathing) |
| Dial | Blood pH, with a red band below 7.30 |
| Red marks on the scales | DKA thresholds: glucose 200 mg/dL, bicarbonate 18 |

## How it works
- **Hover:** moving the pointer from left to right goes from normal insulin to none. Glucose rises first, and ketones climb once fat breakdown is no longer held back.
- **Click (or Space):** runs 24 hours of treatment (fluids plus insulin at 0.1 U/kg/h) in about 15 seconds. Glucose reaches 200 mg/dL by about 5 h, when dextrose is added. Bicarbonate passes 18 at about 5 h, but β-hydroxybutyrate (the main ketone) takes about 15 h to fall below 0.6. That is the main teaching point: insulin keeps running until the ketones clear, not until the glucose does.
- **Readout:** treatment hour (while treating) · glucose · β-hydroxybutyrate · bicarbonate · pH · anion gap.
- **When nobody is interacting:** it loops on its own through normal, DKA developing, treatment and recovery.

## Model and sources
- Diagnosis and thresholds follow the 2024 ADA/EASD/JBDS/AACE/DTS consensus. DKA means glucose ≥ 200 mg/dL (or known diabetes), β-hydroxybutyrate ≥ 3.0 mmol/L, and pH < 7.3 and/or bicarbonate < 18. Resolution is β-hydroxybutyrate < 0.6 plus pH ≥ 7.3 or bicarbonate ≥ 18.
- Breathing follows Winter's formula: expected PaCO₂ = 1.5 × bicarbonate + 8.
- pH comes from the Henderson–Hasselbalch equation.
- The rise in anion gap equals the fall in bicarbonate.
- Water lost through the urine reaches up to about 7 L.

## Limitations
- **Breathing is assumed to keep up fully.** So with no insulin the model reaches pH 7.15, not below 7.0, even though bicarbonate (5) and β-hydroxybutyrate (14) are in the severe range. Real patients often fall short of full compensation and reach lower pH.
- **Potassium is in the caption only, not the drawing or readout.** The caption covers the key point: check potassium is ≥ 3.5 before starting insulin.
- **One possible confusion:** the beaker shows water still owed. It empties during treatment as fluids repay the deficit, not because urine flows back.

---

I've opened the light version (`dka-light.html`) in your browser. To open the dark version, run `open ~/Desktop/02_projects/anatomy-dka/dka.html`.

---

There are no on-screen buttons. Everything is controlled with the mouse or keyboard directly on the figure.

**Mouse**
- **Move across the figure:** sets how much insulin is missing. The far left is normal insulin and the far right is none (full DKA). Pointer movement is ignored while treatment is running.
- **Click:** starts the 24-hour treatment. Clicking again while it runs stops it.

**Keyboard** (press Tab to select the figure first; a thin outline appears)

| Key | Action |
|---|---|
| → or ↑ | Less insulin (5% steps) |
| ← or ↓ | More insulin (5% steps) |
| Shift + arrow | 25% steps |
| Home | Normal insulin |
| End | No insulin (full DKA) |
| Space or Enter | Start or stop treatment |

Clicking also selects the figure for the keys, but it starts treatment at the same time. Tab selects it without that.

**Touch:** a tap starts treatment. Phones have no hover, so you can't set the insulin level by hand there; the automatic loop shows the full range.

When you stop interacting for 4 seconds, the automatic loop takes over again: normal, DKA developing, treatment, recovery.
