/** * Patient Dashboard Page * E2.S3: Default view showing patient overview and status */ import Link from 'next/link'; import { User, ClipboardList, FileText, ArrowRight, AlertCircle, Calendar, Clock, } from 'lucide-react'; import { getIntakesByPatientId } from './intakes/actions'; import type { Intake } from '@/lib/types/intake'; import { format } from 'date-fns'; import { nl } from 'date-fns/locale'; import { getPatientEncounters } from '@/app/epd/agenda/actions'; import { getActiveCarePlan } from './behandelplan/actions'; import type { SmartGoal, Intervention, Behandelstructuur, Evaluatiemoment } from '@/lib/types/behandelplan'; function extractHulpvraag(notes: string | null): string | null { if (!notes) return null; const firstSentence = notes.split(/[.!?]/)[0]; return firstSentence.length > 150 ? firstSentence.slice(0, 150) + '...' : firstSentence; } export default async function PatientDashboardPage({ params, }: { params: Promise<{ id: string }>; }) { const { id } = await params; // Fetch all data in parallel for better performance const [intakesResult, encountersResult, carePlanResult] = await Promise.all([ getIntakesByPatientId(id).catch(() => [] as Intake[]), getPatientEncounters(id).catch(() => []), getActiveCarePlan(id).catch(() => null), ]); // Process intakes const recentIntakes = intakesResult.slice(0, 3); // Process encounters let upcomingEncounters: any[] = []; let recentEncounters: any[] = []; const now = new Date(); const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()); const upcoming = encountersResult.filter((e: any) => new Date(e.period_start) >= todayStart); const recent = encountersResult.filter((e: any) => new Date(e.period_start) < todayStart); upcomingEncounters = upcoming.slice(0, 5); if (upcomingEncounters.length < 5) { recentEncounters = recent.slice(0, 5 - upcomingEncounters.length); } // Process care plan and get hulpvraag from already-fetched intakes const activeCarePlan = carePlanResult; let hulpvraag: string | null = null; if (activeCarePlan?.based_on_intake_id) { const linkedIntake = intakesResult.find((i: Intake) => i.id === activeCarePlan.based_on_intake_id); if (linkedIntake?.notes) { hulpvraag = extractHulpvraag(linkedIntake.notes); } } return (
Overzicht van cliëntgegevens en voortgang
NAW & contactgegevens
Activiteiten & besluit
Gesprekken & registraties
{intake.title}
{encounter.type_display || 'Afspraak'}
Hulpvraag
“{hulpvraag}”
Behandelstructuur
Doelen ({activeCarePlan.goals.length})
{goal.title}
{goal.status === 'bezig' ? 'Bezig' : goal.status === 'gehaald' ? 'Gehaald' : goal.status === 'niet_gestart' ? 'Niet gestart' : goal.status}{goal.progress}% voltooid
+{activeCarePlan.goals.length - 3} meer doelen
)}Interventies ({activeCarePlan.activities.length})
Aankomende evaluatiemomenten
{evaluatie.type === 'tussentijds' ? 'Tussentijdse evaluatie' : evaluatie.type === 'eind' ? 'Eindevaluatie' : 'Crisis evaluatie'}
{evaluatie.plannedDate && (Week {evaluatie.weekNumber} • {format(new Date(evaluatie.plannedDate), 'd MMM yyyy', { locale: nl })}
)}