7 Commits

Author SHA1 Message Date
zack3d 31a0b8a485 feat(ffi): add bloodstream and bladder metrics API
Multi-Platform CI / test-platforms (ubuntu-22.04) (push) Successful in 18s
Multi-Platform CI / test-platforms (windows-latest) (push) Successful in 18s
Multi-Platform CI / Package for Linux x86_64 (push) Has been skipped
Multi-Platform CI / Package for Windows x86_64 (push) Has been skipped
Multi-Platform CI / Create GitHub Release (push) Has been skipped
- add C FFI enums MLBladderPhase, MLMetabolicState, MLPerfusionState
- add C FFI structs MLBloodstreamMetrics and MLBladderMetrics
- add ml_patient_bloodstream_metrics and ml_patient_bladder_metrics
  to populate metrics for a patient (mirrored in src/ffi.rs)
- update examples/c/ffi_example.c to print new metrics
- add tests for FFI metrics (tests/ffi.rs)

organ model expansions
- bloodstream: add metrics() snapshot and detailed physiology:
  plasma proteins/oncotic pressure, lymph return, RBC cohort tracking,
  erythropoiesis/clearance with HIF, iron/folate/B12 stores, platelets,
  coagulation/fibrinolysis, immune cell counts, complement, acid–base
- bladder: introduce adaptive compliance, reflex gating, cortical/voluntary
  modulators, safety indices; add metrics(), summary, and unit tests
- brain: add homeostatic drives (respiratory, thirst, hunger, thermo, pain),
  brainstem nuclei (NTS/RVLM/CVLM, nAmb/DMV, RTN), sleep cycle timing,
  cerebrovascular autoregulation; wire drives into autonomic control
- heart: add phase-based cycle (valves and atria), conduction system,
  RAAS regulation, improved coronary perfusion
- intestines: add micronutrient absorption feeding erythropoiesis

patient coupling
- expose Patient::bloodstream_metrics() and ::bladder_metrics()
- integrate new organ signals (kidney osmolality, spleen culling, liver
  proteins) and brain–lung/continence control pathways
- re-export BladderMetrics and BloodstreamMetrics in lib.rs

note
- existing FFI remains compatible; this is a surface addition
- ffi/medicallib.h kept in sync with src/ffi.rs
2025-09-30 02:38:27 -07:00
zack3d 5cf6bbda48 feat(organs): add bloodstream organ and patient coupling
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.
2025-09-28 16:10:23 -07:00
zack3d a74f9c408b feat(patient): add EKG monitor with configurable leads
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.
2025-09-26 01:01:46 -07:00
zack3d a7638c411a feat(examples): add colorized dashboard to demo
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.
2025-09-24 03:06:22 -07:00
zack3d 886484919d feat(organs): retune heart and bladder dynamics
- 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.
2025-09-24 02:55:29 -07:00
zack3d 3fc010301d dez
Quick CI / quick-test (push) Failing after 1m12s
Multi-Platform CI / test-platforms (ubuntu-22.04) (push) Successful in 7m13s
Multi-Platform CI / test-platforms (windows-latest) (push) Successful in 7m8s
Multi-Platform CI / package (ubuntu-22.04) (push) Failing after 7m12s
Multi-Platform CI / package (windows-latest) (push) Failing after 7m13s
2025-09-22 00:24:27 -07:00
zack3d 0502c756c1 init 2025-09-21 02:14:44 -07:00