66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
"""Current no-pulse workflow; old records and old acceptance fixtures stay intact."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from copy import deepcopy
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
import pytest
|
|
from PySide6.QtCore import QEvent, QTimer
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
from doctor_workstation.core import PermissionSet
|
|
from doctor_workstation.ui.dialogs import ai_consult as module
|
|
from doctor_workstation.ui.dialogs.diagnosis import _DIAGNOSIS_FIELDS
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def application():
|
|
return QApplication.instance() or QApplication([])
|
|
|
|
|
|
def test_current_prompts_and_suggestions_do_not_request_pulse():
|
|
prompts = [prompt for _, prompt in module.QUICK_PROMPTS]
|
|
prompts += [prompt for _, _, prompt in module.TOOL_ITEMS]
|
|
for text in [*prompts, *module.SUGGESTIONS]:
|
|
assert "舌脉" not in text
|
|
assert "脉象" not in text
|
|
assert len(module.TOOL_ITEMS) == 6
|
|
assert len(module.SUGGESTIONS) == 5
|
|
|
|
|
|
def test_context_uses_tongue_without_repurposing_historical_pulse():
|
|
detail = {"diagnosis": {"tongue": "舌淡红", "pulse": "历史脉细", "pulse_condition": "旧字段"}}
|
|
original = deepcopy(detail)
|
|
text, labels = module.build_patient_ai_context(detail=detail)
|
|
assert labels == ["舌象"]
|
|
assert "舌淡红" in text
|
|
assert "脉" not in text
|
|
assert detail == original
|
|
|
|
|
|
def test_pulse_only_does_not_create_current_context_or_collection_field():
|
|
assert module.build_patient_ai_context(detail={"diagnosis": {"pulse": "旧脉象"}}) == ("", [])
|
|
assert "pulse" not in {key for _, key, _ in _DIAGNOSIS_FIELDS}
|
|
|
|
|
|
def test_new_prescription_seed_has_no_active_pulse_fields(application, monkeypatch):
|
|
dialog = module.AiConsultDialog(object(), PermissionSet(["tcm.diagnosis/aiAssistant"]))
|
|
monkeypatch.setattr(dialog, "_load_workspace", lambda _: None)
|
|
detail = {"diagnosis": {"id": 501, "patient_id": 1501, "tongue": "舌淡红", "pulse": "历史脉细"}}
|
|
original = deepcopy(detail)
|
|
try:
|
|
dialog.open_for(diagnosis_id=501, patient_id=1501)
|
|
seed = dialog._prescription_seed(detail)
|
|
assert "pulse" not in seed and "pulse_condition" not in seed
|
|
assert seed["tongue"] == "舌淡红"
|
|
assert detail == original
|
|
finally:
|
|
for timer in dialog.findChildren(QTimer):
|
|
timer.stop()
|
|
dialog.close()
|
|
dialog.deleteLater()
|
|
application.sendPostedEvents(None, QEvent.Type.DeferredDelete)
|
|
application.processEvents()
|