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.
This commit is contained in:
GABRIEL Sebastian 2026-11-12 15:21:34 +01:00
commit c9a5e14567
5 changed files with 153 additions and 9 deletions

View file

@ -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,