| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .. | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| README.md | ||
Patient Monitor Simulation (PaMSim) — v0.4.4
A two-window, Rust/GTK4 patient-monitor simulator for teaching on Fedora Linux.
Synthetic training signals only — not for clinical use. ECG, arterial pressure, plethysmography and capnography are schematic mathematical approximations. The simulation has no clinical validation and is not a medical device.
Build and run on Fedora
sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel
cargo test
cargo run --release
Run these commands from the extracted patient-monitor-simulation folder.
Window titles show the application version. GTK4 requires a functional graphical
session (e.g., Fedora KDE/Wayland).
Windows
Admin sections have a narrow colored stripe on their left edge to match the monitor: ECG green, SpO₂ yellow, invasive arterial pressure red, capnography light grey, NIBP light grey. The Patient section remains neutral. These accents are drawn by GTK and remain visible independently of light/dark themes. This is a visual-only change; control behavior is unchanged.
Admin: Controls patient name; ECG rhythm and rate; mechanical capture; SpO₂, signal quality and sensor connection; invasive arterial pressure, waveform shape and pulse-pressure variation; NIBP; and capnography. Numeric inputs have bidirectionally linked sliders and text fields. Each of the five monitor parameters (ECG, SpO₂/pleth, ART, CO₂, NIBP) has its own Show on monitor checkbox.
Monitor: Black background; ECG green, pleth yellow, ART red and capnogram light grey. The patient name entered in Admin replaces PATIENT MONITOR in the header immediately; leaving the name blank restores the generic title. Long names are automatically resized or clipped to fit the header. Waveforms and vital signs disappear together when their respective visibility checkbox is cleared. Remaining waveform rows expand to use the space. Hiding a display channel does not stop signal generation or physiological coupling: for example, hiding ECG does not stop ART or pleth pulses. NIBP can be hidden independently; this also removes its footer.
The monitor can be resized and toggled fullscreen with F11; Esc exits fullscreen. On Wayland, move the monitor to the presentation screen before activating fullscreen. Fullscreen does not lock down the computer.
Numerical alarm limits (v0.4.0; layout and presets updated in v0.4.1)
Each displayed numeric measurement has an independent optional lower (↓) and
upper (↑) alarm threshold in the corresponding Admin section. The lower
and upper entries are placed in the same row as the corresponding slider.
Derived values with no separate slider (PR, ART MAP, NIBP MAP) have their own
compact alarm rows. The Admin window opens wider to accommodate these controls.
Alarm fields are text inputs; leave a field blank (displayed as off) to disable just
that threshold. With both fields blank, the whole numeric alarm is disabled.
The value may equal either limit without triggering an alarm; only readings
strictly below/above the respective threshold are out of range. If both limits
are present, the lower limit must not exceed the upper limit. Invalid input is
highlighted and the last valid configuration stays active.
| Monitor section | Independently configurable alarms |
|---|---|
| ECG | HR |
| SpO₂ | Oxygen saturation (SpO₂), derived pulse rate (PR) |
| Invasive arterial pressure (ART) | Systolic (SYS), mean (MAP), diastolic (DIA), PPV |
| NIBP | Systolic (SYS), mean (MAP), diastolic (DIA) |
| Capnography | End-tidal CO₂ (EtCO₂), respiratory rate (RR) |
The current limits are displayed in small type at the upper-right corner of
each channel, with an arrow for the corresponding direction. A disabled
boundary is displayed as ---. For instance:
⚠ SYS ↓80 ↑180
MAP ↓60 ↑---
DIA ↓--- ↑---
Alert presets
The Alert presets dropdown at the top of Admin offers Custom (manual) and Adult. Choosing Adult immediately sets all alarm limits and updates the lower/upper text fields alongside the sliders. It changes only alarm limits: it does not change heart rate, blood pressure, channel visibility or any other simulated physiological setting. Editing any alarm field after applying Adult switches the selector to Custom without changing other alarm limits. Select Adult again to reapply the complete preset.
| Parameter | Lower | Upper |
|---|---|---|
| HR (bpm) | 60 | 100 |
| SpO₂ (%) | 90 | --- |
| PR (bpm) | --- | --- |
| ART SYS (mmHg) | 80 | 180 |
| ART MAP (mmHg) | 60 | 100 |
| ART DIA (mmHg) | --- | --- |
| PPV (%) | --- | 10 |
| NIBP SYS (mmHg) | 80 | 180 |
| NIBP MAP (mmHg) | 60 | 100 |
| NIBP DIA (mmHg) | --- | --- |
| EtCO₂ (mmHg) | 30 | 50 |
| RR (/min) | 10 | 20 |
--- denotes a disabled threshold. Adult is a teaching convenience preset,
not a clinically validated set of alarm limits. Initially the selector is
Custom, with all limits disabled (as in v0.4.0).
When a number violates a configured limit, that number flashes by inverting its foreground and background colors (500 ms inverted / 500 ms normal). Each pressure component (SYS, DIA, MAP) and the PPV reading flash independently. The waveform itself remains unchanged. All alarms are disabled by default so old scenarios do not unexpectedly flash.
Numerical threshold alarms only evaluate actual displayed measurements:
--, NO SENSOR, and other unavailable readings do not trigger low-value
alarms. ECG-derived PR and signal visibility continue to work as in v0.3.2.
Alarms are presentation-only: there is no audible alarm, alarm latching,
priority classification or clinical alarm validation. Instructor settings
are held in memory and reset on restart.
Patient name and pulse oximeter signal state (new in v0.3.2)
The new Patient name text field at the top of Admin immediately replaces the monitor headline. It is optional; an empty or whitespace-only name displays PATIENT MONITOR. This is a local teaching label, not a patient record.
Admin → Pulse oximetry has two additional controls:
- Sensor not attached (checkbox): immediately removes the pleth waveform, suppresses SpO₂ and pulse-rate readings, and displays NO SENSOR instead of the numeric saturation. This takes precedence over signal quality.
- Signal quality (dropdown), which changes the visible pleth waveform and quality indicator, independently of the instructor-set SpO₂ percentage:
| Setting | Pleth waveform | Monitor display |
|---|---|---|
| 0 — None | No waveform | Flashing NO READING, PR --; no stars |
| 1 — Poor | Small, irregularly distorted pulse, with temporary losses of signal | 1 star (★) when available; blinking NO READING during loss |
| 2 — Adequate | Medium, smoothly damped pulse | 2 stars (★★) |
| 3 — Good | Full nominal, smoothly damped pulse | 3 stars (★★★) |
Default: sensor attached; signal quality 3 — Good. At levels 1–3, the instructor-set SpO₂ number is shown only when mechanical pulses are detected. In Poor quality, the signal also has intermittent complete dropouts: 30–180 seconds of signal between interruptions, with each interruption lasting 5–20 seconds. During an interruption the pleth trace disappears, SpO₂ and PR are unavailable, and NO READING flashes. Following recovery, the Poor waveform and numerical readings return automatically. These intervals are pseudo-random and driven by simulation time, independent of frame rate; they reset when Poor quality is selected again. The dropout does not affect the actual saturation setting, ECG, derived mechanical pulse generation, or ART. The simulated pulse rate remains derived from captured QRS complexes.
The degraded waveform uses deterministic, smoothly interpolated pseudo-noise that scales only existing pleth pulses: it cannot manufacture pulses during PEA, PVT, ventricular fibrillation or asystole. Unplugging a sensor or selecting quality 0 hides even previously buffered pleth samples immediately. ECG and ART continue unaffected. The Show on monitor checkbox still hides the entire SpO₂ row; sensor/quality controls leave the row visible so the status can be taught.
ECG and mechanical coupling
- ECG rhythms: sinus, atrial fibrillation, monomorphic ventricular tachycardia (potentially perfusing), pulseless ventricular tachycardia (PVT), ventricular fibrillation and asystole.
- Mechanical capture: 1:1, 2:1, 3:1, None (PEA), or deterministic pseudo-random capture (~65%). PR is derived from conducted QRS events, never controlled by a pulse-rate slider.
- A captured QRS leads to an ART upstroke after a schematic 120 ms, and a peripheral pleth pulse after 300 ms. Pleth is strongly damped/filtered.
- VT and PVT selections start with a heart rate of 160 bpm, and update both the HR slider and numeric entry. The instructor may modify this afterward.
- PVT, VF, asystole and PEA suppress mechanical pulses; the ART trace then
drifts smoothly at 0–5 mmHg rather than representing a pulsatile pressure.
The ART SYS number shows the rounded low transducer pressure (0–5 mmHg),
while DIA and MAP show
--because they cannot be reliably estimated. Previous pressure samples scroll out of view. NIBP is a static, separately entered cuff reading.
Invasive arterial pressure and PPV (new in v0.3)
The arterial waveform has a fixed 0–200 mmHg display axis, with tick marks at 0, 50, 100, 150 and 200 mmHg. Nominal ART systolic and diastolic inputs are limited to 0–200 mmHg.
Pulse pressure variation (PPV) is adjustable from 0% to 60%, in 1% increments, via synchronized slider and text field (Admin → Invasive arterial blood pressure). Its default is 0% (no respiratory modulation). The respiratory cycle comes from the same respiratory-rate parameter as the capnogram. RR = 0 disables the respiratory modulation (apnea).
The synthetic PPV definition is:
PPV (%) = 100 × (PPmax − PPmin) / ((PPmax + PPmin) / 2)
The model applies a sinusoidal variation to pulse pressure, sampled for each mechanically conducted beat. The diastolic baseline remains nominally fixed, so this is primarily a beat-to-beat systolic swing, not an arbitrary vertical translation of the entire arterial trace. It does not affect ECG, mechanical capture or pleth amplitude. This is a visual teaching model, not a validated predictor of fluid responsiveness.
Example: ART 120/75 mmHg has nominal pulse pressure 45 mmHg. At PPV 20%, the ideal pulse-pressure extrema are 40.5 and 49.5 mmHg, corresponding to systolic peaks of approximately 115.5 and 124.5 mmHg (assuming the diastolic baseline stays at 75 mmHg). The rendered waveform shape and finite number of beats per respiratory cycle mean the visible maxima may not reach the ideal extrema exactly.
The ART sidebar displays the nominal systolic/diastolic pressures and MAP, plus the configured PPV percentage when PPV is greater than 0. It does not measure PPV from sampled arterial data. At very high nominal systolic pressure, the highest modulated pulses can exceed the 200 mmHg scale; the displayed curve is then clipped at the top, without rescaling the axis.
Display options (new in v0.3)
The five Show on monitor checkboxes affect the presentation only:
| Checkbox | Hidden monitor content |
|---|---|
| ECG | ECG waveform, HR and rhythm alarm (when present) |
| Pulse oximetry | Pleth waveform, SpO₂ and PR |
| Invasive arterial blood pressure | ART waveform, pressure values, MAP and PPV label |
| Capnography | CO₂ waveform, EtCO₂ and RR |
| NIBP | Static cuff pressure values and NIBP footer |
Remaining visible waveforms keep their relative order and receive an equal share of the available area; zero waveform channels is supported.
ECG morphology correction (v0.3.1)
At high heart rates, the previous ECG generator expressed QRS width as a fixed fraction of the R–R interval and sampled at 100 Hz. Narrow R waves could fall between samples, making successive QRS complexes appear to vary dramatically in amplitude despite a regular sinus rhythm.
- Synthetic P/QRS/T components now have widths specified in milliseconds, not fixed fractions of the cardiac cycle. P/T positioning and widths adapt to the R–R interval, while the QRS width remains essentially constant.
- Sampling increased to 250 Hz (4 ms intervals) to capture QRS peaks more consistently, including at 189–240 bpm.
- The ECG morphology remains independent of the respiratory arterial PPV setting. The arterial and pleth delays and mechanical capture options are unchanged.
- Regression tests compare peak heights at 60, 75, 120, 189 and 240 bpm, and verify that changing PPV does not affect the ECG signal.
The ECG remains a schematic educational signal; no voltage calibration, lead placement model, diagnostic criteria, or patient-specific physiology are simulated.
Signal implementation
- 250 Hz synthetic signal samples, 10 s retained history, 8 s scrolling trace.
- Cairo draws into the GTK4
DrawingAreaand scales with the window. - A conducted QRS records its own respiratory PPV multiplier at event time. The arterial pulse thus retains the same amplitude throughout the beat.
- Varying PPV does not alter the peripheral pleth pulse or the number of mechanical pulses.
- Clinical accuracy, dynamic NIBP measurements, alarms, artifacts, calibration, precise waveform timing, and patient physiology are outside this prototype.
Project layout
src/
main.rs GTK application entry point
model.rs Parameters, rhythm/capture settings, display flags
simulation.rs QRS-timed mechanical signals, PPV and respiratory synthesis
render.rs Cairo monitor layout, dynamic visibility, fixed ART axis
ui.rs Admin controls and monitor window
Changes since v0.2.2
- Respiratory PPV with a 0–60% instructor setting, coupled to the simulated respiratory cycle and applied per arterial beat.
- Five independent display visibility toggles, dynamic waveform row layout, and independent NIBP-footer hiding.
- ART axis reduced from 0–250 to 0–200 mmHg, with inputs adjusted to the new range.
- Added regression tests for PPV arithmetic and its effects on ART, for hiding ECG while retaining mechanical pulses, for active channel selection, and for arterial-axis normalization.
Verification: The archive is generated from these sources. Run cargo test
locally to verify the Rust/GTK build; Rust and GTK4 development components
were not available in the environment where this ZIP was prepared.
Changes in v0.3.2
- Added live patient-name header in Admin/Monitor with blank-name fallback.
- Added four levels of SpO₂ signal quality, quality stars and an irregular, low-amplitude pleth waveform for Poor quality.
- Added Sensor not attached with
NO SENSORstatus and suppression of saturation, pulse rate and pleth waveform. - Added tests for signal-quality scaling, displayed readings and disconnected sensor behavior.
Build verification: ZIP integrity and patch application were checked.
The GTK4 application and Rust tests were not compiled in the packaging
environment; run cargo test and cargo run --release on Fedora.
v0.4.2 — Rhythm, sensor and missing-reading alarms
- VT remains potentially perfusing. The new PVT (pulseless ventricular tachycardia) rhythm retains organized broad QRS complexes but produces no arterial/pleth pulses. VF and asystole are also pulseless regardless of capture selection.
- ECG: a flashing ARRHYTHMIA message for VT, PVT and VF; a flashing ASYSTOLE message for asystole. These event alarms do not depend on numerical HR limits.
- SpO₂: when the probe is disconnected, a flashing NO SENSOR replaces the saturation reading. Quality 0, loss of mechanical capture or a pulseless rhythm results in flashing NO READING (no numerical SpO₂/PR). Sensor disconnection takes precedence. No pleth waveform is displayed in these conditions.
- ART: without mechanical pulses (including PVT/VF/asystole/PEA), the simulated invasive pressure line has slow non-pulsatile drift between 0 and 5 mmHg. In v0.4.2, the numeric display showed
--/--; v0.4.3 changes this to a rounded measured SYS of 0–5 mmHg, with--for DIA and MAP. - ECG rhythm name has been removed from the monitor; only HR and the associated alarm message, when present, are visible. The instructor continues to select the rhythm in Admin.
- Numerical alarm thresholds and the Adult preset from v0.4.1 are unchanged. Synthetic demonstration behavior only; not suitable for clinical decisions.
v0.4.3 — Low arterial pressure, VT rate preset and intermittent Poor SpO₂
- Pulseless rhythms, PEA or otherwise absent mechanical capture: invasive SYS
reports the current measured 0–5 mmHg pressure, e.g.
3/--withMAP -- mmHg. Only SYS is tested against configured ART SYS limits; no spurious MAP/DIA threshold alarms are generated from missing readings. - Selecting VT or PVT in Admin sets HR to 160 bpm and updates the associated slider and text field. Subsequent manual rate changes are allowed. Perfusing VT still produces QRS-linked pulses subject to capture settings; PVT remains pulseless.
- Poor (★) SpO₂ signal periodically changes to NO READING for a pseudo-random 5–20 seconds, after a pseudo-random 30–180 seconds of usable low-quality signal. The technical alarm blinks, SpO₂/PR readings are suppressed, and the pleth waveform is absent. On recovery it resumes at Poor quality. The simulated signal history retains visible gaps for outages. Choosing another signal quality immediately clears the intermittent outage.
- No changes to Adult alarm presets, alarm limit ordering, or the 0–200 mmHg arterial scale. All behavior is synthetic and intended for teaching only.