import Link from "next/link"; import { notFound, redirect } from "next/navigation"; import { ArrowLeft, Plus } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { DueBadge } from "@/components/due-badge"; import { JOB_STATUS_LABELS, PROSTHETIC_TYPE_LABELS, } from "@/lib/appwrite/job-types"; import { getPatient, listPatientJobs } from "@/lib/appwrite/patient-queries"; import type { JobStatus } from "@/lib/appwrite/schema"; import { requireTenant, requireTenantKind } from "@/lib/appwrite/tenant-guard"; export const metadata = { title: "DLS — Hasta", }; const dateFormatter = new Intl.DateTimeFormat("tr-TR", { day: "2-digit", month: "2-digit", year: "numeric", }); function statusVariant(s: JobStatus): "default" | "secondary" | "outline" | "destructive" { if (s === "delivered") return "default"; if (s === "sent" || s === "in_progress") return "secondary"; if (s === "cancelled") return "destructive"; return "outline"; } export default async function PatientDetailPage({ params, }: { params: Promise<{ patientId: string }>; }) { const { patientId } = await params; let ctx; try { ctx = await requireTenant(); requireTenantKind(ctx, ["clinic"]); } catch { redirect("/dashboard"); } const patient = await getPatient(patientId, ctx.tenantId); if (!patient) notFound(); const jobs = await listPatientJobs(patient.$id, patient.patientCode, ctx.tenantId); const fullName = [patient.firstName, patient.lastName].filter(Boolean).join(" ") || `Hasta ${patient.patientCode}`; return (

{patient.patientCode}

{fullName}

{patient.archived && ( Arşivlenmiş )}
{patient.notes && ( Notlar

{patient.notes}

)} İş Geçmişi {jobs.length === 0 ? "Bu hastaya ait iş kaydı yok." : `${jobs.length} iş`} {jobs.length === 0 ? (

Henüz bu hasta için iş gönderilmemiş.

) : ( Tarih Tür Üye Durum Termin Detay {jobs.map((j) => ( {dateFormatter.format(new Date(j.$createdAt))} {PROSTHETIC_TYPE_LABELS[j.prostheticType] ?? j.prostheticType} {j.memberCount} {JOB_STATUS_LABELS[j.status]} ))}
)}
); }