1107 lines
43 KiB
Python
1107 lines
43 KiB
Python
"""Zero-sidebar Spatial Clinical OS 3.0 shell inspired by Alveo × Serene.ai."""
|
||
|
||
from __future__ import annotations
|
||
|
||
from collections.abc import Callable
|
||
from functools import wraps
|
||
from typing import Any
|
||
|
||
from PySide6.QtCore import QPointF, QRectF, QSize, Qt, QTimer, Signal
|
||
from PySide6.QtGui import (
|
||
QColor,
|
||
QFont,
|
||
QKeySequence,
|
||
QMouseEvent,
|
||
QPainter,
|
||
QPainterPath,
|
||
QPen,
|
||
QShortcut,
|
||
)
|
||
from PySide6.QtWidgets import (
|
||
QApplication,
|
||
QButtonGroup,
|
||
QFrame,
|
||
QHBoxLayout,
|
||
QLabel,
|
||
QLineEdit,
|
||
QMainWindow,
|
||
QMenu,
|
||
QPushButton,
|
||
QStackedWidget,
|
||
QVBoxLayout,
|
||
QWidget,
|
||
)
|
||
|
||
from . import icons, motion
|
||
from .chat_notifications import (
|
||
CONSULTATION_COMPLETE,
|
||
PATIENT_OPENED_CHAT,
|
||
ChatNotification,
|
||
ChatNotificationCenter,
|
||
)
|
||
from .command_palette import CommandEntry, CommandPaletteDialog
|
||
from .dialogs.ai_consult import can_open_ai_consult, present_ai_consult
|
||
from .dialogs.ai_consult_picker import select_and_present_ai_consult
|
||
from .dialogs.diagnosis import DiagnosisDialog
|
||
from .dialogs.esign_doctor import EsignDoctorDialog
|
||
from .dialogs.local_audio_queue import LocalAudioQueueDialog
|
||
from .dialogs.prescription_esign import can_open_esign_doctor
|
||
from .reception_style import heading_family
|
||
from .shell import (
|
||
_SHELL_MINIMUM_SIZE,
|
||
_bounded_initial_window_size,
|
||
_resolve_navigation,
|
||
)
|
||
from .state import PatientContextStore, PatientSnapshot
|
||
from .viewmodels import derive_cockpit_snapshot
|
||
from .visuals.aurora_sheet import CollapsibleObsidianSheet
|
||
from .widgets import EmptyState, first_value, get_value, has_permission, show_toast
|
||
|
||
_SPATIAL_NAV_LABELS = {
|
||
"reception": "接诊总览",
|
||
"appointments": "门诊日程",
|
||
"patients": "在管患者",
|
||
"prescription_library": "处方智库",
|
||
"prescriptions": "已开处方",
|
||
"consultations": "诊单档案",
|
||
}
|
||
|
||
_SPATIAL_HERO_TITLES = {
|
||
"reception": ("中医糖代谢专科 / 线上联合门诊 / 全息接诊单元", "全息辨证接诊舱"),
|
||
"appointments": ("中医糖代谢专科 / 门诊排班管理 / 号源队列", "门诊日程与号源流"),
|
||
"patients": ("中医糖代谢专科 / 慢病全周期管理 / 随访队列", "在管慢病患者档案"),
|
||
"prescription_library": ("中医糖代谢专科 / 经方与协定方库 / 辨证施治", "专科经方与协定智库"),
|
||
"prescriptions": ("中医糖代谢专科 / CA 双签流转 / 电子处方中心", "已开处方与药师审方"),
|
||
"consultations": ("中医糖代谢专科 / 望闻问切归档 / 病历检索", "全量四诊问诊档案"),
|
||
}
|
||
|
||
_SPATIAL_NAV_PRIORITY = {
|
||
"reception": 0,
|
||
"appointments": 1,
|
||
"patients": 2,
|
||
"prescription_library": 3,
|
||
"prescriptions": 4,
|
||
"consultations": 5,
|
||
}
|
||
|
||
SPATIAL_SHELL_QSS = """
|
||
QWidget#SpatialTopHeader {
|
||
background: transparent;
|
||
}
|
||
QFrame#SpatialPillNavIsland {
|
||
background-color: #FFFFFF;
|
||
border: 1px solid #E1ECE8;
|
||
border-radius: 22px;
|
||
}
|
||
QPushButton#SpatialNavPill {
|
||
min-height: 36px;
|
||
max-height: 36px;
|
||
padding: 0 16px;
|
||
border: 0;
|
||
border-radius: 18px;
|
||
background-color: transparent;
|
||
color: #546A67;
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
}
|
||
QPushButton#SpatialNavPill:hover {
|
||
background-color: #EFF5F3;
|
||
color: #10201E;
|
||
}
|
||
QPushButton#SpatialNavPill:checked {
|
||
background-color: #111918;
|
||
color: #FFFFFF;
|
||
font-weight: 600;
|
||
}
|
||
QPushButton#SpatialAiNavPill {
|
||
min-height: 36px;
|
||
max-height: 36px;
|
||
padding: 0 15px;
|
||
border: 1px solid #DFEAE6;
|
||
border-radius: 18px;
|
||
background-color: #F7FAF9;
|
||
color: #14322E;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
QPushButton#SpatialAiNavPill:hover {
|
||
background-color: #E4F3EE;
|
||
border-color: #9ED0C3;
|
||
color: #0E6F5C;
|
||
}
|
||
QPushButton#SpatialAiNavPill[activeSheet="true"] {
|
||
background-color: #0E6F5C;
|
||
border-color: #0E6F5C;
|
||
color: #FFFFFF;
|
||
}
|
||
QFrame#SpatialSearchCapsule {
|
||
background-color: #FFFFFF;
|
||
border: 1px solid #E1ECE8;
|
||
border-radius: 20px;
|
||
}
|
||
QFrame#SpatialSearchCapsule:focus-within {
|
||
border: 1px solid #0E6F5C;
|
||
}
|
||
QLineEdit#SpatialGlobalSearch {
|
||
background: transparent;
|
||
border: 0;
|
||
color: #132523;
|
||
font-size: 13px;
|
||
padding: 0 4px;
|
||
}
|
||
QPushButton#SpatialKbdBadge {
|
||
background-color: #F2F6F5;
|
||
color: #677E7A;
|
||
border: 1px solid #DFE9E6;
|
||
border-radius: 10px;
|
||
padding: 0 8px;
|
||
min-height: 22px;
|
||
max-height: 22px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
}
|
||
QPushButton#SpatialCircleButton {
|
||
min-width: 38px;
|
||
max-width: 38px;
|
||
min-height: 38px;
|
||
max-height: 38px;
|
||
border-radius: 19px;
|
||
background-color: #FFFFFF;
|
||
border: 1px solid #E1ECE8;
|
||
color: #2B403E;
|
||
padding: 0;
|
||
}
|
||
QPushButton#SpatialCircleButton:hover {
|
||
background-color: #EAF4F1;
|
||
border-color: #B9DCD3;
|
||
}
|
||
QPushButton#SpatialWindowControl {
|
||
min-width: 32px;
|
||
max-width: 32px;
|
||
min-height: 32px;
|
||
max-height: 32px;
|
||
border-radius: 16px;
|
||
background-color: transparent;
|
||
border: 0;
|
||
color: #536966;
|
||
font-size: 14px;
|
||
}
|
||
QPushButton#SpatialWindowControl:hover {
|
||
background-color: #E4ECE9;
|
||
color: #10201E;
|
||
}
|
||
QPushButton#SpatialWindowClose:hover {
|
||
background-color: #E0584C;
|
||
color: #FFFFFF;
|
||
}
|
||
QPushButton#SpatialDoctorCapsule {
|
||
min-height: 42px;
|
||
max-height: 42px;
|
||
padding: 0 14px 0 10px;
|
||
border-radius: 21px;
|
||
background-color: #FFFFFF;
|
||
border: 1px solid #E1ECE8;
|
||
color: #11201E;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
QPushButton#SpatialDoctorCapsule:hover {
|
||
background-color: #F6FAF9;
|
||
border-color: #C3DAD4;
|
||
}
|
||
QFrame#SpatialPatientCapsule {
|
||
background-color: #FFFFFF;
|
||
border: 1px solid #E1ECE8;
|
||
border-radius: 24px;
|
||
}
|
||
QPushButton#SpatialSecondaryPill {
|
||
min-height: 42px;
|
||
max-height: 42px;
|
||
padding: 0 18px;
|
||
border-radius: 21px;
|
||
background-color: #FFFFFF;
|
||
border: 1px solid #DCE7E4;
|
||
color: #192D2B;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
QPushButton#SpatialSecondaryPill:hover {
|
||
background-color: #EDF6F3;
|
||
border-color: #9BCBC0;
|
||
color: #0E6F5C;
|
||
}
|
||
QPushButton#SpatialPrimaryEmeraldPill {
|
||
min-height: 42px;
|
||
max-height: 42px;
|
||
padding: 0 20px;
|
||
border-radius: 21px;
|
||
background-color: #0E6F5C;
|
||
border: 0;
|
||
color: #FFFFFF;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
QPushButton#SpatialPrimaryEmeraldPill:hover {
|
||
background-color: #0A5B4B;
|
||
}
|
||
QPushButton#SpatialPrimaryEmeraldPill:disabled {
|
||
background-color: #C9D9D5;
|
||
color: #FFFFFF;
|
||
}
|
||
"""
|
||
|
||
|
||
class _AlveoJadeEmblem(QWidget):
|
||
"""Alveo × Zhenyangtang twin-meridian jade pill emblem."""
|
||
|
||
def __init__(self, parent: QWidget | None = None) -> None:
|
||
super().__init__(parent)
|
||
self.setFixedSize(36, 36)
|
||
|
||
def paintEvent(self, _event: object) -> None: # noqa: N802
|
||
painter = QPainter(self)
|
||
painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
|
||
rect = QRectF(1.0, 1.0, 34.0, 34.0)
|
||
bg = QPainterPath()
|
||
bg.addRoundedRect(rect, 17.0, 17.0)
|
||
painter.fillPath(bg, QColor("#0E6F5C"))
|
||
|
||
# Twin rounded vertical jade-white pillars + subtle champagne gold dot
|
||
painter.setPen(Qt.PenStyle.NoPen)
|
||
painter.setBrush(QColor("#FFFFFF"))
|
||
painter.drawRoundedRect(QRectF(11.0, 10.0, 5.2, 16.0), 2.6, 2.6)
|
||
painter.drawRoundedRect(QRectF(19.8, 10.0, 5.2, 16.0), 2.6, 2.6)
|
||
painter.setBrush(QColor("#DFC793"))
|
||
painter.drawEllipse(QPointF(28.5, 9.5), 2.4, 2.4)
|
||
|
||
|
||
class _SpatialCanvas(QWidget):
|
||
"""Rounded mist-celadon (#F1F5F3) window ground with native edge resize."""
|
||
|
||
_RESIZE_MARGIN = 7
|
||
|
||
def __init__(self, parent: QWidget | None = None) -> None:
|
||
super().__init__(parent)
|
||
self.setMouseTracking(True)
|
||
|
||
def _edges(self, pos: QPointF) -> Qt.Edge:
|
||
m = self._RESIZE_MARGIN
|
||
w, h = self.width(), self.height()
|
||
edges = Qt.Edge(0)
|
||
if pos.x() <= m:
|
||
edges |= Qt.Edge.LeftEdge
|
||
elif pos.x() >= w - m:
|
||
edges |= Qt.Edge.RightEdge
|
||
if pos.y() <= m:
|
||
edges |= Qt.Edge.TopEdge
|
||
elif pos.y() >= h - m:
|
||
edges |= Qt.Edge.BottomEdge
|
||
return edges
|
||
|
||
def mousePressEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||
if event.button() == Qt.MouseButton.LeftButton and not self.window().isMaximized():
|
||
edges = self._edges(event.position())
|
||
handle = self.window().windowHandle()
|
||
if edges and handle is not None and handle.startSystemResize(edges):
|
||
event.accept()
|
||
return
|
||
super().mousePressEvent(event)
|
||
|
||
def paintEvent(self, _event: object) -> None: # noqa: N802
|
||
painter = QPainter(self)
|
||
painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
|
||
radius = 0.0 if self.window().isMaximized() else 20.0
|
||
rect = QRectF(self.rect()).adjusted(0.5, 0.5, -0.5, -0.5)
|
||
path = QPainterPath()
|
||
path.addRoundedRect(rect, radius, radius)
|
||
painter.fillPath(path, QColor("#F1F5F3"))
|
||
if radius > 0:
|
||
painter.setPen(QPen(QColor("#DCE6E3"), 1.0))
|
||
painter.drawPath(path)
|
||
|
||
|
||
class _DraggableHeaderBar(QWidget):
|
||
"""Top capsule bar supporting native window dragging & double-click maximize."""
|
||
|
||
def mousePressEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||
if event.button() == Qt.MouseButton.LeftButton:
|
||
child = self.childAt(event.position().toPoint())
|
||
if child is None or isinstance(child, QLabel):
|
||
handle = self.window().windowHandle()
|
||
if handle is not None and handle.startSystemMove():
|
||
event.accept()
|
||
return
|
||
super().mousePressEvent(event)
|
||
|
||
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||
if event.button() == Qt.MouseButton.LeftButton:
|
||
win = self.window()
|
||
if win.isMaximized():
|
||
win.showNormal()
|
||
else:
|
||
win.showMaximized()
|
||
event.accept()
|
||
return
|
||
super().mouseDoubleClickEvent(event)
|
||
|
||
|
||
class SpatialShellWindow(QMainWindow):
|
||
"""Zero-sidebar Clinical OS 3.0 application shell (Alveo × Serene.ai)."""
|
||
|
||
logout_requested = Signal()
|
||
close_requested = Signal()
|
||
video_requested = Signal(dict)
|
||
page_changed = Signal(str)
|
||
update_check_requested = Signal()
|
||
|
||
_LOADING_FLAGS = ("_loading", "_queue_loading", "_detail_loading")
|
||
|
||
def __init__(
|
||
self,
|
||
repository: Any,
|
||
session: Any,
|
||
permissions: Any = None,
|
||
parent: QWidget | None = None,
|
||
) -> None:
|
||
super().__init__(parent)
|
||
self.setProperty("doctorMainWindow", True)
|
||
self.setWindowTitle("甄养堂 · 临床智医工作站")
|
||
self.setWindowFlag(Qt.WindowType.FramelessWindowHint, True)
|
||
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground, True)
|
||
self.setStyleSheet("QMainWindow { background: transparent; }\n" + SPATIAL_SHELL_QSS)
|
||
|
||
self.repository = repository
|
||
self.login_payload = session
|
||
self.session = get_value(session, "session", None) or session
|
||
self.current_user = (
|
||
get_value(session, "user", None)
|
||
or get_value(self.session, "user", None)
|
||
or get_value(session, "current_user", None)
|
||
or session
|
||
)
|
||
if permissions is not None:
|
||
self.permissions = permissions
|
||
else:
|
||
session_permissions = get_value(self.session, "permissions", None)
|
||
self.permissions = (
|
||
session_permissions
|
||
if session_permissions is not None
|
||
else get_value(self.current_user, "permissions", None)
|
||
)
|
||
self._can_ai_assistant = can_open_ai_consult(self.permissions)
|
||
session_menu = get_value(self.session, "menu", None)
|
||
self.menu = session_menu if session_menu is not None else get_value(session, "menu", [])
|
||
self.demo_mode = bool(
|
||
get_value(session, "demo_mode", False)
|
||
or get_value(self.session, "metadata.demo", False)
|
||
or get_value(self.session, "metadata.demo_mode", False)
|
||
)
|
||
|
||
raw_nav = _resolve_navigation(self.menu, self.permissions, demo_mode=self.demo_mode)
|
||
self.navigation = sorted(
|
||
raw_nav,
|
||
key=lambda entry: _SPATIAL_NAV_PRIORITY.get(entry[0].key, 99),
|
||
)
|
||
|
||
self.patient_context_store = PatientContextStore(self)
|
||
self.patient_context_store.active_patient_changed.connect(self._on_patient_context_changed)
|
||
self.patient_context_store.bottom_sheet_mode_changed.connect(self._sync_ai_sheet_button)
|
||
|
||
self.pages: dict[str, QWidget] = {}
|
||
self.nav_buttons: dict[str, QPushButton] = {}
|
||
self.page_titles: dict[int, str] = {}
|
||
self._active_page_key: str | None = None
|
||
self._activation_page: QWidget | None = None
|
||
self._activation_generation = 0
|
||
self._activation_refreshed = False
|
||
self._online = True
|
||
self._local_audio_settings_dialog: LocalAudioQueueDialog | None = None
|
||
self._global_diagnosis_dialog: DiagnosisDialog | None = None
|
||
|
||
self.chat_notifications = ChatNotificationCenter(repository, self)
|
||
self.chat_notifications.notification_activated.connect(self._open_chat_notification)
|
||
|
||
self.setMinimumSize(_SHELL_MINIMUM_SIZE)
|
||
screen = self.screen() or QApplication.primaryScreen()
|
||
available_size = screen.availableGeometry().size() if screen is not None else None
|
||
self.resize(_bounded_initial_window_size(available_size))
|
||
|
||
canvas = _SpatialCanvas(self)
|
||
canvas.setObjectName("SpatialAppCanvas")
|
||
self.setCentralWidget(canvas)
|
||
|
||
root = QVBoxLayout(canvas)
|
||
root.setContentsMargins(20, 14, 20, 14)
|
||
root.setSpacing(10)
|
||
|
||
self.topbar = self._build_top_capsule_bar()
|
||
root.addWidget(self.topbar)
|
||
|
||
self.sub_hero = self._build_context_sub_hero()
|
||
root.addWidget(self.sub_hero)
|
||
|
||
self.stack = QStackedWidget(canvas)
|
||
self.stack.setObjectName("SpatialPageStack")
|
||
self.stack.setStyleSheet("QStackedWidget#SpatialPageStack { background: transparent; border: 0; }")
|
||
root.addWidget(self.stack, 1)
|
||
|
||
# Serene.ai Pull-Up Deep Obsidian Aurora-Glass Bottom Sheet
|
||
self.ai_bottom_sheet = CollapsibleObsidianSheet(canvas)
|
||
self.ai_bottom_sheet.expanded_changed.connect(self._on_sheet_expanded_changed)
|
||
self.ai_bottom_sheet.open_ai_report_requested.connect(self._open_active_patient_ai_report)
|
||
self.ai_bottom_sheet.open_ai_consult_requested.connect(self._open_active_patient_ai_consult)
|
||
self.ai_bottom_sheet.model_selected.connect(self._on_sheet_model_selected)
|
||
self.ai_bottom_sheet.set_view_model(derive_cockpit_snapshot().aurora)
|
||
root.addWidget(self.ai_bottom_sheet)
|
||
|
||
self._register_pages()
|
||
self._bind_shortcuts()
|
||
|
||
def _build_top_capsule_bar(self) -> QWidget:
|
||
bar = _DraggableHeaderBar(self)
|
||
bar.setObjectName("SpatialTopHeader")
|
||
bar.setFixedHeight(52)
|
||
layout = QHBoxLayout(bar)
|
||
layout.setContentsMargins(2, 0, 2, 0)
|
||
layout.setSpacing(12)
|
||
|
||
# Left Brand Mark (Alveo × Serene minimal geometric brand)
|
||
brand_wrap = QWidget(bar)
|
||
brand_row = QHBoxLayout(brand_wrap)
|
||
brand_row.setContentsMargins(0, 0, 4, 0)
|
||
brand_row.setSpacing(10)
|
||
self.brand_mark = _AlveoJadeEmblem(brand_wrap)
|
||
brand_row.addWidget(self.brand_mark)
|
||
|
||
brand_text = QLabel("甄养堂", brand_wrap)
|
||
b_font = QFont(heading_family())
|
||
b_font.setPixelSize(18)
|
||
b_font.setWeight(QFont.Weight.DemiBold)
|
||
brand_text.setFont(b_font)
|
||
brand_text.setStyleSheet("color: #0F1F1D; background: transparent;")
|
||
brand_row.addWidget(brand_text)
|
||
|
||
brand_tag = QLabel("clinical.os", brand_wrap)
|
||
brand_tag.setStyleSheet("color: #7A908C; font-size: 13px; background: transparent;")
|
||
brand_row.addWidget(brand_tag)
|
||
layout.addWidget(brand_wrap)
|
||
|
||
layout.addStretch(1)
|
||
|
||
# Center Floating Pill Navigation Island (Zero-sidebar centerpiece!)
|
||
self.nav_island = QFrame(bar)
|
||
self.nav_island.setObjectName("SpatialPillNavIsland")
|
||
self.nav_island.setFixedHeight(44)
|
||
self.nav_layout = QHBoxLayout(self.nav_island)
|
||
self.nav_layout.setContentsMargins(4, 3, 4, 3)
|
||
self.nav_layout.setSpacing(3)
|
||
layout.addWidget(self.nav_island)
|
||
|
||
# Separate AI Coach / Syndrome Lab Pill right beside or inside island
|
||
if self._can_ai_assistant:
|
||
self.ai_nav_button = QPushButton("AI 辨证师", self.nav_island)
|
||
self.ai_nav_button.setObjectName("SpatialAiNavPill")
|
||
self.ai_nav_button.setIcon(icons.icon("ai", "#0E6F5C", 15))
|
||
self.ai_nav_button.setIconSize(QSize(15, 15))
|
||
self.ai_nav_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
self.ai_nav_button.setToolTip("展开底部黑曜极光 AI 辨证舱(Ctrl+])")
|
||
self.ai_nav_button.clicked.connect(self.toggle_ai_bottom_sheet)
|
||
|
||
layout.addStretch(1)
|
||
|
||
# Right Global Search Capsule + Utility Circles + Doctor Identity Pill + Window Controls
|
||
self.search_capsule = QFrame(bar)
|
||
self.search_capsule.setObjectName("SpatialSearchCapsule")
|
||
self.search_capsule.setFixedSize(244, 40)
|
||
s_layout = QHBoxLayout(self.search_capsule)
|
||
s_layout.setContentsMargins(12, 0, 8, 0)
|
||
s_layout.setSpacing(6)
|
||
search_icon_lbl = QLabel(self.search_capsule)
|
||
search_icon_lbl.setPixmap(icons.icon("search", "#6C827E", 15).pixmap(15, 15))
|
||
s_layout.addWidget(search_icon_lbl)
|
||
|
||
self.global_search = QLineEdit(self.search_capsule)
|
||
self.global_search.setObjectName("SpatialGlobalSearch")
|
||
self.global_search.setPlaceholderText("搜索患者、诊单…")
|
||
self.global_search.setClearButtonEnabled(True)
|
||
self.global_search.returnPressed.connect(self._run_global_search)
|
||
s_layout.addWidget(self.global_search, 1)
|
||
|
||
self.palette_badge = QPushButton("Ctrl+K", self.search_capsule)
|
||
self.palette_badge.setObjectName("SpatialKbdBadge")
|
||
self.palette_badge.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
self.palette_badge.setToolTip("打开全局临床命令中枢(Ctrl+K)")
|
||
self.palette_badge.clicked.connect(self.open_command_palette)
|
||
s_layout.addWidget(self.palette_badge)
|
||
layout.addWidget(self.search_capsule)
|
||
|
||
self.refresh_button = QPushButton(bar)
|
||
self.refresh_button.setObjectName("SpatialCircleButton")
|
||
self.refresh_button.setIcon(icons.icon("refresh", "#2B403E", 16))
|
||
self.refresh_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
self.refresh_button.setToolTip("刷新当前视图(F5)")
|
||
self.refresh_button.clicked.connect(self.refresh_current_page)
|
||
layout.addWidget(self.refresh_button)
|
||
|
||
self.notification_button = QPushButton(bar)
|
||
self.notification_button.setObjectName("SpatialCircleButton")
|
||
self.notification_button.setIcon(icons.icon("notification", "#2B403E", 16))
|
||
self.notification_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
self.notification_button.setToolTip("系统会话与问诊通知")
|
||
self.notification_button.clicked.connect(self._show_chat_notification_summary)
|
||
layout.addWidget(self.notification_button)
|
||
|
||
# Doctor Identity Pill (Alveo 'Dr. Lena Hart · Pulmonology')
|
||
doc_name = str(
|
||
first_value(self.current_user, "name", "real_name", "account", default="主任医师")
|
||
).strip()
|
||
dept_name = str(
|
||
first_value(self.current_user, "department_name", "dept_name", default="糖代谢专科")
|
||
).strip()
|
||
self.user_menu_button = QPushButton(f"{doc_name} · {dept_name}", bar)
|
||
self.user_menu_button.setObjectName("SpatialDoctorCapsule")
|
||
self.user_menu_button.setIcon(icons.icon("patients", "#0E6F5C", 16))
|
||
self.user_menu_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
self._build_user_menu()
|
||
layout.addWidget(self.user_menu_button)
|
||
|
||
# Crisp window controls
|
||
self.minimize_button = QPushButton("—", bar)
|
||
self.minimize_button.setObjectName("SpatialWindowControl")
|
||
self.minimize_button.setToolTip("最小化")
|
||
self.minimize_button.clicked.connect(self.showMinimized)
|
||
layout.addWidget(self.minimize_button)
|
||
|
||
self.maximize_button = QPushButton("□", bar)
|
||
self.maximize_button.setObjectName("SpatialWindowControl")
|
||
self.maximize_button.setToolTip("最大化 / 还原")
|
||
self.maximize_button.clicked.connect(self._toggle_maximize)
|
||
layout.addWidget(self.maximize_button)
|
||
|
||
self.close_button = QPushButton("×", bar)
|
||
self.close_button.setObjectName("SpatialWindowControl")
|
||
self.close_button.setStyleSheet(
|
||
"QPushButton { min-width: 32px; max-width: 32px; min-height: 32px; max-height: 32px;"
|
||
" border-radius: 16px; border: 0; color: #536966; font-size: 16px; background: transparent; }"
|
||
"QPushButton:hover { background-color: #E0584C; color: #FFFFFF; }"
|
||
)
|
||
self.close_button.setToolTip("关闭工作站")
|
||
self.close_button.clicked.connect(self.close)
|
||
layout.addWidget(self.close_button)
|
||
|
||
return bar
|
||
|
||
def _build_user_menu(self) -> None:
|
||
menu = QMenu(self.user_menu_button)
|
||
if self._can_ai_assistant:
|
||
act_ai = menu.addAction("AI 深度问诊工作台…")
|
||
act_ai.triggered.connect(self._open_global_ai_picker)
|
||
if can_open_esign_doctor(self.repository, self.permissions):
|
||
act_esign = menu.addAction("医生电子签署身份…")
|
||
act_esign.triggered.connect(self._open_esign_dialog)
|
||
act_audio = menu.addAction("本机录音上传队列…")
|
||
act_audio.triggered.connect(self._open_audio_queue_dialog)
|
||
act_cmd = menu.addAction("全局命令面板(Ctrl+K)")
|
||
act_cmd.triggered.connect(self.open_command_palette)
|
||
act_upd = menu.addAction("检查客户端更新")
|
||
act_upd.triggered.connect(self.update_check_requested.emit)
|
||
menu.addSeparator()
|
||
act_logout = menu.addAction("退出当前账号")
|
||
act_logout.triggered.connect(self.logout_requested.emit)
|
||
self.user_menu_button.setMenu(menu)
|
||
|
||
def _build_context_sub_hero(self) -> QWidget:
|
||
"""Build the Alveo Layer-2 Editorial Sub-Hero + Active Patient Context Pill."""
|
||
|
||
hero = QWidget(self)
|
||
hero.setObjectName("SpatialSubHero")
|
||
hero.setFixedHeight(64)
|
||
layout = QHBoxLayout(hero)
|
||
layout.setContentsMargins(4, 0, 4, 0)
|
||
layout.setSpacing(12)
|
||
|
||
# Left: Specialty Breadcrumb + 28px Editorial Title
|
||
title_col = QVBoxLayout()
|
||
title_col.setContentsMargins(0, 0, 0, 0)
|
||
title_col.setSpacing(2)
|
||
self.breadcrumb_label = QLabel("中医糖代谢专科 / 线上联合门诊 / 全息接诊单元", hero)
|
||
self.breadcrumb_label.setStyleSheet("color: #768C88; font-size: 11px; background: transparent;")
|
||
title_col.addWidget(self.breadcrumb_label)
|
||
|
||
self.hero_title_label = QLabel("全息辨证接诊舱", hero)
|
||
h_font = QFont(heading_family())
|
||
h_font.setPixelSize(28)
|
||
h_font.setWeight(QFont.Weight.DemiBold)
|
||
self.hero_title_label.setFont(h_font)
|
||
self.hero_title_label.setStyleSheet("color: #0E1D1B; background: transparent;")
|
||
title_col.addWidget(self.hero_title_label)
|
||
layout.addLayout(title_col)
|
||
|
||
layout.addStretch(1)
|
||
|
||
# Right: Active Patient Floating Capsule (Alveo 'Margaret Osei · 71 yrs · COPD')
|
||
self.patient_capsule = QFrame(hero)
|
||
self.patient_capsule.setObjectName("SpatialPatientCapsule")
|
||
self.patient_capsule.setFixedHeight(48)
|
||
pc_layout = QHBoxLayout(self.patient_capsule)
|
||
pc_layout.setContentsMargins(8, 4, 16, 4)
|
||
pc_layout.setSpacing(10)
|
||
|
||
self.patient_avatar_badge = QLabel("患", self.patient_capsule)
|
||
self.patient_avatar_badge.setFixedSize(34, 34)
|
||
self.patient_avatar_badge.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||
self.patient_avatar_badge.setStyleSheet(
|
||
"background-color: #E2F3EE; color: #0E6F5C; border: 1px solid #DFC793;"
|
||
" border-radius: 17px; font-size: 14px; font-weight: 600;"
|
||
)
|
||
pc_layout.addWidget(self.patient_avatar_badge)
|
||
|
||
p_meta_col = QVBoxLayout()
|
||
p_meta_col.setContentsMargins(0, 0, 0, 0)
|
||
p_meta_col.setSpacing(1)
|
||
self.context_patient_name = QLabel("等待选择接诊患者", self.patient_capsule)
|
||
self.context_patient_name.setStyleSheet(
|
||
"color: #10201E; font-size: 13px; font-weight: 600; background: transparent;"
|
||
)
|
||
p_meta_col.addWidget(self.context_patient_name)
|
||
|
||
self.context_patient_sub = QLabel("点击今日门诊计划自动同步全站上下文", self.patient_capsule)
|
||
self.context_patient_sub.setStyleSheet(
|
||
"color: #6E8380; font-size: 11px; background: transparent;"
|
||
)
|
||
p_meta_col.addWidget(self.context_patient_sub)
|
||
pc_layout.addLayout(p_meta_col)
|
||
layout.addWidget(self.patient_capsule)
|
||
|
||
# [四诊病历] Secondary White Pill (Alveo 'Share report')
|
||
self.quick_chart_button = QPushButton("四诊病历", hero)
|
||
self.quick_chart_button.setObjectName("SpatialSecondaryPill")
|
||
self.quick_chart_button.setIcon(icons.icon("consultations", "#192D2B", 15))
|
||
self.quick_chart_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
self.quick_chart_button.setEnabled(False)
|
||
self.quick_chart_button.clicked.connect(self._open_active_patient_diagnosis)
|
||
layout.addWidget(self.quick_chart_button)
|
||
|
||
# [▷ 开启视频面诊] Primary Alveo Emerald Pill (Alveo 'Start ward round')
|
||
self.quick_video_button = QPushButton("▷ 开启视频面诊", hero)
|
||
self.quick_video_button.setObjectName("SpatialPrimaryEmeraldPill")
|
||
self.quick_video_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
self.quick_video_button.setEnabled(False)
|
||
self.quick_video_button.clicked.connect(self._trigger_active_patient_video)
|
||
layout.addWidget(self.quick_video_button)
|
||
|
||
return hero
|
||
|
||
def _register_pages(self) -> None:
|
||
self.nav_group = QButtonGroup(self)
|
||
self.nav_group.setExclusive(True)
|
||
first_button: QPushButton | None = None
|
||
|
||
for item, fallback_title in self.navigation:
|
||
page = item.page_type(
|
||
self.repository,
|
||
permissions=self.permissions,
|
||
current_user=self.current_user,
|
||
parent=self.stack,
|
||
)
|
||
self._install_activation_refresh_gate(page)
|
||
if hasattr(page, "set_patient_context_store"):
|
||
page.set_patient_context_store(self.patient_context_store)
|
||
else:
|
||
page.patient_context_store = self.patient_context_store # type: ignore[attr-defined]
|
||
if hasattr(page, "cockpit_snapshot_updated"):
|
||
page.cockpit_snapshot_updated.connect(self._on_cockpit_snapshot_updated)
|
||
if hasattr(page, "video_requested"):
|
||
page.video_requested.connect(lambda payload: self.video_requested.emit(payload))
|
||
|
||
index = self.stack.addWidget(page)
|
||
self.pages[item.key] = page
|
||
pill_title = _SPATIAL_NAV_LABELS.get(item.key, fallback_title)
|
||
self.page_titles[index] = pill_title
|
||
|
||
btn = QPushButton(pill_title, self.nav_island)
|
||
btn.setObjectName("SpatialNavPill")
|
||
btn.setCheckable(True)
|
||
btn.setCursor(Qt.CursorShape.PointingHandCursor)
|
||
btn.clicked.connect(
|
||
lambda _checked=False, page_idx=index, key=item.key: self._navigate(page_idx, key)
|
||
)
|
||
self.nav_group.addButton(btn, index)
|
||
self.nav_layout.addWidget(btn)
|
||
self.nav_buttons[item.key] = btn
|
||
if first_button is None:
|
||
first_button = btn
|
||
|
||
if hasattr(self, "ai_nav_button"):
|
||
self.nav_layout.addWidget(self.ai_nav_button)
|
||
|
||
if first_button is None:
|
||
denied = EmptyState("暂无可用工作区", "当前账号没有医生工作站页面权限,请联系管理员调整授权。")
|
||
idx = self.stack.addWidget(denied)
|
||
self.stack.setCurrentIndex(idx)
|
||
self.hero_title_label.setText("权限受限")
|
||
return
|
||
|
||
# Default to 'reception' (接诊总览) when available so doctor lands in the Digital Twin Cockpit!
|
||
target_key = "reception" if "reception" in self.nav_buttons else next(iter(self.nav_buttons))
|
||
self.navigate(target_key)
|
||
|
||
def _bind_shortcuts(self) -> None:
|
||
QShortcut(QKeySequence("Ctrl+K"), self, activated=self.open_command_palette)
|
||
QShortcut(QKeySequence("Ctrl+Shift+P"), self, activated=self.open_command_palette)
|
||
QShortcut(QKeySequence("F5"), self, activated=self.refresh_current_page)
|
||
QShortcut(QKeySequence("Ctrl+]"), self, activated=self.toggle_ai_bottom_sheet)
|
||
for idx, (item, _title) in enumerate(self.navigation[:6], start=1):
|
||
QShortcut(
|
||
QKeySequence(f"Alt+{idx}"),
|
||
self,
|
||
activated=lambda key=item.key: self.navigate(key),
|
||
)
|
||
|
||
def _install_activation_refresh_gate(self, page: QWidget) -> None:
|
||
refresh = getattr(page, "refresh", None)
|
||
if not callable(refresh):
|
||
return
|
||
|
||
@wraps(refresh)
|
||
def activation_refresh(*args: Any, **kwargs: Any) -> Any:
|
||
if page is self._activation_page:
|
||
if self._activation_refreshed:
|
||
return None
|
||
self._activation_refreshed = True
|
||
return refresh(*args, **kwargs)
|
||
|
||
page.refresh = activation_refresh # type: ignore[attr-defined,method-assign]
|
||
|
||
def _ensure_activation_refresh(self, page: QWidget, generation: int) -> None:
|
||
if generation != self._activation_generation or page is not self._activation_page:
|
||
return
|
||
if not self._activation_refreshed:
|
||
refresh = getattr(page, "refresh", None)
|
||
if callable(refresh):
|
||
refresh()
|
||
|
||
def _finish_activation(self, page: QWidget, generation: int) -> None:
|
||
if generation != self._activation_generation or page is not self._activation_page:
|
||
return
|
||
self._ensure_activation_refresh(page, generation)
|
||
self._activation_page = None
|
||
|
||
def _navigate(
|
||
self,
|
||
index: int,
|
||
key: str,
|
||
*,
|
||
on_activate: Callable[[], None] | None = None,
|
||
) -> None:
|
||
if index < 0 or index >= self.stack.count():
|
||
return
|
||
page = self.stack.widget(index)
|
||
if page is None:
|
||
return
|
||
if self._active_page_key == key and self.stack.currentWidget() is page:
|
||
if on_activate is not None:
|
||
self._activation_refreshed = False
|
||
on_activate()
|
||
return
|
||
self._activation_generation += 1
|
||
gen = self._activation_generation
|
||
self._activation_page = page
|
||
self._activation_refreshed = False
|
||
if on_activate is not None:
|
||
on_activate()
|
||
motion.switch_stack(self.stack, index)
|
||
btn = self.nav_buttons.get(key)
|
||
if btn is not None:
|
||
btn.setChecked(True)
|
||
crumb, hero_title = _SPATIAL_HERO_TITLES.get(
|
||
key,
|
||
("中医糖代谢专科 / 临床智能工作台", self.page_titles.get(index, "临床工作站")),
|
||
)
|
||
self.breadcrumb_label.setText(crumb)
|
||
self.hero_title_label.setText(hero_title)
|
||
self._active_page_key = key
|
||
self._ensure_activation_refresh(page, gen)
|
||
if self.isVisible():
|
||
QTimer.singleShot(0, lambda p=page, g=gen: self._finish_activation(p, g))
|
||
self.page_changed.emit(key)
|
||
|
||
def navigate(self, key: str) -> bool:
|
||
btn = self.nav_buttons.get(key)
|
||
page = self.pages.get(key)
|
||
if btn is None or page is None:
|
||
return False
|
||
self._navigate(self.stack.indexOf(page), key)
|
||
return True
|
||
|
||
def refresh_current_page(self) -> None:
|
||
page = self.stack.currentWidget()
|
||
refresh = getattr(page, "refresh", None)
|
||
if callable(refresh):
|
||
refresh()
|
||
|
||
def toggle_ai_bottom_sheet(self) -> None:
|
||
self.ai_bottom_sheet.toggle_expanded()
|
||
|
||
def _on_sheet_expanded_changed(self, expanded: bool) -> None:
|
||
self.patient_context_store.set_bottom_sheet_expanded(expanded)
|
||
self._sync_ai_sheet_button(expanded)
|
||
|
||
def _sync_ai_sheet_button(self, expanded: bool) -> None:
|
||
if hasattr(self, "ai_nav_button"):
|
||
self.ai_nav_button.setProperty("activeSheet", expanded)
|
||
self.ai_nav_button.setIcon(
|
||
icons.icon("ai", "#FFFFFF" if expanded else "#0E6F5C", 15)
|
||
)
|
||
self.ai_nav_button.style().unpolish(self.ai_nav_button)
|
||
self.ai_nav_button.style().polish(self.ai_nav_button)
|
||
if self.ai_bottom_sheet.is_expanded != expanded:
|
||
self.ai_bottom_sheet.set_expanded(expanded)
|
||
|
||
def _on_cockpit_snapshot_updated(self, snapshot_vm: Any) -> None:
|
||
aurora = getattr(snapshot_vm, "aurora", None)
|
||
if aurora is not None:
|
||
self.ai_bottom_sheet.set_view_model(aurora)
|
||
|
||
def _on_sheet_model_selected(self, model_key: str) -> None:
|
||
rec_page = self.pages.get("reception")
|
||
select_model = getattr(rec_page, "select_cockpit_ai_model", None)
|
||
if callable(select_model):
|
||
select_model(model_key)
|
||
|
||
def _on_patient_context_changed(self, snapshot: PatientSnapshot) -> None:
|
||
if not snapshot or not snapshot.has_patient:
|
||
self.patient_avatar_badge.setText("患")
|
||
self.context_patient_name.setText("等待选择接诊患者")
|
||
self.context_patient_sub.setText("点击今日门诊计划自动同步全站上下文")
|
||
self.quick_chart_button.setEnabled(False)
|
||
self.quick_video_button.setEnabled(False)
|
||
return
|
||
self.patient_avatar_badge.setText(snapshot.patient_name[:1])
|
||
self.context_patient_name.setText(f"{snapshot.patient_name} · {snapshot.status_text}")
|
||
self.context_patient_sub.setText(snapshot.subtitle_line)
|
||
self.quick_chart_button.setEnabled(snapshot.diagnosis_id > 0)
|
||
self.quick_video_button.setEnabled(snapshot.diagnosis_id > 0 or snapshot.appointment_id > 0)
|
||
|
||
def _open_active_patient_diagnosis(self) -> None:
|
||
snap = self.patient_context_store.current_patient
|
||
if snap.diagnosis_id > 0:
|
||
self.open_diagnosis_by_id(snap.diagnosis_id, modeless=True)
|
||
|
||
def _trigger_active_patient_video(self) -> None:
|
||
rec_page = self.pages.get("reception")
|
||
if rec_page is not None and getattr(rec_page, "_selected_appointment_id", None):
|
||
trigger = getattr(rec_page, "_request_video", None)
|
||
if callable(trigger):
|
||
trigger()
|
||
return
|
||
snap = self.patient_context_store.current_patient
|
||
if snap.diagnosis_id > 0:
|
||
self.video_requested.emit(
|
||
{
|
||
"patient_id": snap.patient_id or snap.diagnosis_id,
|
||
"diagnosis_id": snap.diagnosis_id,
|
||
"appointment_id": snap.appointment_id,
|
||
"patient_name": snap.patient_name,
|
||
"mode": "im",
|
||
"record": snap.raw_record,
|
||
}
|
||
)
|
||
|
||
def _open_active_patient_ai_report(self) -> None:
|
||
rec_page = self.pages.get("reception")
|
||
open_rep = getattr(rec_page, "_open_ai_analysis_dialog", None)
|
||
if callable(open_rep) and getattr(rec_page, "_selected_detail", None):
|
||
open_rep()
|
||
return
|
||
self._open_active_patient_ai_consult()
|
||
|
||
def _open_active_patient_ai_consult(self) -> None:
|
||
snap = self.patient_context_store.current_patient
|
||
if snap.diagnosis_id > 0 and self._can_ai_assistant:
|
||
present_ai_consult(
|
||
self.repository,
|
||
diagnosis_id=snap.diagnosis_id,
|
||
patient_name=snap.patient_name,
|
||
permissions=self.permissions,
|
||
parent=self,
|
||
)
|
||
return
|
||
self._open_global_ai_picker()
|
||
|
||
def _open_global_ai_picker(self) -> None:
|
||
if not self._can_ai_assistant:
|
||
show_toast(self, "当前账号未开通 AI 辨证助手权限。", "warning")
|
||
return
|
||
select_and_present_ai_consult(self.repository, self.permissions, self)
|
||
|
||
def _open_esign_dialog(self) -> None:
|
||
dlg = EsignDoctorDialog(self.repository, parent=self)
|
||
dlg.exec()
|
||
dlg.deleteLater()
|
||
|
||
def _open_audio_queue_dialog(self) -> None:
|
||
if self._local_audio_settings_dialog is None:
|
||
self._local_audio_settings_dialog = LocalAudioQueueDialog(self.repository, self)
|
||
self._local_audio_settings_dialog.show()
|
||
self._local_audio_settings_dialog.raise_()
|
||
self._local_audio_settings_dialog.activateWindow()
|
||
|
||
def _run_global_search(self) -> None:
|
||
query = self.global_search.text().strip()
|
||
target_key = next(
|
||
(k for k in ("consultations", "patients") if k in self.pages),
|
||
None,
|
||
)
|
||
if target_key is None:
|
||
show_toast(self, "当前账号没有可用的患者搜索页面。", "warning")
|
||
return
|
||
page = self.pages[target_key]
|
||
search_fn = getattr(page, "search_patient", None)
|
||
if callable(search_fn):
|
||
self._navigate(
|
||
self.stack.indexOf(page),
|
||
target_key,
|
||
on_activate=lambda: search_fn(query),
|
||
)
|
||
|
||
def open_command_palette(self) -> None:
|
||
entries: list[CommandEntry] = []
|
||
for idx, (item, title) in enumerate(self.navigation, start=1):
|
||
label = _SPATIAL_NAV_LABELS.get(item.key, title)
|
||
entries.append(
|
||
CommandEntry(
|
||
key=f"nav:{item.key}",
|
||
title=f"前往 · {label}",
|
||
subtitle="切换顶部胶囊空间视图",
|
||
category="空间导航",
|
||
shortcut=f"Alt+{idx}" if idx <= 6 else "",
|
||
icon_kind=item.key,
|
||
callback=lambda k=item.key: self.navigate(k),
|
||
)
|
||
)
|
||
entries.append(
|
||
CommandEntry(
|
||
key="act:ai_sheet",
|
||
title="展开 / 收起黑曜极光 AI 辨证舱",
|
||
subtitle="查看三联极光毛玻璃循证卡与控糖节律仪表盘",
|
||
category="临床智医",
|
||
shortcut="Ctrl+]",
|
||
icon_kind="ai",
|
||
callback=self.toggle_ai_bottom_sheet,
|
||
)
|
||
)
|
||
entries.append(
|
||
CommandEntry(
|
||
key="act:refresh",
|
||
title="刷新当前临床视图数据",
|
||
subtitle="同步最新号源、四诊详情与 AI 报告",
|
||
category="工作台操作",
|
||
shortcut="F5",
|
||
icon_kind="refresh",
|
||
callback=self.refresh_current_page,
|
||
)
|
||
)
|
||
snap = self.patient_context_store.current_patient
|
||
if snap.has_patient and snap.diagnosis_id > 0:
|
||
entries.append(
|
||
CommandEntry(
|
||
key="act:diag",
|
||
title=f"打开四诊病历 · {snap.patient_name}",
|
||
subtitle=snap.subtitle_line,
|
||
category="当前患者",
|
||
shortcut="",
|
||
icon_kind="consultations",
|
||
callback=self._open_active_patient_diagnosis,
|
||
)
|
||
)
|
||
dlg = CommandPaletteDialog(entries, self)
|
||
dlg.exec()
|
||
|
||
def _toggle_maximize(self) -> None:
|
||
if self.isMaximized():
|
||
self.showNormal()
|
||
else:
|
||
self.showMaximized()
|
||
|
||
def _ensure_global_diagnosis_dialog(self) -> DiagnosisDialog:
|
||
dialog = self._global_diagnosis_dialog
|
||
if dialog is None:
|
||
dialog = DiagnosisDialog(self.repository, self, permissions=self.permissions)
|
||
dialog.saved.connect(self.refresh_current_page)
|
||
self._global_diagnosis_dialog = dialog
|
||
else:
|
||
dialog.refresh_permissions(self.permissions)
|
||
return dialog
|
||
|
||
def open_diagnosis_by_id(
|
||
self,
|
||
diagnosis_id: Any,
|
||
*,
|
||
modeless: bool = False,
|
||
) -> DiagnosisDialog | None:
|
||
try:
|
||
normalized_id = int(diagnosis_id)
|
||
except (TypeError, ValueError):
|
||
normalized_id = 0
|
||
if normalized_id <= 0:
|
||
show_toast(self, "当前视频缺少有效诊单编号。", "warning", 3600)
|
||
return None
|
||
|
||
if has_permission(self.permissions, "tcm.diagnosis/edit", default=False):
|
||
dialog = self._ensure_global_diagnosis_dialog()
|
||
dialog.open_for(normalized_id, editable=True, modeless=modeless)
|
||
elif has_permission(self.permissions, "tcm.diagnosis/readonlyDetail", default=False):
|
||
dialog = self._ensure_global_diagnosis_dialog()
|
||
dialog.open_view_only(normalized_id, modeless=modeless)
|
||
else:
|
||
show_toast(self, "当前账号没有查看该诊单的权限。", "danger", 4200)
|
||
return None
|
||
|
||
dialog.raise_()
|
||
dialog.activateWindow()
|
||
return dialog
|
||
|
||
def _open_chat_notification(self, notification: ChatNotification) -> None:
|
||
if notification.kind == CONSULTATION_COMPLETE and notification.diagnosis_id > 0:
|
||
self.open_diagnosis_by_id(notification.diagnosis_id, modeless=True)
|
||
return
|
||
if notification.kind == PATIENT_OPENED_CHAT and self.navigate("reception"):
|
||
return
|
||
show_toast(self, notification.description, "info", 4200)
|
||
|
||
def _show_chat_notification_summary(self) -> None:
|
||
pending = self.chat_notifications.pending
|
||
if not pending:
|
||
show_toast(self, "当前没有新的系统通知。", "info")
|
||
return
|
||
latest = pending[0]
|
||
show_toast(
|
||
self,
|
||
f"待处理通知 {len(pending)} 条,最新:{latest.title} · {latest.description}",
|
||
"info",
|
||
4200,
|
||
)
|
||
|
||
def set_connection_state(self, online: bool, message: str = "") -> None:
|
||
self._online = online
|
||
tip = message or ("云端同步正常" if online else "云端连接中断")
|
||
self.refresh_button.setToolTip(f"刷新当前视图(F5) · {tip}")
|
||
|
||
def showEvent(self, event: Any) -> None: # noqa: N802
|
||
super().showEvent(event)
|
||
self.chat_notifications.start()
|
||
page = self.stack.currentWidget()
|
||
if page is not None and page is self._activation_page:
|
||
gen = self._activation_generation
|
||
QTimer.singleShot(0, lambda p=page, g=gen: self._finish_activation(p, g))
|
||
|
||
def closeEvent(self, event: Any) -> None: # noqa: N802
|
||
self.chat_notifications.stop()
|
||
super().closeEvent(event)
|
||
if event.isAccepted():
|
||
self.close_requested.emit()
|
||
|
||
|
||
__all__ = ["SpatialShellWindow"]
|