/** * 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 (
{/* Page Header */}

Dashboard

Overzicht van cliëntgegevens en voortgang

{/* Quick Actions Grid */}
{/* Basisgegevens Card */}

Basisgegevens

NAW & contactgegevens

{/* Screening Card */}

Screening

Activiteiten & besluit

{/* Intake Card */}

Intake

Gesprekken & registraties

{/* Recent Intakes Section */} {recentIntakes.length > 0 && (

Recente Intakes

Bekijk alle →
{recentIntakes.map((intake) => (

{intake.title}

{intake.department}
{format(new Date(intake.start_date), 'd MMM yyyy', { locale: nl })}
{intake.status}
))}
)} {/* Agenda Afspraken Section */} {(upcomingEncounters.length > 0 || recentEncounters.length > 0) && (

Agenda Afspraken

Bekijk agenda →
{[...upcomingEncounters, ...recentEncounters].slice(0, 5).map((encounter) => { const encounterDate = new Date(encounter.period_start); const isPast = encounterDate < new Date(); const isToday = encounterDate.toDateString() === new Date().toDateString(); return (

{encounter.type_display || 'Afspraak'}

{format(encounterDate, 'd MMM yyyy HH:mm', { locale: nl })} {encounter.period_end && ( <> {format(new Date(encounter.period_end), 'HH:mm', { locale: nl })} )}
{encounter.status === 'planned' ? 'Gepland' : encounter.status === 'arrived' ? 'Aangekomen' : encounter.status === 'finished' ? 'Afgerond' : encounter.status}
); })}
)} {/* Behandelplan Section */} {activeCarePlan && (

Actief Behandelplan

Bekijk volledig plan →
{/* Hulpvraag */} {hulpvraag && (

Hulpvraag

“{hulpvraag}”

)} {/* Behandelstructuur */} {activeCarePlan.behandelstructuur && (

Behandelstructuur

{(() => { const bs = activeCarePlan.behandelstructuur as unknown as Behandelstructuur; return ( <>
Duur: {bs.duur}
Frequentie: {bs.frequentie}
Aantal sessies: {bs.aantalSessies}
Vorm: {bs.vorm}
); })()}
)} {/* Doelen Overzicht */} {activeCarePlan.goals && Array.isArray(activeCarePlan.goals) && activeCarePlan.goals.length > 0 && (

Doelen ({activeCarePlan.goals.length})

{(activeCarePlan.goals as unknown as SmartGoal[]).slice(0, 3).map((goal) => (

{goal.title}

{goal.status === 'bezig' ? 'Bezig' : goal.status === 'gehaald' ? 'Gehaald' : goal.status === 'niet_gestart' ? 'Niet gestart' : goal.status}
{goal.progress > 0 && (

{goal.progress}% voltooid

)}
))} {activeCarePlan.goals.length > 3 && (

+{activeCarePlan.goals.length - 3} meer doelen

)}
)} {/* Interventies Overzicht */} {activeCarePlan.activities && Array.isArray(activeCarePlan.activities) && activeCarePlan.activities.length > 0 && (

Interventies ({activeCarePlan.activities.length})

{(activeCarePlan.activities as unknown as Intervention[]).slice(0, 5).map((intervention) => ( {intervention.name} ))} {activeCarePlan.activities.length > 5 && ( +{activeCarePlan.activities.length - 5} meer )}
)} {/* Aankomende Evaluatiemomenten */} {activeCarePlan.evaluatiemomenten && Array.isArray(activeCarePlan.evaluatiemomenten) && activeCarePlan.evaluatiemomenten.length > 0 && (

Aankomende evaluatiemomenten

{(activeCarePlan.evaluatiemomenten as unknown as Evaluatiemoment[]) .filter((evaluatie) => evaluatie.status === 'gepland') .slice(0, 2) .map((evaluatie) => (

{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 })}

)}
Gepland
))}
)}
)} {/* Next Steps Section */}

Volgende stappen

  • • Controleer en vul basisgegevens aan indien nodig
  • • Start screening door activiteiten te loggen
  • • Upload relevante documenten (verwijsbrief, etc.)
  • • Neem screeningsbesluit om door te gaan naar intake
  • • Start een nieuwe intake via de{' '} Intake module
); }