Merge branch '11-5' of http://git.zhenyangtang.com.cn/ZYT/zyt
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
"""Doctor queries keep appointment relationships and pagination intact."""
|
||||
|
||||
from copy import deepcopy
|
||||
from datetime import date
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from doctor_workstation.core.models import Consultation, Prescription
|
||||
from doctor_workstation.services.mock_repository import DemoDoctorRepository
|
||||
from doctor_workstation.services.repository import RemoteDoctorRepository
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repository() -> DemoDoctorRepository:
|
||||
repository = DemoDoctorRepository(today=date(2026, 11, 5))
|
||||
|
||||
def row(diagnosis_id: int, appointments: list[dict[str, Any]]) -> Consultation:
|
||||
appointments = [dict(appointment, id=diagnosis_id * 10 + index) for index, appointment in enumerate(appointments)]
|
||||
primary = appointments[0] if appointments else {}
|
||||
return Consultation.from_dict({
|
||||
"id": diagnosis_id,
|
||||
"patient_name": f"患者{diagnosis_id}",
|
||||
"doctor_name": primary.get("doctor_name", "陈医生"),
|
||||
"doctor_id": primary.get("doctor_id"),
|
||||
"appointment_id": primary.get("id"),
|
||||
"appointment_date": "2026-11-05",
|
||||
"appointment_type": primary.get("appointment_type"),
|
||||
"appointment_status": primary.get("status"),
|
||||
"has_appointment": bool(appointments),
|
||||
"appointments": appointments,
|
||||
})
|
||||
|
||||
def appointment(doctor: str, day: str = "2026-11-05", status: int = 1) -> dict[str, Any]:
|
||||
return {
|
||||
"doctor_name": doctor, "doctor_id": 201 if doctor == "陈医生" else 202,
|
||||
"appointment_date": day, "appointment_time": "09:00", "status": status,
|
||||
"appointment_type": "video" if doctor == "陈医生" else "text",
|
||||
}
|
||||
|
||||
repository._consultations = [
|
||||
row(1, [appointment("李医生"), appointment("陈医生"), appointment("陈医生", status=4), appointment("陈医生")]),
|
||||
row(2, [appointment("李医生"), appointment("陈医生", "2026-11-04", 3)]),
|
||||
row(3, [appointment("李医生"), appointment("陈医生", status=3)]),
|
||||
row(4, [appointment("陈医生", status=2)]),
|
||||
row(5, []),
|
||||
]
|
||||
repository._prescriptions = [
|
||||
Prescription.from_dict({"id": 101, "appointment_id": 10, "audit_status": 0}),
|
||||
Prescription.from_dict({"id": 102, "appointment_id": 11, "audit_status": 1}),
|
||||
]
|
||||
return repository
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("filters", "expected"),
|
||||
[
|
||||
({"doctor_name": " 陈医生 "}, [1, 2, 3]),
|
||||
({"doctor_name": "陈"}, [1, 2, 3]),
|
||||
({"doctor_name": "不存在"}, []),
|
||||
({"doctor_name": " "}, [1, 2, 3, 4, 5]),
|
||||
({"doctor_name": "陈医生", "appointment_date": "2026-11-05"}, [1, 3]),
|
||||
({"doctor_name": "陈医生", "appointment_date": "2026-11-05", "appointment_status": 1}, [1]),
|
||||
({"doctor_name": "陈医生", "appointment_date": "2026-11-05", "completed_appointment": 1}, [3]),
|
||||
({"doctor_name": "陈医生", "keyword": "患者3"}, [3]),
|
||||
({"doctor_name": "陈医生", "pending_assign": 1, "pending_assign_keyword": "患者",
|
||||
"appointment_date": "1900-01-01", "appointment_status": 2, "status": 99}, [1, 2, 3]),
|
||||
],
|
||||
)
|
||||
def test_demo_doctor_filter_matches_effective_same_appointment(
|
||||
repository: DemoDoctorRepository, filters: dict[str, Any], expected: list[int]
|
||||
) -> None:
|
||||
result = repository.list_consultations(**filters)
|
||||
assert [row.id for row in result.items] == expected
|
||||
assert result.count == len(expected)
|
||||
if str(filters.get("doctor_name") or "").strip():
|
||||
for row in result.items:
|
||||
assert row.doctor_name == "陈医生"
|
||||
assert row.doctor_id == 201
|
||||
assert row.appointment_id == row.appointments[0]["id"]
|
||||
assert row.appointment_status == row.appointments[0]["status"]
|
||||
assert row.appointment_date == row.appointments[0]["appointment_date"]
|
||||
assert all(appointment["doctor_name"] == "陈医生" for appointment in row.appointments)
|
||||
assert row.raw["appointment_doctor_name"] == row.doctor_name
|
||||
assert row.raw["appointment_type"] == "video"
|
||||
|
||||
|
||||
def test_demo_projection_preserves_source_and_uses_current_appointment_prescription(
|
||||
repository: DemoDoctorRepository,
|
||||
) -> None:
|
||||
before = deepcopy(repository._consultations)
|
||||
result = repository.list_consultations(doctor_name="陈医生", appointment_status=1)
|
||||
row = result.items[0]
|
||||
assert [appointment["id"] for appointment in row.appointments] == [11, 13]
|
||||
assert row.raw["current_prescription_id"] == 102
|
||||
assert row.raw["prescription_audit_status"] == 1
|
||||
row.appointments[0]["doctor_name"] = "changed"
|
||||
assert repository._consultations == before
|
||||
assert [item.raw for item in repository._consultations] == [item.raw for item in before]
|
||||
other = repository.list_consultations(doctor_name="李医生").items[0]
|
||||
assert other.appointment_id == 10
|
||||
assert other.raw["current_prescription_id"] == 101
|
||||
assert repository.list_consultations().count == 5
|
||||
|
||||
|
||||
def test_demo_doctor_filter_runs_before_pagination(repository: DemoDoctorRepository) -> None:
|
||||
result = repository.list_consultations(doctor_name="陈医生", page_no=2, page_size=1)
|
||||
assert [row.id for row in result.items] == [2]
|
||||
assert result.count == 3
|
||||
|
||||
|
||||
def test_default_demo_data_supports_doctor_filter() -> None:
|
||||
repository = DemoDoctorRepository(today=date(2026, 11, 5))
|
||||
result = repository.list_consultations(doctor_name="陈医生")
|
||||
assert [row.id for row in result.items] == [501, 502, 503]
|
||||
assert result.count == 3
|
||||
|
||||
|
||||
def test_remote_preserves_doctor_query_and_server_pagination() -> None:
|
||||
class Client:
|
||||
calls: list[tuple[str, dict[str, Any]]] = []
|
||||
|
||||
def get(self, endpoint: str, params: dict[str, Any]) -> dict[str, Any]:
|
||||
self.calls.append((endpoint, params))
|
||||
return {"lists": [{"id": 502, "patient_name": "患者"}], "count": 7}
|
||||
|
||||
client = Client()
|
||||
repository = RemoteDoctorRepository(client) # type: ignore[arg-type]
|
||||
result = repository.list_consultations(
|
||||
doctor_name="陈医生", start_date="2026-11-05", end_date="2026-11-05",
|
||||
status=3, department_id=10, page_no=2, page_size=1,
|
||||
)
|
||||
assert client.calls == [("tcm.diagnosis/lists", {
|
||||
"doctor_name": "陈医生", "appointment_date": "2026-11-05",
|
||||
"completed_appointment": 1, "assistant_dept_id": 10, "page_no": 2, "page_size": 1,
|
||||
})]
|
||||
assert [row.id for row in result.items] == [502]
|
||||
assert result.count == 7
|
||||
@@ -0,0 +1,62 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QPoint, Qt
|
||||
from PySide6.QtTest import QTest
|
||||
from PySide6.QtWidgets import QApplication, QLabel
|
||||
|
||||
from doctor_workstation.ui.diagnosis_index_widgets import DiagnosisTableHost
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def application() -> QApplication:
|
||||
return QApplication.instance() or QApplication([])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tech_blue", [True, False])
|
||||
def test_patient_name_can_be_drag_selected_and_copied_without_opening_or_editing(
|
||||
application: QApplication, tech_blue: bool,
|
||||
) -> None:
|
||||
host = DiagnosisTableHost(tech_blue=tech_blue)
|
||||
host.resize(1400, 400)
|
||||
rows = [{"id": 1, "patient_name": "测试甲"}, {"id": 2, "patient_name": "测试乙"}]
|
||||
host.set_rows(rows)
|
||||
opened = []
|
||||
host.main.itemDoubleClicked.connect(opened.append)
|
||||
host.show()
|
||||
for _ in range(10):
|
||||
application.processEvents()
|
||||
|
||||
label = host.main.indexWidget(host.model.index(1, 2))
|
||||
assert isinstance(label, QLabel)
|
||||
start = QPoint(label.contentsMargins().left(), label.height() // 2)
|
||||
end = QPoint(start.x() + label.fontMetrics().horizontalAdvance(label.text()) + 2, start.y())
|
||||
QTest.mousePress(label, Qt.MouseButton.LeftButton, pos=start)
|
||||
QTest.mouseMove(label, end, 30)
|
||||
QTest.mouseRelease(label, Qt.MouseButton.LeftButton, pos=end)
|
||||
|
||||
assert label.selectedText() == "测试乙"
|
||||
assert host.main.currentRow() == 1
|
||||
QTest.keyClick(label, Qt.Key.Key_C, Qt.KeyboardModifier.ControlModifier)
|
||||
assert application.clipboard().text() == "测试乙"
|
||||
QTest.keyClicks(label, "renamed")
|
||||
assert label.text() == "测试乙"
|
||||
assert host.model.rows == rows
|
||||
assert host.selected_records() == []
|
||||
|
||||
# Double-clicking text must stay in text selection, not open the diagnosis.
|
||||
QTest.mouseDClick(label, Qt.MouseButton.LeftButton, pos=QPoint(start.x() + 7, start.y()))
|
||||
assert label.hasSelectedText()
|
||||
assert opened == []
|
||||
# An unchanged poll preserves the live text selection and label instance.
|
||||
selected = label.selectedText()
|
||||
host.set_rows([dict(row) for row in rows])
|
||||
assert host.main.indexWidget(host.model.index(1, 2)) is label
|
||||
assert label.selectedText() == selected
|
||||
host.close()
|
||||
host.deleteLater()
|
||||
application.processEvents()
|
||||
@@ -288,6 +288,46 @@ def test_default_query_matches_admin_today_and_page_size_contract(
|
||||
"sort_unserved_days",
|
||||
}.issubset(query)
|
||||
assert "consultation_type" not in query
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"pending_keyword_field",
|
||||
[None, "patient_name_edit", "keyword_edit", "pending_assign_keyword"],
|
||||
)
|
||||
def test_doctor_search_scopes_list_and_counts_and_reset_clears_it(
|
||||
application: QApplication,
|
||||
immediate_async: None,
|
||||
pending_keyword_field: str | None,
|
||||
) -> None:
|
||||
calls: list[dict[str, Any]] = []
|
||||
|
||||
class Repository:
|
||||
def list_consultations(self, **kwargs: Any) -> dict[str, Any]:
|
||||
calls.append(kwargs)
|
||||
return {"lists": [], "count": 0}
|
||||
|
||||
page = ConsultationsPage(Repository(), permissions=PermissionSet(["*"]))
|
||||
page.doctor_edit.setText(" 测试医生 ")
|
||||
if pending_keyword_field:
|
||||
getattr(page, pending_keyword_field).setText("测试患者")
|
||||
page._choose_pending_assign()
|
||||
else:
|
||||
page.search_button.click()
|
||||
|
||||
assert any(query["page_size"] == 15 for query in calls)
|
||||
assert any(query["page_size"] == 1 for query in calls)
|
||||
assert all(query["doctor_name"] == "测试医生" for query in calls)
|
||||
if pending_keyword_field:
|
||||
pending_queries = [query for query in calls if query.get("pending_assign") == "1"]
|
||||
assert {query["page_size"] for query in pending_queries} == {1, 15}
|
||||
assert all(query["pending_assign_keyword"] == "测试患者" for query in pending_queries)
|
||||
|
||||
calls.clear()
|
||||
page.reset_button.click()
|
||||
assert calls
|
||||
assert all(not query.get("doctor_name") for query in calls)
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user