CoolFace
Apppublic

liammatt5/GLAM_Web_App

sourceHugging Facemitupdated 3mo agoView on Hugging Face
0likes
notifications.py68 linesDownload Raw Back to root
1import re2from typing import List, Dict, Any3 4 5def summarize_live_alerts(rows: List[List[Any]], patient_names: List[str] = None) -> Dict[str, Any]:6    alerts = []7    has_patients = patient_names is not None and any(name is not None for name in patient_names)8    9    for row in rows or []:10        if not row:11            continue12        patient_name = row[0] if len(row) > 0 else "Unknown"13        comment = str(row[-1] or "")14        level = None15        lowered = comment.lower()16        if re.search(r"\bred\b", lowered):17            level = "red"18        elif re.search(r"\borange\b", lowered):19            level = "orange"20 21        if level:22            alerts.append({23                "patient_name": patient_name,24                "level": level,25                "message": comment,26            })27 28    return {"count": len(alerts), "alerts": alerts, "has_patients": has_patients}29 30 31def build_live_notification_html(rows: List[List[Any]], patient_names: List[str] = None) -> str:32    summary = summarize_live_alerts(rows, patient_names)33    count = summary["count"]34    alerts = summary["alerts"]35    has_patients = summary.get("has_patients", True)36 37    if not alerts and not has_patients:38        return (39            "<div class='live-notifications empty no-patients' style='opacity:1; filter:none; -webkit-filter:none;'>"40            "<div class='notification-header'><span class='notification-badge'>0</span><span>No Critical Patients</span></div>"41            "<div class='notification-body'>Begin Live Monitoring to detect critical patients.</div>"42            "</div>"43        )44 45    if not alerts and has_patients:46        return (47            "<div class='live-notifications empty' style='opacity:1; filter:none; -webkit-filter:none;'>"48            "<div class='notification-header'><span class='notification-badge'>0</span><span>All stable</span></div>"49            "<div class='notification-body'>No critical alerts detected.</div>"50            "</div>"51        )52 53    items = []54    for entry in alerts:55        items.append(56            f"<div class='notification-item notification-{entry['level']}' style='opacity:1; filter:none; -webkit-filter:none;'>"57            f"<div class='notification-title'>{entry['patient_name']}</div>"58            f"<div class='notification-message'>{entry['message']}</div>"59            f"</div>"60        )61 62    return (63        "<div class='live-notifications' style='opacity:1; filter:none; -webkit-filter:none;'>"64        f"<div class='notification-header'><span class='notification-badge'>{count}</span><span>Critical patients</span></div>"65        f"<div class='notification-list'>{''.join(items)}</div>"66        "</div>"67    )68