v0.4.3: Debug and optimize alarms and rhythms
This commit is contained in:
parent
5e397019fc
commit
d4162c49e8
8 changed files with 995 additions and 54 deletions
|
|
@ -105,8 +105,9 @@ fn pleth_trace_enabled(p: &Parameters) -> bool {
|
|||
p.spo2_sensor_attached && p.spo2_quality != Spo2Quality::None
|
||||
}
|
||||
|
||||
fn spo2_vitals(p: &Parameters, pulse_rate: Option<i32>) -> (String, String, String) {
|
||||
match p.spo2_status(pulse_rate) {
|
||||
fn spo2_vitals(p: &Parameters, pulse_rate: Option<i32>, signal_lost: bool)
|
||||
-> (String, String, String) {
|
||||
match p.spo2_status_during(pulse_rate, signal_lost) {
|
||||
Spo2Status::NoSensor => (
|
||||
"SpO₂".to_owned(), "NO SENSOR".to_owned(), "PR -- bpm".to_owned()),
|
||||
Spo2Status::NoReading => (
|
||||
|
|
@ -143,7 +144,7 @@ fn draw_vitals(cr: &Context, ch: Channel, color: Color, x: f64,
|
|||
let ecg_hr = if p.ecg_rhythm.has_qrs() && p.heart_rate > 0 {
|
||||
Some(p.heart_rate)
|
||||
} else { None };
|
||||
let spo2_status = p.spo2_status(pulse_rate);
|
||||
let spo2_status = p.spo2_status_during(pulse_rate, sim.poor_signal_lost());
|
||||
let oxygen = if spo2_status == Spo2Status::Available { Some(p.spo2) } else { None };
|
||||
let art_map = mean_arterial_pressure(p.art_systolic, p.art_diastolic);
|
||||
|
||||
|
|
@ -173,7 +174,7 @@ fn draw_vitals(cr: &Context, ch: Channel, color: Color, x: f64,
|
|||
}
|
||||
}
|
||||
Channel::Pleth => {
|
||||
let (label, value, info) = spo2_vitals(p, pulse_rate);
|
||||
let (label, value, info) = spo2_vitals(p, pulse_rate, sim.poor_signal_lost());
|
||||
text(cr, &label, x, top + row_h * 0.24, label_size, color, false);
|
||||
let technical_alarm = spo2_status != Spo2Status::Available;
|
||||
let value_size = if technical_alarm {
|
||||
|
|
@ -212,8 +213,14 @@ fn draw_vitals(cr: &Context, ch: Channel, color: Color, x: f64,
|
|||
alarmed(p.alarms.art_map, Some(art_map)), flash);
|
||||
}
|
||||
} else {
|
||||
draw_alarm_number(cr, "--/--", x, value_y, number_size * 0.78,
|
||||
width, color, false, flash);
|
||||
// Without mechanical activity the transducer still reads the
|
||||
// slowly drifting 0..5 mmHg pressure. DIA/MAP are indeterminate.
|
||||
let pulseless = !has_capture;
|
||||
let sys = if pulseless { sim.measured_art_pressure() } else { None };
|
||||
let displayed_sys = sys.map_or_else(|| "--".to_owned(), |v| v.to_string());
|
||||
draw_pressure_components(cr, &displayed_sys, "--", x, value_y,
|
||||
number_size * 0.78, width, color,
|
||||
alarmed(p.alarms.art_sys, sys), false, flash);
|
||||
text(cr, "MAP -- mmHg", x, info_y, sub_size, color, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -270,17 +277,24 @@ fn draw_pressure_value(cr: &Context, systolic: i32, diastolic: i32,
|
|||
x: f64, baseline: f64, nominal_size: f64,
|
||||
available_width: f64, color: Color,
|
||||
sys_alarm: bool, dia_alarm: bool, flash: bool) {
|
||||
let sys = systolic.to_string();
|
||||
let dia = diastolic.to_string();
|
||||
draw_pressure_components(cr, &systolic.to_string(), &diastolic.to_string(),
|
||||
x, baseline, nominal_size, available_width, color, sys_alarm, dia_alarm, flash);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn draw_pressure_components(cr: &Context, sys: &str, dia: &str,
|
||||
x: f64, baseline: f64, nominal_size: f64,
|
||||
available_width: f64, color: Color,
|
||||
sys_alarm: bool, dia_alarm: bool, flash: bool) {
|
||||
let full = format!("{}/{}", sys, dia);
|
||||
let size = fitting_size(cr, &full, nominal_size, available_width, true);
|
||||
let _ = cr.save();
|
||||
cr.rectangle(x, baseline - size * 1.28, available_width.max(1.0), size * 1.65);
|
||||
cr.clip();
|
||||
let mut cursor = x;
|
||||
cursor += draw_segment(cr, &sys, cursor, baseline, size, color, sys_alarm && flash, true);
|
||||
cursor += draw_segment(cr, sys, cursor, baseline, size, color, sys_alarm && flash, true);
|
||||
cursor += draw_segment(cr, "/", cursor, baseline, size, color, false, true);
|
||||
draw_segment(cr, &dia, cursor, baseline, size, color, dia_alarm && flash, true);
|
||||
draw_segment(cr, dia, cursor, baseline, size, color, dia_alarm && flash, true);
|
||||
let _ = cr.restore();
|
||||
}
|
||||
|
||||
|
|
@ -378,7 +392,7 @@ fn draw_trace(cr: &Context, channel: Channel, color: Color,
|
|||
// Disconnected or absent pleth signal: no curve, including historical pulses.
|
||||
if matches!(channel, Channel::Pleth)
|
||||
&& (!pleth_trace_enabled(p)
|
||||
|| p.spo2_status(sim.pulse_rate()) != Spo2Status::Available)
|
||||
|| p.spo2_status_during(sim.pulse_rate(), sim.poor_signal_lost()) != Spo2Status::Available)
|
||||
{
|
||||
let _ = cr.restore();
|
||||
return;
|
||||
|
|
@ -393,6 +407,10 @@ fn draw_trace(cr: &Context, channel: Channel, color: Color,
|
|||
let x = right - (last_t - s.time) / VISIBLE_SECONDS * trace_width;
|
||||
let amplitude = normalized(channel, s, p);
|
||||
let y = bottom - amplitude * trace_height;
|
||||
if matches!(channel, Channel::Pleth) && !s.pleth_valid {
|
||||
if started { let _ = cr.stroke(); started = false; }
|
||||
continue;
|
||||
}
|
||||
if started { cr.line_to(x, y); }
|
||||
else { cr.move_to(x, y); started = true; }
|
||||
}
|
||||
|
|
@ -540,13 +558,13 @@ mod tests {
|
|||
assert!(pleth_trace_enabled(&p));
|
||||
p.spo2_sensor_attached = false;
|
||||
assert!(!pleth_trace_enabled(&p));
|
||||
assert_eq!(spo2_vitals(&p, Some(75)).1, "NO SENSOR");
|
||||
assert!(spo2_vitals(&p, Some(75)).2.contains("PR --"));
|
||||
assert_eq!(spo2_vitals(&p, Some(75), false).1, "NO SENSOR");
|
||||
assert!(spo2_vitals(&p, Some(75), false).2.contains("PR --"));
|
||||
p.spo2_sensor_attached = true;
|
||||
p.spo2_quality = Spo2Quality::None;
|
||||
assert!(!pleth_trace_enabled(&p));
|
||||
assert_eq!(spo2_vitals(&p, Some(75)).1, "NO READING");
|
||||
assert!(spo2_vitals(&p, Some(75)).2.contains("PR --"));
|
||||
assert_eq!(spo2_vitals(&p, Some(75), false).1, "NO READING");
|
||||
assert!(spo2_vitals(&p, Some(75), false).2.contains("PR --"));
|
||||
assert!(p.show_spo2); // no readings, but visible row and status
|
||||
}
|
||||
|
||||
|
|
@ -554,29 +572,37 @@ mod tests {
|
|||
fn poor_and_good_quality_keep_derived_pr_and_quality_indicators() {
|
||||
let mut p = Parameters::default();
|
||||
p.spo2_quality = Spo2Quality::Poor;
|
||||
assert_eq!(spo2_vitals(&p, Some(75)).0, "SpO₂ ★");
|
||||
assert_eq!(spo2_vitals(&p, Some(75)).1, "98");
|
||||
assert!(spo2_vitals(&p, Some(75)).2.contains("PR 75 bpm"));
|
||||
assert_eq!(spo2_vitals(&p, Some(75), false).0, "SpO₂ ★");
|
||||
assert_eq!(spo2_vitals(&p, Some(75), false).1, "98");
|
||||
assert!(spo2_vitals(&p, Some(75), false).2.contains("PR 75 bpm"));
|
||||
p.spo2_quality = Spo2Quality::Good;
|
||||
assert_eq!(spo2_vitals(&p, Some(75)).0, "SpO₂ ★★★");
|
||||
assert_eq!(spo2_vitals(&p, None).1, "NO READING");
|
||||
assert!(spo2_vitals(&p, None).2.contains("PR --"));
|
||||
assert_eq!(spo2_vitals(&p, Some(75), false).0, "SpO₂ ★★★");
|
||||
assert_eq!(spo2_vitals(&p, None, false).1, "NO READING");
|
||||
assert!(spo2_vitals(&p, None, false).2.contains("PR --"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_sensor_precedes_no_reading_and_both_are_spo2_alarms() {
|
||||
let mut p = Parameters::default();
|
||||
assert_eq!(spo2_vitals(&p, None).1, "NO READING");
|
||||
assert_eq!(spo2_vitals(&p, None, false).1, "NO READING");
|
||||
p.ecg_rhythm = crate::model::EcgRhythm::PulselessVentricularTachycardia;
|
||||
assert_eq!(spo2_vitals(&p, Some(100)).1, "NO READING");
|
||||
assert_eq!(spo2_vitals(&p, Some(100), false).1, "NO READING");
|
||||
p.spo2_sensor_attached = false;
|
||||
assert_eq!(spo2_vitals(&p, Some(100)).1, "NO SENSOR");
|
||||
assert_eq!(spo2_vitals(&p, Some(100), false).1, "NO SENSOR");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intermittent_poor_spo2_loss_raises_no_reading_not_no_sensor() {
|
||||
let p = Parameters { spo2_quality: Spo2Quality::Poor, ..Parameters::default() };
|
||||
assert_eq!(spo2_vitals(&p, Some(75), true).1, "NO READING");
|
||||
assert!(spo2_vitals(&p, Some(75), true).2.contains("PR --"));
|
||||
assert_eq!(spo2_vitals(&p, Some(75), false).1, "98");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arterial_axis_is_absolute_and_fixed_to_200_mmhg() {
|
||||
let p = Parameters::default();
|
||||
let mut s = Sample { time: 0.0, ecg: 0.0, pleth: 0.0, art: 100.0, co2: 0.0 };
|
||||
let mut s = Sample { time: 0.0, ecg: 0.0, pleth: 0.0, pleth_valid: true, art: 100.0, co2: 0.0 };
|
||||
assert_eq!(normalized(Channel::Art, &s, &p), 0.5);
|
||||
s.art = 200.0;
|
||||
assert_eq!(normalized(Channel::Art, &s, &p), 1.0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue