更新
This commit is contained in:
@@ -288,122 +288,121 @@ def test_paid_order_response_is_bound_to_active_diagnosis_and_blocks_save(
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_diagnosis_order_detail_lookup_is_queued_before_repository_call(
|
||||
def test_prescription_diagnosis_detail_uses_shared_structured_readonly_ui(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
queued: list[tuple[Any, dict[str, Any]]] = []
|
||||
requested: list[int] = []
|
||||
shown: list[tuple[int, str]] = []
|
||||
|
||||
class Repository:
|
||||
def get_prescription_order(self, order_id: int) -> dict[str, Any]:
|
||||
requested.append(order_id)
|
||||
return {"id": order_id, "order_no": f"DETAIL-{order_id}"}
|
||||
def get_doctor_notes(self, diagnosis_id: int) -> list[dict[str, Any]]:
|
||||
assert diagnosis_id == 745
|
||||
return []
|
||||
|
||||
def queue_async(function: Any, **options: Any) -> object:
|
||||
queued.append((function, options))
|
||||
return object()
|
||||
|
||||
def present_order_detail(
|
||||
_host: Any,
|
||||
order: dict[str, Any],
|
||||
*,
|
||||
order_id: int,
|
||||
permissions: Any,
|
||||
exec_: bool,
|
||||
) -> None:
|
||||
del permissions, exec_
|
||||
shown.append((order_id, order["order_no"]))
|
||||
|
||||
monkeypatch.setattr(dialog_module, "run_async", queue_async)
|
||||
monkeypatch.setattr(diagnosis_module, "present_order_detail", present_order_detail)
|
||||
monkeypatch.setattr(diagnosis_module, "run_async", _immediate_async)
|
||||
dialog = DiagnosisDetailDialog(
|
||||
{"orders": [{"id": 17, "order_no": "ROW-17"}]},
|
||||
{
|
||||
"diagnosis": {
|
||||
"id": 745,
|
||||
"patient_id": 745,
|
||||
"patient_name": "庄志芳",
|
||||
"phone": "13823549442",
|
||||
"id_card": "440305196701011234",
|
||||
"gender": 0,
|
||||
"age": 59,
|
||||
"chief_complaint": "睡眠不好、出汗多",
|
||||
"past_history": ["高血压", "高脂血症"],
|
||||
},
|
||||
"patient": {"id": 745},
|
||||
},
|
||||
repository=Repository(),
|
||||
permissions=PermissionSet(["tcm.diagnosis/readonlyDetail"]),
|
||||
)
|
||||
table = dialog._order_detail_table
|
||||
button = dialog._order_detail_button
|
||||
assert table is not None
|
||||
assert button is not None
|
||||
table.setCurrentCell(0, 0)
|
||||
|
||||
button.click()
|
||||
|
||||
assert len(queued) == 1
|
||||
assert requested == []
|
||||
assert shown == []
|
||||
assert not table.isEnabled()
|
||||
assert not button.isEnabled()
|
||||
|
||||
function, options = queued[0]
|
||||
options["on_success"](function())
|
||||
options["on_finished"]()
|
||||
assert requested == [17]
|
||||
assert shown == [(17, "DETAIL-17")]
|
||||
assert table.isEnabled()
|
||||
assert button.isEnabled()
|
||||
assert isinstance(dialog, DiagnosisDialog)
|
||||
assert dialog.view_stack.currentWidget() is dialog.readonly_page
|
||||
assert dialog.edit_fields["chief_complaint"].toPlainText() == "睡眠不好、出汗多"
|
||||
assert dialog.summary_fields["phone"].text() == "138****9442"
|
||||
assert dialog.case_grid.isVisibleTo(dialog)
|
||||
assert not dialog.findChildren(dialog_module.QTextBrowser)
|
||||
dialog.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_diagnosis_order_detail_ignores_stale_result_and_keeps_row_fallback(
|
||||
@pytest.mark.parametrize("owner_width", [1024, 1440, 1710])
|
||||
def test_prescription_editor_embeds_scrollable_diagnosis_beside_editable_form(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
owner_width: int,
|
||||
) -> None:
|
||||
queued: list[dict[str, Any]] = []
|
||||
shown: list[tuple[int, str]] = []
|
||||
class Repository:
|
||||
def get_diagnosis_detail(
|
||||
self, diagnosis_id: int, *, readonly: bool = False
|
||||
) -> dict[str, Any]:
|
||||
assert readonly
|
||||
return {
|
||||
"diagnosis": {
|
||||
"id": diagnosis_id,
|
||||
"patient_id": 745,
|
||||
"patient_name": "庄志芳",
|
||||
"chief_complaint": "睡眠不好、出汗多",
|
||||
}
|
||||
}
|
||||
|
||||
def queue_async(_function: Any, **options: Any) -> object:
|
||||
queued.append(options)
|
||||
return object()
|
||||
def get_doctor_notes(self, _diagnosis_id: int) -> list[dict[str, Any]]:
|
||||
return []
|
||||
|
||||
def present_order_detail(
|
||||
_host: Any,
|
||||
order: dict[str, Any],
|
||||
*,
|
||||
order_id: int,
|
||||
permissions: Any,
|
||||
exec_: bool,
|
||||
) -> None:
|
||||
del permissions, exec_
|
||||
shown.append((order_id, order["order_no"]))
|
||||
|
||||
repository = SimpleNamespace(get_prescription_order=lambda order_id: {"id": order_id})
|
||||
monkeypatch.setattr(dialog_module, "run_async", queue_async)
|
||||
monkeypatch.setattr(diagnosis_module, "present_order_detail", present_order_detail)
|
||||
dialog = DiagnosisDetailDialog(
|
||||
{
|
||||
"orders": [
|
||||
{"id": 21, "order_no": "ROW-21"},
|
||||
{"id": 22, "order_no": "ROW-22"},
|
||||
]
|
||||
},
|
||||
repository=repository,
|
||||
monkeypatch.setattr(diagnosis_module, "run_async", _immediate_async)
|
||||
owner = QDialog()
|
||||
owner.resize(owner_width, 720)
|
||||
owner.show()
|
||||
repository = Repository()
|
||||
editor = PrescriptionEditorDialog(
|
||||
repository,
|
||||
{"diagnosis_id": 745, "patient_name": "庄志芳"},
|
||||
mode="edit",
|
||||
current_user=SimpleNamespace(id=9, name="周医生"),
|
||||
permissions=PermissionSet(["tcm.diagnosis/readonlyDetail"]),
|
||||
parent=owner,
|
||||
)
|
||||
table = dialog._order_detail_table
|
||||
button = dialog._order_detail_button
|
||||
assert table is not None
|
||||
assert button is not None
|
||||
editor.show()
|
||||
application.processEvents()
|
||||
assert QApplication.activeModalWidget() is editor
|
||||
assert editor.width() == editor.DRAWER_WIDTH
|
||||
|
||||
table.setCurrentCell(0, 0)
|
||||
dialog._open_selected_order()
|
||||
table.setCurrentCell(1, 0)
|
||||
dialog._open_selected_order()
|
||||
assert len(queued) == 2
|
||||
editor.diagnosis_button.click()
|
||||
application.processEvents()
|
||||
|
||||
queued[0]["on_success"]({"id": 21, "order_no": "STALE-21"})
|
||||
queued[0]["on_finished"]()
|
||||
assert shown == []
|
||||
assert not table.isEnabled()
|
||||
assert not button.isEnabled()
|
||||
detail = editor._diagnosis_view
|
||||
assert detail is not None
|
||||
assert QApplication.activeModalWidget() is editor
|
||||
assert not detail.isWindow()
|
||||
assert detail.parentWidget() is editor.diagnosis_host
|
||||
assert editor.diagnosis_host.isVisibleTo(editor)
|
||||
assert editor.drawer_surface.isVisibleTo(editor)
|
||||
assert editor.width() == owner.width()
|
||||
assert editor.diagnosis_host.geometry().right() < editor.drawer_surface.geometry().left()
|
||||
scroll_bar = detail.readonly_scroll.verticalScrollBar()
|
||||
assert scroll_bar.maximum() > 0
|
||||
scroll_bar.setValue(scroll_bar.maximum())
|
||||
assert scroll_bar.value() == scroll_bar.maximum()
|
||||
|
||||
queued[1]["on_error"](RuntimeError("detail unavailable"))
|
||||
queued[1]["on_finished"]()
|
||||
assert shown == [(22, "ROW-22")]
|
||||
assert table.isEnabled()
|
||||
assert button.isEnabled()
|
||||
dialog.close()
|
||||
editor.patient_name.setText("庄志芳(已核对)")
|
||||
assert editor.patient_name.isEnabled()
|
||||
assert editor.payload()["patient_name"] == "庄志芳(已核对)"
|
||||
|
||||
detail.readonly_close_button.click()
|
||||
application.processEvents()
|
||||
assert editor.isVisible()
|
||||
assert not editor.diagnosis_host.isVisible()
|
||||
assert editor.width() == editor.DRAWER_WIDTH
|
||||
assert editor.patient_name.text() == "庄志芳(已核对)"
|
||||
editor.diagnosis_button.click()
|
||||
application.processEvents()
|
||||
assert editor.diagnosis_host.isVisibleTo(editor)
|
||||
editor.reject()
|
||||
application.processEvents()
|
||||
assert not editor.isVisible()
|
||||
assert not detail.isVisible()
|
||||
owner.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user