moce patches
This commit is contained in:
parent
2c0dc760d9
commit
5665d68db0
37 changed files with 1472 additions and 570 deletions
769
patches/patient-monitor-simulation-v0.6.7-to-v0.6.8.patch
Normal file
769
patches/patient-monitor-simulation-v0.6.7-to-v0.6.8.patch
Normal file
|
|
@ -0,0 +1,769 @@
|
|||
diff --git a/Cargo.toml b/Cargo.toml
|
||||
index eda3ddf..54bac15 100644
|
||||
--- a/Cargo.toml
|
||||
+++ b/Cargo.toml
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "patient-monitor-simulation"
|
||||
-version = "0.6.7"
|
||||
+version = "0.6.8"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
description = "Synthetic patient-monitor simulation for teaching (not for clinical use)"
|
||||
diff --git a/README.de.md b/README.de.md
|
||||
index 17890f5..64f4476 100644
|
||||
--- a/README.de.md
|
||||
+++ b/README.de.md
|
||||
@@ -1,4 +1,30 @@
|
||||
-# Patient Monitor Simulation (PaMSim) — v0.6.7
|
||||
+# Patient Monitor Simulation (PaMSim) — v0.6.8
|
||||
+
|
||||
+## Kopfzeile: selektive Alarmpause und Einstellungen (v0.6.8)
|
||||
+
|
||||
+Rechts in der Kopfzeile befinden sich zwei per Touch oder Maus bedienbare
|
||||
+Symbole:
|
||||
+
|
||||
+- **Gelbe Glocke (ganz rechts):** Schaltet ausschließlich jene akustischen
|
||||
+ Alarmbedingungen für **120 Sekunden** stumm, die beim Drücken gerade
|
||||
+ anstehen. Darunter zeigt `paused for x s` die verbleibende Zeit. Erneutes
|
||||
+ Drücken erfasst die aktuell aktiven Bedingungen neu und startet die Frist
|
||||
+ erneut. Neu hinzukommende Alarmbedingungen sind sofort hörbar, auch bei
|
||||
+ gleicher Alarmpriorität. Ein abgeklungener Alarm ist bei einem späteren
|
||||
+ erneuten Auftreten wieder hörbar. Optische Alarme und der unabhängige
|
||||
+ QRS-/Pulston bleiben unverändert. Ohne aktiven Alarm wird keine Pause
|
||||
+ gestartet.
|
||||
+- **Zahnrad (links daneben):** Öffnet ein schwarz/hellgraues Einstellfenster
|
||||
+ mit **QRS beep**, **Audible alarms**, **Alert presets** (`Custom`, `Adult`),
|
||||
+ dem Eingabefeld **Patient name** und dem Text
|
||||
+ `PaMSim by Critical Care Club Austria, (c) 2026`. Eine Bildschirmtastatur
|
||||
+ wird nicht zusätzlich bereitgestellt. **Apply** übernimmt die Einstellungen
|
||||
+ und gleicht sie mit dem Admin-Fenster ab, **Cancel/Esc** verwirft sie.
|
||||
+ Die Vorgabe Adult verändert nur die Alarmgrenzen.
|
||||
+
|
||||
+Die bisherigen Touch-Menüs bleiben erhalten. Das NIBP-Menü enthält weiterhin
|
||||
+manuelle Messung, Messautomatik und Messintervall.
|
||||
+
|
||||
|
||||
Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenstern für die Lehre unter Fedora Linux.
|
||||
|
||||
@@ -691,3 +717,14 @@ zwischen 740 und 87 Hz nach der Sauerstoffsättigung; ohne SpO₂-Messwert
|
||||
erfolgt bei EKG-QRS oder arteriellem Puls ein 500-Hz-Ton. Die bisherigen
|
||||
Zweitonalarme bleiben unverändert. Zusätzliche Tests prüfen die
|
||||
Frequenzbereiche, Ereigniszuordnung und WAV-Ausgabe.
|
||||
+
|
||||
+
|
||||
+### v0.6.8 – Kopfzeilenmenü und selektive Alarmpause
|
||||
+
|
||||
+Zwei Touch-Schaltflächen in der Kopfzeile: gelbe Glocke für 120 Sekunden
|
||||
+selektive Unterdrückung bereits aktiver akustischer Alarme mit Countdown und
|
||||
+Zahnrad für globale Einstellungen. Neu auftretende oder nach zwischenzeitlichem
|
||||
+Abklingen wiederkehrende Alarmbedingungen bleiben hörbar; optische Alarme und
|
||||
+QRS-Töne laufen unverändert. Das Menü ermöglicht QRS-/Alarnton, Alarmvorgabe
|
||||
+und Patientennamen und enthält den Copyright-Hinweis. Die Admin-Oberfläche wird
|
||||
+synchronisiert.
|
||||
diff --git a/README.md b/README.md
|
||||
index 793a3d4..105c082 100644
|
||||
--- a/README.md
|
||||
+++ b/README.md
|
||||
@@ -1,4 +1,4 @@
|
||||
-# Patient Monitor Simulation (PaMSim) — v0.6.7
|
||||
+# Patient Monitor Simulation (PaMSim) — v0.6.8
|
||||
|
||||
A Rust/GTK4 patient-monitor simulator with two main windows for teaching on Fedora Linux.
|
||||
|
||||
@@ -6,6 +6,29 @@ A Rust/GTK4 patient-monitor simulator with two main windows for teaching on Fedo
|
||||
> plethysmography and capnography are schematic mathematical approximations. The
|
||||
> simulation has no clinical validation and is not a medical device.
|
||||
|
||||
+## Header controls: selective alarm pause and settings (v0.6.8)
|
||||
+
|
||||
+Two touch/mouse controls are drawn at the far right of the monitor header:
|
||||
+
|
||||
+- **Yellow bell (rightmost):** pauses only the *currently active* audible
|
||||
+ alarm conditions for **120 seconds**. The caption `paused for x s` counts
|
||||
+ down the remaining seconds. Pressing the bell again replaces the suppressed
|
||||
+ set with the conditions active at that moment and restarts the 120-second
|
||||
+ timer. A newly triggered alarm condition sounds normally, even if another
|
||||
+ alarm of the same priority is paused. When a condition clears, it loses its
|
||||
+ paused status so a later recurrence can sound. Pauses never change visual
|
||||
+ alarms or the separate beat-synchronous QRS sound. Pressing the bell when
|
||||
+ no alarms are active does not start a countdown.
|
||||
+- **Gear (left of bell):** opens a black/light-grey monitor-side settings panel
|
||||
+ with **QRS beep**, **Audible alarms**, **Alert presets** (`Custom`, `Adult`),
|
||||
+ an editable **Patient name** field and the attribution
|
||||
+ `PaMSim by Critical Care Club Austria, (c) 2026`. It does **not** create
|
||||
+ an on-screen keyboard. **Apply** synchronizes settings with Admin;
|
||||
+ **Cancel/Esc** discards changes. The Adult preset affects alarm limits only.
|
||||
+
|
||||
+Other channel touch menus are unchanged. NIBP retains its explicitly requested
|
||||
+manual measurement, automatic measurement and interval controls.
|
||||
+
|
||||
## Smooth HR transitions (v0.6.7)
|
||||
|
||||
Changing the HR slider now preserves the recent history of *mechanically
|
||||
@@ -703,3 +726,13 @@ saturation determines the pitch in eleven steps from 740 to 87 Hz; otherwise
|
||||
ECG QRS or ART pulses trigger a fixed 500 Hz tone. The two-tone alarm sounds
|
||||
remain unchanged. Added regression tests for band boundaries, event selection
|
||||
and single-tone WAV output.
|
||||
+
|
||||
+
|
||||
+### v0.6.8 — Monitor header controls and selective audible-alarm pause
|
||||
+
|
||||
+Added a yellow bell button with a 120-second pause countdown and a grey settings
|
||||
+gear to the monitor header. The pause suppresses only alarm conditions active
|
||||
+when pressed, with automatic un-silencing of new/recurrent conditions; visual
|
||||
+alarms and QRS tones continue. The global monitor settings window contains
|
||||
+QRS and audible-alarm switches, alert preset selection, patient name and
|
||||
+attribution, and synchronizes its changes with Admin.
|
||||
diff --git a/src/alarm.rs b/src/alarm.rs
|
||||
index 89814d6..f992589 100644
|
||||
--- a/src/alarm.rs
|
||||
+++ b/src/alarm.rs
|
||||
@@ -4,6 +4,7 @@
|
||||
//! as the monitor. Sound is played using Fedora's PipeWire command-line player
|
||||
//! (or paplay) without adding a native audio-library dependency to Cargo.
|
||||
|
||||
+use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::env;
|
||||
use std::fs::{self, OpenOptions};
|
||||
use std::io::{self, Write};
|
||||
@@ -11,7 +12,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
-use crate::model::{AlarmLimits, AlarmState, Parameters, PulseConduction, Spo2Status};
|
||||
+use crate::model::{AlarmLimits, AlarmState, EcgRhythm, Parameters, PulseConduction, Spo2Status};
|
||||
use crate::simulation::{BeatEvent, BeatSource, Simulator};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||
@@ -22,66 +23,126 @@ pub enum AlarmLevel {
|
||||
Critical,
|
||||
}
|
||||
|
||||
-fn outside(limits: AlarmLimits, value: Option<i32>) -> bool {
|
||||
- limits.evaluate(value) != AlarmState::Normal
|
||||
+/// One identifiable alarm condition. Upper and lower alarms of a parameter
|
||||
+/// have different identities, as do individual arrhythmias and technical errors.
|
||||
+/// A pause must silence identities, never a whole priority class.
|
||||
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
+pub enum AlarmKey {
|
||||
+ Low(&'static str),
|
||||
+ High(&'static str),
|
||||
+ NoSensor,
|
||||
+ NoReading,
|
||||
+ Rhythm(&'static str),
|
||||
}
|
||||
|
||||
-/// Only parameters actually shown on the monitor contribute audible alarms.
|
||||
-/// Missing numeric values do not trigger threshold alarms, but missing SpO2
|
||||
-/// readings and disconnected sensors are explicit technical alarms.
|
||||
-pub fn level(p: &Parameters, sim: &Simulator) -> AlarmLevel {
|
||||
- let mut result = AlarmLevel::None;
|
||||
+pub type ActiveAlarms = BTreeMap<AlarmKey, AlarmLevel>;
|
||||
+
|
||||
+fn add_limit(alarms: &mut ActiveAlarms, name: &'static str,
|
||||
+ limits: AlarmLimits, value: Option<i32>) {
|
||||
+ let key = match limits.evaluate(value) {
|
||||
+ AlarmState::Low => Some(AlarmKey::Low(name)),
|
||||
+ AlarmState::High => Some(AlarmKey::High(name)),
|
||||
+ AlarmState::Normal => None,
|
||||
+ };
|
||||
+ if let Some(key) = key { alarms.insert(key, AlarmLevel::Standard); }
|
||||
+}
|
||||
+
|
||||
+/// Evaluate every independent audible alarm from the same data used by the
|
||||
+/// visual display. Hidden channels do not generate audible alarms.
|
||||
+pub fn active_conditions(p: &Parameters, sim: &Simulator) -> ActiveAlarms {
|
||||
+ let mut alarms = ActiveAlarms::new();
|
||||
let hr = (p.ecg_rhythm.has_qrs() && p.heart_rate > 0).then_some(p.heart_rate);
|
||||
let captured = p.ecg_rhythm.can_generate_pulse()
|
||||
&& p.heart_rate > 0
|
||||
&& p.pulse_conduction != PulseConduction::None;
|
||||
|
||||
if p.show_ecg {
|
||||
- if p.ecg_rhythm.rhythm_alarm().is_some() {
|
||||
- return AlarmLevel::Critical;
|
||||
- }
|
||||
- if outside(p.alarms.hr, hr) {
|
||||
- result = AlarmLevel::Standard;
|
||||
+ let rhythm = match p.ecg_rhythm {
|
||||
+ EcgRhythm::VentricularTachycardia => Some("VT"),
|
||||
+ EcgRhythm::PulselessVentricularTachycardia => Some("PVT"),
|
||||
+ EcgRhythm::VentricularFibrillation => Some("VF"),
|
||||
+ EcgRhythm::Asystole => Some("ASYSTOLE"),
|
||||
+ _ => None,
|
||||
+ };
|
||||
+ if let Some(name) = rhythm {
|
||||
+ alarms.insert(AlarmKey::Rhythm(name), AlarmLevel::Critical);
|
||||
}
|
||||
+ add_limit(&mut alarms, "HR", p.alarms.hr, hr);
|
||||
}
|
||||
|
||||
if p.show_spo2 {
|
||||
- let status = sim.spo2_status(p);
|
||||
- if status != Spo2Status::Available
|
||||
- || outside(p.alarms.spo2, Some(p.spo2))
|
||||
- || outside(p.alarms.pr, sim.spo2_pulse_rate(p))
|
||||
- {
|
||||
- result = AlarmLevel::Standard;
|
||||
+ match sim.spo2_status(p) {
|
||||
+ Spo2Status::NoSensor => {
|
||||
+ alarms.insert(AlarmKey::NoSensor, AlarmLevel::Standard);
|
||||
+ }
|
||||
+ Spo2Status::NoReading => {
|
||||
+ alarms.insert(AlarmKey::NoReading, AlarmLevel::Standard);
|
||||
+ }
|
||||
+ Spo2Status::Available => {
|
||||
+ add_limit(&mut alarms, "SpO2", p.alarms.spo2, Some(p.spo2));
|
||||
+ add_limit(&mut alarms, "PR", p.alarms.pr, sim.spo2_pulse_rate(p));
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
if p.show_art {
|
||||
let (sys, dia, map) = sim.displayed_art_pressures(p, captured);
|
||||
- if outside(p.alarms.art_sys, sys)
|
||||
- || outside(p.alarms.art_dia, dia)
|
||||
- || outside(p.alarms.art_map, map)
|
||||
- || outside(p.alarms.ppv, Some(p.pulse_pressure_variation))
|
||||
- {
|
||||
- result = AlarmLevel::Standard;
|
||||
- }
|
||||
+ add_limit(&mut alarms, "ART SYS", p.alarms.art_sys, sys);
|
||||
+ add_limit(&mut alarms, "ART DIA", p.alarms.art_dia, dia);
|
||||
+ add_limit(&mut alarms, "ART MAP", p.alarms.art_map, map);
|
||||
+ add_limit(&mut alarms, "PPV", p.alarms.ppv, Some(p.pulse_pressure_variation));
|
||||
}
|
||||
-
|
||||
- if p.show_capno && (outside(p.alarms.etco2, Some(p.etco2))
|
||||
- || outside(p.alarms.rr, Some(p.respiratory_rate)))
|
||||
- {
|
||||
- result = AlarmLevel::Standard;
|
||||
+ if p.show_capno {
|
||||
+ add_limit(&mut alarms, "EtCO2", p.alarms.etco2, Some(p.etco2));
|
||||
+ add_limit(&mut alarms, "RR", p.alarms.rr, Some(p.respiratory_rate));
|
||||
}
|
||||
-
|
||||
if p.show_nibp {
|
||||
let reading = sim.nibp().reading();
|
||||
- if outside(p.alarms.nibp_sys, reading.map(|r| r.systolic))
|
||||
- || outside(p.alarms.nibp_dia, reading.map(|r| r.diastolic))
|
||||
- || outside(p.alarms.nibp_map, reading.map(|r| r.mean()))
|
||||
- {
|
||||
- result = AlarmLevel::Standard;
|
||||
+ add_limit(&mut alarms, "NIBP SYS", p.alarms.nibp_sys, reading.map(|r| r.systolic));
|
||||
+ add_limit(&mut alarms, "NIBP DIA", p.alarms.nibp_dia, reading.map(|r| r.diastolic));
|
||||
+ add_limit(&mut alarms, "NIBP MAP", p.alarms.nibp_map, reading.map(|r| r.mean()));
|
||||
+ }
|
||||
+ alarms
|
||||
+}
|
||||
+
|
||||
+/// Preserve the legacy priority interface for tests and audio playback.
|
||||
+#[cfg(test)]
|
||||
+pub fn level(p: &Parameters, sim: &Simulator) -> AlarmLevel {
|
||||
+ active_conditions(p, sim).values().copied().max().unwrap_or_default()
|
||||
+}
|
||||
+
|
||||
+/// A two-minute pause captures *only* the alarm conditions that are active
|
||||
+/// at button press. A new condition bypasses it; a condition that clears is
|
||||
+/// removed from the snapshot so that a later recurrence sounds normally.
|
||||
+#[derive(Default)]
|
||||
+pub struct AlarmPause {
|
||||
+ until: Option<Instant>,
|
||||
+ muted: BTreeSet<AlarmKey>,
|
||||
+}
|
||||
+
|
||||
+impl AlarmPause {
|
||||
+ pub fn pause_current(&mut self, now: Instant, active: &ActiveAlarms) {
|
||||
+ self.muted = active.keys().copied().collect();
|
||||
+ self.until = (!self.muted.is_empty()).then_some(now + Duration::from_secs(120));
|
||||
+ }
|
||||
+
|
||||
+ pub fn effective_level(&mut self, now: Instant, active: &ActiveAlarms) -> AlarmLevel {
|
||||
+ if self.until.is_some_and(|deadline| now >= deadline) {
|
||||
+ self.until = None;
|
||||
+ self.muted.clear();
|
||||
}
|
||||
+ self.muted.retain(|key| active.contains_key(key));
|
||||
+ active.iter().filter(|(key, _)| !self.muted.contains(key))
|
||||
+ .map(|(_, priority)| *priority).max().unwrap_or_default()
|
||||
+ }
|
||||
+
|
||||
+ pub fn remaining_seconds(&self, now: Instant) -> Option<u64> {
|
||||
+ self.until.and_then(|deadline| {
|
||||
+ let remaining = deadline.saturating_duration_since(now);
|
||||
+ (!remaining.is_zero()).then_some(remaining.as_secs().saturating_add(
|
||||
+ u64::from(remaining.subsec_nanos() > 0)))
|
||||
+ })
|
||||
}
|
||||
- result
|
||||
}
|
||||
|
||||
/// Single-note QRS/pulse beep. The oximeter is the source when it has a
|
||||
@@ -508,6 +569,71 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::model::{AlarmSettings, EcgRhythm};
|
||||
|
||||
+ #[test]
|
||||
+ fn pause_silences_only_current_alarm_conditions() {
|
||||
+ let t0 = Instant::now();
|
||||
+ let mut pause = AlarmPause::default();
|
||||
+ let mut alarms = ActiveAlarms::new();
|
||||
+ alarms.insert(AlarmKey::High("HR"), AlarmLevel::Standard);
|
||||
+ assert_eq!(pause.effective_level(t0, &alarms), AlarmLevel::Standard);
|
||||
+ pause.pause_current(t0, &alarms);
|
||||
+ assert_eq!(pause.remaining_seconds(t0), Some(120));
|
||||
+ assert_eq!(pause.effective_level(t0, &alarms), AlarmLevel::None);
|
||||
+ // New lower-limit or technical alarms sound even during the pause.
|
||||
+ alarms.insert(AlarmKey::NoSensor, AlarmLevel::Standard);
|
||||
+ assert_eq!(pause.effective_level(t0, &alarms), AlarmLevel::Standard);
|
||||
+ // Pressing again captures both current alarms and restarts the clock.
|
||||
+ pause.pause_current(t0 + Duration::from_secs(5), &alarms);
|
||||
+ assert_eq!(pause.remaining_seconds(t0 + Duration::from_secs(5)), Some(120));
|
||||
+ assert_eq!(pause.effective_level(t0 + Duration::from_secs(5), &alarms), AlarmLevel::None);
|
||||
+ alarms.insert(AlarmKey::Rhythm("VF"), AlarmLevel::Critical);
|
||||
+ assert_eq!(pause.effective_level(t0 + Duration::from_secs(6), &alarms), AlarmLevel::Critical);
|
||||
+ assert_eq!(pause.effective_level(t0 + Duration::from_secs(126), &alarms), AlarmLevel::Critical);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn alarm_recurrence_and_expiration_are_not_muted() {
|
||||
+ let t0 = Instant::now();
|
||||
+ let mut pause = AlarmPause::default();
|
||||
+ let mut active = ActiveAlarms::new();
|
||||
+ active.insert(AlarmKey::Low("SpO2"), AlarmLevel::Standard);
|
||||
+ pause.pause_current(t0, &active);
|
||||
+ assert_eq!(pause.effective_level(t0, &active), AlarmLevel::None);
|
||||
+ // The condition clears; a recurrence is a fresh alarm.
|
||||
+ active.clear();
|
||||
+ assert_eq!(pause.effective_level(t0 + Duration::from_secs(2), &active), AlarmLevel::None);
|
||||
+ active.insert(AlarmKey::Low("SpO2"), AlarmLevel::Standard);
|
||||
+ assert_eq!(pause.effective_level(t0 + Duration::from_secs(3), &active), AlarmLevel::Standard);
|
||||
+ pause.pause_current(t0 + Duration::from_secs(4), &active);
|
||||
+ assert_eq!(pause.effective_level(t0 + Duration::from_secs(123), &active), AlarmLevel::None);
|
||||
+ assert_eq!(pause.effective_level(t0 + Duration::from_secs(124), &active), AlarmLevel::Standard);
|
||||
+ assert_eq!(pause.remaining_seconds(t0 + Duration::from_secs(124)), None);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn pause_does_not_start_without_an_active_alarm() {
|
||||
+ let mut pause = AlarmPause::default();
|
||||
+ let now = Instant::now();
|
||||
+ pause.pause_current(now, &ActiveAlarms::new());
|
||||
+ assert_eq!(pause.remaining_seconds(now), None);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn separate_lower_upper_and_rhythm_alarm_identities() {
|
||||
+ let mut p = Parameters::default();
|
||||
+ let sim = Simulator::new(&p);
|
||||
+ p.alarms.hr = AlarmLimits { lower: Some(60), upper: Some(100) };
|
||||
+ p.heart_rate = 110;
|
||||
+ assert!(active_conditions(&p, &sim).contains_key(&AlarmKey::High("HR")));
|
||||
+ p.heart_rate = 50;
|
||||
+ let conditions = active_conditions(&p, &sim);
|
||||
+ assert!(conditions.contains_key(&AlarmKey::Low("HR")));
|
||||
+ assert!(!conditions.contains_key(&AlarmKey::High("HR")));
|
||||
+ p.ecg_rhythm = EcgRhythm::VentricularFibrillation;
|
||||
+ assert_eq!(active_conditions(&p, &sim).get(&AlarmKey::Rhythm("VF")),
|
||||
+ Some(&AlarmLevel::Critical));
|
||||
+ }
|
||||
+
|
||||
#[test]
|
||||
fn saturation_pitches_follow_exact_bands_and_decrease_to_87_hz() {
|
||||
assert_eq!(QRS_SPO2_HZ.first(), Some(&740.0));
|
||||
diff --git a/src/render.rs b/src/render.rs
|
||||
index 9b9b711..de8a9c3 100644
|
||||
--- a/src/render.rs
|
||||
+++ b/src/render.rs
|
||||
@@ -25,7 +25,8 @@ fn visible_channels(p: &Parameters) -> Vec<(Channel, &'static str, Color)> {
|
||||
channels
|
||||
}
|
||||
|
||||
-pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulator) {
|
||||
+pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters,
|
||||
+ sim: &Simulator, alarm_pause_seconds: Option<u64>) {
|
||||
let w = f64::from(width.max(1));
|
||||
let h = f64::from(height.max(1));
|
||||
set_color(cr, BG);
|
||||
@@ -60,6 +61,7 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
|
||||
text(cr, "SIMULATION", split_x - 128.0 * text_scale, header * 0.58,
|
||||
11.0 * text_scale, MUTED, false);
|
||||
}
|
||||
+ draw_header_controls(cr, w, h, alarm_pause_seconds);
|
||||
stroke_line(cr, pad, header, w - pad, header, MUTED, 0.8);
|
||||
stroke_line(cr, split_x, header, split_x, h - pad, MUTED, 0.9);
|
||||
|
||||
@@ -85,6 +87,95 @@ pub fn draw(cr: &Context, width: i32, height: i32, p: &Parameters, sim: &Simulat
|
||||
numeric_width, p, sim);
|
||||
}
|
||||
|
||||
+/// Header controls use the same Cairo canvas as the waveform. Their hit
|
||||
+/// rectangles are shared by mouse and Wayland touch; no OSK is necessary.
|
||||
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
+pub enum HeaderControl { Settings, PauseAlarms }
|
||||
+
|
||||
+fn header_buttons(width: f64, height: f64) -> [(HeaderControl, f64, f64, f64); 2] {
|
||||
+ let pad = (width.min(height) * 0.018).clamp(6.0, 20.0);
|
||||
+ let header = (height * 0.083).clamp(32.0, 68.0);
|
||||
+ let side = (header * 0.54).clamp(22.0, 34.0);
|
||||
+ let top = ((header - side - 14.0) * 0.5).max(2.0);
|
||||
+ let pause_x = width - pad - side;
|
||||
+ [
|
||||
+ (HeaderControl::Settings, pause_x - side - 9.0, top, side),
|
||||
+ (HeaderControl::PauseAlarms, pause_x, top, side),
|
||||
+ ]
|
||||
+}
|
||||
+
|
||||
+pub fn header_control_hit_test(x: f64, y: f64, width: i32, height: i32)
|
||||
+ -> Option<HeaderControl> {
|
||||
+ header_buttons(f64::from(width.max(1)), f64::from(height.max(1)))
|
||||
+ .into_iter().find_map(|(control, left, top, side)| {
|
||||
+ (x >= left && x <= left + side && y >= top && y <= top + side)
|
||||
+ .then_some(control)
|
||||
+ })
|
||||
+}
|
||||
+
|
||||
+fn draw_header_controls(cr: &Context, w: f64, h: f64, paused: Option<u64>) {
|
||||
+ use std::f64::consts::TAU;
|
||||
+ let buttons = header_buttons(w, h);
|
||||
+ for (control, x, y, side) in buttons {
|
||||
+ let is_bell = control == HeaderControl::PauseAlarms;
|
||||
+ set_color(cr, if is_bell { YELLOW } else { (0.11, 0.12, 0.13) });
|
||||
+ cr.rectangle(x, y, side, side);
|
||||
+ let _ = cr.fill();
|
||||
+ set_color(cr, if is_bell { (0.0, 0.0, 0.0) } else { LIGHT_GREY });
|
||||
+ cr.set_line_width((side * 0.065).max(1.3));
|
||||
+ let cx = x + side * 0.5;
|
||||
+ let cy = y + side * 0.49;
|
||||
+ if is_bell {
|
||||
+ // Bell dome, lower lip and clapper in the monitor's own palette.
|
||||
+ let r = side * 0.23;
|
||||
+ cr.move_to(cx - r, cy + r * 0.54);
|
||||
+ cr.line_to(cx - r * 0.83, cy - r * 0.25);
|
||||
+ cr.curve_to(cx - r * 0.85, cy - r * 1.65, cx + r * 0.85, cy - r * 1.65,
|
||||
+ cx + r * 0.83, cy - r * 0.25);
|
||||
+ cr.line_to(cx + r, cy + r * 0.54);
|
||||
+ cr.close_path();
|
||||
+ let _ = cr.stroke();
|
||||
+ cr.move_to(cx - r * 1.12, cy + r * 0.66);
|
||||
+ cr.line_to(cx + r * 1.12, cy + r * 0.66);
|
||||
+ let _ = cr.stroke();
|
||||
+ cr.arc(cx, cy + r * 0.83, r * 0.17, 0.0, TAU);
|
||||
+ let _ = cr.fill();
|
||||
+ } else {
|
||||
+ let r = side * 0.22;
|
||||
+ cr.arc(cx, cy, r, 0.0, TAU);
|
||||
+ let _ = cr.stroke();
|
||||
+ cr.arc(cx, cy, side * 0.065, 0.0, TAU);
|
||||
+ let _ = cr.fill();
|
||||
+ for i in 0..8 {
|
||||
+ let angle = i as f64 * TAU / 8.0;
|
||||
+ cr.move_to(cx + (r + side * 0.02) * angle.cos(),
|
||||
+ cy + (r + side * 0.02) * angle.sin());
|
||||
+ cr.line_to(cx + (r + side * 0.12) * angle.cos(),
|
||||
+ cy + (r + side * 0.12) * angle.sin());
|
||||
+ }
|
||||
+ let _ = cr.stroke();
|
||||
+ }
|
||||
+ }
|
||||
+ if let Some(seconds) = paused {
|
||||
+ let (_, x, top, side) = buttons[1];
|
||||
+ let message = format!("paused for {seconds} s");
|
||||
+ let size = (side * 0.28).clamp(8.0, 10.0);
|
||||
+ // Right-align below the bell, safely above the header divider.
|
||||
+ let _ = cr.save();
|
||||
+ cr.select_font_face("Sans", FontSlant::Normal, FontWeight::Normal);
|
||||
+ cr.set_font_size(size);
|
||||
+ if let Ok(extents) = cr.text_extents(&message) {
|
||||
+ let text_x = (x + side - extents.width()).max(0.0);
|
||||
+ let baseline = (top + side + size + 2.0)
|
||||
+ .min((h * 0.083).clamp(32.0, 68.0) - 1.0);
|
||||
+ set_color(cr, YELLOW);
|
||||
+ cr.move_to(text_x, baseline);
|
||||
+ let _ = cr.show_text(&message);
|
||||
+ }
|
||||
+ let _ = cr.restore();
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/// Touch regions track the actual layout, including hidden and reordered rows.
|
||||
/// The last row uses four equal cells: only the NIBP cell is interactive.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -813,3 +904,22 @@ mod tests {
|
||||
}
|
||||
|
||||
}
|
||||
+
|
||||
+#[cfg(test)]
|
||||
+mod header_control_tests {
|
||||
+ use super::*;
|
||||
+
|
||||
+ #[test]
|
||||
+ fn header_buttons_are_distinct_touch_targets_outside_parameter_rows() {
|
||||
+ for (w, h) in [(1200, 760), (700, 440), (1920, 1080)] {
|
||||
+ let buttons = header_buttons(w as f64, h as f64);
|
||||
+ for (kind, x, y, size) in buttons {
|
||||
+ assert_eq!(header_control_hit_test(x + size / 2.0,
|
||||
+ y + size / 2.0, w, h), Some(kind));
|
||||
+ assert_eq!(monitor_hit_test(x + size / 2.0,
|
||||
+ y + size / 2.0, w, h, &Parameters::default()), None);
|
||||
+ }
|
||||
+ assert_eq!(header_control_hit_test(10.0, h as f64 * 0.5, w, h), None);
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/ui.rs b/src/ui.rs
|
||||
index 0c02b36..210e862 100644
|
||||
--- a/src/ui.rs
|
||||
+++ b/src/ui.rs
|
||||
@@ -34,10 +34,11 @@ pub fn create_windows(app: &Application) {
|
||||
let simulator = Rc::new(RefCell::new(Simulator::new(¶meters.borrow())));
|
||||
let audio = Rc::new(RefCell::new(AlarmAudio::new()));
|
||||
let qrs_audio = Rc::new(RefCell::new(QrsAudio::new()));
|
||||
+ let alarm_pause = Rc::new(RefCell::new(alarm::AlarmPause::default()));
|
||||
install_ecg_menu_style(); // neutral style shared by all parameter panels
|
||||
let admin_changed: AdminChanged = Rc::new(RefCell::new(None));
|
||||
let monitor = create_monitor(app, parameters.clone(), simulator.clone(),
|
||||
- admin_changed.clone());
|
||||
+ admin_changed.clone(), alarm_pause.clone());
|
||||
let admin = create_admin(app, parameters.clone(), simulator.clone(), &monitor,
|
||||
audio.clone(), admin_changed);
|
||||
|
||||
@@ -47,7 +48,8 @@ pub fn create_windows(app: &Application) {
|
||||
let config = parameters.borrow();
|
||||
let mut sim = simulator.borrow_mut();
|
||||
let events = sim.take_audio_events();
|
||||
- let current = alarm::level(&config, &sim);
|
||||
+ let active = alarm::active_conditions(&config, &sim);
|
||||
+ let current = alarm_pause.borrow_mut().effective_level(Instant::now(), &active);
|
||||
let beat_tone = alarm::qrs_tone(&config, &sim, &events);
|
||||
drop(sim);
|
||||
audio.borrow_mut().update(current, config.audible_alarms);
|
||||
@@ -62,7 +64,8 @@ pub fn create_windows(app: &Application) {
|
||||
|
||||
fn create_monitor(app: &Application, params: SharedParams,
|
||||
simulator: Rc<RefCell<Simulator>>,
|
||||
- admin_changed: AdminChanged) -> ApplicationWindow {
|
||||
+ admin_changed: AdminChanged,
|
||||
+ alarm_pause: Rc<RefCell<alarm::AlarmPause>>) -> ApplicationWindow {
|
||||
let window = ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.title(concat!("Patient Monitor — Simulation v", env!("CARGO_PKG_VERSION")))
|
||||
@@ -76,9 +79,11 @@ fn create_monitor(app: &Application, params: SharedParams,
|
||||
canvas.set_draw_func({
|
||||
let params = params.clone();
|
||||
let simulator = simulator.clone();
|
||||
+ let alarm_pause = alarm_pause.clone();
|
||||
move |_area, cr, width, height| {
|
||||
let config = params.borrow();
|
||||
- render::draw(cr, width, height, &config, &simulator.borrow());
|
||||
+ let remaining = alarm_pause.borrow().remaining_seconds(Instant::now());
|
||||
+ render::draw(cr, width, height, &config, &simulator.borrow(), remaining);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -124,7 +129,27 @@ fn create_monitor(app: &Application, params: SharedParams,
|
||||
let canvas = canvas.clone();
|
||||
let params = params.clone();
|
||||
let simulator = simulator.clone();
|
||||
+ let alarm_pause = alarm_pause.clone();
|
||||
+ let admin_changed = admin_changed.clone();
|
||||
+ let monitor_menu = monitor_menu.clone();
|
||||
move |_gesture, _press_count, x, y| {
|
||||
+ // Header actions do not activate parameter touch menus.
|
||||
+ if let Some(control) = render::header_control_hit_test(
|
||||
+ x, y, canvas.width(), canvas.height()) {
|
||||
+ match control {
|
||||
+ render::HeaderControl::PauseAlarms => {
|
||||
+ let current = alarm::active_conditions(
|
||||
+ ¶ms.borrow(), &simulator.borrow());
|
||||
+ alarm_pause.borrow_mut().pause_current(Instant::now(), ¤t);
|
||||
+ canvas.queue_draw();
|
||||
+ }
|
||||
+ render::HeaderControl::Settings => {
|
||||
+ open_monitor_settings(&app, &window, params.clone(),
|
||||
+ admin_changed.clone(), monitor_menu.clone());
|
||||
+ }
|
||||
+ }
|
||||
+ return;
|
||||
+ }
|
||||
let touched = {
|
||||
let p = params.borrow();
|
||||
render::monitor_hit_test(x, y, canvas.width(), canvas.height(), &p)
|
||||
@@ -535,7 +560,7 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
||||
let params = params.clone();
|
||||
let updating_preset = updating_preset.clone();
|
||||
move |dropdown| {
|
||||
- if dropdown.selected() != 1 { return; }
|
||||
+ if updating_preset.get() || dropdown.selected() != 1 { return; }
|
||||
let limits = AlarmSettings::adult();
|
||||
// Suppress per-field callbacks while writing both entries in each row.
|
||||
// Otherwise a half-updated pair could temporarily be invalid.
|
||||
@@ -562,7 +587,17 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
|
||||
editor.set_limits(get_limits(&snapshot.alarms));
|
||||
}
|
||||
updating_preset.set(false);
|
||||
- if alarm_changed { preset_dropdown.set_selected(0); }
|
||||
+ // Keep Adult preset and the monitor settings synchronized. A
|
||||
+ // manually edited matrix selects Custom unless it equals Adult.
|
||||
+ let _ = alarm_changed;
|
||||
+ updating_preset.set(true);
|
||||
+ preset_dropdown.set_selected(if snapshot.alarms == AlarmSettings::adult() { 1 } else { 0 });
|
||||
+ updating_preset.set(false);
|
||||
+ audible.set_active(snapshot.audible_alarms);
|
||||
+ qrs_enabled.set_active(snapshot.qrs_tone_enabled);
|
||||
+ if name_entry.text().as_str() != snapshot.patient_name {
|
||||
+ name_entry.set_text(&snapshot.patient_name);
|
||||
+ }
|
||||
lead_dropdown.set_selected(snapshot.ecg_lead.index());
|
||||
spo2_quality_dropdown.set_selected(snapshot.spo2_quality as u32);
|
||||
sensor.set_active(!snapshot.spo2_sensor_attached);
|
||||
@@ -629,6 +664,11 @@ fn install_ecg_menu_style() {
|
||||
min-height: 48px; min-width: 52px;
|
||||
}
|
||||
window.ecg-settings button:hover { background-color: #303437; }
|
||||
+ window.ecg-settings entry {
|
||||
+ color: #e5e9eb; background-color: #171717;
|
||||
+ border: 1px solid #6b757d; min-height: 42px;
|
||||
+ }
|
||||
+ window.ecg-settings checkbutton { color: #e5e9eb; }
|
||||
window.ecg-settings dropdown {
|
||||
color: #e5e9eb; background-color: #171717;
|
||||
border: 1px solid #6b757d; min-height: 48px;
|
||||
@@ -987,6 +1027,135 @@ fn apply_module_alarm_changes(
|
||||
p.alarms != previous
|
||||
}
|
||||
|
||||
+/// Global controls requested for the monitor header. The settings window
|
||||
+/// follows the existing black/light-grey touch-menu style. Only the patient
|
||||
+/// name uses text input; no on-screen keyboard is constructed.
|
||||
+fn open_monitor_settings(app: &Application, monitor: &ApplicationWindow,
|
||||
+ params: SharedParams, on_change: AdminChanged,
|
||||
+ open_menu: MonitorMenuHandle) {
|
||||
+ if let Some(existing) = open_menu.borrow().as_ref().and_then(|weak| weak.upgrade()) {
|
||||
+ existing.present();
|
||||
+ return;
|
||||
+ }
|
||||
+ let current = params.borrow().clone();
|
||||
+ let dialog = gtk::Window::builder()
|
||||
+ .application(app)
|
||||
+ .title("MONITOR / SETTINGS")
|
||||
+ .transient_for(monitor)
|
||||
+ .modal(true)
|
||||
+ .resizable(true)
|
||||
+ .default_width(570)
|
||||
+ .default_height(480)
|
||||
+ .build();
|
||||
+ dialog.add_css_class("ecg-settings");
|
||||
+ dialog.set_decorated(false);
|
||||
+ *open_menu.borrow_mut() = Some(dialog.downgrade());
|
||||
+
|
||||
+ let content = gtk::Box::new(Orientation::Vertical, 12);
|
||||
+ content.add_css_class("ecg-panel");
|
||||
+ content.set_margin_top(1);
|
||||
+ content.set_margin_bottom(1);
|
||||
+ content.set_margin_start(1);
|
||||
+ content.set_margin_end(1);
|
||||
+ let inner = gtk::Box::new(Orientation::Vertical, 14);
|
||||
+ inner.set_margin_top(20);
|
||||
+ inner.set_margin_bottom(20);
|
||||
+ inner.set_margin_start(20);
|
||||
+ inner.set_margin_end(20);
|
||||
+ let scroller = gtk::ScrolledWindow::new();
|
||||
+ scroller.set_vexpand(true);
|
||||
+ scroller.set_policy(gtk::PolicyType::Never, gtk::PolicyType::Automatic);
|
||||
+ scroller.set_child(Some(&inner));
|
||||
+ content.append(&scroller);
|
||||
+ let heading = gtk::Label::new(Some("MONITOR / SETTINGS"));
|
||||
+ heading.set_xalign(0.0);
|
||||
+ heading.add_css_class("title-2");
|
||||
+ inner.append(&heading);
|
||||
+ inner.append(&ecg_menu_divider());
|
||||
+
|
||||
+ let qrs = gtk::CheckButton::with_label("QRS beep");
|
||||
+ qrs.set_active(current.qrs_tone_enabled);
|
||||
+ inner.append(&qrs);
|
||||
+ let audible = gtk::CheckButton::with_label("Audible alarms");
|
||||
+ audible.set_active(current.audible_alarms);
|
||||
+ inner.append(&audible);
|
||||
+ inner.append(&ecg_menu_divider());
|
||||
+
|
||||
+ let preset_row = gtk::Box::new(Orientation::Horizontal, 12);
|
||||
+ let preset_label = gtk::Label::new(Some("Alert presets"));
|
||||
+ preset_label.set_xalign(0.0);
|
||||
+ preset_label.set_hexpand(true);
|
||||
+ let preset = gtk::DropDown::from_strings(&["Custom", "Adult"]);
|
||||
+ preset.set_selected(if current.alarms == AlarmSettings::adult() { 1 } else { 0 });
|
||||
+ preset_row.append(&preset_label);
|
||||
+ preset_row.append(&preset);
|
||||
+ inner.append(&preset_row);
|
||||
+
|
||||
+ let patient_label = gtk::Label::new(Some("Patient name"));
|
||||
+ patient_label.set_xalign(0.0);
|
||||
+ inner.append(&patient_label);
|
||||
+ let patient = gtk::Entry::new();
|
||||
+ patient.set_max_length(80);
|
||||
+ patient.set_text(¤t.patient_name);
|
||||
+ patient.set_placeholder_text(Some("Enter name with a physical keyboard"));
|
||||
+ inner.append(&patient);
|
||||
+ inner.append(&ecg_menu_divider());
|
||||
+ let attribution = gtk::Label::new(Some(
|
||||
+ "PaMSim by Critical Care Club Austria, (c) 2026"));
|
||||
+ attribution.set_xalign(0.0);
|
||||
+ attribution.set_wrap(true);
|
||||
+ inner.append(&attribution);
|
||||
+
|
||||
+ let footer = gtk::Box::new(Orientation::Horizontal, 12);
|
||||
+ footer.set_halign(gtk::Align::End);
|
||||
+ footer.set_margin_start(20);
|
||||
+ footer.set_margin_end(20);
|
||||
+ footer.set_margin_bottom(14);
|
||||
+ let cancel = gtk::Button::with_label("Cancel");
|
||||
+ cancel.add_css_class("ecg-close");
|
||||
+ cancel.connect_clicked({
|
||||
+ let weak = dialog.downgrade();
|
||||
+ move |_| { if let Some(window) = weak.upgrade() { window.close(); } }
|
||||
+ });
|
||||
+ let apply = gtk::Button::with_label("Apply");
|
||||
+ apply.add_css_class("ecg-apply");
|
||||
+ apply.connect_clicked({
|
||||
+ let weak = dialog.downgrade();
|
||||
+ move |_| {
|
||||
+ let changed_alarms = {
|
||||
+ let mut config = params.borrow_mut();
|
||||
+ config.qrs_tone_enabled = qrs.is_active();
|
||||
+ config.audible_alarms = audible.is_active();
|
||||
+ config.patient_name = patient.text().to_string();
|
||||
+ if preset.selected() == 1 && config.alarms != AlarmSettings::adult() {
|
||||
+ config.alarms = AlarmSettings::adult();
|
||||
+ true
|
||||
+ } else { false }
|
||||
+ };
|
||||
+ if let Some(callback) = on_change.borrow().as_ref() {
|
||||
+ callback(changed_alarms);
|
||||
+ }
|
||||
+ if let Some(window) = weak.upgrade() { window.close(); }
|
||||
+ }
|
||||
+ });
|
||||
+ footer.append(&cancel);
|
||||
+ footer.append(&apply);
|
||||
+ content.append(&footer);
|
||||
+ dialog.set_child(Some(&content));
|
||||
+ let keys = gtk::EventControllerKey::new();
|
||||
+ keys.connect_key_pressed({
|
||||
+ let weak = dialog.downgrade();
|
||||
+ move |_, key, _, _| {
|
||||
+ if key == gdk::Key::Escape {
|
||||
+ if let Some(window) = weak.upgrade() { window.close(); }
|
||||
+ glib::Propagation::Stop
|
||||
+ } else { glib::Propagation::Proceed }
|
||||
+ }
|
||||
+ });
|
||||
+ dialog.add_controller(keys);
|
||||
+ dialog.present();
|
||||
+}
|
||||
+
|
||||
/// Open a modal monitor settings panel in neutral black/grey styling.
|
||||
/// All modules edit alarm limits; NIBP also retains its explicit controls.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
Loading…
Reference in a new issue