更新
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtWidgets import QApplication, QLabel
|
||||
from PySide6.QtWidgets import QApplication, QDialog, QLabel
|
||||
|
||||
from doctor_workstation.core.errors import ApiProtocolError
|
||||
from doctor_workstation.core.models import Appointment, PageResult
|
||||
@@ -174,6 +175,93 @@ def test_diagnosis_and_patient_ids_stay_distinct_for_video() -> None:
|
||||
)
|
||||
assert prescription_action_label(approved) == "查看"
|
||||
|
||||
pending = Appointment.from_dict(
|
||||
{
|
||||
"id": 103,
|
||||
"prescription_audit_status": 0,
|
||||
"prescription_void_status": 0,
|
||||
"has_prescription": 1,
|
||||
}
|
||||
)
|
||||
assert prescription_action_label(pending) == "编辑处方"
|
||||
|
||||
|
||||
def test_appointment_pending_prescription_uses_full_edit_contract(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
updated: list[tuple[int, dict[str, Any]]] = []
|
||||
existing = {
|
||||
"id": 81,
|
||||
"diagnosis_id": 501,
|
||||
"audit_status": 0,
|
||||
"void_status": 0,
|
||||
"patient_name": "林晓岚",
|
||||
}
|
||||
|
||||
class Repository:
|
||||
def update_prescription(
|
||||
self, prescription: int, changes: dict[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
updated.append((prescription, dict(changes)))
|
||||
return {"id": prescription}
|
||||
|
||||
class AcceptedEditor:
|
||||
def __init__(self, _repository: Any, source: Any, **kwargs: Any) -> None:
|
||||
assert source is existing
|
||||
assert kwargs["mode"] == "edit"
|
||||
|
||||
def exec(self) -> QDialog.DialogCode:
|
||||
return QDialog.DialogCode.Accepted
|
||||
|
||||
def payload(self) -> dict[str, Any]:
|
||||
return {"id": 81, "clinical_diagnosis": "脾气虚"}
|
||||
|
||||
def run_immediately(function: Any, **callbacks: Any) -> object:
|
||||
try:
|
||||
result = function()
|
||||
except Exception as error:
|
||||
callbacks["on_error"](error)
|
||||
else:
|
||||
callbacks["on_success"](result)
|
||||
finally:
|
||||
callbacks["on_finished"]()
|
||||
return object()
|
||||
|
||||
monkeypatch.setattr(appointments_module, "PrescriptionEditorDialog", AcceptedEditor)
|
||||
monkeypatch.setattr(appointments_module, "run_async", run_immediately)
|
||||
page = AppointmentsPage(Repository(), permissions=PermissionSet(["*"]))
|
||||
monkeypatch.setattr(page, "refresh", lambda **_kwargs: None)
|
||||
|
||||
page._prescription_loaded(existing, {"id": 101}, page._prescription_generation)
|
||||
|
||||
assert updated == [(81, {"id": 81, "clinical_diagnosis": "脾气虚"})]
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_appointment_prescription_seed_keeps_admin_observation_fields(
|
||||
application: QApplication,
|
||||
) -> None:
|
||||
page = AppointmentsPage(SimpleNamespace(), permissions=PermissionSet(["*"]))
|
||||
seed = page._prescription_seed(
|
||||
{"id": 101, "appointment_id": 101, "diagnosis_id": 501},
|
||||
{
|
||||
"id": 501,
|
||||
"patient_name": "林晓岚",
|
||||
"tongue": "面象哨兵",
|
||||
"tongue_image": "舌象哨兵",
|
||||
"pulse": "脉象哨兵",
|
||||
"pulse_condition": "脉象详情哨兵",
|
||||
},
|
||||
)
|
||||
assert seed["tongue"] == "面象哨兵"
|
||||
assert seed["tongue_image"] == "舌象哨兵"
|
||||
assert seed["pulse"] == "脉象哨兵"
|
||||
assert seed["pulse_condition"] == "脉象详情哨兵"
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_appointments_page_default_query_is_today_pending(
|
||||
application: QApplication,
|
||||
|
||||
Reference in New Issue
Block a user