import streamlit as st import plotly.graph_objects as go import pandas as pd import numpy as np # Page setup st.set_page_config(page_title="IMPROVE Framework", layout="wide") st.markdown(""" """, unsafe_allow_html=True) # Patient data PATIENTS = [ {"id": "ICU-001", "age": 58, "sex": "M", "weight": 78, "diagnosis": "ARDS", "rr": 18, "vt": 450, "peep": 8, "p_plat": 25, "mort_7d": 0.15, "mort_48h": 0.09}, {"id": "ICU-002", "age": 67, "sex": "F", "weight": 65, "diagnosis": "Sepsis", "rr": 24, "vt": 380, "peep": 12, "p_plat": 28, "mort_7d": 0.28, "mort_48h": 0.17}, {"id": "ICU-003", "age": 45, "sex": "M", "weight": 82, "diagnosis": "Trauma", "rr": 12, "vt": 550, "peep": 5, "p_plat": 20, "mort_7d": 0.08, "mort_48h": 0.05}, {"id": "ICU-004", "age": 72, "sex": "F", "weight": 60, "diagnosis": "Pneumonia", "rr": 32, "vt": 320, "peep": 15, "p_plat": 32, "mort_7d": 0.45, "mort_48h": 0.27}, {"id": "ICU-005", "age": 55, "sex": "M", "weight": 90, "diagnosis": "ARDS", "rr": 16, "vt": 500, "peep": 10, "p_plat": 22, "mort_7d": 0.12, "mort_48h": 0.07}, {"id": "ICU-006", "age": 63, "sex": "F", "weight": 55, "diagnosis": "Sepsis", "rr": 28, "vt": 350, "peep": 14, "p_plat": 30, "mort_7d": 0.35, "mort_48h": 0.21}, {"id": "ICU-007", "age": 49, "sex": "M", "weight": 75, "diagnosis": "Trauma", "rr": 20, "vt": 480, "peep": 8, "p_plat": 26, "mort_7d": 0.18, "mort_48h": 0.11}, {"id": "ICU-008", "age": 38, "sex": "F", "weight": 68, "diagnosis": "Pneumonia", "rr": 14, "vt": 600, "peep": 6, "p_plat": 18, "mort_7d": 0.05, "mort_48h": 0.03}, {"id": "ICU-009", "age": 71, "sex": "M", "weight": 70, "diagnosis": "ARDS", "rr": 26, "vt": 400, "peep": 12, "p_plat": 29, "mort_7d": 0.32, "mort_48h": 0.19}, {"id": "ICU-010", "age": 52, "sex": "F", "weight": 62, "diagnosis": "Sepsis", "rr": 22, "vt": 420, "peep": 9, "p_plat": 24, "mort_7d": 0.22, "mort_48h": 0.13}, ] def calculate_mp(rr, vt, p_plat, peep): """Gattinoni formula""" return 0.098 * rr * (vt/1000) * (p_plat - peep/2) def predict_outcomes(base_mort_7d, base_mort_48h, current_mp, new_mp): """Simple prediction model""" ratio = new_mp / current_mp if current_mp > 0 else 1 if ratio < 0.85: # Good reduction mort_7d = base_mort_7d * 0.85 mort_48h = base_mort_48h * 0.80 oxy = 0.75 elif ratio < 1.0: # Small reduction mort_7d = base_mort_7d * 0.95 mort_48h = base_mort_48h * 0.92 oxy = 0.70 else: # Increase mort_7d = base_mort_7d * min(1.3, (1 + (ratio - 1) * 1.5)) mort_48h = base_mort_48h * min(1.4, (1 + (ratio - 1) * 2)) oxy = max(0.40, 0.65 - (ratio - 1) * 0.5) return (max(0.01, min(0.99, mort_7d)), max(0.01, min(0.99, mort_48h)), oxy) # Main App st.markdown("
Mechanical Power Optimization for Ventilator Settings
", unsafe_allow_html=True) # Sidebar - Patient Selection (with white text on dark background) selected_id = st.sidebar.selectbox("Select Patient", [p["id"] for p in PATIENTS]) patient = next(p for p in PATIENTS if p["id"] == selected_id) # Calculate baseline MP current_mp = calculate_mp(patient["rr"], patient["vt"], patient["p_plat"], patient["peep"]) # Sidebar - Patient Details st.sidebar.markdown("---") st.sidebar.subheader("Demographics") st.sidebar.write(f"**Age:** {patient['age']} years") st.sidebar.write(f"**Sex:** {patient['sex']}") st.sidebar.write(f"**Weight:** {patient['weight']} kg") st.sidebar.write(f"**Diagnosis:** {patient['diagnosis']}") st.sidebar.markdown("---") st.sidebar.subheader("Current Ventilator Settings") st.sidebar.write(f"**Respiratory Rate:** {patient['rr']} b/min") st.sidebar.write(f"**Tidal Volume:** {patient['vt']} mL") st.sidebar.write(f"**PEEP:** {patient['peep']} cmH₂O") st.sidebar.write(f"**Plateau Pressure:** {patient['p_plat']} cmH₂O") st.sidebar.write(f"**Mechanical Power:** {current_mp:.1f} J/min") st.sidebar.write(f"**Mortality (7d):** {patient['mort_7d']:.0%}") # Main content col1, col2 = st.columns([1, 2]) with col1: st.markdown("Baseline MP: {current_mp:.1f} J/min
", unsafe_allow_html=True) # RR Slider with current value marker st.markdown(f"""