# Patient Monitor Simulation (PaMSim) — v0.4.1 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 ```bash 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:** 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: ```text ⚠ 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 | SpO₂ `--`, PR `--`, **NO SIGNAL**; no stars | | **1 — Poor** | Small, irregularly amplitude-distorted pulse | 1 star (★) | | **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. The signal quality does **not** randomly alter that number: it affects the pleth morphology and the quality indicator only. The simulated pulse rate remains derived from mechanically captured QRS complexes. The degraded waveform uses deterministic, smoothly interpolated pseudo-noise that scales only existing pleth pulses: it cannot manufacture pulses during PEA, 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, 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. - VF, asystole and PEA suppress mechanical pulses; old 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: ```text 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 label | | 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 `DrawingArea` and 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 ```text 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 1. Respiratory PPV with a 0–60% instructor setting, coupled to the simulated respiratory cycle and applied **per arterial beat**. 2. Five independent display visibility toggles, dynamic waveform row layout, and independent NIBP-footer hiding. 3. ART axis reduced from **0–250** to **0–200 mmHg**, with inputs adjusted to the new range. 4. 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 1. Added live patient-name header in Admin/Monitor with blank-name fallback. 2. Added four levels of SpO₂ signal quality, quality stars and an irregular, low-amplitude pleth waveform for Poor quality. 3. Added **Sensor not attached** with `NO SENSOR` status and suppression of saturation, pulse rate and pleth waveform. 4. 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.