Introduce OrganType::Bloodstream and new organ module, exporting
Bloodstream, PerfusionState, and MetabolicState.
- Patient:
- initialize_default now attaches a bloodstream model
- add with_bloodstream() builder and with_organ support
- update() couples bloodstream with heart, lungs, brain, spinal cord,
kidneys, liver, pancreas, stomach, intestines, gallbladder,
esophagus, bladder, and spleen
- bloodstream ingests hemodynamics, respiratory exchange, renal,
hepatic, splenic, and nutrient feedback; propagates perfusion and
metabolic signals back to organs
- blood metrics (SpO2, hemoglobin, hematocrit, glucose) can be driven
by bloodstream
- Signals:
- Lungs: add O2 delivery, CO2 elimination, V/Q ratio
- Liver: add detox and ammonia clearance
- Kidneys: add plasma volume, urea excretion, erythropoietin
- FFI:
- add ML_ORGAN_BLOODSTREAM (Rust and C header) and mapping in
ml_patient_organ_summary
- Examples/Tests:
- demo monitors "Bloodstream"
- add tests for bloodstream coupling and organ discovery
- lib tests updated to include Bloodstream
Rationale: centralize systemic transport and inter-organ homeostasis for
richer physiology simulation and expose it to C consumers via FFI.
Introduce crate-level ekg module and re-export EkgLead, EkgMonitor,
EkgSnapshot, and HeartElectricalState from lib.
Patient now owns an optional EKG monitor that:
- auto-initializes and syncs to the first Heart organ (lead count)
- supports configure_ekg_leads() for custom lead sets
- exposes ekg_monitor(), ekg_monitor_mut(), and ekg_snapshot()
- is advanced during Patient::update() by observing heart electrical
state
- contributes to patient_summary() output
Examples:
- demo_app adds "set ekg <lead...>" command
- dashboard renders Electrocardiogram section (rhythm, rate, axis,
lead amplitudes)
- lead parsing and human-readable labels added
Organs:
- export CardiacRhythmState from organs::heart
- minor refactors in heart (dedupe impl placement), bladder and brain
code style cleanups
Tests:
- extend patient_lifecycle with EKG assertions
- add ekg_monitor_tracks_leads to validate lead config and snapshot
No breaking changes.
Revamp the console monitor UI in examples/demo_app.rs with ANSI-colored
sections and improved layout for readability.
- Add color palette, dashboard width, and styling helpers
- Introduce banner, section, and stat line builders
- Colorize prompt, status lines, and organ snapshots
- Display validity tags for measurements and styled warnings/errors
- Restructure output into Simulation, Circulation, Heart, Organ
Snapshots, and Status sections
- Cache TTY color detection via OnceLock and respect NO_COLOR
No API changes; improvements are limited to the example app.
- Heart:
- Raise baseline SVR to 18.5 and derive initial CO/afterload from baseline
- Correct baroreflex direction: SVR increases with sympathetic tone
- Recompute BP via raw diastolic + pulse pressure relationship
- Tighten clamps for physiologic ranges and stabilize resting state
- Add unit test: resting_state_stays_stable
- Bladder:
- Replace steep nonlinear compliance with scaled linear compliance
- Add volume-based abdominal term and nonlinear passive gain
- Reduce active pressure gain and clamp max pressure to 80 cm H2O
- Patient/tests:
- Add multi-organ homeostasis stability integration test (5h sim)
- Assert physiologic bounds across lungs, brain, kidneys, liver,
GI, pancreas, spleen, bladder, esophagus, and spinal cord
- Build/examples:
- Add demo-monitor feature flag and demo_app example
These changes improve physiologic realism and long-run stability while
adding coverage to prevent regressions.