import { useState } from 'react'; import { Microscope, Search, Calendar, AlertCircle, CheckCircle2 } from 'lucide-react'; import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Input } from '@/components/ui/input'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import type { Cultivo, Paciente, Cama, Internacion } from '@/types'; interface CultivosProps { cultivos: Cultivo[]; pacientes?: Paciente[]; internaciones?: Internacion[]; camas?: Cama[]; patient?: Paciente; internacionId?: string; onAgregarCultivo?: (cultivo: Omit) => void; onActualizarCultivo?: (id: string, datos: Partial) => void; onEliminarCultivo?: (id: string) => void; getPacienteById?: (id: string) => Paciente | undefined; getInternacionActivaByPaciente?: (pacienteId: string) => Internacion | undefined; canEdit?: boolean; } export function Cultivos({ cultivos, pacientes = [], internaciones = [], camas = [], patient, getPacienteById, }: CultivosProps) { const [busqueda, setBusqueda] = useState(''); const [filtroEstado, setFiltroEstado] = useState<'todos' | 'NAF/Pendiente' | 'Parcial' | 'Positivo' | 'Negativo'>('todos'); const findPaciente = (pacienteId: string): Paciente | undefined => { if (patient && patient.id === pacienteId) return patient; if (getPacienteById) return getPacienteById(pacienteId); return pacientes.find(p => p.id === pacienteId); }; const getCamaNombreForPaciente = (pacienteId: string) => { const inter = internaciones.find(i => i.pacienteId === pacienteId && i.activa); if (!inter) return ''; const cama = camas.find(c => c.id === inter.camaId); return cama ? `Cama ${cama.numero}` : ''; }; const cultivosFiltrados = cultivos.filter(c => { if (filtroEstado !== 'todos' && c.estado !== filtroEstado) return false; if (busqueda) { const term = busqueda.toLowerCase(); const pac = findPaciente(c.pacienteId); const nombrePac = pac ? `${pac.apellido} ${pac.nombre} ${pac.dni}`.toLowerCase() : ''; return ( c.protocolo?.toLowerCase().includes(term) || c.germen?.toLowerCase().includes(term) || c.tipoMuestra.toLowerCase().includes(term) || nombrePac.includes(term) ); } return true; }); const getEstadoColor = (estado: string) => { switch (estado) { case 'NAF/Pendiente': return 'bg-amber-100 text-amber-800 dark:bg-amber-950/80 dark:text-amber-300 dark:border dark:border-amber-800'; case 'Parcial': return 'bg-orange-100 text-orange-800 dark:bg-orange-950/80 dark:text-orange-300 dark:border dark:border-orange-800'; case 'Positivo': return 'bg-red-100 text-red-800 dark:bg-red-950/80 dark:text-red-300 dark:border dark:border-red-800'; case 'Negativo': return 'bg-green-100 text-green-800 dark:bg-green-950/80 dark:text-green-300 dark:border dark:border-green-800'; default: return 'bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-300'; } }; const getEstadoLabel = (estado: string) => { switch (estado) { case 'NAF/Pendiente': return 'NAF'; case 'Parcial': return 'Parcial'; case 'Positivo': return 'Positivo'; case 'Negativo': return 'Negativo'; default: return estado; } }; return (
{/* Header */}

Cultivos

Informe y registro de cultivos y muestras

setBusqueda(e.target.value)} className="pl-8" />
{cultivosFiltrados.map((cultivo) => { const pac = findPaciente(cultivo.pacienteId); const camaNombre = getCamaNombreForPaciente(cultivo.pacienteId); return (
{camaNombre && ( {camaNombre} )}

{pac ? `${pac.apellido}, ${pac.nombre}` : 'Paciente no encontrado'}

{cultivo.fechaToma} {cultivo.tipoMuestra} {getEstadoLabel(cultivo.estado)}
{cultivo.protocolo && (

Protocolo: {cultivo.protocolo}

)} {cultivo.observaciones && (

{cultivo.observaciones}

)} {cultivo.estado === 'Parcial' && cultivo.germen && (

PARCIAL - Germen: {cultivo.germen}

{(cultivo.sensible || cultivo.resistente) && (
{cultivo.sensible && (

Sensible: {cultivo.sensible}

)} {cultivo.resistente && (

Resistente: {cultivo.resistente}

)}
)}
)} {cultivo.estado === 'Positivo' && cultivo.germen && (

Germen: {cultivo.germen}

{cultivo.fechaResultado && (

Resultado: {cultivo.fechaResultado}

)} {(cultivo.sensible || cultivo.resistente) && (
{cultivo.sensible && (

Sensible a:

{cultivo.sensible}

)} {cultivo.resistente && (

Resistente a:

{cultivo.resistente}

)}
)}
)} {cultivo.estado === 'Negativo' && (

Cultivo Negativo

)}
); })} {cultivosFiltrados.length === 0 && (

No se encontraron cultivos con los filtros seleccionados

)}
); }