SimPaM/patches/patient-monitor-simulation-v0.6.6-to-v0.6.7.patch

189 lines
8.6 KiB
Diff
Raw Normal View History

2026-11-12 22:49:12 +01:00
diff --git a/Cargo.toml b/Cargo.toml
index f3abff3..eda3ddf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "patient-monitor-simulation"
-version = "0.6.6"
+version = "0.6.7"
edition = "2021"
license = "MIT"
description = "Synthetic patient-monitor simulation for teaching (not for clinical use)"
diff --git a/README.de.md b/README.de.md
index 605a34f..17890f5 100644
--- a/README.de.md
+++ b/README.de.md
@@ -1,4 +1,4 @@
-# Patient Monitor Simulation (PaMSim) — v0.6.6
+# Patient Monitor Simulation (PaMSim) — v0.6.7
Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenstern für die Lehre unter Fedora Linux.
@@ -6,6 +6,17 @@ Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenst
> EKG, invasive arterielle Druckkurve, Plethysmogramm und Kapnogramm sind schematische mathematische Annäherungen.
> Die Simulation wurde nicht klinisch validiert und ist kein Medizinprodukt.
+## Stufenlose Herzfrequenzänderung (v0.6.7)
+
+Bei Änderungen der Herzfrequenz bleibt die Historie der zuletzt *mechanisch
+wirksamen* Herzschläge erhalten. Die angezeigte Pulsfrequenz passt sich über
+den gleitenden Mittelwert der letzten drei Pulsintervalle an, ohne
+zwischenzeitlich zu verschwinden. SpO₂-Wert, Plethysmogramm und
+sättigungsabhängiger Pulston bleiben bei gewöhnlichen Änderungen der
+Herzfrequenz erhalten. Ein tatsächlicher Verlust der mechanischen
+Pulsüberleitung, ein abgesteckter Sensor und wirkliche Signalausfälle lösen
+weiterhin unmittelbar die vorgesehenen Alarme aus.
+
## Monitoraufteilung (v0.5.7)
Der nutzbare Monitorbereich wird in einem festen Verhältnis von **75 % für die
@@ -175,7 +186,7 @@ Mit **F11** wird der Vollbildmodus aktiviert bzw. umgeschaltet, mit **Esc** wird
Unter Wayland sollte das Fenster vor dem Wechsel in den Vollbildmodus auf den gewünschten Präsentationsbildschirm verschoben werden.
Der Vollbildmodus sperrt den Computer nicht gegen andere Eingaben.
-## Akustische Alarme und QRS-Ton (aktualisiert v0.6.6)
+## Akustische Alarme und QRS-Ton (aktualisiert v0.6.7)
Die akustische Alarmierung ist **standardmäßig eingeschaltet**. Im
Admin-Fenster lässt sie sich mit **Audible alarms** aktivieren bzw. stummschalten.
diff --git a/README.md b/README.md
index 250b938..793a3d4 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Patient Monitor Simulation (PaMSim) — v0.6.6
+# Patient Monitor Simulation (PaMSim) — v0.6.7
A Rust/GTK4 patient-monitor simulator with two main windows for teaching on Fedora Linux.
@@ -6,6 +6,16 @@ A Rust/GTK4 patient-monitor simulator with two main windows for teaching on Fedo
> plethysmography and capnography are schematic mathematical approximations. The
> simulation has no clinical validation and is not a medical device.
+## Smooth HR transitions (v0.6.7)
+
+Changing the HR slider now preserves the recent history of *mechanically
+captured* beats. PR converges to the new rate using the existing rolling
+three-interval average instead of temporarily disappearing. The SpO₂ value,
+plethysmography and saturation-dependent QRS tone remain available during
+ordinary HR adjustments. Actual loss of mechanical capture, disconnected
+sensors, deliberate signal dropout and low-quality/absent signals still
+produce their intended alarms immediately.
+
## Monitor layout (v0.5.7)
The monitor uses a fixed **3:1 column ratio** over the drawable area:
@@ -166,7 +176,7 @@ 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.
-## Audible alarms and QRS tone (updated v0.6.6)
+## Audible alarms and QRS tone (updated v0.6.7)
Sound is **enabled by default**. The Admin window has an **Audible alarms**
checkbox for muting and a **Test tone** button (works even while muted).
diff --git a/src/simulation.rs b/src/simulation.rs
index ec88a5a..800293f 100644
--- a/src/simulation.rs
+++ b/src/simulation.rs
@@ -197,12 +197,11 @@ pub struct Simulator {
respiratory_phase: f64,
ecg_beat_number: u64,
conducted_qrs: VecDeque<ConductedBeat>, // captured QRS with respiratory beat amplitude
- rate_qrs: VecDeque<f64>, // captured beats for measured PR; reset after rate changes
+ rate_qrs: VecDeque<f64>, // captured beats for measured PR; rolling history smooths HR changes
audio_events: VecDeque<BeatEvent>, // consumed by the 100-ms UI audio timer
filtered_pleth: f64,
previous_rhythm: EcgRhythm,
previous_conduction: PulseConduction,
- previous_heart_rate: i32,
poor_signal_outages: PoorSignalOutages,
compressions: ChestCompressions,
nibp: NibpMachine,
@@ -224,7 +223,6 @@ impl Simulator {
filtered_pleth: 0.0,
previous_rhythm: params.ecg_rhythm,
previous_conduction: params.pulse_conduction,
- previous_heart_rate: params.heart_rate,
poor_signal_outages: PoorSignalOutages::new(),
compressions: ChestCompressions::new(),
nibp: NibpMachine::new(),
@@ -427,12 +425,12 @@ impl Simulator {
self.previous_rhythm = params.ecg_rhythm;
self.previous_conduction = params.pulse_conduction;
}
- if params.heart_rate != self.previous_heart_rate {
- // Old captured events remain in the *waveforms* until they pass.
- // They must not bias the pulse rate after an HR slider change.
- self.rate_qrs.clear();
- self.previous_heart_rate = params.heart_rate;
- }
+ // Keep recent mechanically captured beats when only HR changes.
+ // The rolling three-interval PR calculation then converges naturally
+ // to the new rate as new pulses arrive. Clearing this history on every
+ // slider update would briefly make PR unavailable and falsely trigger
+ // SpO2 NO READING, even though perfusion and the sensor are intact.
+ // Actual loss of capture is still handled above, immediately.
// Respiratory phase drives both the capnogram and arterial PPV.
let respiratory_rate = params.respiratory_rate.max(0) as f64 / 60.0;
@@ -1181,12 +1179,55 @@ mod tests {
assert_eq!(sim.pulse_rate(), Some(75));
p.heart_rate = 189;
sim.step(&p);
- // No old 75 bpm PR is displayed while the new beat interval is measured.
- assert_eq!(sim.pulse_rate(), None);
- for _ in 0..200 { sim.step(&p); }
+ // A new HR must not invalidate existing mechanical pulse history.
+ // The displayed PR is smoothed from actual conducted QRS intervals.
+ assert_eq!(sim.pulse_rate(), Some(75));
+ assert_eq!(sim.spo2_status(&p), Spo2Status::Available);
+ for _ in 0..800 {
+ sim.step(&p);
+ assert!(sim.pulse_rate().is_some(), "PR must remain available");
+ assert_eq!(sim.spo2_status(&p), Spo2Status::Available);
+ assert!(sim.samples.back().unwrap().pleth_valid,
+ "no artificial gap in the pleth trace during HR adjustment");
+ }
assert_eq!(sim.pulse_rate(), Some(189));
}
+ #[test]
+ fn repeated_heart_rate_slider_moves_do_not_trigger_spo2_no_reading() {
+ let mut p = Parameters::default();
+ let mut sim = Simulator::new(&p);
+ for rate in [90, 105, 120, 140, 110, 80, 75] {
+ p.heart_rate = rate;
+ for _ in 0..40 { // only 160 ms between successive slider updates
+ sim.step(&p);
+ assert!(sim.pulse_rate().is_some());
+ assert_eq!(sim.spo2_status(&p), Spo2Status::Available);
+ assert!(sim.samples.back().unwrap().pleth_valid);
+ }
+ }
+ }
+
+ #[test]
+ fn conducted_two_to_one_pulses_remain_available_during_hr_change() {
+ let mut p = Parameters { pulse_conduction: PulseConduction::TwoToOne,
+ ..Parameters::default() };
+ let mut sim = Simulator::new(&p);
+ assert_eq!(sim.pulse_rate(), Some(38));
+ p.heart_rate = 150;
+ for _ in 0..1200 {
+ sim.step(&p);
+ assert!(sim.pulse_rate().is_some());
+ assert_eq!(sim.spo2_status(&p), Spo2Status::Available);
+ }
+ assert_eq!(sim.pulse_rate(), Some(75));
+ // Genuine mechanical capture loss still produces NO READING immediately.
+ p.pulse_conduction = PulseConduction::None;
+ sim.step(&p);
+ assert_eq!(sim.pulse_rate(), None);
+ assert_eq!(sim.spo2_status(&p), Spo2Status::NoReading);
+ }
+
#[test]
fn new_rate_respects_two_to_one_mechanical_capture() {
let mut p = Parameters::default();