更新
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,
|
||||
|
||||
Reference in New Issue
Block a user