From 2c0dc760d976cbb3bde9937b4e409b254da29d0d Mon Sep 17 00:00:00 2001 From: GABRIEL Sebastian Date: Thu, 12 Nov 2026 22:49:12 +0100 Subject: [PATCH] v0.6.7: fix: Smooth HR transitions --- ...-monitor-simulation-v0.6.6-to-v0.6.7.patch | 189 ++++++++++++++++++ patient-monitor-simulation/Cargo.lock | 2 +- patient-monitor-simulation/Cargo.toml | 2 +- patient-monitor-simulation/README.de.md | 13 +- patient-monitor-simulation/README.de.md.orig | 45 ++++- patient-monitor-simulation/README.de.md.rej | 19 +- patient-monitor-simulation/README.md | 14 +- patient-monitor-simulation/src/simulation.rs | 65 ++++-- 8 files changed, 311 insertions(+), 38 deletions(-) create mode 100644 patient-monitor-simulation-v0.6.6-to-v0.6.7.patch diff --git a/patient-monitor-simulation-v0.6.6-to-v0.6.7.patch b/patient-monitor-simulation-v0.6.6-to-v0.6.7.patch new file mode 100644 index 0000000..e2fbc1e --- /dev/null +++ b/patient-monitor-simulation-v0.6.6-to-v0.6.7.patch @@ -0,0 +1,189 @@ +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, // captured QRS with respiratory beat amplitude +- rate_qrs: VecDeque, // captured beats for measured PR; reset after rate changes ++ rate_qrs: VecDeque, // captured beats for measured PR; rolling history smooths HR changes + audio_events: VecDeque, // 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(); diff --git a/patient-monitor-simulation/Cargo.lock b/patient-monitor-simulation/Cargo.lock index 9b61a68..a77fee9 100644 --- a/patient-monitor-simulation/Cargo.lock +++ b/patient-monitor-simulation/Cargo.lock @@ -438,7 +438,7 @@ dependencies = [ [[package]] name = "patient-monitor-simulation" -version = "0.6.6" +version = "0.6.7" dependencies = [ "gtk4", ] diff --git a/patient-monitor-simulation/Cargo.toml b/patient-monitor-simulation/Cargo.toml index f3abff3..eda3ddf 100644 --- a/patient-monitor-simulation/Cargo.toml +++ b/patient-monitor-simulation/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/patient-monitor-simulation/README.de.md b/patient-monitor-simulation/README.de.md index ff063ce..e3fdb3e 100644 --- a/patient-monitor-simulation/README.de.md +++ b/patient-monitor-simulation/README.de.md @@ -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 @@ -172,7 +183,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/patient-monitor-simulation/README.de.md.orig b/patient-monitor-simulation/README.de.md.orig index 8d65b6b..ff063ce 100644 --- a/patient-monitor-simulation/README.de.md.orig +++ b/patient-monitor-simulation/README.de.md.orig @@ -172,7 +172,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 (aktualisiert v0.6.5) +## Akustische Alarme und QRS-Ton (aktualisiert v0.6.6) Die akustische Alarmierung ist **standardmäßig eingeschaltet**. Im Admin-Fenster lässt sie sich mit **Audible alarms** aktivieren bzw. stummschalten. @@ -185,9 +185,10 @@ werden. Die optischen Alarme blinken bei stummgeschalteter Tonausgabe weiterhin. - **Numerische und technische Alarme:** Grenzwertüberschreitungen sowie **NO SENSOR** und **NO READING** lösen ebenfalls einen **Zweitonalarm** aus (700 Hz gefolgt von 950 Hz), der ungefähr alle 2,5 Sekunden wiederholt wird. -- Zwischen beiden Tönen liegt jeweils eine kurze Pause. Ein einzelner - **QRS-Piepton** ist für eine spätere Version vorgesehen und wird derzeit - noch nicht ausgegeben. +- Zwischen beiden Tönen liegt jeweils eine kurze Pause. Zusätzlich gibt es + einen separaten, kurzen **QRS-/Pulston**, der im Admin-Fenster über + **QRS tone** unabhängig von **Audible alarms** ein- und ausgeschaltet wird + (standardmäßig eingeschaltet). - Kritische Alarme haben Vorrang. Auch bei mehreren gleichzeitig aktiven Alarmen wird nur eine Tonfolge ausgegeben. Bei behobenem Alarm oder Stummschaltung verstummt die Ausgabe. Ausgeblendete Monitorbereiche @@ -197,6 +198,42 @@ werden. Die optischen Alarme blinken bei stummgeschalteter Tonausgabe weiterhin. selbst ist kein Alarm. Die Audioausgabe wird unabhängig von der Darstellung der Kurven verarbeitet. +### Synchroner QRS-/Pulston + +**QRS tone** ist unabhängig von **Audible alarms** schaltbar. Jeder kurze +Piepton (85 ms) wird durch ein tatsächliches simuliertes elektrisches oder +mechanisches Ereignis ausgelöst, nicht durch einen eigenen Taktgeber: + +- **SpO₂-Messwert vorhanden:** Auslösung beim verzögerten Pleth-Puls. + Die Frequenz richtet sich nach der angezeigten Sauerstoffsättigung. + Nicht übergeleitete mechanische Pulse erzeugen keinen Pleth-Piepton. +- **Kein SpO₂-Messwert:** fester Ton mit **500 Hz** bei einem sichtbaren, + organisierten EKG-QRS; andernfalls bei einem dargestellten arteriellen + Pulsschlag. Bei gleichzeitig sichtbarem EKG und ART wird ein Herzschlag + nicht doppelt vertont. +- **Kammerflimmern/Asystolie ohne wirksame Herzdruckmassage:** kein + Pulston. Bei Herzdruckmassage können ART-Pulse einen 500-Hz-Ton auslösen; + bei guter Kompressionsqualität und gültigem SpO₂-Messwert wird die + sättigungsabhängige Tonhöhe verwendet. + +| SpO₂ (%) | Frequenz (Hz) | +| --- | ---: | +| 97–100 | 740 | +| 94–96 | 675 | +| 90–93 | 609 | +| 80–89 | 544 | +| 70–79 | 479 | +| 60–69 | 413 | +| 50–59 | 348 | +| 40–49 | 283 | +| 30–39 | 218 | +| 20–29 | 152 | +| 0–19 | 87 | + +Die Frequenzen sind ausschließlich didaktische Simulationen, keine +kalibrierten Töne eines klinischen Pulsoxymeters. QRS-/Pulston und +Zweitonalarm können unabhängig voneinander erklingen. + Unter Fedora wird **`pw-play`** aus dem Paket `pipewire-utils` verwendet, alternativ **`paplay`**. Es sind weder zusätzliche Rust-Bibliotheken noch mitzuliefernde Audiodateien notwendig: Das Programm erzeugt seine WAV-Töne diff --git a/patient-monitor-simulation/README.de.md.rej b/patient-monitor-simulation/README.de.md.rej index b8a9295..f657f5a 100644 --- a/patient-monitor-simulation/README.de.md.rej +++ b/patient-monitor-simulation/README.de.md.rej @@ -1,23 +1,8 @@ --- README.de.md +++ README.de.md @@ -1,4 +1,4 @@ --# Patient Monitor Simulation (PaMSim) — v0.6.5 -+# Patient Monitor Simulation (PaMSim) — v0.6.6 +-# 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. -@@ -669,3 +706,14 @@ Die Priorisierung und die Wiederholungsintervalle bleiben unverändert. - **Test tone** spielt den Standard-Zweitonalarm. Ein einzelner QRS-Piepton - ist für eine spätere Erweiterung reserviert. Optische Alarme und - Simulationsverhalten wurden nicht verändert. -+ -+ -+### v0.6.6 – Schaltbarer QRS-/Pulston -+ -+Ein neuer Admin-Schalter **QRS tone** aktiviert oder deaktiviert den -+kurzen, beat-synchronen Einzelton unabhängig von den Zweitonalarmen. -+Bei vorhandenem SpO₂-Messwert richtet sich die Tonhöhe in elf Stufen -+zwischen 740 und 87 Hz nach der Sauerstoffsättigung; ohne SpO₂-Messwert -+erfolgt bei EKG-QRS oder arteriellem Puls ein 500-Hz-Ton. Die bisherigen -+Zweitonalarme bleiben unverändert. Zusätzliche Tests prüfen die -+Frequenzbereiche, Ereigniszuordnung und WAV-Ausgabe. diff --git a/patient-monitor-simulation/README.md b/patient-monitor-simulation/README.md index 250b938..793a3d4 100644 --- a/patient-monitor-simulation/README.md +++ b/patient-monitor-simulation/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/patient-monitor-simulation/src/simulation.rs b/patient-monitor-simulation/src/simulation.rs index ec88a5a..800293f 100644 --- a/patient-monitor-simulation/src/simulation.rs +++ b/patient-monitor-simulation/src/simulation.rs @@ -197,12 +197,11 @@ pub struct Simulator { respiratory_phase: f64, ecg_beat_number: u64, conducted_qrs: VecDeque, // captured QRS with respiratory beat amplitude - rate_qrs: VecDeque, // captured beats for measured PR; reset after rate changes + rate_qrs: VecDeque, // captured beats for measured PR; rolling history smooths HR changes audio_events: VecDeque, // 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();