56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Dictionary payload contracts for diagnosis choice fields."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from doctor_workstation.services.mock_repository import DemoDoctorRepository
|
|
from doctor_workstation.services.repository import RemoteDoctorRepository, _dictionary_rows
|
|
from doctor_workstation.ui.dialogs.diagnosis import _CHOICE_DICTIONARIES, _dictionary_choices
|
|
|
|
|
|
class RecordingClient:
|
|
def __init__(self, payload: Any) -> None:
|
|
self.payload = payload
|
|
self.get_calls: list[tuple[str, dict[str, Any]]] = []
|
|
|
|
def get(self, endpoint: str, params: dict[str, Any] | None = None) -> Any:
|
|
self.get_calls.append((endpoint, dict(params or {})))
|
|
return self.payload
|
|
|
|
|
|
def test_dictionary_rows_unwrap_admin_type_map() -> None:
|
|
rows = _dictionary_rows(
|
|
{
|
|
"sleep_condition": [
|
|
{"name": "入睡困难", "value": "入睡困难"},
|
|
{"name": "多梦", "value": "多梦"},
|
|
]
|
|
},
|
|
"sleep_condition",
|
|
)
|
|
assert [row["value"] for row in rows] == ["入睡困难", "多梦"]
|
|
|
|
|
|
def test_remote_get_dictionary_uses_admin_dict_shape() -> None:
|
|
client = RecordingClient(
|
|
{
|
|
"appetite": [
|
|
{"name": "口干", "value": "口干"},
|
|
{"name": "口苦", "value": "口苦"},
|
|
]
|
|
}
|
|
)
|
|
repository = RemoteDoctorRepository(client) # type: ignore[arg-type]
|
|
rows = repository.get_dictionary("appetite")
|
|
assert client.get_calls == [("config/dict", {"type": "appetite"})]
|
|
assert _dictionary_choices(rows, "appetite") == [("口干", "口干"), ("口苦", "口苦")]
|
|
|
|
|
|
def test_demo_exposes_all_diagnosis_choice_dictionaries() -> None:
|
|
repository = DemoDoctorRepository()
|
|
for dictionary_type, _multiple in _CHOICE_DICTIONARIES.values():
|
|
rows = repository.get_dictionary(dictionary_type)
|
|
assert rows, dictionary_type
|
|
assert _dictionary_choices(rows, dictionary_type)
|