SimPaM/patches/PaMSim-0.5.5-to-0.5.6-retry.patch

106 lines
5.4 KiB
Diff
Raw Permalink Normal View History

diff --git a/Cargo.toml b/Cargo.toml
index 35b29c9..13195d0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "patient-monitor-simulation"
-version = "0.5.5"
+version = "0.5.6"
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 f69dacf..4082c89 100644
--- a/README.de.md
+++ b/README.de.md
@@ -474,3 +474,8 @@ Das Messverhalten und die Alarmfunktionen bleiben unverändert.
### v0.5.5 – Korrektur der CPR-Plethysmographie
Die verzögerte Plethysmographiekurve bei Thoraxkompressionen überlappt nicht mehr mit der nächsten Kompression. Der Regressionstest gibt bei einem Fehlschlag die maximale gültige Kurvenamplitude aus. Sonstige Simulationseinstellungen bleiben unverändert.
+
+
+### v0.5.6 – Persistenz des Pleth-Filters bei Thoraxkompressionen
+
+Die eigentliche Ursache des Testfehlers aus v0.5.5 wurde behoben: Bei pulslosen Rhythmen wurde der Pleth-Tiefpassfilter bislang mit jedem 250-Hz-Abtastwert zurückgesetzt. Während qualitativ guter Thoraxkompressionen bleibt der Filterzustand nun erhalten; QRS-getriggerte mechanische Pulse werden weiterhin verworfen. Nach dem Beenden der Kompressionen bei VF/PVT verschwindet das Pleth-Signal sofort. Ein zusätzlicher Regressionstest deckt PVT ab.
diff --git a/README.md b/README.md
index 09f8506..dc19c84 100644
--- a/README.md
+++ b/README.md
@@ -495,3 +495,8 @@ No NIBP measurement logic or alarm behavior was changed.
### v0.5.5 — CPR plethysmography correction
The delayed CPR pleth waveform no longer wraps its trailing portion into the next compression. The regression test now reports the maximum valid waveform amplitude when failing. No other simulation controls were changed.
+
+
+### v0.5.6 — CPR pleth filter persistence
+
+Corrects the underlying cause of the v0.5.5 test failure: in pulseless rhythms, the simulation had reset the pleth low-pass filter at every 250 Hz sample, preventing CPR-induced signals from accumulating. The filter now persists during good-quality chest compressions while QRS-triggered mechanical pulses are still cleared. Stopping CPR in VF/PVT immediately restores no reading. Additional regression coverage includes PVT.
diff --git a/src/simulation.rs b/src/simulation.rs
index fddf191..e947f69 100644
--- a/src/simulation.rs
+++ b/src/simulation.rs
@@ -361,16 +361,25 @@ impl Simulator {
let start_quality = self.nibp_start_quality(params);
self.nibp.update(self.time, params, start_quality);
- if params.ecg_rhythm != self.previous_rhythm
- || params.pulse_conduction != self.previous_conduction
- || !params.ecg_rhythm.can_generate_pulse()
+ let capture_changed = params.ecg_rhythm != self.previous_rhythm
+ || params.pulse_conduction != self.previous_conduction;
+ let no_intrinsic_pulse = !params.ecg_rhythm.can_generate_pulse()
|| params.pulse_conduction == PulseConduction::None
- || params.heart_rate <= 0
- {
- // A rhythm/capture change terminates previously queued mechanical events.
+ || params.heart_rate <= 0;
+ if capture_changed || no_intrinsic_pulse {
+ // Cancel stale QRS-triggered pulses immediately when capture is lost.
self.conducted_qrs.clear();
self.rate_qrs.clear();
- self.filtered_pleth = 0.0;
+ // VF/PVT/asystole/PEA remain pulseless without effective CPR.
+ // During Good CPR, however, keep the filter history so the
+ // compression-driven pleth can build up over multiple 4 ms steps.
+ // Reset once on a rhythm/capture transition, never on *every*
+ // sample merely because the underlying rhythm is pulseless.
+ let cpr_produces_pleth = params.chest_compressions_active
+ && params.chest_compression_quality == ChestCompressionQuality::Good;
+ if capture_changed || !cpr_produces_pleth {
+ self.filtered_pleth = 0.0;
+ }
self.previous_rhythm = params.ecg_rhythm;
self.previous_conduction = params.pulse_conduction;
}
@@ -762,6 +771,30 @@ mod tests {
assert!(recent.iter().all(|s| s.pleth_quality == Spo2Quality::Poor));
}
+ #[test]
+ fn pleth_filter_accumulates_during_good_cpr_but_clears_when_stopped() {
+ let mut p = Parameters {
+ ecg_rhythm: EcgRhythm::PulselessVentricularTachycardia,
+ chest_compressions_active: true,
+ chest_compression_quality: ChestCompressionQuality::Good,
+ spo2_quality: Spo2Quality::None,
+ ..Parameters::default()
+ };
+ let mut sim = Simulator::new(&p);
+ for _ in 0..500 { sim.step(&p); }
+ let max_valid_pleth = sim.samples.iter().rev().take(500)
+ .filter(|s| s.pleth_valid).map(|s| s.pleth)
+ .fold(0.0_f64, f64::max);
+ assert!(max_valid_pleth > 0.05,
+ "PVT with good CPR must accumulate pleth across samples: {max_valid_pleth:.4}");
+
+ p.chest_compressions_active = false;
+ sim.step(&p);
+ let after_stop = sim.samples.back().unwrap();
+ assert!(!after_stop.pleth_valid);
+ assert_eq!(after_stop.pleth, 0.0);
+ }
+
#[test]
fn only_good_cpr_shows_pleth_and_sensor_disconnect_takes_precedence() {
for quality in [ChestCompressionQuality::Adequate,