This commit is contained in:
GABRIEL Sebastian 2026-11-12 10:43:11 +01:00
commit 35a380b808
8 changed files with 954 additions and 46 deletions

View file

@ -58,12 +58,45 @@ pub enum CapnoShape {
Obstructive,
}
#[derive(Clone, Copy, Debug)]
/// Instructor-selected plethysmography signal quality; separate from the
/// physiological oxygen-saturation setting and mechanical pulse capture.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Spo2Quality {
None,
Poor,
Adequate,
Good,
}
impl Spo2Quality {
pub fn stars(self) -> &'static str {
match self {
Self::None => "",
Self::Poor => "★",
Self::Adequate => "★★",
Self::Good => "★★★",
}
}
pub fn amplitude_scale(self) -> f64 {
match self {
Self::None => 0.0,
Self::Poor => 0.25,
Self::Adequate => 0.56,
Self::Good => 1.0,
}
}
}
#[derive(Clone, Debug)]
pub struct Parameters {
pub patient_name: String, // displayed in the monitor header, blank = generic title
pub ecg_rhythm: EcgRhythm,
pub heart_rate: i32, // bpm, organized electrical rate; not mechanical pulse rate
pub pulse_conduction: PulseConduction,
pub spo2: i32, // %
pub spo2: i32, // %; instructor-set nominal saturation
pub spo2_quality: Spo2Quality,
pub spo2_sensor_attached: bool,
pub art_systolic: i32, // mmHg, nominal pressure; display axis 0..200
pub art_diastolic: i32, // mmHg
pub arterial_shape: ArterialShape,
@ -84,10 +117,13 @@ pub struct Parameters {
impl Default for Parameters {
fn default() -> Self {
Self {
patient_name: String::new(),
ecg_rhythm: EcgRhythm::Sinus,
heart_rate: 75,
pulse_conduction: PulseConduction::OneToOne,
spo2: 98,
spo2_quality: Spo2Quality::Good,
spo2_sensor_attached: true,
art_systolic: 120,
art_diastolic: 75,
arterial_shape: ArterialShape::Normal,
@ -119,6 +155,17 @@ mod tests {
assert_eq!(mean_arterial_pressure(120, 75), 90);
}
#[test]
fn spo2_quality_stars_and_amplitude_progress_monotonically() {
assert_eq!(Spo2Quality::None.stars(), "");
assert_eq!(Spo2Quality::Poor.stars(), "★");
assert_eq!(Spo2Quality::Adequate.stars(), "★★");
assert_eq!(Spo2Quality::Good.stars(), "★★★");
assert_eq!(Spo2Quality::None.amplitude_scale(), 0.0);
assert!(Spo2Quality::Poor.amplitude_scale() < Spo2Quality::Adequate.amplitude_scale());
assert!(Spo2Quality::Adequate.amplitude_scale() < Spo2Quality::Good.amplitude_scale());
}
#[test]
fn grouped_mechanical_capture_follows_requested_patterns() {
assert_eq!((1..=8).filter(|&b| PulseConduction::TwoToOne.conducts(b)).collect::<Vec<_>>(),