/** * VitalsBlock Component * E5.S2: Vitale functies metingen vandaag */ import { Activity, TrendingUp, TrendingDown, Minus } from 'lucide-react'; import type { VitalSign } from '@/lib/types/overdracht'; interface VitalsBlockProps { vitals: VitalSign[]; } function getInterpretationStyle(code: string | null | undefined): { bg: string; text: string; icon: React.ReactNode; label: string; } { switch (code) { case 'HH': return { bg: 'bg-red-100', text: 'text-red-700', icon: , label: 'Kritisch hoog', }; case 'H': return { bg: 'bg-orange-100', text: 'text-orange-700', icon: , label: 'Hoog', }; case 'LL': return { bg: 'bg-red-100', text: 'text-red-700', icon: , label: 'Kritisch laag', }; case 'L': return { bg: 'bg-orange-100', text: 'text-orange-700', icon: , label: 'Laag', }; case 'N': default: return { bg: 'bg-green-100', text: 'text-green-700', icon: , label: 'Normaal', }; } } function formatTime(datetime: string): string { return new Date(datetime).toLocaleTimeString('nl-NL', { hour: '2-digit', minute: '2-digit', }); } function formatValue(value: number | null, unit: string | null): string { if (value === null) return '-'; if (unit) return `${value} ${unit}`; return String(value); } export function VitalsBlock({ vitals }: VitalsBlockProps) { // Group vitals by type (code_display) const groupedVitals = vitals.reduce((acc, vital) => { const key = vital.code_display; if (!acc[key]) { acc[key] = []; } acc[key].push(vital); return acc; }, {} as Record); // Get most recent vital per type const latestVitals = Object.entries(groupedVitals).map(([type, measurements]) => ({ type, latest: measurements[0], // Already sorted by time desc count: measurements.length, })); const abnormalCount = vitals.filter( v => v.interpretation_code && ['H', 'L', 'HH', 'LL'].includes(v.interpretation_code) ).length; return (
{/* Header */}

Vitale functies

{vitals.length} metingen vandaag

{abnormalCount > 0 && ( {abnormalCount} afwijkend )}
{/* Content */} {latestVitals.length === 0 ? (

Geen vitale functies gemeten vandaag

) : (
{latestVitals.map(({ type, latest, count }) => { const style = getInterpretationStyle(latest.interpretation_code); const isAbnormal = latest.interpretation_code && ['H', 'L', 'HH', 'LL'].includes(latest.interpretation_code); return (
{style.icon}

{type}

{formatTime(latest.effective_datetime)} {count > 1 && ` • ${count} metingen`}

{formatValue(latest.value_quantity_value, latest.value_quantity_unit)}

{isAbnormal && (

{style.label}

)}
); })}
)}
); }