'use client'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { cn } from '@/lib/utils'; import { type Behandeldoel, type Behandelstructuur, type Evaluatiemoment, type Veiligheidsplan, type SmartGoal, type Intervention, type FhirCarePlanStatus, FHIR_STATUS_LABELS, transformToFlat, createEmptyBehandeldoel, calculateBehandeldoelenProgress, } from '@/lib/types/behandelplan'; import { type LifeDomainScore } from '@/lib/types/leefgebieden'; import { ContextHeader } from './context-header'; import { BehandeldoelCard } from './behandeldoel-card'; import { PlanningSection } from './planning-section'; import { Plus, Sparkles, FileText, CheckCircle2 } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { Progress } from '@/components/ui/progress'; interface Condition { id: string; category: string; code_display: string; severity_code: string | null; severity_display: string | null; } interface CarePlan { id: string; title: string; status: FhirCarePlanStatus; version: number | null; goals: SmartGoal[] | null; activities: Intervention[] | null; behandelstructuur: Behandelstructuur | null; sessie_planning: unknown[] | null; evaluatiemomenten: Evaluatiemoment[] | null; veiligheidsplan: Veiligheidsplan | null; created_at: string | null; published_at: string | null; period_start: string | null; } interface BehandelplanFlatProps { patientId: string; carePlan: CarePlan | null; condition: Condition | null; hulpvraag: string | null; lifeDomainScores: LifeDomainScore[] | null; // Callbacks onGenerate?: () => Promise; onCreateManual?: () => Promise; onStatusChange?: (status: FhirCarePlanStatus) => Promise; onSaveBehandeldoel?: (doel: Behandeldoel) => Promise; onDeleteBehandeldoel?: (doelId: string) => Promise; className?: string; } /** * BehandelplanFlat - Hoofdcomponent voor plat behandelplan * * 3 blokken: * 1. Context Header (read-only): Diagnose, hulpvraag, leefgebieden * 2. Behandeldoelen (editable): Cards met inline interventies * 3. Planning & Evaluatie (collapsed): Evaluaties, sessies, veiligheidsplan */ export function BehandelplanFlat({ patientId, carePlan, condition, hulpvraag, lifeDomainScores, onGenerate, onCreateManual, onStatusChange, onSaveBehandeldoel, onDeleteBehandeldoel, className, }: BehandelplanFlatProps) { const [editingDoelId, setEditingDoelId] = useState(null); const [isGenerating, setIsGenerating] = useState(false); const [isCreating, setIsCreating] = useState(false); // Transform old structure to flat const behandeldoelen: Behandeldoel[] = carePlan?.goals && carePlan?.activities ? transformToFlat(carePlan.goals, carePlan.activities) : []; const totalProgress = calculateBehandeldoelenProgress(behandeldoelen); const statusInfo = carePlan?.status ? FHIR_STATUS_LABELS[carePlan.status] : null; // Handlers const handleGenerate = async () => { if (!onGenerate) return; setIsGenerating(true); try { await onGenerate(); } finally { setIsGenerating(false); } }; const handleCreateManual = async () => { if (!onCreateManual) return; setIsCreating(true); try { await onCreateManual(); } finally { setIsCreating(false); } }; const handleSaveDoel = async (doel: Behandeldoel) => { if (!onSaveBehandeldoel) return; await onSaveBehandeldoel(doel); setEditingDoelId(null); }; const handleDeleteDoel = async (doelId: string) => { if (!onDeleteBehandeldoel) return; await onDeleteBehandeldoel(doelId); setEditingDoelId(null); }; const handleAddDoel = () => { const newDoel = createEmptyBehandeldoel(); // Start editing immediately setEditingDoelId(newDoel.id); // We need to save this empty doel first, then edit // For now, we'll handle this in the parent component }; // No plan yet - show creation options if (!carePlan) { return (
{/* Context header */} {/* Creation options */}

Nog geen behandelplan

Maak een nieuw behandelplan aan

); } return (
{/* Plan header with status */}

{carePlan.title || 'Behandelplan'}

{statusInfo && ( {statusInfo.label} )} {carePlan.version && ( v{carePlan.version} )}
{/* Overall progress */}
Voortgang:
{totalProgress}%
{/* Status actions */} {carePlan.status === 'draft' && onStatusChange && ( )}
{/* Block 1: Context Header */} {/* Block 2: Behandeldoelen */}

Behandeldoelen ({behandeldoelen.length})

{behandeldoelen.length === 0 ? (

Nog geen behandeldoelen. Klik op "Nieuw doel" om te beginnen.

) : (
{behandeldoelen.map((doel) => ( setEditingDoelId(doel.id)} onSave={handleSaveDoel} onCancel={() => setEditingDoelId(null)} onDelete={() => handleDeleteDoel(doel.id)} /> ))}
)}
{/* Block 3: Planning & Evaluatie */}
); }