v0.5.0: tweak NIBP
This commit is contained in:
parent
e831364e43
commit
ef269099bd
12 changed files with 2900 additions and 109 deletions
|
|
@ -1,7 +1,7 @@
|
|||
//! Size-independent Cairo drawing of the synthetic bedside monitor.
|
||||
use gtk::cairo::{Context, FontSlant, FontWeight, LineCap, LineJoin};
|
||||
|
||||
use crate::model::{mean_arterial_pressure, AlarmLimits, AlarmState, Parameters, PulseConduction, Spo2Quality, Spo2Status};
|
||||
use crate::model::{AlarmLimits, AlarmState, Parameters, PulseConduction, Spo2Quality, Spo2Status};
|
||||
use crate::simulation::{Sample, Simulator};
|
||||
|
||||
type Color = (f64, f64, f64);
|
||||
|
|
@ -33,10 +33,14 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
|
|||
|
||||
let pad = (w.min(h) * 0.018).clamp(6.0, 20.0);
|
||||
let header = (h * 0.083).clamp(32.0, 68.0);
|
||||
let footer = if p.show_nibp { (h * 0.13).clamp(52.0, 102.0) } else { 0.0 };
|
||||
let channels = visible_channels(p);
|
||||
let row_height = ((h - header - footer - pad).max(20.0))
|
||||
/ (channels.len().max(1) as f64);
|
||||
let body_height = (h - header - pad).max(20.0);
|
||||
// NIBP occupies a dedicated box at the bottom of the numerical right column.
|
||||
// Trace rows remain full height on the left.
|
||||
let nibp_box_height = if p.show_nibp { (h * 0.24).clamp(135.0, 210.0).min(body_height * 0.55) }
|
||||
else { 0.0 };
|
||||
let trace_row_height = body_height / channels.len().max(1) as f64;
|
||||
let vital_row_height = (body_height - nibp_box_height) / channels.len().max(1) as f64;
|
||||
let sidebar = (w * 0.235).clamp(125.0, 370.0).min(w * 0.44);
|
||||
let split_x = w - sidebar - pad;
|
||||
let trace_left = pad + 6.0;
|
||||
|
|
@ -60,60 +64,112 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
|
|||
11.0 * text_scale, MUTED, false);
|
||||
}
|
||||
stroke_line(cr, pad, header, w - pad, header, MUTED, 0.8);
|
||||
stroke_line(cr, split_x, header, split_x, h - footer, MUTED, 0.9);
|
||||
stroke_line(cr, split_x, header, split_x, h - pad, MUTED, 0.9);
|
||||
|
||||
for (index, (channel, title, color)) in channels.iter().copied().enumerate() {
|
||||
let top = header + index as f64 * row_height;
|
||||
let bottom = top + row_height;
|
||||
stroke_line(cr, pad, bottom, w - pad, bottom, MUTED, 0.65);
|
||||
text(cr, title, trace_left + 4.0, top + row_height * 0.17,
|
||||
(row_height * 0.11).clamp(10.0, 17.0), color, false);
|
||||
let top = header + index as f64 * trace_row_height;
|
||||
let bottom = top + trace_row_height;
|
||||
stroke_line(cr, pad, bottom, split_x, bottom, MUTED, 0.65);
|
||||
text(cr, title, trace_left + 4.0, top + trace_row_height * 0.17,
|
||||
(trace_row_height * 0.11).clamp(10.0, 17.0), color, false);
|
||||
draw_trace(cr, channel, color, trace_left, trace_right,
|
||||
top + row_height * 0.25, bottom - row_height * 0.06, p, sim);
|
||||
top + trace_row_height * 0.25, bottom - trace_row_height * 0.06, p, sim);
|
||||
let vital_top = header + index as f64 * vital_row_height;
|
||||
stroke_line(cr, split_x, vital_top + vital_row_height,
|
||||
w - pad, vital_top + vital_row_height, MUTED, 0.65);
|
||||
draw_vitals(cr, channel, color, split_x + pad,
|
||||
top, row_height, sidebar - 2.0 * pad, p, sim);
|
||||
vital_top, vital_row_height, sidebar - 2.0 * pad, p, sim);
|
||||
}
|
||||
|
||||
if p.show_nibp {
|
||||
let footer_top = h - footer;
|
||||
let flash = alarm_flash_on(sim);
|
||||
let mean = mean_arterial_pressure(p.nibp_systolic, p.nibp_diastolic);
|
||||
text(cr, "NIBP", pad + 6.0, footer_top + footer * 0.32,
|
||||
(footer * 0.21).clamp(12.0, 20.0), LIGHT_GREY, false);
|
||||
draw_pressure_value(cr, p.nibp_systolic, p.nibp_diastolic,
|
||||
pad + 6.0, footer_top + footer * 0.77,
|
||||
(footer * 0.42).clamp(20.0, 44.0),
|
||||
(w * 0.28).min(255.0).max(70.0), LIGHT_GREY,
|
||||
alarmed(p.alarms.nibp_sys, Some(p.nibp_systolic)),
|
||||
alarmed(p.alarms.nibp_dia, Some(p.nibp_diastolic)), flash);
|
||||
if w >= 510.0 {
|
||||
draw_alarm_inline(cr, pad + (w * 0.28).min(260.0),
|
||||
footer_top + footer * 0.73, (footer * 0.24).clamp(12.0, 23.0),
|
||||
(w * 0.25).max(90.0), LIGHT_GREY,
|
||||
"MAP ", &mean.to_string(), " mmHg",
|
||||
alarmed(p.alarms.nibp_map, Some(mean)), flash);
|
||||
}
|
||||
draw_alarm_annotations(cr, &[
|
||||
("SYS", p.alarms.nibp_sys),
|
||||
("MAP", p.alarms.nibp_map),
|
||||
("DIA", p.alarms.nibp_dia),
|
||||
], w - pad - 8.0, footer_top, footer, (w * 0.24).max(115.0));
|
||||
draw_nibp_box(cr, split_x + pad, h - pad - nibp_box_height,
|
||||
sidebar - 2.0 * pad, nibp_box_height, p, sim);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_nibp_box(cr: &Context, x: f64, top: f64, width: f64, height: f64,
|
||||
p: &Parameters, sim: &Simulator) {
|
||||
let right = x + width;
|
||||
let pressure = sim.nibp().cuff_pressure(sim.time());
|
||||
let in_progress = sim.nibp().measuring();
|
||||
let reading = sim.nibp().reading();
|
||||
let value_width = (width - 35.0).max(30.0);
|
||||
let small = (height * 0.095).clamp(10.0, 14.0);
|
||||
let number_size = (height * 0.25).clamp(18.0, 41.0);
|
||||
// Subtle red outline distinguishes the independent cuff reading box.
|
||||
let _ = cr.save();
|
||||
cr.set_source_rgb(0.28, 0.09, 0.10);
|
||||
cr.set_line_width(1.0);
|
||||
cr.rectangle(x - 7.0, top, width + 13.0, height - 1.0);
|
||||
let _ = cr.stroke();
|
||||
let _ = cr.restore();
|
||||
text(cr, "NIBP", x, top + height * 0.13, small * 1.15, RED, true);
|
||||
if in_progress {
|
||||
text(cr, "MEASURING", x, top + height * 0.27, small, RED, false);
|
||||
} else {
|
||||
text(cr, "mmHg", x, top + height * 0.27, small, MUTED, false);
|
||||
}
|
||||
|
||||
if sim.nibp().show_new_value(sim.time()) {
|
||||
let (sys, dia) = reading.map_or(("---".to_owned(), "---".to_owned()), |r|
|
||||
(r.systolic.to_string(), r.diastolic.to_string()));
|
||||
draw_pressure_components(cr, &sys, &dia, x, top + height * 0.60,
|
||||
number_size, value_width, RED,
|
||||
alarmed(p.alarms.nibp_sys, reading.map(|r| r.systolic)),
|
||||
alarmed(p.alarms.nibp_dia, reading.map(|r| r.diastolic)), alarm_flash_on(sim));
|
||||
let map = reading.map_or("---".to_owned(), |r| r.mean().to_string());
|
||||
draw_alarm_inline(cr, x, top + height * 0.72, small * 1.15, value_width,
|
||||
RED, "MAP ", &map, " mmHg",
|
||||
alarmed(p.alarms.nibp_map, reading.map(|r| r.mean())), alarm_flash_on(sim));
|
||||
}
|
||||
|
||||
// Horizontal: elapsed fraction of the selected measurement interval.
|
||||
let progress_y = top + height * 0.85;
|
||||
let progress_width = (width - 9.0).max(8.0);
|
||||
stroke_line(cr, x, progress_y, x + progress_width, progress_y, MUTED, 4.0);
|
||||
stroke_line(cr, x, progress_y,
|
||||
x + progress_width * sim.nibp().interval_progress(sim.time(), p.nibp_interval_minutes),
|
||||
progress_y, RED, 4.0);
|
||||
text(cr, &format!("Every {} min", p.nibp_interval_minutes),
|
||||
x, top + height * 0.97, small * 0.85, MUTED, false);
|
||||
|
||||
// Vertical cuff-pressure gauge (0..200 mmHg), always visible when measuring.
|
||||
let gauge_x = right - 15.0;
|
||||
let gauge_top = top + height * 0.31;
|
||||
let gauge_h = height * 0.40;
|
||||
stroke_line(cr, gauge_x, gauge_top, gauge_x, gauge_top + gauge_h, MUTED, 7.0);
|
||||
if in_progress {
|
||||
stroke_line(cr, gauge_x, gauge_top + gauge_h,
|
||||
gauge_x, gauge_top + gauge_h * (1.0 - pressure / 200.0), RED, 6.0);
|
||||
}
|
||||
text(cr, &format!("{:.0}", pressure), gauge_x - 12.0,
|
||||
gauge_top - 3.0, small * 0.75, RED, false);
|
||||
draw_alarm_annotations(cr, &[
|
||||
("SYS", p.alarms.nibp_sys),
|
||||
("MAP", p.alarms.nibp_map),
|
||||
("DIA", p.alarms.nibp_dia),
|
||||
], right, top, height * 0.65, width * 0.72);
|
||||
}
|
||||
|
||||
fn pleth_trace_enabled(p: &Parameters) -> bool {
|
||||
p.spo2_sensor_attached && p.spo2_quality != Spo2Quality::None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn spo2_vitals(p: &Parameters, pulse_rate: Option<i32>, signal_lost: bool)
|
||||
-> (String, String, String) {
|
||||
match p.spo2_status_during(pulse_rate, signal_lost) {
|
||||
spo2_vitals_at_quality(p, pulse_rate, signal_lost, p.spo2_quality)
|
||||
}
|
||||
|
||||
fn spo2_vitals_at_quality(p: &Parameters, pulse_rate: Option<i32>, signal_lost: bool,
|
||||
quality: Spo2Quality) -> (String, String, String) {
|
||||
match p.spo2_status_at_quality(pulse_rate, signal_lost, quality) {
|
||||
Spo2Status::NoSensor => (
|
||||
"SpO₂".to_owned(), "NO SENSOR".to_owned(), "PR -- bpm".to_owned()),
|
||||
Spo2Status::NoReading => (
|
||||
"SpO₂".to_owned(), "NO READING".to_owned(), "PR -- bpm".to_owned()),
|
||||
Spo2Status::Available => (
|
||||
format!("SpO₂ {}", p.spo2_quality.stars()),
|
||||
format!("SpO₂ {}", quality.stars()),
|
||||
p.spo2.to_string(),
|
||||
format!("% PR {} bpm", pulse_rate.unwrap_or_default()),
|
||||
),
|
||||
|
|
@ -144,9 +200,8 @@ 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_during(pulse_rate, sim.poor_signal_lost());
|
||||
let spo2_status = p.spo2_status_at_quality(pulse_rate, sim.poor_signal_lost(), sim.spo2_quality(p));
|
||||
let oxygen = if spo2_status == Spo2Status::Available { Some(p.spo2) } else { None };
|
||||
let art_map = mean_arterial_pressure(p.art_systolic, p.art_diastolic);
|
||||
|
||||
let limits: Vec<(&str, AlarmLimits)> = match ch {
|
||||
Channel::Ecg => vec![("HR", p.alarms.hr)],
|
||||
|
|
@ -174,7 +229,8 @@ fn draw_vitals(cr: &Context, ch: Channel, color: Color, x: f64,
|
|||
}
|
||||
}
|
||||
Channel::Pleth => {
|
||||
let (label, value, info) = spo2_vitals(p, pulse_rate, sim.poor_signal_lost());
|
||||
let (label, value, info) = spo2_vitals_at_quality(p, pulse_rate,
|
||||
sim.poor_signal_lost(), sim.spo2_quality(p));
|
||||
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 {
|
||||
|
|
@ -192,36 +248,27 @@ fn draw_vitals(cr: &Context, ch: Channel, color: Color, x: f64,
|
|||
}
|
||||
Channel::Art => {
|
||||
text(cr, "ART", x, top + row_h * 0.24, label_size, color, false);
|
||||
if pulse_rate.is_some() {
|
||||
draw_pressure_value(cr, p.art_systolic, p.art_diastolic,
|
||||
x, value_y, number_size * 0.78, width, color,
|
||||
alarmed(p.alarms.art_sys, Some(p.art_systolic)),
|
||||
alarmed(p.alarms.art_dia, Some(p.art_diastolic)), flash);
|
||||
if p.pulse_pressure_variation > 0 || p.alarms.ppv.enabled() {
|
||||
let map_text = art_map.to_string();
|
||||
let ppv_text = p.pulse_pressure_variation.to_string();
|
||||
draw_alarm_parts(cr, x, info_y, sub_size, width, color, &[
|
||||
("MAP ", false),
|
||||
(&map_text, alarmed(p.alarms.art_map, Some(art_map))),
|
||||
(" · PPV ", false),
|
||||
(&ppv_text, alarmed(p.alarms.ppv, Some(p.pulse_pressure_variation))),
|
||||
("%", false),
|
||||
], flash);
|
||||
} else {
|
||||
draw_alarm_inline(cr, x, info_y, sub_size, width, color,
|
||||
"MAP ", &art_map.to_string(), " mmHg",
|
||||
alarmed(p.alarms.art_map, Some(art_map)), flash);
|
||||
}
|
||||
let (sys, dia, map) = sim.displayed_art_pressures(p, pulse_rate.is_some());
|
||||
let sys_text = sys.map_or("--".to_owned(), |v| v.to_string());
|
||||
let dia_text = dia.map_or("--".to_owned(), |v| v.to_string());
|
||||
draw_pressure_components(cr, &sys_text, &dia_text,
|
||||
x, value_y, number_size * 0.78, width, color,
|
||||
alarmed(p.alarms.art_sys, sys),
|
||||
alarmed(p.alarms.art_dia, dia), flash);
|
||||
let map_text = map.map_or("--".to_owned(), |v| v.to_string());
|
||||
if p.pulse_pressure_variation > 0 || p.alarms.ppv.enabled() {
|
||||
let ppv_text = p.pulse_pressure_variation.to_string();
|
||||
draw_alarm_parts(cr, x, info_y, sub_size, width, color, &[
|
||||
("MAP ", false),
|
||||
(&map_text, alarmed(p.alarms.art_map, map)),
|
||||
(" · PPV ", false),
|
||||
(&ppv_text, alarmed(p.alarms.ppv, Some(p.pulse_pressure_variation))),
|
||||
("%", false),
|
||||
], flash);
|
||||
} else {
|
||||
// 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);
|
||||
draw_alarm_inline(cr, x, info_y, sub_size, width, color,
|
||||
"MAP ", &map_text, " mmHg",
|
||||
alarmed(p.alarms.art_map, map), flash);
|
||||
}
|
||||
}
|
||||
Channel::Capno => {
|
||||
|
|
@ -270,17 +317,7 @@ fn draw_alarm_number(cr: &Context, value: &str, x: f64, baseline: f64,
|
|||
let _ = cr.restore();
|
||||
}
|
||||
|
||||
/// Draw pressure components independently: only SYS or DIA flashes when it
|
||||
/// breaches its respective limit. The separator remains the normal color.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
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) {
|
||||
draw_pressure_components(cr, &systolic.to_string(), &diastolic.to_string(),
|
||||
x, baseline, nominal_size, available_width, color, sys_alarm, dia_alarm, flash);
|
||||
}
|
||||
|
||||
/// Draw SYS and DIA independently; their threshold alarms can invert separately.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn draw_pressure_components(cr: &Context, sys: &str, dia: &str,
|
||||
x: f64, baseline: f64, nominal_size: f64,
|
||||
|
|
@ -392,7 +429,8 @@ 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_during(sim.pulse_rate(), sim.poor_signal_lost()) != Spo2Status::Available)
|
||||
|| p.spo2_status_at_quality(sim.pulse_rate(), sim.poor_signal_lost(),
|
||||
sim.spo2_quality(p)) != Spo2Status::Available)
|
||||
{
|
||||
let _ = cr.restore();
|
||||
return;
|
||||
|
|
@ -421,7 +459,7 @@ fn draw_trace(cr: &Context, channel: Channel, color: Color,
|
|||
fn normalized(channel: Channel, s: &Sample, p: &Parameters) -> f64 {
|
||||
match channel {
|
||||
Channel::Ecg => (0.40 + s.ecg * 0.38).clamp(0.02, 0.98),
|
||||
Channel::Pleth => (0.10 + pleth_visual_amplitude(s.pleth, s.time, p.spo2_quality) * 0.78)
|
||||
Channel::Pleth => (0.10 + pleth_visual_amplitude(s.pleth, s.time, s.pleth_quality) * 0.78)
|
||||
.clamp(0.02, 0.98),
|
||||
Channel::Art => (s.art / 200.0).clamp(0.0, 1.0),
|
||||
Channel::Capno => (0.08 + (s.co2 / f64::from(p.etco2.max(1))) * 0.80)
|
||||
|
|
@ -602,7 +640,7 @@ mod tests {
|
|||
#[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, pleth_valid: true, art: 100.0, co2: 0.0 };
|
||||
let mut s = Sample { time: 0.0, ecg: 0.0, pleth: 0.0, pleth_valid: true, pleth_quality: Spo2Quality::Good, 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