v0.5.8 — ECG touchscreen controls

This commit is contained in:
GABRIEL Sebastian 2026-11-12 16:10:57 +01:00
commit 14ee042a0a
10 changed files with 1027 additions and 41 deletions

View file

@ -33,6 +33,48 @@ impl EcgRhythm {
}
}
/// Displayed single-channel ECG lead. Synthetic morphology is lead-II-like;
/// projection below provides illustrative polarity/gain, not a 12-lead model.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EcgLead {
I, II, III, AVR, AVL, AVF, V1, V2, V3, V4, V5, V6,
}
impl EcgLead {
pub const LABELS: &'static [&'static str] = &[
"I", "II", "III", "aVR", "aVL", "aVF", "V1", "V2", "V3", "V4", "V5", "V6",
];
pub fn from_index(index: u32) -> Self {
match index {
0 => Self::I, 2 => Self::III, 3 => Self::AVR, 4 => Self::AVL,
5 => Self::AVF, 6 => Self::V1, 7 => Self::V2, 8 => Self::V3,
9 => Self::V4, 10 => Self::V5, 11 => Self::V6, _ => Self::II,
}
}
pub fn index(self) -> u32 {
match self {
Self::I => 0, Self::II => 1, Self::III => 2, Self::AVR => 3,
Self::AVL => 4, Self::AVF => 5, Self::V1 => 6, Self::V2 => 7,
Self::V3 => 8, Self::V4 => 9, Self::V5 => 10, Self::V6 => 11,
}
}
pub fn label(self) -> &'static str { Self::LABELS[self.index() as usize] }
/// Illustrative polarity and voltage gain relative to lead II. This changes
/// only the trace, never ECG event timing or mechanical capture.
pub fn display_gain(self) -> f64 {
match self {
Self::I => 0.82, Self::II => 1.0, Self::III => 0.67,
Self::AVR => -0.85, Self::AVL => 0.52, Self::AVF => 0.75,
Self::V1 => -0.75, Self::V2 => -0.38, Self::V3 => 0.52,
Self::V4 => 1.08, Self::V5 => 1.0, Self::V6 => 0.83,
}
}
}
/// Pulse-oximeter availability and technical alarms. Sensor loss takes precedence.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Spo2Status {
@ -228,6 +270,7 @@ pub struct Parameters {
pub chest_compressions_active: bool,
pub chest_compression_quality: ChestCompressionQuality,
pub ecg_rhythm: EcgRhythm,
pub ecg_lead: EcgLead, // ECG trace label and illustrative lead projection
pub heart_rate: i32, // bpm, organized electrical rate; not mechanical pulse rate
pub pulse_conduction: PulseConduction,
pub spo2: i32, // %; instructor-set nominal saturation
@ -305,6 +348,7 @@ impl Default for Parameters {
chest_compressions_active: false,
chest_compression_quality: ChestCompressionQuality::Adequate,
ecg_rhythm: EcgRhythm::Sinus,
ecg_lead: EcgLead::II,
heart_rate: 75,
pulse_conduction: PulseConduction::OneToOne,
spo2: 98,
@ -351,6 +395,21 @@ mod tests {
assert_eq!(ChestCompressionQuality::Bad.peak_range(), None);
}
#[test]
fn ecg_lead_defaults_to_ii_and_selection_is_bijective() {
let p = Parameters::default();
assert_eq!(p.ecg_lead, EcgLead::II);
assert_eq!(p.ecg_lead.label(), "II");
for index in 0..EcgLead::LABELS.len() as u32 {
let lead = EcgLead::from_index(index);
assert_eq!(lead.index(), index);
assert_eq!(lead.label(), EcgLead::LABELS[index as usize]);
}
assert_eq!(EcgLead::from_index(999), EcgLead::II);
assert!(EcgLead::AVR.display_gain() < 0.0);
assert_eq!(EcgLead::II.display_gain(), 1.0);
}
#[test]
fn mean_pressure_uses_one_third_pulse_pressure() {
assert_eq!(mean_arterial_pressure(120, 75), 90);