更新
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
@@ -17,9 +18,13 @@ from doctor_workstation.ui.dialogs.ai_consult import (
|
||||
present_ai_consult,
|
||||
render_chat_payload,
|
||||
)
|
||||
from doctor_workstation.ui.pages import appointments as appointments_module
|
||||
from doctor_workstation.ui.pages import consultations as consultations_module
|
||||
from doctor_workstation.ui.pages import patients as patients_module
|
||||
from doctor_workstation.ui.pages import reception as reception_module
|
||||
from doctor_workstation.ui.pages.appointments import AppointmentsPage
|
||||
from doctor_workstation.ui.pages.consultations import ConsultationsPage
|
||||
from doctor_workstation.ui.pages.patients import PatientListWorkspace
|
||||
from doctor_workstation.ui.pages.patients import PatientListWorkspace, PatientsPage
|
||||
from doctor_workstation.ui.pages.reception import ReceptionPage
|
||||
|
||||
|
||||
@@ -135,6 +140,80 @@ def test_four_entry_points_expose_ai_consult_action(application: QApplication) -
|
||||
consultations.close()
|
||||
|
||||
|
||||
def test_global_ai_openers_keep_the_selected_diagnosis_context(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
opened: list[tuple[int, int, str]] = []
|
||||
|
||||
def capture(_repository: Any, _permissions: Any, _parent: Any, **kwargs: Any) -> None:
|
||||
opened.append(
|
||||
(
|
||||
int(kwargs["diagnosis_id"]),
|
||||
int(kwargs["patient_id"]),
|
||||
str(kwargs["source_title"]),
|
||||
)
|
||||
)
|
||||
|
||||
for module in (
|
||||
appointments_module,
|
||||
consultations_module,
|
||||
patients_module,
|
||||
reception_module,
|
||||
):
|
||||
monkeypatch.setattr(module, "present_ai_consult", capture)
|
||||
|
||||
allowed = PermissionSet(["tcm.diagnosis/aiAssistant"])
|
||||
row = {"diagnosis_id": 501, "source_patient_id": 301, "patient_id": 301}
|
||||
|
||||
appointment_page = SimpleNamespace(
|
||||
repository=object(),
|
||||
permissions=allowed,
|
||||
_current_row=lambda: row,
|
||||
)
|
||||
assert AppointmentsPage.open_selected_ai_consult(appointment_page)
|
||||
|
||||
consultation_page = SimpleNamespace(
|
||||
repository=object(),
|
||||
permissions=allowed,
|
||||
table=SimpleNamespace(current_data=lambda: row),
|
||||
)
|
||||
assert ConsultationsPage.open_selected_ai_consult(consultation_page)
|
||||
|
||||
patient_workspace = SimpleNamespace(
|
||||
table=SimpleNamespace(current_data=lambda: row),
|
||||
)
|
||||
patient_page = SimpleNamespace(
|
||||
repository=object(),
|
||||
permissions=allowed,
|
||||
tabs=SimpleNamespace(currentWidget=lambda: patient_workspace),
|
||||
)
|
||||
patient_page._diagnosis_id = lambda value: PatientsPage._diagnosis_id(
|
||||
patient_page, value
|
||||
)
|
||||
patient_page._open_ai_consult = lambda value: PatientsPage._open_ai_consult(
|
||||
patient_page, value
|
||||
)
|
||||
assert PatientsPage.open_selected_ai_consult(patient_page)
|
||||
|
||||
reception_page = SimpleNamespace(
|
||||
repository=object(),
|
||||
permissions=allowed,
|
||||
_can_ai_assistant=True,
|
||||
_detail_loading=False,
|
||||
_selection_context=lambda: (1, 101, 501, 301),
|
||||
_selected_detail=row,
|
||||
_selected_record=None,
|
||||
)
|
||||
assert ReceptionPage.open_selected_ai_consult(reception_page)
|
||||
|
||||
assert opened == [
|
||||
(501, 301, "问诊列表"),
|
||||
(501, 301, "问诊列表"),
|
||||
(501, 301, "我的患者"),
|
||||
(501, 301, "接诊台"),
|
||||
]
|
||||
|
||||
|
||||
def test_ai_consult_sidebar_loads_patient_facts_and_reports(
|
||||
application: QApplication,
|
||||
immediate_async: None,
|
||||
|
||||
@@ -346,6 +346,54 @@ def test_shell_hides_global_ai_entries_without_ai_permission(
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_shell_ai_entry_reports_when_reception_is_not_available(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
navigation = [
|
||||
NavigationItem(
|
||||
"appointments",
|
||||
"问诊列表",
|
||||
"号",
|
||||
_ShellPageDouble,
|
||||
("doctor.appointment/lists",),
|
||||
)
|
||||
]
|
||||
monkeypatch.setattr(
|
||||
shell_module,
|
||||
"_resolve_navigation",
|
||||
lambda _menu, _permissions, *, demo_mode: [
|
||||
(item, item.title) for item in navigation
|
||||
],
|
||||
)
|
||||
messages: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
shell_module,
|
||||
"show_toast",
|
||||
lambda _parent, message, *_args, **_kwargs: messages.append(message),
|
||||
)
|
||||
window = ShellWindow(
|
||||
object(),
|
||||
{"user": {"name": "无接诊台医生"}, "demo_mode": True},
|
||||
permissions={
|
||||
"doctor.appointment/lists",
|
||||
"tcm.diagnosis/aiAssistant",
|
||||
},
|
||||
)
|
||||
window.show()
|
||||
application.processEvents()
|
||||
|
||||
window.assistant_button.click()
|
||||
application.processEvents()
|
||||
|
||||
assert any("没有可用的接诊台" in message for message in messages)
|
||||
assert all("已进入接诊台" not in message for message in messages)
|
||||
assert window.stack.currentWidget() is window.pages["appointments"]
|
||||
|
||||
window.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_shell_settings_opens_global_local_audio_upload_manager(
|
||||
application: QApplication,
|
||||
shell_window: ShellWindow,
|
||||
|
||||
Reference in New Issue
Block a user