import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { useParams, Link } from 'react-router-dom'; import { ChevronRightIcon, PencilIcon, ClipboardDocumentCheckIcon, DocumentTextIcon, CalendarDaysIcon, CreditCardIcon, BanknotesIcon, ChatBubbleLeftRightIcon, PhoneArrowUpRightIcon, PaperClipIcon, ClipboardDocumentListIcon, } from '@heroicons/react/24/outline'; import { api } from '../lib/api'; import type { ApiResponse } from '../lib/api'; import type { PatientRecord } from '../types'; import { formatDate } from '../lib/utils'; type TabKey = 'services' | 'info' | 'appointments' | 'payments' | 'wallet' | 'messages' | 'callcenter' | 'attach' | 'records'; const TABS: { key: TabKey; label: string; icon: React.ElementType }[] = [ { key: 'services', label: 'سرویس‌ها', icon: ClipboardDocumentCheckIcon }, { key: 'info', label: 'اطلاعات پرونده', icon: DocumentTextIcon }, { key: 'appointments', label: 'نوبت‌ها', icon: CalendarDaysIcon }, { key: 'payments', label: 'پرداخت‌ها', icon: CreditCardIcon }, { key: 'wallet', label: 'کیف پول', icon: BanknotesIcon }, { key: 'messages', label: 'پیام‌ها', icon: ChatBubbleLeftRightIcon }, { key: 'callcenter', label: 'کال سنتر', icon: PhoneArrowUpRightIcon }, { key: 'attach', label: 'ضمیمه', icon: PaperClipIcon }, { key: 'records', label: 'پرونده پزشکی', icon: ClipboardDocumentListIcon }, ]; const GENDER_LABEL: Record = { male: 'مرد', female: 'زن' }; function Placeholder({ label }: { label: string }) { return (
محتوای «{label}» به‌زودی تکمیل می‌شود.
); } function InfoRow({ label, value }: { label: string; value?: string | null }) { return (
{label} {value || '—'}
); } /** پرونده — the tabbed patient case-file (Figma "جزئیات پرونده"). */ export default function PatientDetailPage() { const { uuid } = useParams<{ uuid: string }>(); const [tab, setTab] = useState('services'); const { data, isLoading } = useQuery>({ queryKey: ['patient', uuid], queryFn: () => api.get(`/api/v1/patient/${uuid}`), enabled: !!uuid, }); const record = data?.data; const profile: any = record?.profile ?? {}; const sessionsQ = useQuery>({ queryKey: ['patient-sessions', uuid], queryFn: () => api.get(`/api/v1/patient/${uuid}/sessions`), enabled: !!uuid && tab === 'services', }); const appointmentsQ = useQuery>({ queryKey: ['patient-appointments', uuid], queryFn: () => api.get(`/api/v1/patient/${uuid}/appointments`), enabled: !!uuid && tab === 'appointments', }); return (
{/* header */}
بازگشت
{record?.user_name || 'پرونده'}
{record?.record_number && #{record.record_number}}
ویرایش
{/* tab bar */}
{TABS.map((t) => { const on = t.key === tab; const Icon = t.icon; return ( ); })}
{/* tab content */} {isLoading ? (
در حال بارگذاری...
) : tab === 'info' ? (
) : tab === 'services' ? ( ({ title: s.section_name || s.name || 'سرویس', meta: s.created_at ? formatDate(s.created_at) : '', badge: s.status })} /> ) : tab === 'appointments' ? ( ({ title: a.service_name || a.doctor_name || 'نوبت', meta: a.date ? formatDate(a.date) : (a.starts_at ? formatDate(a.starts_at) : ''), badge: a.status_label || a.status })} /> ) : ( t.key === tab)!.label} /> )}
); } function TabList({ q, emptyLabel, row }: { q: { data?: ApiResponse; isLoading: boolean }; emptyLabel: string; row: (item: any) => { title: string; meta?: string; badge?: string }; }) { if (q.isLoading) return
در حال بارگذاری...
; const items = q.data?.data ?? []; if (items.length === 0) return
{emptyLabel}
; return (
{items.map((item, i) => { const r = row(item); return (
{r.title}
{r.meta &&
{r.meta}
}
{r.badge && {r.badge}}
); })}
); }