/** * 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, getPatientIntakes } 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 recent intakes (optional) let recentIntakes: Intake[] = []; try { const intakes = await getIntakesByPatientId(id); recentIntakes = intakes.slice(0, 3); // Get up to 3 most recent } catch (error) { // Silently fail - intakes are optional for dashboard console.error('Failed to fetch intakes for dashboard:', error); } // Fetch encounters (vandaag, toekomst en recente) let upcomingEncounters: any[] = []; let recentEncounters: any[] = []; try { const allEncounters = await getPatientEncounters(id); const now = new Date(); const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()); // Split into upcoming (vandaag + toekomst) and recent (verleden) const upcoming = allEncounters.filter(e => new Date(e.period_start) >= todayStart); const recent = allEncounters.filter(e => new Date(e.period_start) < todayStart); // Take 5 most relevant: prioritize upcoming, then recent upcomingEncounters = upcoming.slice(0, 5); if (upcomingEncounters.length < 5) { recentEncounters = recent.slice(0, 5 - upcomingEncounters.length); } } catch (error) { console.error('Failed to fetch encounters:', error); } // Fetch active care plan let activeCarePlan: any = null; let hulpvraag: string | null = null; try { activeCarePlan = await getActiveCarePlan(id); // Get hulpvraag from linked intake if (activeCarePlan?.based_on_intake_id) { const intakes = await getPatientIntakes(id); const linkedIntake = intakes.find(i => i.id === activeCarePlan.based_on_intake_id); if (linkedIntake?.notes) { hulpvraag = extractHulpvraag(linkedIntake.notes); } } } catch (error) { console.error('Failed to fetch care plan:', error); } 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 })}
)}