v0.6.10: Instructor shortcuts on the Actions tab

This commit is contained in:
GABRIEL Sebastian 2026-11-13 12:10:38 +01:00
commit 436299c1e4
7 changed files with 606 additions and 102 deletions

View file

@ -16,11 +16,6 @@ pub enum Kind {
LethalPropofol,
}
impl Kind {
pub const ALL: [Kind; 8] = [
Self::Defibrillation, Self::DefibrillationRhythm, Self::Hypoxia,
Self::Shock, Self::ChestCompressions, Self::Norepinephrine,
Self::ExcessivePropofol, Self::LethalPropofol,
];
pub fn label(self) -> &'static str {
match self {
Self::Defibrillation => "Defibrillation (ECG artifact)",

View file

@ -17,6 +17,30 @@ use crate::simulation::Simulator;
type SharedParams = Rc<RefCell<Parameters>>;
type SharedActions = Rc<RefCell<ActionRunner>>;
// CPR has permanent controls above this menu; do not offer it twice.
// The array also keeps the dropdown and action dispatcher in the same order.
const SCRIPTED_ACTION_CHOICES: [Kind; 7] = [
Kind::Defibrillation,
Kind::DefibrillationRhythm,
Kind::Hypoxia,
Kind::Shock,
Kind::Norepinephrine,
Kind::ExcessivePropofol,
Kind::LethalPropofol,
];
fn action_choice(index: u32) -> Kind {
SCRIPTED_ACTION_CHOICES.get(index as usize)
.copied().unwrap_or(Kind::Defibrillation)
}
fn sync_cpr_button(button: &gtk::Button, active: bool) {
button.set_label(if active { "Stop Chest Compressions" }
else { "Start Chest Compressions" });
button.remove_css_class(if active { "cpr-start" } else { "cpr-stop" });
button.add_css_class(if active { "cpr-stop" } else { "cpr-start" });
}
/// Refresh all Admin widgets whenever a monitor touch-menu commits changes.
/// The bool indicates whether alarm limits changed (mark preset as Custom).
type AdminChanged = Rc<RefCell<Option<Box<dyn Fn(bool)>>>>;
@ -293,7 +317,16 @@ fn create_admin(app: &Application, params: SharedParams,
let provider = gtk::CssProvider::new();
provider.load_from_data(
"button.cpr-start { background-image: none; background-color: #158742; color: #ffffff; font-weight: bold; }
button.cpr-stop { background-image: none; background-color: #c53035; color: #ffffff; font-weight: bold; }"
button.cpr-stop { background-image: none; background-color: #c53035; color: #ffffff; font-weight: bold; }
button.defib-shortcut {
background-image: none; background-color: #ffda2b; color: #151515;
border: 1px solid #b48e14; font-weight: bold; min-height: 44px;
}
button.defib-shortcut:hover { background-color: #ffe763; }
button.defib-shortcut label { color: #151515; }
button.defib-shortcut label.defib-bolt {
color: #cb242b; font-size: 22px; font-weight: bold;
}"
);
gtk::style_context_add_provider_for_display(
&display, &provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
@ -307,15 +340,7 @@ fn create_admin(app: &Application, params: SharedParams,
move |button| {
let mut p = params.borrow_mut();
p.chest_compressions_active = !p.chest_compressions_active;
if p.chest_compressions_active {
button.set_label("Stop Chest Compressions");
button.remove_css_class("cpr-start");
button.add_css_class("cpr-stop");
} else {
button.set_label("Start Chest Compressions");
button.remove_css_class("cpr-stop");
button.add_css_class("cpr-start");
}
sync_cpr_button(button, p.chest_compressions_active);
}
});
cpr.append(&compression_button);
@ -631,8 +656,7 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
tabs.set_hexpand(true);
tabs.set_vexpand(true);
tabs.append_page(&scroller, Some(&gtk::Label::new(Some("Direct Mode"))));
let scripted = actions_page(params.clone(), simulator.clone(), actions.clone(),
compression_button.clone(), compression_quality_dropdown.clone());
let scripted = actions_page(params.clone(), simulator.clone(), actions.clone());
tabs.append_page(&scripted, Some(&gtk::Label::new(Some("Actions & Occurrences"))));
main_box.append(&tabs);
@ -676,10 +700,7 @@ ART and pleth are delayed. VT can be perfusing; PVT, VF and asystole are pulsele
spo2_quality_dropdown.set_selected(snapshot.spo2_quality as u32);
}
let active = snapshot.chest_compressions_active;
compression_button.set_label(if active { "Stop Chest Compressions" }
else { "Start Chest Compressions" });
compression_button.remove_css_class(if active { "cpr-start" } else { "cpr-stop" });
compression_button.add_css_class(if active { "cpr-stop" } else { "cpr-start" });
sync_cpr_button(&compression_button, active);
let qindex = match snapshot.chest_compression_quality {
ChestCompressionQuality::Good => 0,
ChestCompressionQuality::Adequate => 1,
@ -1744,8 +1765,7 @@ fn update_alarm_limits(low_entry: &gtk::Entry, high_entry: &gtk::Entry, max: i32
/// Scripted instructor actions are additive to Direct Mode, never a replacement
/// for its sliders, ECG rhythms, alarm limits or NIBP scheduling controls.
fn actions_page(params: SharedParams, simulator: Rc<RefCell<Simulator>>,
actions: SharedActions, direct_cpr_button: gtk::Button,
direct_cpr_quality: gtk::DropDown) -> gtk::ScrolledWindow {
actions: SharedActions) -> gtk::ScrolledWindow {
let scroller = gtk::ScrolledWindow::new();
scroller.set_policy(gtk::PolicyType::Never, gtk::PolicyType::Automatic);
let panel = gtk::Box::new(Orientation::Vertical, 14);
@ -1766,12 +1786,84 @@ fn actions_page(params: SharedParams, simulator: Rc<RefCell<Simulator>>,
note.set_wrap(true);
panel.append(&note);
let selection = gtk::DropDown::from_strings(&[
"Defibrillation (ECG artifact)", "Defibrillation + rhythm change",
"Deterioration: Hypoxia", "Deterioration: Shock",
"Chest compressions", "Norepinephrine bolus",
"Too much propofol", "Lethal propofol",
]);
// These resuscitation controls are always accessible, independent of which
// scripted action is selected. Both Admin tabs edit the same Parameters.
let cpr_controls = group(&panel, "Chest compressions", None);
let cpr_button = gtk::Button::with_label("Start Chest Compressions");
cpr_button.set_hexpand(true);
cpr_button.add_css_class("cpr-start");
sync_cpr_button(&cpr_button, params.borrow().chest_compressions_active);
cpr_controls.append(&cpr_button);
let initial_cpr_quality = match params.borrow().chest_compression_quality {
ChestCompressionQuality::Good => 0,
ChestCompressionQuality::Adequate => 1,
ChestCompressionQuality::Poor => 2,
ChestCompressionQuality::Bad => 3,
};
let cpr_quality = add_dropdown_at(&cpr_controls, "Compression quality",
&["Good", "Adequate", "Poor", "Bad"], initial_cpr_quality,
params.clone(), |p, selected| {
p.chest_compression_quality = match selected {
0 => ChestCompressionQuality::Good,
2 => ChestCompressionQuality::Poor,
3 => ChestCompressionQuality::Bad,
_ => ChestCompressionQuality::Adequate,
};
});
cpr_button.connect_clicked({
let params = params.clone();
let actions = actions.clone();
move |button| {
let mut p = params.borrow_mut();
actions.borrow_mut().remember_baseline(&p);
p.chest_compressions_active = !p.chest_compressions_active;
sync_cpr_button(button, p.chest_compressions_active);
}
});
// Direct Mode, scripted baseline restoration, and this panel may all
// change CPR state; update the visible controls without duplicating state.
glib::timeout_add_local(Duration::from_millis(250), {
let params = params.clone();
let cpr_button = cpr_button.clone();
let cpr_quality = cpr_quality.clone();
move || {
let p = params.borrow().clone();
sync_cpr_button(&cpr_button, p.chest_compressions_active);
let index = match p.chest_compression_quality {
ChestCompressionQuality::Good => 0,
ChestCompressionQuality::Adequate => 1,
ChestCompressionQuality::Poor => 2,
ChestCompressionQuality::Bad => 3,
};
if cpr_quality.selected() != index { cpr_quality.set_selected(index); }
glib::ControlFlow::Continue
}
});
// Independent one-tap defibrillation: ECG artifact only. Do not start an
// Actions timeline and do not change ECG rhythm, blood pressure or EtCO₂.
let defib_shortcut = gtk::Button::new();
defib_shortcut.set_hexpand(true);
defib_shortcut.add_css_class("defib-shortcut");
defib_shortcut.set_tooltip_text(Some("ECG shock artifact only — no rhythm change"));
let defib_content = gtk::Box::new(Orientation::Horizontal, 8);
defib_content.set_halign(gtk::Align::Center);
let bolt = gtk::Label::new(Some("⚡"));
bolt.add_css_class("defib-bolt");
defib_content.append(&bolt);
defib_content.append(&gtk::Label::new(Some("Defibrillation")));
defib_shortcut.set_child(Some(&defib_content));
defib_shortcut.connect_clicked({
let simulator = simulator.clone();
move |_| simulator.borrow_mut().defibrillate()
});
panel.append(&defib_shortcut);
let actions_title = gtk::Label::new(Some("Scripted actions"));
actions_title.set_xalign(0.0);
panel.append(&actions_title);
let selection = gtk::DropDown::from_strings(
&SCRIPTED_ACTION_CHOICES.map(Kind::label));
selection.set_hexpand(true);
panel.append(&selection);
@ -1808,66 +1900,6 @@ fn actions_page(params: SharedParams, simulator: Rc<RefCell<Simulator>>,
defib_config.set_visible(false);
panel.append(&defib_config);
let cpr_config = gtk::Box::new(Orientation::Vertical, 8);
let cpr_quality = gtk::DropDown::from_strings(&["Good", "Adequate", "Poor", "Bad"]);
cpr_quality.set_selected(1);
let quality_caption = gtk::Label::new(Some("Chest-compression quality"));
quality_caption.set_xalign(0.0);
cpr_config.append(&quality_caption);
cpr_config.append(&cpr_quality);
let cpr_button = gtk::Button::with_label("Start Chest Compressions");
cpr_button.set_hexpand(true);
cpr_button.add_css_class("cpr-start");
cpr_config.append(&cpr_button);
cpr_config.set_visible(false);
panel.append(&cpr_config);
cpr_quality.connect_selected_notify({
let params = params.clone();
move |widget| {
params.borrow_mut().chest_compression_quality = match widget.selected() {
0 => ChestCompressionQuality::Good,
2 => ChestCompressionQuality::Poor,
3 => ChestCompressionQuality::Bad,
_ => ChestCompressionQuality::Adequate,
};
}
});
cpr_button.connect_clicked({
let params = params.clone();
let actions = actions.clone();
move |_| {
let mut p = params.borrow_mut();
actions.borrow_mut().remember_baseline(&p);
p.chest_compressions_active = !p.chest_compressions_active;
}
});
// Update CPR actions when the instructor also uses Direct Mode.
glib::timeout_add_local(Duration::from_millis(250), {
let params = params.clone();
let cpr_button = cpr_button.clone();
let cpr_quality = cpr_quality.clone();
let direct_cpr_button = direct_cpr_button.clone();
let direct_cpr_quality = direct_cpr_quality.clone();
move || {
let p = params.borrow().clone();
let active = p.chest_compressions_active;
cpr_button.set_label(if active { "Stop Chest Compressions" }
else { "Start Chest Compressions" });
cpr_button.remove_css_class(if active { "cpr-start" } else { "cpr-stop" });
cpr_button.add_css_class(if active { "cpr-stop" } else { "cpr-start" });
// Keep the existing Direct Mode controls as the authoritative UI.
let _ = (&direct_cpr_button, &direct_cpr_quality);
let quality_index = match p.chest_compression_quality {
ChestCompressionQuality::Good => 0,
ChestCompressionQuality::Adequate => 1,
ChestCompressionQuality::Poor => 2,
ChestCompressionQuality::Bad => 3,
};
if cpr_quality.selected() != quality_index { cpr_quality.set_selected(quality_index); }
glib::ControlFlow::Continue
}
});
let info = gtk::Label::new(Some("Instant artifact; does not automatically alter rhythm."));
info.set_wrap(true);
info.set_xalign(0.0);
@ -1876,15 +1908,10 @@ fn actions_page(params: SharedParams, simulator: Rc<RefCell<Simulator>>,
panel.append(&trigger);
selection.connect_selected_notify({
let defib_config = defib_config.clone();
let cpr_config = cpr_config.clone();
let trigger = trigger.clone();
let info = info.clone();
move |dropdown| {
let kind = Kind::ALL.get(dropdown.selected() as usize)
.copied().unwrap_or(Kind::Defibrillation);
let kind = action_choice(dropdown.selected());
defib_config.set_visible(kind == Kind::DefibrillationRhythm);
cpr_config.set_visible(kind == Kind::ChestCompressions);
trigger.set_visible(kind != Kind::ChestCompressions);
info.set_text(match kind {
Kind::Defibrillation => "Brief ECG shock artifact without automatic conversion.",
Kind::DefibrillationRhythm => "Instant rhythm change, ART target after 60 s, EtCO₂ after 30 s if cardiac output exists.",
@ -1915,9 +1942,7 @@ fn actions_page(params: SharedParams, simulator: Rc<RefCell<Simulator>>,
let action_rows = action_rows.clone();
let info = info.clone();
move |_| {
let kind = Kind::ALL.get(selection.selected() as usize)
.copied().unwrap_or(Kind::Defibrillation);
if kind == Kind::ChestCompressions { return; }
let kind = action_choice(selection.selected());
let defib = if kind == Kind::DefibrillationRhythm {
let rhythm = match defib_rhythm.selected() {
1 => EcgRhythm::AtrialFibrillation,
@ -1993,3 +2018,23 @@ fn actions_page(params: SharedParams, simulator: Rc<RefCell<Simulator>>,
scroller.set_child(Some(&panel));
scroller
}
#[cfg(test)]
mod actions_tab_layout_tests {
use super::*;
#[test]
fn cpr_is_a_permanent_control_not_a_duplicate_dropdown_action() {
assert_eq!(SCRIPTED_ACTION_CHOICES.len(), 7);
assert!(!SCRIPTED_ACTION_CHOICES.contains(&Kind::ChestCompressions));
assert_eq!(action_choice(0), Kind::Defibrillation);
assert_eq!(action_choice(1), Kind::DefibrillationRhythm);
assert_eq!(action_choice(4), Kind::Norepinephrine);
assert_eq!(action_choice(6), Kind::LethalPropofol);
}
#[test]
fn unknown_action_selection_falls_back_to_artifact_only() {
assert_eq!(action_choice(u32::MAX), Kind::Defibrillation);
}
}