feat(web): screens from docs/mock — focus flow, today, meds, doctor, profile
- /flow renders the dialog engine's current step as a mock screen (consent,
age, onboarding and scales with progress, mood 0–10, free text, dose
reminder, crisis with hotlines and breathing, safety plan), so every
engine scenario gets the design without duplicating its logic
- today / meds / doctor / profile / messages tabs; navy sidebar and
emergency rail on desktop, emergency block and tab bar on phones
- API: GET /me/{token}/today (today's doses, week marks, next visit, demo
clock time); demo ЕМИАС sign-in seeds the persona's synthetic profile and
prescription from the dashboard fixtures
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Patient web app API: ЕМИАС (demo) and anonymous sign-in, crisis resources, hand-off to the dialog engine."""
|
||||
|
||||
from collections.abc import AsyncIterator
|
||||
from datetime import datetime, time, timedelta
|
||||
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
@@ -9,6 +10,7 @@ from app.api import fixtures
|
||||
from app.core import clock
|
||||
from app.db import identity_repo, repo, session
|
||||
from app.db.bootstrap import init_db
|
||||
from app.db.clinical import Dose, Prescription
|
||||
from app.main import app
|
||||
|
||||
MEM = "sqlite+aiosqlite:///:memory:"
|
||||
@@ -81,6 +83,37 @@ async def test_emias_demo_persona(client: AsyncClient) -> None:
|
||||
assert missing.status_code == 404
|
||||
|
||||
|
||||
async def test_today_plan_and_week_marks(client: AsyncClient) -> None:
|
||||
now = clock.now()
|
||||
today = now.date()
|
||||
async with session.get_clinical_session() as s:
|
||||
await repo.upsert_profile(s, token=TOKEN, doctor_id="doc-1", next_visit=today + timedelta(days=5))
|
||||
rx = Prescription(token=TOKEN, drug="sertraline", dose="50 мг", schedule={"times": ["09:00", "21:00"]})
|
||||
s.add(rx)
|
||||
await s.flush()
|
||||
morning = datetime.combine(today, time(9, 0), now.tzinfo)
|
||||
s.add_all(
|
||||
[
|
||||
Dose(token=TOKEN, prescription_id=rx.id, planned_at=morning, status="taken"),
|
||||
Dose(token=TOKEN, prescription_id=rx.id, planned_at=morning + timedelta(hours=12)),
|
||||
]
|
||||
)
|
||||
await repo.upsert_checkin(s, token=TOKEN, day=today, now=now, mood=6)
|
||||
|
||||
body = (await client.get(f"/api/v1/me/{TOKEN}/today")).json()
|
||||
assert body["has_doctor"] and body["checkin_done"]
|
||||
assert body["next_visit"] == (today + timedelta(days=5)).isoformat()
|
||||
assert [(d["time"], d["status"]) for d in body["doses"]] == [("09:00", "taken"), ("21:00", "pending")]
|
||||
week = body["prescriptions"][0]["week"]
|
||||
assert len(week) == 7 and next(w for w in week if w["day"] == today.isoformat())["status"] == "pending"
|
||||
|
||||
|
||||
async def test_today_for_anonymous_is_empty(client: AsyncClient) -> None:
|
||||
token = (await client.post("/api/v1/auth/anonymous")).json()["token"]
|
||||
body = (await client.get(f"/api/v1/me/{token}/today")).json()
|
||||
assert body["has_doctor"] is False and body["doses"] == [] and body["prescriptions"] == []
|
||||
|
||||
|
||||
async def test_crisis_resources_come_from_config(client: AsyncClient) -> None:
|
||||
phones = [r["phone"] for r in (await client.get("/api/v1/crisis/resources")).json()]
|
||||
assert "112" in phones
|
||||
|
||||
Reference in New Issue
Block a user