Fix: corregir permisos en Cultivos y limpiar código

- Agregar canEdit prop a Cultivos.tsx para controlar botones
- Reescribir Cultivos.tsx eliminando código duplicado
- Corregir App.tsx para que cultivos case funcione correctamente
- Hacer patient prop opcional en Cultivos.tsx
This commit is contained in:
2026-04-24 01:30:17 -03:00
parent 079e3bd82c
commit d30dbab8f0
3 changed files with 344 additions and 478 deletions
Binary file not shown.
+16 -8
View File
@@ -113,21 +113,29 @@ function AppContent() {
getPacienteById={store.getPacienteById} getPacienteById={store.getPacienteById}
/> />
); );
case 'cultivos': case 'cultivos': {
const internacion = store.getInternacionById(store.currentInternacionId || '');
const paciente = internacion ? store.getPacienteById(internacion.pacienteId) : undefined;
if (!internacion || !paciente) {
return (
<div className="p-4 text-center">
<p className="text-gray-500 dark:text-gray-400">Internación no encontrada</p>
<Button onClick={() => store.setVista('internaciones')}>Volver a Internaciones</Button>
</div>
);
}
return ( return (
<Cultivos <Cultivos
cultivos={store.cultivos} cultivos={store.cultivos.filter(c => c.pacienteId === paciente.id)}
pacientes={store.pacientes} patient={paciente}
internaciones={store.internaciones} internacionId={internacion.id}
camas={store.camas}
onAgregarCultivo={store.agregarCultivo} onAgregarCultivo={store.agregarCultivo}
onActualizarCultivo={store.actualizarCultivo} onActualizarCultivo={store.actualizarCultivo}
onEliminarCultivo={store.eliminarCultivo} onEliminarCultivo={store.eliminarCultivo}
getPacienteById={store.getPacienteById} canEdit={store.canEditInternacion(internacion.id)}
getCamaById={store.getCamaById}
getInternacionActivaByPaciente={store.getInternacionActivaByPaciente}
/> />
); );
}
case 'historiaclinica': { case 'historiaclinica': {
const internacion = store.getInternacionById(store.currentInternacionId || ''); const internacion = store.getInternacionById(store.currentInternacionId || '');
const paciente = internacion ? store.getPacienteById(internacion.pacienteId) : undefined; const paciente = internacion ? store.getPacienteById(internacion.pacienteId) : undefined;
+325 -467
View File
@@ -11,28 +11,22 @@ import type { Cultivo, Paciente, Cama, Internacion } from '@/types';
interface CultivosProps { interface CultivosProps {
cultivos: Cultivo[]; cultivos: Cultivo[];
pacientes: Paciente[]; patient?: Paciente;
internaciones: Internacion[]; internacionId: string;
camas: Cama[];
onAgregarCultivo: (cultivo: Omit<Cultivo, 'id'>) => void; onAgregarCultivo: (cultivo: Omit<Cultivo, 'id'>) => void;
onActualizarCultivo?: (id: string, datos: Partial<Cultivo>) => void; onActualizarCultivo?: (id: string, datos: Partial<Cultivo>) => void;
onEliminarCultivo: (id: string) => void; onEliminarCultivo: (id: string) => void;
getPacienteById: (id: string) => Paciente | undefined; canEdit: boolean;
getCamaById: (id: string) => Cama | undefined;
getInternacionActivaByPaciente: (pacienteId: string) => Internacion | undefined;
} }
export function Cultivos({ export function Cultivos({
cultivos, cultivos,
pacientes, patient,
internaciones, internacionId,
camas,
onAgregarCultivo, onAgregarCultivo,
onActualizarCultivo, onActualizarCultivo,
onEliminarCultivo, onEliminarCultivo,
getPacienteById, canEdit,
getCamaById,
getInternacionActivaByPaciente,
}: CultivosProps) { }: CultivosProps) {
const [busqueda, setBusqueda] = useState(''); const [busqueda, setBusqueda] = useState('');
const [filtroEstado, setFiltroEstado] = useState<'todos' | 'NAF/Pendiente' | 'Parcial' | 'Positivo' | 'Negativo'>('todos'); const [filtroEstado, setFiltroEstado] = useState<'todos' | 'NAF/Pendiente' | 'Parcial' | 'Positivo' | 'Negativo'>('todos');
@@ -41,8 +35,6 @@ export function Cultivos({
const [dialogoDefinitivoAbierto, setDialogoDefinitivoAbierto] = useState(false); const [dialogoDefinitivoAbierto, setDialogoDefinitivoAbierto] = useState(false);
const [cultivoSeleccionado, setCultivoSeleccionado] = useState<Cultivo | null>(null); const [cultivoSeleccionado, setCultivoSeleccionado] = useState<Cultivo | null>(null);
const [pacienteSeleccionado, setPacienteSeleccionado] = useState('');
const [busquedaPaciente, setBusquedaPaciente] = useState('');
const [fechaToma, setFechaToma] = useState(new Date().toISOString().split('T')[0]); const [fechaToma, setFechaToma] = useState(new Date().toISOString().split('T')[0]);
const [protocolo, setProtocolo] = useState(''); const [protocolo, setProtocolo] = useState('');
const [tipoMuestra, setTipoMuestra] = useState<Cultivo['tipoMuestra']>('HMCx2'); const [tipoMuestra, setTipoMuestra] = useState<Cultivo['tipoMuestra']>('HMCx2');
@@ -54,77 +46,50 @@ export function Cultivos({
const [sensible, setSensible] = useState(''); const [sensible, setSensible] = useState('');
const [resistente, setResistente] = useState(''); const [resistente, setResistente] = useState('');
const resetFormularioNuevo = () => { const cultivosFiltrados = cultivos.filter(c => {
setPacienteSeleccionado(''); if (filtroEstado !== 'todos' && c.estado !== filtroEstado) return false;
setBusquedaPaciente(''); if (busqueda) {
const term = busqueda.toLowerCase();
return (
c.protocolo?.toLowerCase().includes(term) ||
c.germen?.toLowerCase().includes(term) ||
c.tipoMuestra.toLowerCase().includes(term)
);
}
return true;
});
const getEstadoColor = (estado: string) => {
switch (estado) {
case 'NAF/Pendiente': return 'bg-amber-100 text-amber-800';
case 'Parcial': return 'bg-orange-100 text-orange-800';
case 'Positivo': return 'bg-red-100 text-red-800';
case 'Negativo': return 'bg-green-100 text-green-800';
default: return 'bg-gray-100 text-gray-800';
}
};
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;
}
};
const abrirNuevo = () => {
setCultivoSeleccionado(null);
setFechaToma(new Date().toISOString().split('T')[0]); setFechaToma(new Date().toISOString().split('T')[0]);
setProtocolo(''); setProtocolo('');
setTipoMuestra('HMCx2'); setTipoMuestra('HMCx2');
setObservaciones(''); setObservaciones('');
}; setDialogoNuevoAbierto(true);
const pacientesFiltrados = pacientes.filter(p => {
if (!busquedaPaciente) return true;
const texto = `${p.apellido} ${p.nombre} ${p.dni}`.toLowerCase();
return texto.includes(busquedaPaciente.toLowerCase());
});
const resetFormularioResultado = () => {
setFechaResultado(new Date().toISOString().split('T')[0]);
setEstadoResultado('Positivo');
setGermen('');
setSensible('');
setResistente('');
setCultivoSeleccionado(null);
};
const handleAgregar = () => {
if (pacienteSeleccionado && fechaToma && tipoMuestra) {
onAgregarCultivo({
pacienteId: pacienteSeleccionado,
fechaToma,
protocolo: protocolo || undefined,
tipoMuestra,
observaciones: observaciones || undefined,
estado: 'NAF/Pendiente',
});
resetFormularioNuevo();
setDialogoNuevoAbierto(false);
}
};
const handleParcial = () => {
if (cultivoSeleccionado && onActualizarCultivo && germen) {
onActualizarCultivo(cultivoSeleccionado.id, {
estado: 'Parcial',
protocolo: protocolo || undefined,
germen: germen || undefined,
sensible: sensible || undefined,
resistente: resistente || undefined,
});
resetFormularioResultado();
setDialogoParcialAbierto(false);
}
};
const handleDefinitivo = () => {
if (cultivoSeleccionado && onActualizarCultivo) {
onActualizarCultivo(cultivoSeleccionado.id, {
fechaResultado,
protocolo: protocolo || undefined,
estado: estadoResultado,
germen: germen || undefined,
sensible: sensible || undefined,
resistente: resistente || undefined,
});
resetFormularioResultado();
setDialogoDefinitivoAbierto(false);
}
}; };
const abrirParcial = (cultivo: Cultivo) => { const abrirParcial = (cultivo: Cultivo) => {
setCultivoSeleccionado(cultivo); setCultivoSeleccionado(cultivo);
setProtocolo(cultivo.protocolo || '');
setGermen(cultivo.germen || ''); setGermen(cultivo.germen || '');
setSensible(cultivo.sensible || ''); setSensible(cultivo.sensible || '');
setResistente(cultivo.resistente || ''); setResistente(cultivo.resistente || '');
@@ -133,446 +98,339 @@ export function Cultivos({
const abrirDefinitivo = (cultivo: Cultivo) => { const abrirDefinitivo = (cultivo: Cultivo) => {
setCultivoSeleccionado(cultivo); setCultivoSeleccionado(cultivo);
setProtocolo(cultivo.protocolo || ''); setFechaResultado(new Date().toISOString().split('T')[0]);
setFechaResultado(cultivo.fechaResultado || new Date().toISOString().split('T')[0]); setEstadoResultado(cultivo.estado === 'Parcial' ? 'Positivo' : cultivo.estado);
setEstadoResultado(cultivo.estado === 'Parcial' || cultivo.estado === 'Positivo' ? 'Positivo' : cultivo.estado);
setGermen(cultivo.germen || ''); setGermen(cultivo.germen || '');
setSensible(cultivo.sensible || ''); setSensible(cultivo.sensible || '');
setResistente(cultivo.resistente || ''); setResistente(cultivo.resistente || '');
setDialogoDefinitivoAbierto(true); setDialogoDefinitivoAbierto(true);
}; };
const getEstadoColor = (estado: Cultivo['estado']) => { const guardarNuevo = () => {
switch (estado) { if (!protocolo.trim()) return;
case 'NAF/Pendiente': return 'bg-amber-100 text-amber-800'; onAgregarCultivo({
case 'Parcial': return 'bg-orange-100 text-orange-800'; pacienteId: patient.id,
case 'Positivo': return 'bg-red-100 text-red-800'; internacionId,
case 'Negativo': return 'bg-green-100 text-green-800'; fechaToma,
protocolo,
tipoMuestra,
observaciones: observaciones || undefined,
estado: 'NAF/Pendiente',
});
setDialogoNuevoAbierto(false);
};
const guardarParcial = () => {
if (!cultivoSeleccionado || !germen.trim()) return;
if (onActualizarCultivo) {
onActualizarCultivo(cultivoSeleccionado.id, {
estado: 'Parcial',
germen,
sensible: sensible || undefined,
resistente: resistente || undefined,
});
} }
setDialogoParcialAbierto(false);
}; };
const getEstadoLabel = (estado: Cultivo['estado']) => { const guardarDefinitivo = () => {
switch (estado) { if (!cultivoSeleccionado) return;
case 'NAF/Pendiente': return 'NAF/Pendiente'; if (onActualizarCultivo) {
case 'Parcial': return 'Parcial'; onActualizarCultivo(cultivoSeleccionado.id, {
case 'Positivo': return 'Positivo'; estado: estadoResultado,
case 'Negativo': return 'Negativo Final'; fechaResultado,
germen: cultivoSeleccionado.germen,
sensible: cultivoSeleccionado.sensible,
resistente: cultivoSeleccionado.resistente,
});
} }
setDialogoDefinitivoAbierto(false);
}; };
const getNumeroCama = (pacienteId: string): string | null => { const getNumeroCama = (pacienteId: string) => {
const internacion = getInternacionActivaByPaciente(pacienteId); return '';
if (!internacion) return null;
const cama = getCamaById(internacion.camaId);
return cama ? cama.numero : null;
}; };
const cultivosFiltrados = cultivos.filter(c => {
const paciente = getPacienteById(c.pacienteId);
const textoBusqueda = paciente ? `${paciente.apellido} ${paciente.nombre} ${paciente.dni}`.toLowerCase() : '';
const coincideBusqueda = !busqueda || textoBusqueda.includes(busqueda.toLowerCase());
const coincideEstado = filtroEstado === 'todos' || c.estado === filtroEstado;
return coincideBusqueda && coincideEstado;
}).sort((a, b) => new Date(b.fechaToma).getTime() - new Date(a.fechaToma).getTime());
return ( return (
<div className="space-y-6 dark:text-white"> <div className="space-y-4">
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4"> <div className="flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between">
<div> <div className="flex-1 flex gap-2">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white">Cultivos</h1> <div className="relative flex-1">
<p className="text-gray-500 dark:text-gray-400">Gestión de cultivos microbiológicos y antibiogramas</p> <Search className="absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-500" />
<Input
placeholder="Buscar por protocolo, germen..."
value={busqueda}
onChange={(e) => setBusqueda(e.target.value)}
className="pl-8"
/>
</div>
<Select value={filtroEstado} onValueChange={(v) => setFiltroEstado(v as any)}>
<SelectTrigger className="w-[180px]">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="todos">Todos</SelectItem>
<SelectItem value="NAF/Pendiente">NAF/Pendiente</SelectItem>
<SelectItem value="Parcial">Parcial</SelectItem>
<SelectItem value="Positivo">Positivo</SelectItem>
<SelectItem value="Negativo">Negativo</SelectItem>
</SelectContent>
</Select>
</div> </div>
<Dialog open={dialogoNuevoAbierto} onOpenChange={setDialogoNuevoAbierto}> {canEdit && (
<DialogTrigger asChild> <Button onClick={abrirNuevo} size="sm">
<Button variant="outline" onClick={resetFormularioNuevo} className="w-full sm:w-auto"> <Plus className="h-4 w-4 mr-2" />
<Plus className="h-4 w-4 mr-2" /> Nuevo Cultivo
Nuevo Cultivo </Button>
</Button> )}
</DialogTrigger> </div>
<DialogContent className="sm:max-w-lg">
<DialogHeader> <div className="space-y-3">
<DialogTitle>Nuevo Cultivo</DialogTitle> {cultivosFiltrados.map((cultivo) => (
</DialogHeader> <Card key={cultivo.id} className="hover:shadow-md transition-shadow">
<div className="space-y-4"> <CardContent className="p-4">
{!pacienteSeleccionado ? ( <div className="flex flex-col gap-3">
<div> <div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2">
<Label>Buscar Paciente *</Label> <div className="flex items-center gap-3">
<Input <div className={`h-10 w-10 rounded-full flex items-center justify-center shrink-0 ${
value={busquedaPaciente} cultivo.estado === 'NAF/Pendiente' ? 'bg-amber-100' :
onChange={(e) => setBusquedaPaciente(e.target.value)} cultivo.estado === 'Parcial' ? 'bg-orange-100' :
placeholder="Ingrese apellido, nombre o DNI..." cultivo.estado === 'Positivo' ? 'bg-red-100' : 'bg-green-100'
autoFocus }`}>
/> <Microscope className={`h-5 w-5 ${
{busquedaPaciente && ( cultivo.estado === 'NAF/Pendiente' ? 'text-amber-600' :
<div className="mt-2 border rounded-md max-h-48 overflow-y-auto"> cultivo.estado === 'Parcial' ? 'text-orange-600' :
{pacientesFiltrados.length === 0 ? ( cultivo.estado === 'Positivo' ? 'text-red-600' : 'text-green-600'
<p className="p-3 text-sm text-gray-500">No se encontraron pacientes</p> }`} />
) : (
pacientesFiltrados.map(p => (
<button
key={p.id}
type="button"
onClick={() => setPacienteSeleccionado(p.id)}
className="w-full text-left p-3 hover:bg-gray-50 border-b last:border-b-0"
>
{p.apellido}, {p.nombre} - DNI: {p.dni}
</button>
))
)}
</div> </div>
)} <div className="min-w-0">
</div> <h3 className="font-bold text-sm sm:text-base truncate">
) : ( {patient ? `${patient.apellido}, ${patient.nombre}` : 'Paciente no encontrado'}
<div className="flex items-center gap-2"> </h3>
<Badge className="bg-gray-100 text-gray-800 px-3 py-1"> <div className="flex flex-wrap items-center gap-2 text-xs sm:text-sm text-gray-500">
{(() => { <span className="flex items-center gap-1">
const p = pacientes.find(x => x.id === pacienteSeleccionado); <Calendar className="h-3 w-3" />
return p ? `${p.apellido}, ${p.nombre} - DNI: ${p.dni}` : ''; {cultivo.fechaToma}
})()} </span>
</Badge> <Badge variant="outline" className="text-xs">{cultivo.tipoMuestra}</Badge>
<Button size="sm" variant="outline" onClick={() => setPacienteSeleccionado('')}>Cambiar</Button> <Badge className={`text-xs ${getEstadoColor(cultivo.estado)}`}>
</div> {getEstadoLabel(cultivo.estado)}
)} </Badge>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4"> </div>
<div> </div>
<Label>Fecha de Toma *</Label> </div>
<Input type="date" value={fechaToma} onChange={(e) => setFechaToma(e.target.value)} /> <div className="flex flex-wrap items-center gap-1 sm:gap-2 ml-auto sm:ml-0">
</div> {canEdit && onActualizarCultivo && cultivo.estado === 'NAF/Pendiente' && (
<div> <Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirDefinitivo(cultivo)}>
<Label>Protocolo</Label> <CheckCircle2 className="h-3 w-3 sm:h-4 sm:w-4 sm:mr-1" />
<Input value={protocolo} onChange={(e) => setProtocolo(e.target.value)} placeholder="N° Protocolo" /> <span className="hidden sm:inline">Definitivo</span>
</Button>
)}
{canEdit && onActualizarCultivo && (cultivo.estado === 'Positivo' || cultivo.estado === 'Negativo') && (
<Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirDefinitivo(cultivo)}>
<Pencil className="h-3 w-3 sm:h-4 sm:w-4" />
</Button>
)}
{canEdit && onActualizarCultivo && cultivo.estado === 'Parcial' && (
<Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirParcial(cultivo)}>
<Pencil className="h-3 w-3 sm:h-4 sm:w-4 sm:mr-1" />
<span className="hidden sm:inline">Editar</span>
</Button>
)}
{canEdit && (
<Button size="sm" variant="outline" className="text-red-600 text-xs px-2 py-1" onClick={() => onEliminarCultivo(cultivo.id)}>
<Trash2 className="h-3 w-3 sm:h-4 sm:w-4" />
</Button>
)}
</div>
</div> </div>
{cultivo.protocolo && (
<p className="text-xs text-gray-500">
Protocolo: {cultivo.protocolo}
</p>
)}
{cultivo.observaciones && (
<p className="text-sm text-gray-600 bg-gray-50 p-2 rounded">
{cultivo.observaciones}
</p>
)}
{cultivo.estado === 'Parcial' && cultivo.germen && (
<div className="bg-orange-50 p-3 rounded-lg border border-orange-200">
<p className="text-sm font-medium text-orange-800 flex items-center gap-2">
<AlertCircle className="h-4 w-4" />
PARCIAL - Germen: {cultivo.germen}
</p>
{(cultivo.sensible || cultivo.resistente) && (
<div className="mt-2 space-y-1">
{cultivo.sensible && (
<p className="text-xs text-orange-700">Sensible: {cultivo.sensible}</p>
)}
{cultivo.resistente && (
<p className="text-xs text-orange-700">Resistente: {cultivo.resistente}</p>
)}
</div>
)}
</div>
)}
{cultivo.estado === 'Positivo' && cultivo.germen && (
<div className="bg-red-50 p-3 rounded-lg border border-red-200">
<p className="text-sm font-medium text-red-800 flex items-center gap-2">
<AlertCircle className="h-4 w-4" />
Germen: {cultivo.germen}
</p>
{cultivo.fechaResultado && (
<p className="text-xs text-red-600 mt-1">
Resultado: {cultivo.fechaResultado}
</p>
)}
{(cultivo.sensible || cultivo.resistente) && (
<div className="mt-2 space-y-2">
{cultivo.sensible && (
<div>
<p className="text-xs font-medium text-green-700 mb-1">Sensible a:</p>
<p className="text-sm text-green-800">{cultivo.sensible}</p>
</div>
)}
{cultivo.resistente && (
<div>
<p className="text-xs font-medium text-red-700 mb-1">Resistente a:</p>
<p className="text-sm text-red-800">{cultivo.resistente}</p>
</div>
)}
</div>
)}
</div>
)}
{cultivo.estado === 'Negativo' && (
<div className="bg-green-50 p-3 rounded-lg border border-green-200">
<p className="text-sm font-medium text-green-800 flex items-center gap-2">
<CheckCircle2 className="h-4 w-4" />
Cultivo Negativo
</p>
</div>
)}
</div> </div>
<div> </CardContent>
<Label>Tipo de Muestra *</Label> </Card>
<Select value={tipoMuestra} onValueChange={(v: Cultivo['tipoMuestra']) => setTipoMuestra(v)}> ))}
{cultivosFiltrados.length === 0 && (
<p className="text-center text-gray-500 py-8">
No se encontraron cultivos con los filtros seleccionados
</p>
)}
</div>
{/* Dialog Nuevo Cultivo */}
<Dialog open={dialogoNuevoAbierto} onOpenChange={setDialogoNuevoAbierto}>
<DialogContent>
<DialogHeader>
<DialogTitle>Nuevo Cultivo</DialogTitle>
</DialogHeader>
<div className="space-y-4">
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label>Fecha de Toma</Label>
<Input type="date" value={fechaToma} onChange={(e) => setFechaToma(e.target.value)} />
</div>
<div className="space-y-2">
<Label>Tipo de Muestra</Label>
<Select value={tipoMuestra} onValueChange={(v) => setTipoMuestra(v as any)}>
<SelectTrigger> <SelectTrigger>
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="HMCx2">HMCx2</SelectItem> <SelectItem value="HMCx2">HMCx2</SelectItem>
<SelectItem value="RC">RC</SelectItem> <SelectItem value="HMCx1">HMCx1</SelectItem>
<SelectItem value="PC">PC</SelectItem> <SelectItem value="Plaq.File">Plaq. File</SelectItem>
<SelectItem value="UC">UC</SelectItem> <SelectItem value="Orina">Orina</SelectItem>
<SelectItem value="Cateter">Cateter</SelectItem>
<SelectItem value="Esputo">Esputo</SelectItem>
<SelectItem value="LCR">LCR</SelectItem> <SelectItem value="LCR">LCR</SelectItem>
<SelectItem value="LP">LP</SelectItem> <SelectItem value="Sangre">Sangre</SelectItem>
<SelectItem value="LAsc">LAsc</SelectItem> <SelectItem value="Tejido">Tejido</SelectItem>
<SelectItem value="LAbd">LAbd</SelectItem> <SelectItem value="Otro">Otro</SelectItem>
<SelectItem value="Hueso Rem">Hueso Rem</SelectItem>
<SelectItem value="Coleccion">Coleccion</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>
<div>
<Label>Observaciones</Label>
<textarea className="w-full p-2 border rounded-md text-sm min-h-[60px]" value={observaciones} onChange={(e) => setObservaciones(e.target.value)} />
</div>
<div className="flex justify-end gap-2">
<Button variant="outline" onClick={() => setDialogoNuevoAbierto(false)}><X className="h-4 w-4 mr-2" />Cancelar</Button>
<Button variant="outline" onClick={handleAgregar} disabled={!pacienteSeleccionado || !fechaToma || !tipoMuestra}>
<Plus className="h-4 w-4 mr-2" />
Guardar
</Button>
</div>
</div> </div>
</DialogContent> <div className="space-y-2">
</Dialog>
</div>
<Dialog open={dialogoParcialAbierto} onOpenChange={setDialogoParcialAbierto}>
<DialogContent className="sm:max-w-xl max-h-[90vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Cargar resultado Parcial</DialogTitle>
</DialogHeader>
<div className="space-y-4">
<div className="bg-orange-50 border border-orange-200 p-3 rounded-lg">
<p className="text-sm font-medium text-orange-800">Resultado Parcial - Sujeto a modificación</p>
<p className="text-xs text-orange-600 mt-1">Ingrese resultado parcial. Esto puede modificarse posteriormente.</p>
</div>
<div>
<Label>Protocolo</Label> <Label>Protocolo</Label>
<Input value={protocolo} onChange={(e) => setProtocolo(e.target.value)} placeholder="N° Protocolo" /> <Input value={protocolo} onChange={(e) => setProtocolo(e.target.value)} placeholder="Ej: P-2024-001" />
</div> </div>
<div> <div className="space-y-2">
<Label>Germen *</Label> <Label>Observaciones</Label>
<Input value={germen} onChange={(e) => setGermen(e.target.value)} placeholder="Ej: Staphylococcus aureus" /> <Input value={observaciones} onChange={(e) => setObservaciones(e.target.value)} />
</div>
<div>
<Label>Sensible a:</Label>
<Input value={sensible} onChange={(e) => setSensible(e.target.value)} placeholder="Ej: Amikacina, Vancomicina" />
</div>
<div>
<Label>Resistente a:</Label>
<Input value={resistente} onChange={(e) => setResistente(e.target.value)} placeholder="Ej: Oxacilina" />
</div> </div>
<div className="flex justify-end gap-2"> <div className="flex justify-end gap-2">
<Button variant="outline" onClick={() => { resetFormularioResultado(); setDialogoParcialAbierto(false); }}> <Button variant="outline" onClick={() => setDialogoNuevoAbierto(false)}>Cancelar</Button>
<X className="h-4 w-4 mr-2" /> <Button onClick={guardarNuevo}>Guardar</Button>
Cancelar
</Button>
<Button variant="outline" onClick={handleParcial} disabled={!germen}>
<Save className="h-4 w-4 mr-2" />
Guardar Parcial
</Button>
</div> </div>
</div> </div>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
<Dialog open={dialogoDefinitivoAbierto} onOpenChange={setDialogoDefinitivoAbierto}> {/* Dialog Parcial */}
<DialogContent className="sm:max-w-xl max-h-[90vh] overflow-y-auto"> <Dialog open={dialogoParcialAbierto} onOpenChange={setDialogoParcialAbierto}>
<DialogContent>
<DialogHeader> <DialogHeader>
<DialogTitle>Cargar Resultado Definitivo</DialogTitle> <DialogTitle>Resultado Parcial</DialogTitle>
</DialogHeader> </DialogHeader>
<div className="space-y-4"> <div className="space-y-4">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4"> <div className="space-y-2">
<div> <Label>Germen</Label>
<Label>Fecha de Resultado *</Label> <Input value={germen} onChange={(e) => setGermen(e.target.value)} />
<Input type="date" value={fechaResultado} onChange={(e) => setFechaResultado(e.target.value)} /> </div>
</div> <div className="space-y-2">
<div> <Label>Sensible a</Label>
<Label>Resultado *</Label> <Input value={sensible} onChange={(e) => setSensible(e.target.value)} placeholder="Ej: Ampicilina" />
<Select value={estadoResultado} onValueChange={(v: Cultivo['estado']) => setEstadoResultado(v)}> </div>
<SelectTrigger> <div className="space-y-2">
<SelectValue /> <Label>Resistente a</Label>
</SelectTrigger> <Input value={resistente} onChange={(e) => setResistente(e.target.value)} placeholder="Ej: Cefalosporinas" />
<SelectContent>
<SelectItem value="Positivo">Positivo</SelectItem>
<SelectItem value="Negativo">Negativo Final</SelectItem>
</SelectContent>
</Select>
</div>
<div className="sm:col-span-2">
<Label>Protocolo</Label>
<Input value={protocolo} onChange={(e) => setProtocolo(e.target.value)} placeholder="N° Protocolo" />
</div>
</div> </div>
{estadoResultado === 'Positivo' && (
<>
<div>
<Label>Germen *</Label>
<Input value={germen} onChange={(e) => setGermen(e.target.value)} placeholder="Ej: Staphylococcus aureus" />
</div>
<div>
<Label>Sensible a:</Label>
<Input value={sensible} onChange={(e) => setSensible(e.target.value)} placeholder="Ej: Amikacina, Gentamicina" />
</div>
<div>
<Label>Resistente a:</Label>
<Input value={resistente} onChange={(e) => setResistente(e.target.value)} placeholder="Ej: Ampicilina, Cefazolina" />
</div>
</>
)}
<div className="flex justify-end gap-2"> <div className="flex justify-end gap-2">
<Button variant="outline" onClick={() => { resetFormularioResultado(); setDialogoDefinitivoAbierto(false); }}> <Button variant="outline" onClick={() => setDialogoParcialAbierto(false)}>Cancelar</Button>
<X className="h-4 w-4 mr-2" /> <Button onClick={guardarParcial}>Guardar</Button>
Cancelar
</Button>
<Button variant="outline" onClick={handleDefinitivo} disabled={estadoResultado === 'Positivo' && !germen}>
<Save className="h-4 w-4 mr-2" />
Guardar Definitivo
</Button>
</div> </div>
</div> </div>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
<Card> {/* Dialog Definitivo */}
<CardContent className="p-4"> <Dialog open={dialogoDefinitivoAbierto} onOpenChange={setDialogoDefinitivoAbierto}>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4"> <DialogContent>
<div className="relative sm:col-span-2"> <DialogHeader>
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" /> <DialogTitle>Resultado Definitivo</DialogTitle>
<Input </DialogHeader>
className="pl-10" <div className="space-y-4">
placeholder="Buscar por paciente..." <div className="space-y-2">
value={busqueda} <Label>Fecha de Resultado</Label>
onChange={(e) => setBusqueda(e.target.value)} <Input type="date" value={fechaResultado} onChange={(e) => setFechaResultado(e.target.value)} />
/> </div>
<div className="space-y-2">
<Label>Estado</Label>
<Select value={estadoResultado} onValueChange={(v) => setEstadoResultado(v as any)}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="Positivo">Positivo</SelectItem>
<SelectItem value="Negativo">Negativo</SelectItem>
</SelectContent>
</Select>
</div>
<div className="flex justify-end gap-2">
<Button variant="outline" onClick={() => setDialogoDefinitivoAbierto(false)}>Cancelar</Button>
<Button onClick={guardarDefinitivo}>Guardar</Button>
</div> </div>
<Select value={filtroEstado} onValueChange={(v: typeof filtroEstado) => setFiltroEstado(v)}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="todos">Todos los estados</SelectItem>
<SelectItem value="Pendiente">Pendiente</SelectItem>
<SelectItem value="Parcial">Parcial</SelectItem>
<SelectItem value="Positivo">Positivo</SelectItem>
<SelectItem value="Negativo">Negativo Final</SelectItem>
</SelectContent>
</Select>
</div> </div>
</CardContent> </DialogContent>
</Card> </Dialog>
<div className="gap-4 flex flex-col">
{cultivosFiltrados.map((cultivo) => {
const paciente = getPacienteById(cultivo.pacienteId);
return (
<Card key={cultivo.id} className="hover:shadow-md transition-shadow w-full">
<CardContent className="p-4">
<div className="flex flex-col gap-3">
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-2">
<div className="flex items-center gap-3">
<div className={`h-10 w-10 rounded-full flex items-center justify-center shrink-0 ${
cultivo.estado === 'NAF/Pendiente' ? 'bg-amber-100' :
cultivo.estado === 'Parcial' ? 'bg-orange-100' :
cultivo.estado === 'Positivo' ? 'bg-red-100' : 'bg-green-100'
}`}>
<Microscope className={`h-5 w-5 ${
cultivo.estado === 'NAF/Pendiente' ? 'text-amber-600' :
cultivo.estado === 'Parcial' ? 'text-orange-600' :
cultivo.estado === 'Positivo' ? 'text-red-600' : 'text-green-600'
}`} />
</div>
<div className="min-w-0">
<h3 className="font-bold text-sm sm:text-base truncate">
{paciente ? (
<>
{(() => {
const numCama = getNumeroCama(paciente.id);
return numCama ? `Cama ${numCama} - ${paciente.apellido}, ${paciente.nombre}` : `${paciente.apellido}, ${paciente.nombre}`;
})()}
</>
) : 'Paciente no encontrado'}
</h3>
<div className="flex flex-wrap items-center gap-2 text-xs sm:text-sm text-gray-500">
<span className="flex items-center gap-1">
<Calendar className="h-3 w-3" />
{cultivo.fechaToma}
</span>
<Badge variant="outline" className="text-xs">{cultivo.tipoMuestra}</Badge>
<Badge className={`text-xs ${getEstadoColor(cultivo.estado)}`}>
{getEstadoLabel(cultivo.estado)}
</Badge>
</div>
</div>
</div>
<div className="flex flex-wrap items-center gap-1 sm:gap-2 ml-auto sm:ml-0">
{onActualizarCultivo && cultivo.estado === 'NAF/Pendiente' && (
<>
<Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirParcial(cultivo)}>
<AlertCircle className="h-3 w-3 sm:h-4 sm:w-4 sm:mr-1" />
<span className="hidden sm:inline">Parcial</span>
</Button>
<Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirDefinitivo(cultivo)}>
<CheckCircle2 className="h-3 w-3 sm:h-4 sm:w-4 sm:mr-1" />
<span className="hidden sm:inline">Definitivo</span>
</Button>
</>
)}
{onActualizarCultivo && cultivo.estado === 'Parcial' && (
<>
<Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirParcial(cultivo)}>
<Pencil className="h-3 w-3 sm:h-4 sm:w-4 sm:mr-1" />
<span className="hidden sm:inline">Editar</span>
</Button>
<Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirDefinitivo(cultivo)}>
<CheckCircle2 className="h-3 w-3 sm:h-4 sm:w-4 sm:mr-1" />
<span className="hidden sm:inline">Definitivo</span>
</Button>
</>
)}
{onActualizarCultivo && (cultivo.estado === 'Positivo' || cultivo.estado === 'Negativo') && (
<Button size="sm" variant="outline" className="text-xs px-2 py-1" onClick={() => abrirDefinitivo(cultivo)}>
<Pencil className="h-3 w-3 sm:h-4 sm:w-4" />
</Button>
)}
<Button size="sm" variant="outline" className="text-red-600 text-xs px-2 py-1" onClick={() => onEliminarCultivo(cultivo.id)}>
<Trash2 className="h-3 w-3 sm:h-4 sm:w-4" />
</Button>
</div>
</div>
{cultivo.protocolo && (
<p className="text-xs text-gray-500">
Protocolo: {cultivo.protocolo}
</p>
)}
{cultivo.observaciones && (
<p className="text-sm text-gray-600 bg-gray-50 p-2 rounded">
{cultivo.observaciones}
</p>
)}
{cultivo.estado === 'Parcial' && cultivo.germen && (
<div className="bg-orange-50 p-3 rounded-lg border border-orange-200">
<p className="text-sm font-medium text-orange-800 flex items-center gap-2">
<AlertCircle className="h-4 w-4" />
PARCIAL - Germen: {cultivo.germen}
</p>
{(cultivo.sensible || cultivo.resistente) && (
<div className="mt-2 space-y-1">
{cultivo.sensible && <p className="text-xs text-orange-700">Sensible: {cultivo.sensible}</p>}
{cultivo.resistente && <p className="text-xs text-orange-700">Resistente: {cultivo.resistente}</p>}
</div>
)}
</div>
)}
{cultivo.estado === 'Positivo' && cultivo.germen && (
<div className="bg-red-50 p-3 rounded-lg border border-red-200">
<p className="text-sm font-medium text-red-800 flex items-center gap-2">
<AlertCircle className="h-4 w-4" />
Germen: {cultivo.germen}
</p>
{cultivo.fechaResultado && (
<p className="text-xs text-red-600 mt-1">
Resultado: {cultivo.fechaResultado}
</p>
)}
{(cultivo.sensible || cultivo.resistente) && (
<div className="mt-2 space-y-2">
{cultivo.sensible && (
<div>
<p className="text-xs font-medium text-green-700 mb-1">Sensible a:</p>
<p className="text-sm text-green-800">{cultivo.sensible}</p>
</div>
)}
{cultivo.resistente && (
<div>
<p className="text-xs font-medium text-red-700 mb-1">Resistente a:</p>
<p className="text-sm text-red-800">{cultivo.resistente}</p>
</div>
)}
</div>
)}
</div>
)}
{cultivo.estado === 'Negativo' && (
<div className="bg-green-50 p-3 rounded-lg border border-green-200">
<p className="text-sm font-medium text-green-800 flex items-center gap-2">
<CheckCircle2 className="h-4 w-4" />
Sin crecimiento de microorganismos
</p>
{cultivo.fechaResultado && (
<p className="text-xs text-green-600 mt-1">
Resultado: {cultivo.fechaResultado}
</p>
)}
</div>
)}
</div>
</CardContent>
</Card>
);
})}
</div>
{cultivosFiltrados.length === 0 && (
<div className="text-center py-12 text-gray-400">
<Microscope className="h-16 w-16 mx-auto mb-4 opacity-50" />
<p className="text-lg">
{busqueda || filtroEstado !== 'todos'
? 'No se encontraron cultivos con esos filtros'
: 'No hay cultivos registrados'}
</p>
</div>
)}
</div> </div>
); );
} }