--- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "patient-monitor-simulation" -version = "0.6.3" +version = "0.6.4" edition = "2021" license = "MIT" description = "Synthetic patient-monitor simulation for teaching (not for clinical use)" --- a/README.de.md +++ b/README.de.md @@ -1,4 +1,4 @@ -# Patient Monitor Simulation (PaMSim) — v0.6.3 +# Patient Monitor Simulation (PaMSim) — v0.6.4 Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenstern für die Lehre unter Fedora Linux. @@ -26,7 +26,7 @@ Beim Ausblenden anderer Parameter werden die verbleibenden Kurvenzeilen wie bisher dynamisch verteilt. -## Touch-Bedienung am Monitor: ausschließlich Alarmgrenzen (v0.6.1) +## Touch-Bedienung am Monitor: Alarmgrenzen und NIBP-Funktionen (v0.6.4) Durch Berühren oder Anklicken der **Kurve oder des numerischen Wertefeldes** von EKG, SpO₂, ART oder CO₂ öffnet sich das entsprechende Alarmmenü. Bei @@ -36,7 +36,7 @@ Hintergrund, sehr hellgraue Schrift sowie 0,8 Pixel breite Begrenzungs- und Trennlinien** wie der Hauptmonitor. -**Am Monitor können ausschließlich Alarmgrenzen eingestellt werden.** +**In allen Monitor-Menüs können die Alarmgrenzen eingestellt werden.** Für jede untere und obere Alarmgrenze stehen große **−/+**-Tasten sowie separate **ON/OFF**-Tasten zur Verfügung. Nicht gesetzte Grenzwerte sind deaktiviert. Ein unterer Grenzwert darf den oberen nicht überschreiten. @@ -55,18 +55,20 @@ **Cancel** oder **Esc** werden nicht übernommene Änderungen verworfen. Die Auswahl der EKG-Ableitung, SpO₂-Signalqualität und Sensorverbindung, -der arteriellen Kurvenform, der Kapnogrammform sowie **sämtliche NIBP- -Messfunktionen** sind ausschließlich im **Admin-Fenster** verfügbar. Dazu -zählen Messintervall, automatische Messung, **Measure now**, simulierter -Messausfall und Manschettenlokalisation. Diese Parameter können über die -Alarmmenüs am Monitor nicht verändert werden. +der arteriellen Kurvenform und der Kapnogrammform bleiben ausschließlich im +**Admin-Fenster**. Das **NIBP-Touchmenü** bietet zusätzlich **Measure now**, +**Automatic measurement ON/OFF** und **Measurement interval** (1, 3, 5, 10, +20, 30 oder 60 Minuten). Intervall und Automatik werden erst mit **Apply** +übernommen; **Measure now** startet dagegen sofort, auch bei deaktivierter +Automatik. Eine bereits laufende Messung wird nicht erneut gestartet. +Simulierter Messausfall und Manschettenlokalisation bleiben Admin-only. ### NIBP beim Programmstart Die **automatische NIBP-Messung ist beim Start ausgeschaltet**. Anfangs zeigt der Monitor `---/---` (MAP `---`); es findet keine Messung statt. -Die erste Messung wird über **Measure now** im Admin-Fenster oder durch -Aktivieren von **Automatic NIBP measurement** ausgelöst. Beim Einschalten +Die erste Messung wird über **Measure now** im NIBP-Touchmenü oder Admin-Fenster +oder durch Aktivieren von **Automatic NIBP measurement** ausgelöst. Beim Einschalten von Auto beginnt sofort ein Messzyklus; das Intervall zählt anschließend jeweils ab Ende der vorherigen Messung. Beim Ausschalten von Auto wird eine bereits laufende Messung nicht abgebrochen. **Measure now** funktioniert @@ -83,8 +85,8 @@ Deaktivieren liegt unmittelbar rechts von Minus. Größe, Gestaltung, Schrittweite, Wiederherstellung des letzten Werts sowie Apply/Cancel bleiben erhalten. Bei Platzmangel lässt sich die Matrix scrollen, während -Apply und Cancel zugänglich bleiben. Andere Einstellungen bleiben dem -Admin-Fenster vorbehalten. +Apply und Cancel zugänglich bleiben. Andere Einstellungen bleiben dem Admin-Fenster vorbehalten, mit Ausnahme der +expliziten NIBP-Messfunktionen im Touchmenü. ## Thoraxkompressionen (v0.5.4) @@ -607,3 +609,13 @@ Kurvenformen sowie NIBP-Messfunktionen wurden aus den Monitor-Menüs entfernt und bleiben im Admin-Fenster verfügbar. Die Simulationslogik, Alarmprüfung und das NIBP-Startverhalten wurden nicht verändert. + +### v0.6.4 – NIBP-Touchbedienung wiederhergestellt + +Das NIBP-Menü enthält wieder **Measure now**, **Automatic measurement ON/OFF** +und das **Messintervall** (1, 3, 5, 10, 20, 30 oder 60 Minuten) oberhalb der +SYS/MAP/DIA-Alarmmatrix. Die Einstellungen für Intervall und Automatik werden +mit **Apply** gespeichert; **Measure now** startet unmittelbar einen Messzyklus, +auch wenn die Automatik ausgeschaltet ist. Die Admin-Oberfläche wird +synchronisiert. Die anderen Parametermenüs bleiben auf Alarmgrenzen beschränkt. +Manschettenzuordnung und simulierter Messausfall verbleiben im Admin-Fenster. --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Patient Monitor Simulation (PaMSim) — v0.6.3 +# Patient Monitor Simulation (PaMSim) — v0.6.4 A Rust/GTK4 patient-monitor simulator with two main windows for teaching on Fedora Linux. @@ -23,7 +23,7 @@ bottom measurement row and other three groups remain present. Disabling one of the four waveform channels still reflows the remaining rows above it. -## Monitor touchscreen: alarm limits only (v0.6.1) +## Monitor touchscreen: alarm limits and NIBP controls (v0.6.4) Tap or click the **waveform or numerical readout** of ECG, SpO₂, ART or CO₂ to open that channel's alarm-limit panel. For NIBP, tap the **rightmost @@ -32,7 +32,7 @@ are available in fullscreen and retain a **black background, very light-grey text, and 0.8-pixel borders and dividers**, in the style of the main monitor. -**Only alarm thresholds can be modified from the monitor-side menus.** +**Alarm thresholds can be modified from every monitor-side menu.** No keyboard is required: every lower/upper limit has large **− / +** controls with a parameter-specific increment and an independent **ON/OFF** control. Unset limits remain disabled. The lower limit cannot exceed the upper limit. @@ -49,18 +49,20 @@ Changing a threshold sets the alarm preset to **Custom**. **Cancel** or **Esc** discards the draft changes. -ECG lead selection, SpO₂ signal quality and sensor status, ART waveform shape, -capnogram shape, and all NIBP measurement controls are **Admin-only**. This -includes NIBP measurement interval, Auto ON/OFF, **Measure now**, simulated -failed reading, and cuff placement. None of these physiological or technical -parameters is changed by the monitor-side alarm menus. +**NIBP is the exception:** its monitor-side menu additionally provides **Measure now**, +**Automatic measurement ON/OFF**, and the **1/3/5/10/20/30/60-minute interval**. +Interval and Auto changes take effect with **Apply** (or are discarded with +Cancel/Esc); **Measure now starts immediately**, even with Auto OFF and before +Apply. The touch controls synchronize with Admin. A measurement already in +progress is not restarted. The simulated failure option and cuff placement +remain Admin-only, as do ECG lead, SpO₂ sensor/quality and waveform choices. ### NIBP startup and automatic measurements **Auto measurement is OFF by default.** On startup the monitor shows `---/---` (MAP `---`) and no measurement is initiated. To obtain a reading, -select **Measure now** in Admin, or enable **Automatic NIBP measurement** -there. The first automatic cycle begins immediately after enabling Auto; +select **Measure now** in the NIBP monitor menu (or in Admin), or enable +**Automatic NIBP measurement** via the menu (or Admin). The first automatic cycle begins immediately after enabling Auto; subsequent measurement intervals count from completion of the prior cycle. Disabling Auto stops further scheduled measurements without interrupting a cycle already in progress. Manual measurement remains possible while Auto @@ -77,7 +79,8 @@ large button styling, per-parameter increments, last-value restoration, optional bounds and Apply/Cancel semantics are unchanged. The matrix scrolls if necessary while Apply and Cancel remain accessible below it. Other -physiological and NIBP controls remain Admin-only. +physiological controls remain Admin-only, except for the three explicitly +requested NIBP measurement controls. ## Chest compressions (v0.5.4) @@ -620,3 +623,14 @@ measurement controls from monitor-side menus. These remain available in Admin, including manual NIBP measurement and Auto ON/OFF. No physiological model, alarm evaluation or NIBP startup behavior was changed. + +### v0.6.4 — NIBP touch controls restored + +The monitor-side NIBP settings menu again contains **Measure now**, +**Automatic measurement ON/OFF** and the **measurement interval** (1, 3, 5, +10, 20, 30, 60 minutes). These controls are above the horizontal SYS/MAP/DIA +alarm matrix and share its monochrome touchscreen styling. Auto and interval +are saved with Apply; Measure now starts a cuff cycle immediately regardless +of Auto. Both monitor and Admin display the selected settings. Other monitor +menus remain limited to alarm thresholds; NIBP cuff placement, the simulated +failed-reading option and non-NIBP signal settings remain Admin-only. --- a/src/simulation.rs +++ b/src/simulation.rs @@ -277,6 +277,10 @@ } p.spo2_status_at_quality(self.pulse_rate(), self.poor_signal_lost(), self.spo2_quality(p)) + } + + pub fn nibp_measuring(&self) -> bool { + self.nibp.measuring() } pub fn start_nibp_now(&mut self, p: &Parameters) { --- a/src/ui.rs +++ b/src/ui.rs @@ -108,8 +108,8 @@ }); window.add_controller(keys); - // One gesture opens alarm-only panels for visible waveform/numeric rows - // and NIBP's bottom-right cell. Mouse and Wayland touch share geometry. + // Mouse and Wayland touch open the visible module's settings panel. + // NIBP alone also includes its explicitly requested measurement controls. let monitor_menu: MonitorMenuHandle = Rc::new(RefCell::new(None)); let click = gtk::GestureClick::new(); click.connect_released({ @@ -117,13 +117,14 @@ let window = window.clone(); let canvas = canvas.clone(); let params = params.clone(); + let simulator = simulator.clone(); move |_gesture, _press_count, x, y| { let touched = { let p = params.borrow(); render::monitor_hit_test(x, y, canvas.width(), canvas.height(), &p) }; if let Some(channel) = touched { - open_module_menu(&app, &window, params.clone(), + open_module_menu(&app, &window, params.clone(), simulator.clone(), admin_changed.clone(), monitor_menu.clone(), channel); } } @@ -133,11 +134,25 @@ window } -/// Map an Admin NIBP measurement interval to its dropdown selection. -/// The touchscreen alarm menus do not expose scheduling controls. +/// Both Admin and the monitor NIBP menu use the same interval options. +const NIBP_INTERVALS: [i32; 7] = [1, 3, 5, 10, 20, 30, 60]; + fn nibp_interval_index(minutes: i32) -> u32 { - const INTERVALS: [i32; 7] = [1, 3, 5, 10, 20, 30, 60]; - INTERVALS.iter().position(|&value| value == minutes).unwrap_or(2) as u32 + NIBP_INTERVALS.iter().position(|&value| value == minutes).unwrap_or(2) as u32 +} + +fn nibp_interval_minutes(selected: u32) -> i32 { + NIBP_INTERVALS.get(selected as usize).copied().unwrap_or(5) +} + +/// Apply only the explicitly requested monitor-side NIBP measurement settings. +/// Neither cuff settings nor any other module's configuration is changed. +fn apply_nibp_measurement_settings(p: &mut Parameters, selected: u32, auto: bool) -> bool { + let minutes = nibp_interval_minutes(selected); + let changed = p.nibp_interval_minutes != minutes || p.nibp_auto_measurement != auto; + p.nibp_interval_minutes = minutes; + p.nibp_auto_measurement = auto; + changed } fn create_admin(app: &Application, params: SharedParams, @@ -437,10 +452,9 @@ let nibp_interval_dropdown = add_dropdown_at(&nibp, "Measurement interval", &["1 min", "3 min", "5 min", "10 min", "20 min", "30 min", "60 min"], - 2, params.clone(), |p, selected| { - p.nibp_interval_minutes = match selected { - 0 => 1, 1 => 3, 2 => 5, 3 => 10, 4 => 20, 5 => 30, _ => 60, - }; + nibp_interval_index(params.borrow().nibp_interval_minutes), + params.clone(), |p, selected| { + p.nibp_interval_minutes = nibp_interval_minutes(selected); }); let nibp_auto = gtk::CheckButton::with_label("Automatic NIBP measurement"); nibp_auto.set_active(params.borrow().nibp_auto_measurement); @@ -602,6 +616,10 @@ min-height: 48px; min-width: 52px; } window.ecg-settings button:hover { background-color: #303437; } + window.ecg-settings dropdown { + color: #e5e9eb; background-color: #171717; + border: 1px solid #6b757d; min-height: 48px; + } window.ecg-settings button.ecg-apply { color: #000000; background-color: #e5e9eb; font-weight: bold; } @@ -866,8 +884,85 @@ frame } -/// A monitor-side menu may change only alarm limits. All patient and -/// measurement configuration (including NIBP scheduling) stays Admin-only. +/// Add the three explicitly requested NIBP actions to the monitor menu. +/// Alarm limits, interval and Auto are staged until Apply. "Measure now" is +/// an immediate command, independent of Auto and of the staged settings. +fn nibp_touch_measurement_controls( + current: &Parameters, + params: SharedParams, + simulator: Rc>, +) -> (gtk::Box, gtk::DropDown, gtk::ToggleButton) { + let section = gtk::Box::new(Orientation::Vertical, 12); + section.add_css_class("alarm-limit-frame"); + section.set_hexpand(true); + + let heading = gtk::Label::new(Some("NIBP measurement")); + heading.add_css_class("alarm-limit-heading"); + heading.set_xalign(0.0); + section.append(&heading); + + let row = gtk::Box::new(Orientation::Horizontal, 12); + let label = gtk::Label::new(Some("Measurement interval")); + label.set_hexpand(true); + label.set_xalign(0.0); + let interval = gtk::DropDown::from_strings(&[ + "1 min", "3 min", "5 min", "10 min", "20 min", "30 min", "60 min", + ]); + interval.set_selected(nibp_interval_index(current.nibp_interval_minutes)); + interval.set_size_request(160, 52); + row.append(&label); + row.append(&interval); + section.append(&row); + + let action_row = gtk::Box::new(Orientation::Horizontal, 12); + action_row.set_homogeneous(true); + let auto = gtk::ToggleButton::new(); + auto.set_active(current.nibp_auto_measurement); + auto.set_label(if auto.is_active() { + "Automatic measurement: ON" + } else { + "Automatic measurement: OFF" + }); + auto.connect_toggled(|button| { + button.set_label(if button.is_active() { + "Automatic measurement: ON" + } else { + "Automatic measurement: OFF" + }); + }); + action_row.append(&auto); + + let measure_now = gtk::Button::with_label("Measure now"); + measure_now.set_tooltip_text(Some("Start an NIBP cuff measurement immediately")); + action_row.append(&measure_now); + section.append(&action_row); + + let feedback = gtk::Label::new(Some( + "Measure now acts immediately. Interval and Auto are saved with Apply." + )); + feedback.set_xalign(0.0); + feedback.set_wrap(true); + measure_now.connect_clicked({ + let feedback = feedback.clone(); + move |_| { + // Drop the immutable Ref before borrowing the simulator mutably. + let measuring = { simulator.borrow().nibp_measuring() }; + if measuring { + feedback.set_text("NIBP measurement already in progress."); + } else { + simulator.borrow_mut().start_nibp_now(¶ms.borrow()); + feedback.set_text("NIBP measurement started."); + } + } + }); + // Keep the explanatory label visible while the button changes its status. + // It is owned by the section, not by the button callback. + section.append(&feedback); + (section, interval, auto) +} + +/// All monitor modules can edit alarm limits. Only NIBP additionally offers +/// the explicitly requested interval, Auto and immediate measurement controls. fn apply_module_alarm_changes( p: &mut Parameters, limits: &[(fn(&mut AlarmSettings, AlarmLimits), AlarmLimits)], @@ -879,12 +974,13 @@ p.alarms != previous } -/// Open a modal alarm-limit panel with the same black, grey, 0.8 px divider -/// and border design as the ECG panel. Other parameters are Admin-only. +/// 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)] fn open_module_menu(app: &Application, monitor: &ApplicationWindow, - params: SharedParams, on_change: AdminChanged, - open_menu: MonitorMenuHandle, channel: render::TouchChannel) { + params: SharedParams, simulator: Rc>, + on_change: AdminChanged, open_menu: MonitorMenuHandle, + channel: render::TouchChannel) { if let Some(existing) = open_menu.borrow().as_ref().and_then(|weak| weak.upgrade()) { existing.present(); return; @@ -906,7 +1002,7 @@ .default_width(800) .default_height(match channel { render::TouchChannel::Art => 560, - render::TouchChannel::Nibp => 490, + render::TouchChannel::Nibp => 640, render::TouchChannel::Ecg => 310, _ => 420, }) @@ -937,6 +1033,18 @@ heading.add_css_class("title-2"); inner.append(&heading); inner.append(&ecg_menu_divider()); + + // NIBP is the explicit exception to the alarm-only monitor menu policy. + // Put the manual measurement action above the limit matrix for easy access. + let nibp_controls = if channel == render::TouchChannel::Nibp { + let (section, interval, auto) = nibp_touch_measurement_controls( + ¤t, params.clone(), simulator); + inner.append(§ion); + inner.append(&ecg_menu_divider()); + Some((interval, auto)) + } else { + None + }; // A shared horizontal matrix is used in every monitor-side touch menu. let specs = module_alarm_specs(channel, ¤t); @@ -983,7 +1091,12 @@ } let changed_alarms = { let mut p = params.borrow_mut(); - apply_module_alarm_changes(&mut p, &selected_limits) + let changed = apply_module_alarm_changes(&mut p, &selected_limits); + if let Some((interval, auto)) = &nibp_controls { + apply_nibp_measurement_settings(&mut p, + interval.selected(), auto.is_active()); + } + changed }; if let Some(callback) = on_change.borrow().as_ref() { callback(changed_alarms); @@ -1064,7 +1177,7 @@ } #[test] - fn touchscreen_applies_only_alarm_limits_and_preserves_other_controls() { + fn monitor_alarm_edits_preserve_other_controls() { let mut p = Parameters::default(); p.ecg_lead = EcgLead::V1; p.spo2_quality = Spo2Quality::Poor; @@ -1093,6 +1206,40 @@ assert!(p.nibp_cuff_on_art); } + #[test] + fn nibp_touch_interval_roundtrip_and_startup_off() { + let p = Parameters::default(); + assert!(!p.nibp_auto_measurement); + assert_eq!(p.nibp_interval_minutes, 5); + for (index, minutes) in NIBP_INTERVALS.into_iter().enumerate() { + assert_eq!(nibp_interval_index(minutes), index as u32); + assert_eq!(nibp_interval_minutes(index as u32), minutes); + } + assert_eq!(nibp_interval_minutes(99), 5); + } + + #[test] + fn nibp_touch_apply_changes_only_interval_and_auto() { + let mut p = Parameters::default(); + p.nibp_no_reading = true; + p.nibp_cuff_on_spo2 = true; + p.nibp_cuff_on_art = true; + p.show_nibp = false; + p.alarms.nibp_sys.lower = Some(80); + assert!(apply_nibp_measurement_settings(&mut p, 5, true)); + assert_eq!(p.nibp_interval_minutes, 30); + assert!(p.nibp_auto_measurement); + assert!(!apply_nibp_measurement_settings(&mut p, 5, true)); + assert!(apply_nibp_measurement_settings(&mut p, 0, false)); + assert_eq!(p.nibp_interval_minutes, 1); + assert!(!p.nibp_auto_measurement); + assert!(p.nibp_no_reading); + assert!(p.nibp_cuff_on_spo2); + assert!(p.nibp_cuff_on_art); + assert!(!p.show_nibp); + assert_eq!(p.alarms.nibp_sys.lower, Some(80)); + } + } /// Frame a parameter section with an optional monitor-colored left sidebar.