"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import type { PatientProfile } from "@duoc-thu/shared-types"; import { getPatientProfile, savePatientProfile } from "@duoc-thu/api-client"; const EMPTY: PatientProfile = { ageText: null, weightKg: null, renalFunction: null, hepaticFunction: null, knownAllergies: null, }; /** Optional per-account clinical context. Nothing here is required — an * empty profile behaves exactly like no profile: the chatbot keeps asking * age/weight per turn, same as an anonymous session. Only a logged-in user * ever sees this page (`AccountMenu` is the only link to it). */ export function ProfileForm() { const [profile, setProfile] = useState(EMPTY); const [loaded, setLoaded] = useState(false); const [saved, setSaved] = useState(false); const [error, setError] = useState(null); const [pending, setPending] = useState(false); useEffect(() => { getPatientProfile() .then((p) => p && setProfile(p)) .finally(() => setLoaded(true)); }, []); async function onSubmit(event: React.FormEvent) { event.preventDefault(); setError(null); setSaved(false); setPending(true); try { const result = await savePatientProfile(profile); setProfile(result); setSaved(true); } catch { setError("Không lưu được lúc này. Vui lòng thử lại."); } finally { setPending(false); } } if (!loaded) return null; return (

Hồ sơ bệnh nhân

Điền sẵn để không phải nhắc lại tuổi/cân nặng mỗi lượt hỏi. Bỏ trống mục nào thì chatbot vẫn hỏi lại mục đó như bình thường.

{error &&

{error}

} {saved && !error && (

Đã lưu.

)}
Về trang tra cứu
); }