Initial commit: Sistema de Gestión Hospitalaria
This commit is contained in:
@@ -0,0 +1,455 @@
|
||||
import { useState } from 'react';
|
||||
import { Activity, Plus, Search, Calendar, Clock } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import type { AcidoBase, Paciente } from '@/types';
|
||||
|
||||
interface AcidoBaseProps {
|
||||
acidosBase: AcidoBase[];
|
||||
pacientes: Paciente[];
|
||||
onAgregarAcidoBase: (acidoBase: Omit<AcidoBase, 'id'>) => void;
|
||||
onEliminarAcidoBase: (id: string) => void;
|
||||
getPacienteById: (id: string) => Paciente | undefined;
|
||||
}
|
||||
|
||||
const REFERENCIAS = {
|
||||
ph: { min: 7.35, max: 7.45, unidad: '' },
|
||||
pco2: { min: 35, max: 45, unidad: 'mmHg' },
|
||||
po2: { min: 80, max: 100, unidad: 'mmHg' },
|
||||
hco3: { min: 22, max: 26, unidad: 'mEq/L' },
|
||||
be: { min: -2, max: 2, unidad: 'mEq/L' },
|
||||
sato2: { min: 95, max: 100, unidad: '%' },
|
||||
lactato: { min: 0.5, max: 2.2, unidad: 'mmol/L' },
|
||||
};
|
||||
|
||||
export function AcidoBaseSection({
|
||||
acidosBase,
|
||||
pacientes,
|
||||
onAgregarAcidoBase,
|
||||
onEliminarAcidoBase,
|
||||
getPacienteById,
|
||||
}: AcidoBaseProps) {
|
||||
const [busqueda, setBusqueda] = useState('');
|
||||
const [dialogoAbierto, setDialogoAbierto] = useState(false);
|
||||
|
||||
// Formulario
|
||||
const [pacienteSeleccionado, setPacienteSeleccionado] = useState('');
|
||||
const [busquedaPaciente, setBusquedaPaciente] = useState('');
|
||||
const [fecha, setFecha] = useState(new Date().toISOString().split('T')[0]);
|
||||
const [hora, setHora] = useState(new Date().toTimeString().slice(0, 5));
|
||||
const [ph, setPh] = useState('');
|
||||
const [pco2, setPco2] = useState('');
|
||||
const [po2, setPo2] = useState('');
|
||||
const [hco3, setHco3] = useState('');
|
||||
const [be, setBe] = useState('');
|
||||
const [sato2, setSato2] = useState('');
|
||||
const [lactato, setLactato] = useState('');
|
||||
const [interpretacion, setInterpretacion] = useState('');
|
||||
|
||||
const resetFormulario = () => {
|
||||
setPacienteSeleccionado('');
|
||||
setBusquedaPaciente('');
|
||||
setFecha(new Date().toISOString().split('T')[0]);
|
||||
setHora(new Date().toTimeString().slice(0, 5));
|
||||
setPh('');
|
||||
setPco2('');
|
||||
setPo2('');
|
||||
setHco3('');
|
||||
setBe('');
|
||||
setSato2('');
|
||||
setLactato('');
|
||||
setInterpretacion('');
|
||||
};
|
||||
|
||||
const getEstadoParametro = (parametro: keyof typeof REFERENCIAS, valor: number) => {
|
||||
const ref = REFERENCIAS[parametro];
|
||||
if (valor < ref.min) return { estado: 'Bajo', color: 'text-blue-600' };
|
||||
if (valor > ref.max) return { estado: 'Alto', color: 'text-red-600' };
|
||||
return { estado: 'Normal', color: 'text-green-600' };
|
||||
};
|
||||
|
||||
const pacientesFiltrados = pacientes.filter(p => {
|
||||
if (!busquedaPaciente) return true;
|
||||
const texto = `${p.apellido} ${p.nombre} ${p.dni}`.toLowerCase();
|
||||
return texto.includes(busquedaPaciente.toLowerCase());
|
||||
});
|
||||
|
||||
const interpretarGasometria = () => {
|
||||
const phVal = parseFloat(ph);
|
||||
const pco2Val = parseFloat(pco2);
|
||||
const hco3Val = parseFloat(hco3);
|
||||
const beVal = parseFloat(be);
|
||||
|
||||
if (!phVal || !pco2Val || !hco3Val) return '';
|
||||
|
||||
let interpretacion = '';
|
||||
|
||||
// Determinar acidosis o alcalosis
|
||||
if (phVal < 7.35) {
|
||||
interpretacion += 'Acidemia - ';
|
||||
if (pco2Val > 45) interpretacion += 'Acidosis Respiratoria';
|
||||
else if (hco3Val < 22) interpretacion += 'Acidosis Metabólica';
|
||||
else interpretacion += 'Acidosis Mixta';
|
||||
} else if (phVal > 7.45) {
|
||||
interpretacion += 'Alcalemia - ';
|
||||
if (pco2Val < 35) interpretacion += 'Alcalosis Respiratoria';
|
||||
else if (hco3Val > 26) interpretacion += 'Alcalosis Metabólica';
|
||||
else interpretacion += 'Alcalosis Mixta';
|
||||
} else {
|
||||
interpretacion += 'pH Normal - ';
|
||||
if (pco2Val > 45 || hco3Val < 22) interpretacion += 'Compensación en curso';
|
||||
else interpretacion += 'Equilibrio Ácido-Base';
|
||||
}
|
||||
|
||||
// Agregar información sobre compensación
|
||||
if (beVal && Math.abs(beVal) > 2) {
|
||||
interpretacion += beVal > 0 ? ' (Exceso de bases elevado)' : ' (Déficit de bases)';
|
||||
}
|
||||
|
||||
return interpretacion;
|
||||
};
|
||||
|
||||
const handleGuardar = () => {
|
||||
if (!pacienteSeleccionado || !ph || !pco2 || !po2 || !hco3 || !be || !sato2) return;
|
||||
|
||||
const interpretacionAuto = interpretarGasometria();
|
||||
|
||||
onAgregarAcidoBase({
|
||||
pacienteId: pacienteSeleccionado,
|
||||
fecha,
|
||||
hora,
|
||||
ph: parseFloat(ph),
|
||||
pco2: parseFloat(pco2),
|
||||
po2: parseFloat(po2),
|
||||
hco3: parseFloat(hco3),
|
||||
be: parseFloat(be),
|
||||
sato2: parseFloat(sato2),
|
||||
lactato: lactato ? parseFloat(lactato) : undefined,
|
||||
interpretacion: interpretacion || interpretacionAuto,
|
||||
});
|
||||
|
||||
resetFormulario();
|
||||
setDialogoAbierto(false);
|
||||
};
|
||||
|
||||
const acidosBaseFiltrados = acidosBase
|
||||
.filter(ab => {
|
||||
const paciente = getPacienteById(ab.pacienteId);
|
||||
if (!paciente) return false;
|
||||
|
||||
return !busqueda ||
|
||||
paciente.nombre.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
paciente.apellido.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
paciente.dni.includes(busqueda);
|
||||
})
|
||||
.sort((a, b) => new Date(b.fecha + 'T' + b.hora).getTime() - new Date(a.fecha + 'T' + a.hora).getTime());
|
||||
|
||||
const getColorPh = (ph: number) => {
|
||||
if (ph < 7.2 || ph > 7.6) return 'bg-red-100 text-red-800';
|
||||
if (ph < 7.35 || ph > 7.45) return 'bg-amber-100 text-amber-800';
|
||||
return 'bg-green-100 text-green-800';
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Estados Ácido-Base</h1>
|
||||
<p className="text-gray-500">Gasometrías y análisis de equilibrio ácido-base</p>
|
||||
</div>
|
||||
<Dialog open={dialogoAbierto} onOpenChange={setDialogoAbierto}>
|
||||
<DialogTrigger asChild>
|
||||
<Button onClick={resetFormulario}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Nueva Gasometría
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-3xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Nueva Gasometría Arterial</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div className="sm:col-span-3">
|
||||
{!pacienteSeleccionado ? (
|
||||
<div>
|
||||
<Label>Buscar Paciente *</Label>
|
||||
<Input
|
||||
value={busquedaPaciente}
|
||||
onChange={(e) => setBusquedaPaciente(e.target.value)}
|
||||
placeholder="Ingrese apellido, nombre o DNI..."
|
||||
autoFocus
|
||||
/>
|
||||
{busquedaPaciente && (
|
||||
<div className="mt-2 border rounded-md max-h-48 overflow-y-auto">
|
||||
{pacientesFiltrados.length === 0 ? (
|
||||
<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="flex items-center gap-2 flex-wrap">
|
||||
<Badge className="bg-green-100 text-green-800 px-3 py-1">
|
||||
{(() => {
|
||||
const p = pacientes.find(x => x.id === pacienteSeleccionado);
|
||||
return p ? `${p.apellido}, ${p.nombre} - DNI: ${p.dni}` : '';
|
||||
})()}
|
||||
</Badge>
|
||||
<Button size="sm" variant="ghost" onClick={() => setPacienteSeleccionado('')}>Cambiar</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<Label>Fecha *</Label>
|
||||
<Input type="date" value={fecha} onChange={(e) => setFecha(e.target.value)} />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Hora *</Label>
|
||||
<Input type="time" value={hora} onChange={(e) => setHora(e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-7 gap-2">
|
||||
<div>
|
||||
<Label>pH *</Label>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
value={ph}
|
||||
onChange={(e) => setPh(e.target.value)}
|
||||
placeholder="7.40"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>pCO2 *</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={pco2}
|
||||
onChange={(e) => setPco2(e.target.value)}
|
||||
placeholder="40"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>pO2 *</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={po2}
|
||||
onChange={(e) => setPo2(e.target.value)}
|
||||
placeholder="85"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>HCO3- *</Label>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.1"
|
||||
value={hco3}
|
||||
onChange={(e) => setHco3(e.target.value)}
|
||||
placeholder="24"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>BE *</Label>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.1"
|
||||
value={be}
|
||||
onChange={(e) => setBe(e.target.value)}
|
||||
placeholder="0"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>SatO2 *</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={sato2}
|
||||
onChange={(e) => setSato2(e.target.value)}
|
||||
placeholder="97"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Lactato</Label>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.1"
|
||||
value={lactato}
|
||||
onChange={(e) => setLactato(e.target.value)}
|
||||
placeholder="1.0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{ph && pco2 && hco3 && (
|
||||
<div className="bg-blue-50 p-3 rounded-lg border border-blue-200">
|
||||
<p className="text-sm font-medium text-blue-800 flex items-center gap-2">
|
||||
<Activity className="h-4 w-4" />
|
||||
Interpretación automática: {interpretarGasometria()}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<Label>Interpretación / Comentarios</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
|
||||
value={interpretacion}
|
||||
onChange={(e) => setInterpretacion(e.target.value)}
|
||||
placeholder="Interpretación clínica..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2 mt-4">
|
||||
<Button variant="outline" onClick={() => {
|
||||
resetFormulario();
|
||||
setDialogoAbierto(false);
|
||||
}}>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleGuardar}
|
||||
disabled={!pacienteSeleccionado || !ph || !pco2 || !po2 || !hco3 || !be || !sato2}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Guardar Gasometría
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
{/* Búsqueda */}
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
className="pl-10"
|
||||
placeholder="Buscar por paciente..."
|
||||
value={busqueda}
|
||||
onChange={(e) => setBusqueda(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Lista de Gasometrías */}
|
||||
<div className="space-y-4">
|
||||
{acidosBaseFiltrados.map((ab) => {
|
||||
const paciente = getPacienteById(ab.pacienteId);
|
||||
const phEstado = getEstadoParametro('ph', ab.ph);
|
||||
|
||||
return (
|
||||
<Card key={ab.id} className="hover:shadow-md transition-shadow">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 bg-teal-100 rounded-full flex items-center justify-center">
|
||||
<Activity className="h-5 w-5 text-teal-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-bold">
|
||||
{paciente ? `${paciente.apellido}, ${paciente.nombre}` : 'Paciente no encontrado'}
|
||||
</h3>
|
||||
<div className="flex items-center gap-3 text-sm text-gray-500">
|
||||
<span className="flex items-center gap-1">
|
||||
<Calendar className="h-3 w-3" />
|
||||
{ab.fecha}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
{ab.hora}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge className={getColorPh(ab.ph)}>
|
||||
pH: {ab.ph}
|
||||
</Badge>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-red-600 hover:bg-red-50"
|
||||
onClick={() => onEliminarAcidoBase(ab.id)}
|
||||
>
|
||||
Eliminar
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 sm:grid-cols-7 gap-2">
|
||||
<div className="bg-gray-50 p-2 rounded text-center">
|
||||
<p className="text-xs text-gray-500">pH</p>
|
||||
<p className={`font-bold ${phEstado.color}`}>{ab.ph}</p>
|
||||
</div>
|
||||
<div className="bg-gray-50 p-2 rounded text-center">
|
||||
<p className="text-xs text-gray-500">pCO2</p>
|
||||
<p className="font-bold">{ab.pco2}</p>
|
||||
</div>
|
||||
<div className="bg-gray-50 p-2 rounded text-center">
|
||||
<p className="text-xs text-gray-500">pO2</p>
|
||||
<p className="font-bold">{ab.po2}</p>
|
||||
</div>
|
||||
<div className="bg-gray-50 p-2 rounded text-center">
|
||||
<p className="text-xs text-gray-500">HCO3</p>
|
||||
<p className="font-bold">{ab.hco3}</p>
|
||||
</div>
|
||||
<div className="bg-gray-50 p-2 rounded text-center">
|
||||
<p className="text-xs text-gray-500">BE</p>
|
||||
<p className="font-bold">{ab.be}</p>
|
||||
</div>
|
||||
<div className="bg-gray-50 p-2 rounded text-center">
|
||||
<p className="text-xs text-gray-500">SatO2</p>
|
||||
<p className="font-bold">{ab.sato2}%</p>
|
||||
</div>
|
||||
{ab.lactato && (
|
||||
<div className="bg-gray-50 p-2 rounded text-center">
|
||||
<p className="text-xs text-gray-500">Lactato</p>
|
||||
<p className="font-bold">{ab.lactato}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{ab.interpretacion && (
|
||||
<div className="bg-teal-50 p-3 rounded-lg border border-teal-200">
|
||||
<p className="text-sm font-medium text-teal-800 flex items-center gap-2">
|
||||
Interpretación: {ab.interpretacion}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{acidosBaseFiltrados.length === 0 && (
|
||||
<div className="text-center py-12 text-gray-400">
|
||||
<Activity className="h-16 w-16 mx-auto mb-4 opacity-50" />
|
||||
<p className="text-lg">
|
||||
{busqueda ? 'No se encontraron gasometrías con esa búsqueda' : 'No hay gasometrías registradas'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,565 @@
|
||||
import { useState } from 'react';
|
||||
import { Microscope, Plus, Search, Calendar, AlertCircle, Trash2, CheckCircle2, Save, X, Pencil } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
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[];
|
||||
onAgregarCultivo: (cultivo: Omit<Cultivo, 'id'>) => void;
|
||||
onActualizarCultivo?: (id: string, datos: Partial<Cultivo>) => void;
|
||||
onEliminarCultivo: (id: string) => void;
|
||||
getPacienteById: (id: string) => Paciente | undefined;
|
||||
getCamaById: (id: string) => Cama | undefined;
|
||||
getInternacionActivaByPaciente: (pacienteId: string) => Internacion | undefined;
|
||||
}
|
||||
|
||||
export function Cultivos({
|
||||
cultivos,
|
||||
pacientes,
|
||||
internaciones,
|
||||
camas,
|
||||
onAgregarCultivo,
|
||||
onActualizarCultivo,
|
||||
onEliminarCultivo,
|
||||
getPacienteById,
|
||||
getCamaById,
|
||||
getInternacionActivaByPaciente,
|
||||
}: CultivosProps) {
|
||||
const [busqueda, setBusqueda] = useState('');
|
||||
const [filtroEstado, setFiltroEstado] = useState<'todos' | 'NAF/Pendiente' | 'Parcial' | 'Positivo' | 'Negativo'>('todos');
|
||||
const [dialogoNuevoAbierto, setDialogoNuevoAbierto] = useState(false);
|
||||
const [dialogoParcialAbierto, setDialogoParcialAbierto] = useState(false);
|
||||
const [dialogoDefinitivoAbierto, setDialogoDefinitivoAbierto] = useState(false);
|
||||
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 [protocolo, setProtocolo] = useState('');
|
||||
const [tipoMuestra, setTipoMuestra] = useState<Cultivo['tipoMuestra']>('HMCx2');
|
||||
const [observaciones, setObservaciones] = useState('');
|
||||
|
||||
const [fechaResultado, setFechaResultado] = useState(new Date().toISOString().split('T')[0]);
|
||||
const [estadoResultado, setEstadoResultado] = useState<Cultivo['estado']>('Positivo');
|
||||
const [germen, setGermen] = useState('');
|
||||
const [sensible, setSensible] = useState('');
|
||||
const [resistente, setResistente] = useState('');
|
||||
|
||||
const resetFormularioNuevo = () => {
|
||||
setPacienteSeleccionado('');
|
||||
setBusquedaPaciente('');
|
||||
setFechaToma(new Date().toISOString().split('T')[0]);
|
||||
setProtocolo('');
|
||||
setTipoMuestra('HMCx2');
|
||||
setObservaciones('');
|
||||
};
|
||||
|
||||
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',
|
||||
germen: germen || undefined,
|
||||
sensible: sensible || undefined,
|
||||
resistente: resistente || undefined,
|
||||
});
|
||||
resetFormularioResultado();
|
||||
setDialogoParcialAbierto(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDefinitivo = () => {
|
||||
if (cultivoSeleccionado && onActualizarCultivo) {
|
||||
onActualizarCultivo(cultivoSeleccionado.id, {
|
||||
fechaResultado,
|
||||
estado: estadoResultado,
|
||||
germen: germen || undefined,
|
||||
sensible: sensible || undefined,
|
||||
resistente: resistente || undefined,
|
||||
});
|
||||
resetFormularioResultado();
|
||||
setDialogoDefinitivoAbierto(false);
|
||||
}
|
||||
};
|
||||
|
||||
const abrirParcial = (cultivo: Cultivo) => {
|
||||
setCultivoSeleccionado(cultivo);
|
||||
setGermen(cultivo.germen || '');
|
||||
setSensible(cultivo.sensible || '');
|
||||
setResistente(cultivo.resistente || '');
|
||||
setDialogoParcialAbierto(true);
|
||||
};
|
||||
|
||||
const abrirDefinitivo = (cultivo: Cultivo) => {
|
||||
setCultivoSeleccionado(cultivo);
|
||||
setFechaResultado(cultivo.fechaResultado || new Date().toISOString().split('T')[0]);
|
||||
setEstadoResultado(cultivo.estado === 'Parcial' || cultivo.estado === 'Positivo' ? 'Positivo' : cultivo.estado);
|
||||
setGermen(cultivo.germen || '');
|
||||
setSensible(cultivo.sensible || '');
|
||||
setResistente(cultivo.resistente || '');
|
||||
setDialogoDefinitivoAbierto(true);
|
||||
};
|
||||
|
||||
const getEstadoColor = (estado: Cultivo['estado']) => {
|
||||
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';
|
||||
}
|
||||
};
|
||||
|
||||
const getEstadoLabel = (estado: Cultivo['estado']) => {
|
||||
switch (estado) {
|
||||
case 'NAF/Pendiente': return 'NAF/Pendiente';
|
||||
case 'Parcial': return 'Parcial';
|
||||
case 'Positivo': return 'Positivo';
|
||||
case 'Negativo': return 'Negativo Final';
|
||||
}
|
||||
};
|
||||
|
||||
const getNumeroCama = (pacienteId: string): string | null => {
|
||||
const internacion = getInternacionActivaByPaciente(pacienteId);
|
||||
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 (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Cultivos</h1>
|
||||
<p className="text-gray-500">Gestión de cultivos microbiológicos y antibiogramas</p>
|
||||
</div>
|
||||
<Dialog open={dialogoNuevoAbierto} onOpenChange={setDialogoNuevoAbierto}>
|
||||
<DialogTrigger asChild>
|
||||
<Button onClick={resetFormularioNuevo}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Nuevo Cultivo
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Nuevo Cultivo</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
{!pacienteSeleccionado ? (
|
||||
<div>
|
||||
<Label>Buscar Paciente *</Label>
|
||||
<Input
|
||||
value={busquedaPaciente}
|
||||
onChange={(e) => setBusquedaPaciente(e.target.value)}
|
||||
placeholder="Ingrese apellido, nombre o DNI..."
|
||||
autoFocus
|
||||
/>
|
||||
{busquedaPaciente && (
|
||||
<div className="mt-2 border rounded-md max-h-48 overflow-y-auto">
|
||||
{pacientesFiltrados.length === 0 ? (
|
||||
<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="flex items-center gap-2">
|
||||
<Badge className="bg-gray-100 text-gray-800 px-3 py-1">
|
||||
{(() => {
|
||||
const p = pacientes.find(x => x.id === pacienteSeleccionado);
|
||||
return p ? `${p.apellido}, ${p.nombre} - DNI: ${p.dni}` : '';
|
||||
})()}
|
||||
</Badge>
|
||||
<Button size="sm" variant="ghost" onClick={() => setPacienteSeleccionado('')}>Cambiar</Button>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Fecha de Toma *</Label>
|
||||
<Input type="date" value={fechaToma} onChange={(e) => setFechaToma(e.target.value)} />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Protocolo</Label>
|
||||
<Input value={protocolo} onChange={(e) => setProtocolo(e.target.value)} placeholder="N° Protocolo" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Tipo de Muestra *</Label>
|
||||
<Select value={tipoMuestra} onValueChange={(v: Cultivo['tipoMuestra']) => setTipoMuestra(v)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="HMCx2">HMCx2</SelectItem>
|
||||
<SelectItem value="RC">RC</SelectItem>
|
||||
<SelectItem value="PC">PC</SelectItem>
|
||||
<SelectItem value="UC">UC</SelectItem>
|
||||
<SelectItem value="LCR">LCR</SelectItem>
|
||||
<SelectItem value="LP">LP</SelectItem>
|
||||
<SelectItem value="LAsc">LAsc</SelectItem>
|
||||
<SelectItem value="LAbd">LAbd</SelectItem>
|
||||
<SelectItem value="Coleccion">Coleccion</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</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)}>Cancelar</Button>
|
||||
<Button onClick={handleAgregar} disabled={!pacienteSeleccionado || !fechaToma || !tipoMuestra}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Guardar
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</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 el germen crecido para tomar conducta. Podrá editarse posteriormente.</p>
|
||||
</div>
|
||||
<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, Vancomicina" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Resistente a:</Label>
|
||||
<Input value={resistente} onChange={(e) => setResistente(e.target.value)} placeholder="Ej: Oxacilina" />
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={() => { resetFormularioResultado(); setDialogoParcialAbierto(false); }}>
|
||||
<X className="h-4 w-4 mr-2" />
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button onClick={handleParcial} disabled={!germen}>
|
||||
<Save className="h-4 w-4 mr-2" />
|
||||
Guardar Parcial
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={dialogoDefinitivoAbierto} onOpenChange={setDialogoDefinitivoAbierto}>
|
||||
<DialogContent className="sm:max-w-xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Cargar Resultado Definitivo</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Fecha de Resultado *</Label>
|
||||
<Input type="date" value={fechaResultado} onChange={(e) => setFechaResultado(e.target.value)} />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Resultado *</Label>
|
||||
<Select value={estadoResultado} onValueChange={(v: Cultivo['estado']) => setEstadoResultado(v)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Positivo">Positivo</SelectItem>
|
||||
<SelectItem value="Negativo">Negativo Final</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</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">
|
||||
<Button variant="outline" onClick={() => { resetFormularioResultado(); setDialogoDefinitivoAbierto(false); }}>
|
||||
<X className="h-4 w-4 mr-2" />
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button onClick={handleDefinitivo} disabled={estadoResultado === 'Positivo' && !germen}>
|
||||
<Save className="h-4 w-4 mr-2" />
|
||||
Guardar Definitivo
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div className="relative sm:col-span-2">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
className="pl-10"
|
||||
placeholder="Buscar por paciente..."
|
||||
value={busqueda}
|
||||
onChange={(e) => setBusqueda(e.target.value)}
|
||||
/>
|
||||
</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>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<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">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className={`h-10 w-10 rounded-full flex items-center justify-center ${
|
||||
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>
|
||||
<h3 className="font-bold">
|
||||
{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 items-center gap-3 text-sm text-gray-500">
|
||||
<span className="flex items-center gap-1">
|
||||
<Calendar className="h-3 w-3" />
|
||||
Toma: {cultivo.fechaToma}
|
||||
</span>
|
||||
<Badge variant="outline">{cultivo.tipoMuestra}</Badge>
|
||||
<Badge className={getEstadoColor(cultivo.estado)}>
|
||||
{getEstadoLabel(cultivo.estado)}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{onActualizarCultivo && cultivo.estado === 'NAF/Pendiente' && (
|
||||
<>
|
||||
<Button size="sm" onClick={() => abrirParcial(cultivo)}>
|
||||
<AlertCircle className="h-4 w-4 mr-1" />
|
||||
Parcial
|
||||
</Button>
|
||||
<Button size="sm" variant="default" onClick={() => abrirDefinitivo(cultivo)}>
|
||||
<CheckCircle2 className="h-4 w-4 mr-1" />
|
||||
Definitivo
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{onActualizarCultivo && cultivo.estado === 'Parcial' && (
|
||||
<>
|
||||
<Button size="sm" variant="outline" onClick={() => abrirParcial(cultivo)}>
|
||||
<Pencil className="h-4 w-4 mr-1" />
|
||||
Editar Parcial
|
||||
</Button>
|
||||
<Button size="sm" variant="default" onClick={() => abrirDefinitivo(cultivo)}>
|
||||
<CheckCircle2 className="h-4 w-4 mr-1" />
|
||||
Definitivo
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{onActualizarCultivo && (cultivo.estado === 'Positivo' || cultivo.estado === 'Negativo') && (
|
||||
<Button size="sm" variant="outline" onClick={() => abrirDefinitivo(cultivo)}>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" variant="ghost" className="text-red-600" onClick={() => onEliminarCultivo(cultivo.id)}>
|
||||
<Trash2 className="h-4 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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
import {
|
||||
Bed,
|
||||
Users,
|
||||
ClipboardList,
|
||||
FlaskConical,
|
||||
Activity,
|
||||
Microscope,
|
||||
TrendingUp,
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
Clock
|
||||
} from 'lucide-react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import type { Vista, Internacion, Paciente, Cultivo } from '@/types';
|
||||
|
||||
interface DashboardProps {
|
||||
estadisticas: {
|
||||
camasOcupadas: number;
|
||||
camasDisponibles: number;
|
||||
camasMantenimiento: number;
|
||||
totalCamas: number;
|
||||
totalCamasActivas: number;
|
||||
camasFueraDeArea: number;
|
||||
internacionesActivas: number;
|
||||
totalPacientes: number;
|
||||
cultivosPendientes: number;
|
||||
porcentajeOcupacion: number;
|
||||
};
|
||||
internaciones: Internacion[];
|
||||
cultivos: Cultivo[];
|
||||
onCambiarVista: (vista: Vista) => void;
|
||||
getPacienteById: (id: string) => Paciente | undefined;
|
||||
}
|
||||
|
||||
export function Dashboard({
|
||||
estadisticas,
|
||||
internaciones,
|
||||
cultivos,
|
||||
onCambiarVista,
|
||||
getPacienteById
|
||||
}: DashboardProps) {
|
||||
const internacionesActivas = internaciones.filter(i => i.activa).slice(0, 5);
|
||||
const cultivosRecientes = cultivos
|
||||
.filter(c => c.estado === 'NAF/Pendiente')
|
||||
.slice(0, 5);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Dashboard</h1>
|
||||
<p className="text-gray-500">Resumen del servicio - Clinica Medica</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="outline" className="bg-green-50 text-green-700 border-green-200">
|
||||
<CheckCircle2 className="h-3 w-3 mr-1" />
|
||||
Sistema Operativo
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Estadísticas Principales */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<Card className="border-l-4 border-l-blue-500">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
||||
<Bed className="h-4 w-4" />
|
||||
Ocupación de Camas
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-3xl font-bold">{estadisticas.porcentajeOcupacion}%</span>
|
||||
<span className="text-sm text-gray-500">{estadisticas.camasOcupadas}/{estadisticas.totalCamas}</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
{estadisticas.camasDisponibles} camas disponibles
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="border-l-4 border-l-green-500">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
||||
<Users className="h-4 w-4" />
|
||||
Camas Fuera de Área
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-3xl font-bold">{estadisticas.camasFueraDeArea}</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
outside of active service
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="border-l-4 border-l-purple-500">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
||||
<ClipboardList className="h-4 w-4" />
|
||||
Internaciones Activas
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-3xl font-bold">{estadisticas.internacionesActivas}</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
En curso actualmente
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="border-l-4 border-l-amber-500">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-gray-500 flex items-center gap-2">
|
||||
<Microscope className="h-4 w-4" />
|
||||
Cultivos Pendientes
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-3xl font-bold">{estadisticas.cultivosPendientes}</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
Esperando resultados
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Contenido Principal */}
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{/* Estado de Camas */}
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<Bed className="h-5 w-5 text-blue-600" />
|
||||
Estado de Camas
|
||||
</CardTitle>
|
||||
<Button variant="ghost" size="sm" onClick={() => onCambiarVista('camas')}>
|
||||
Ver todas
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="bg-green-50 p-3 rounded-lg">
|
||||
<div className="flex items-center gap-2">
|
||||
<CheckCircle2 className="h-4 w-4 text-green-600" />
|
||||
<span className="text-sm font-medium text-green-800">Disponibles</span>
|
||||
</div>
|
||||
<p className="text-2xl font-bold text-green-700 mt-1">{estadisticas.camasDisponibles}</p>
|
||||
</div>
|
||||
<div className="bg-red-50 p-3 rounded-lg">
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertCircle className="h-4 w-4 text-red-600" />
|
||||
<span className="text-sm font-medium text-red-800">Ocupadas</span>
|
||||
</div>
|
||||
<p className="text-2xl font-bold text-red-700 mt-1">{estadisticas.camasOcupadas}</p>
|
||||
</div>
|
||||
<div className="bg-amber-50 p-3 rounded-lg">
|
||||
<div className="flex items-center gap-2">
|
||||
<Clock className="h-4 w-4 text-amber-600" />
|
||||
<span className="text-sm font-medium text-amber-800">Mantenimiento</span>
|
||||
</div>
|
||||
<p className="text-2xl font-bold text-amber-700 mt-1">{estadisticas.camasMantenimiento}</p>
|
||||
</div>
|
||||
<div className="bg-blue-50 p-3 rounded-lg">
|
||||
<div className="flex items-center gap-2">
|
||||
<TrendingUp className="h-4 w-4 text-blue-600" />
|
||||
<span className="text-sm font-medium text-blue-800">Ocupación</span>
|
||||
</div>
|
||||
<p className="text-2xl font-bold text-blue-700 mt-1">{estadisticas.porcentajeOcupacion}%</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Internaciones Activas */}
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<ClipboardList className="h-5 w-5 text-purple-600" />
|
||||
Internaciones Activas
|
||||
</CardTitle>
|
||||
<Button variant="ghost" size="sm" onClick={() => onCambiarVista('internaciones')}>
|
||||
Ver todas
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{internacionesActivas.length === 0 ? (
|
||||
<div className="text-center py-8 text-gray-400">
|
||||
<ClipboardList className="h-12 w-12 mx-auto mb-2 opacity-50" />
|
||||
<p>No hay internaciones activas</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{internacionesActivas.map((internacion) => {
|
||||
const paciente = getPacienteById(internacion.pacienteId);
|
||||
return (
|
||||
<div key={internacion.id} className="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
|
||||
<div>
|
||||
<p className="font-medium text-gray-900">
|
||||
{paciente ? `${paciente.apellido}, ${paciente.nombre}` : 'Paciente no encontrado'}
|
||||
</p>
|
||||
<p className="text-sm text-gray-500">
|
||||
Ingreso: {internacion.fechaIngreso}
|
||||
</p>
|
||||
</div>
|
||||
<Badge variant="outline" className="bg-purple-50 text-purple-700">
|
||||
Activa
|
||||
</Badge>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Accesos Rápidos */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<Activity className="h-5 w-5 text-green-600" />
|
||||
Accesos Rápidos
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-auto py-4 flex flex-col items-center gap-2"
|
||||
onClick={() => onCambiarVista('pacientes')}
|
||||
>
|
||||
<Users className="h-6 w-6 text-blue-600" />
|
||||
<span className="text-sm">Nuevo Paciente</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-auto py-4 flex flex-col items-center gap-2"
|
||||
onClick={() => onCambiarVista('internaciones')}
|
||||
>
|
||||
<ClipboardList className="h-6 w-6 text-purple-600" />
|
||||
<span className="text-sm">Nueva Internación</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-auto py-4 flex flex-col items-center gap-2"
|
||||
onClick={() => onCambiarVista('laboratorios')}
|
||||
>
|
||||
<FlaskConical className="h-6 w-6 text-amber-600" />
|
||||
<span className="text-sm">Laboratorio</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-auto py-4 flex flex-col items-center gap-2"
|
||||
onClick={() => onCambiarVista('cultivos')}
|
||||
>
|
||||
<Microscope className="h-6 w-6 text-teal-600" />
|
||||
<span className="text-sm">Cultivo</span>
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Cultivos Pendientes */}
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-lg flex items-center gap-2">
|
||||
<Microscope className="h-5 w-5 text-teal-600" />
|
||||
Cultivos Pendientes
|
||||
</CardTitle>
|
||||
<Button variant="ghost" size="sm" onClick={() => onCambiarVista('cultivos')}>
|
||||
Ver todos
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{cultivosRecientes.length === 0 ? (
|
||||
<div className="text-center py-8 text-gray-400">
|
||||
<Microscope className="h-12 w-12 mx-auto mb-2 opacity-50" />
|
||||
<p>No hay cultivos pendientes</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{cultivosRecientes.map((cultivo) => {
|
||||
const paciente = getPacienteById(cultivo.pacienteId);
|
||||
return (
|
||||
<div key={cultivo.id} className="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
|
||||
<div>
|
||||
<p className="font-medium text-gray-900">
|
||||
{paciente ? `${paciente.apellido}, ${paciente.nombre}` : 'Paciente no encontrado'}
|
||||
</p>
|
||||
<p className="text-sm text-gray-500">
|
||||
{cultivo.tipoMuestra} - {cultivo.fechaToma}
|
||||
</p>
|
||||
</div>
|
||||
<Badge className="bg-amber-100 text-amber-800">
|
||||
<Clock className="h-3 w-3 mr-1" />
|
||||
Pendiente
|
||||
</Badge>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,540 @@
|
||||
import { useState } from 'react';
|
||||
import { FileText, Plus, Search, Calendar, Clock, Thermometer, Heart, Activity, Wind, Droplets, Pencil, Trash2, ChevronDown, ChevronUp } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import type { Evolucion, Internacion, Paciente, SignosVitales, ExamenFisico } from '@/types';
|
||||
|
||||
interface EvolucionesProps {
|
||||
evoluciones: Evolucion[];
|
||||
internaciones: Internacion[];
|
||||
pacientes: Paciente[];
|
||||
onAgregarEvolucion: (evolucion: Omit<Evolucion, 'id'>) => void;
|
||||
onActualizarEvolucion?: (id: string, datos: Partial<Evolucion>) => void;
|
||||
onEliminarEvolucion: (id: string) => void;
|
||||
getPacienteById: (id: string) => Paciente | undefined;
|
||||
getInternacionActivaByPaciente: (pacienteId: string) => Internacion | undefined;
|
||||
}
|
||||
|
||||
export function Evoluciones({
|
||||
evoluciones,
|
||||
internaciones,
|
||||
pacientes,
|
||||
onAgregarEvolucion,
|
||||
onActualizarEvolucion,
|
||||
onEliminarEvolucion,
|
||||
getPacienteById,
|
||||
getInternacionActivaByPaciente
|
||||
}: EvolucionesProps) {
|
||||
const [busqueda, setBusqueda] = useState('');
|
||||
const [pacienteSeleccionado, setPacienteSeleccionado] = useState<string>('');
|
||||
const [dialogoAbierto, setDialogoAbierto] = useState(false);
|
||||
const [evolucionExpandida, setEvolucionExpandida] = useState<string | null>(null);
|
||||
const [evolucionEditando, setEvolucionEditando] = useState<Evolucion | null>(null);
|
||||
|
||||
const [fecha, setFecha] = useState(new Date().toISOString().split('T')[0]);
|
||||
const [hora, setHora] = useState(new Date().toTimeString().slice(0, 5));
|
||||
const [medico, setMedico] = useState('');
|
||||
const [temperatura, setTemperatura] = useState('');
|
||||
const [presionSistolica, setPresionSistolica] = useState('');
|
||||
const [presionDiastolica, setPresionDiastolica] = useState('');
|
||||
const [frecuenciaCardiaca, setFrecuenciaCardiaca] = useState('');
|
||||
const [frecuenciaRespiratoria, setFrecuenciaRespiratoria] = useState('');
|
||||
const [saturacionO2, setSaturacionO2] = useState('');
|
||||
const [snc, setSnc] = useState('');
|
||||
const [cardiovascular, setCardiovascular] = useState('');
|
||||
const [respiratorio, setRespiratorio] = useState('');
|
||||
const [abdominal, setAbdominal] = useState('');
|
||||
const [genitourinario, setGenitourinario] = useState('');
|
||||
const [pielAnexos, setPielAnexos] = useState('');
|
||||
const [soma, setSoma] = useState('');
|
||||
const [novedades, setNovedades] = useState('');
|
||||
const [comentario, setComentario] = useState('');
|
||||
const [pendientes, setPendientes] = useState('');
|
||||
|
||||
const resetFormulario = () => {
|
||||
setFecha(new Date().toISOString().split('T')[0]);
|
||||
setHora(new Date().toTimeString().slice(0, 5));
|
||||
setMedico('');
|
||||
setTemperatura('');
|
||||
setPresionSistolica('');
|
||||
setPresionDiastolica('');
|
||||
setFrecuenciaCardiaca('');
|
||||
setFrecuenciaRespiratoria('');
|
||||
setSaturacionO2('');
|
||||
setSnc('');
|
||||
setCardiovascular('');
|
||||
setRespiratorio('');
|
||||
setAbdominal('');
|
||||
setGenitourinario('');
|
||||
setPielAnexos('');
|
||||
setSoma('');
|
||||
setNovedades('');
|
||||
setComentario('');
|
||||
setPendientes('');
|
||||
setEvolucionEditando(null);
|
||||
};
|
||||
|
||||
const abrirEditar = (evo: Evolucion) => {
|
||||
setEvolucionEditando(evo);
|
||||
setFecha(evo.fecha);
|
||||
setHora(evo.hora);
|
||||
setMedico(evo.medico);
|
||||
setTemperatura(evo.signosVitales?.temperatura?.toString() || '');
|
||||
setPresionSistolica(evo.signosVitales?.presionSistolica?.toString() || '');
|
||||
setPresionDiastolica(evo.signosVitales?.presionDiastolica?.toString() || '');
|
||||
setFrecuenciaCardiaca(evo.signosVitales?.frecuenciaCardiaca?.toString() || '');
|
||||
setFrecuenciaRespiratoria(evo.signosVitales?.frecuenciaRespiratoria?.toString() || '');
|
||||
setSaturacionO2(evo.signosVitales?.saturacionO2?.toString() || '');
|
||||
setSnc(evo.examenFisico?.SNC || '');
|
||||
setCardiovascular(evo.examenFisico?.Cardiovascular || '');
|
||||
setRespiratorio(evo.examenFisico?.Respiratorio || '');
|
||||
setAbdominal(evo.examenFisico?.Abdominal || '');
|
||||
setGenitourinario(evo.examenFisico?.Genitourinario || '');
|
||||
setPielAnexos(evo.examenFisico?.PielAnexos || '');
|
||||
setSoma(evo.examenFisico?.SOMA || '');
|
||||
setNovedades(evo.novedades || '');
|
||||
setComentario(evo.comentario || '');
|
||||
setPendientes(evo.pendientes || '');
|
||||
setDialogoAbierto(true);
|
||||
};
|
||||
|
||||
const handleGuardar = () => {
|
||||
const internacion = getInternacionActivaByPaciente(pacienteSeleccionado);
|
||||
if (!internacion || !medico) return;
|
||||
|
||||
const signosVitales: SignosVitales | undefined =
|
||||
temperatura || presionSistolica || frecuenciaCardiaca
|
||||
? {
|
||||
temperatura: temperatura ? parseFloat(temperatura) : undefined,
|
||||
presionSistolica: presionSistolica ? parseInt(presionSistolica) : undefined,
|
||||
presionDiastolica: presionDiastolica ? parseInt(presionDiastolica) : undefined,
|
||||
frecuenciaCardiaca: frecuenciaCardiaca ? parseInt(frecuenciaCardiaca) : undefined,
|
||||
frecuenciaRespiratoria: frecuenciaRespiratoria ? parseInt(frecuenciaRespiratoria) : undefined,
|
||||
saturacionO2: saturacionO2 ? parseInt(saturacionO2) : undefined,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const examenFisico: ExamenFisico | undefined =
|
||||
snc || cardiovascular || respiratorio || abdominal || genitourinario || pielAnexos || soma
|
||||
? {
|
||||
SNC: snc || undefined,
|
||||
Cardiovascular: cardiovascular || undefined,
|
||||
Respiratorio: respiratorio || undefined,
|
||||
Abdominal: abdominal || undefined,
|
||||
Genitourinario: genitourinario || undefined,
|
||||
PielAnexos: pielAnexos || undefined,
|
||||
SOMA: soma || undefined,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const evolucionData = {
|
||||
fecha,
|
||||
hora,
|
||||
medico,
|
||||
signosVitales,
|
||||
examenFisico,
|
||||
novedades: novedades || undefined,
|
||||
comentario: comentario || undefined,
|
||||
pendientes: pendientes || undefined,
|
||||
};
|
||||
|
||||
if (evolucionEditando && onActualizarEvolucion) {
|
||||
onActualizarEvolucion(evolucionEditando.id, evolucionData);
|
||||
} else {
|
||||
onAgregarEvolucion({ ...evolucionData, internacionId: internacion.id });
|
||||
}
|
||||
|
||||
resetFormulario();
|
||||
setDialogoAbierto(false);
|
||||
};
|
||||
|
||||
const pacientesInternados = pacientes.filter(p => {
|
||||
const internacion = getInternacionActivaByPaciente(p.id);
|
||||
return internacion !== undefined;
|
||||
});
|
||||
|
||||
const evolucionesFiltradas = evoluciones
|
||||
.filter(e => {
|
||||
const internacion = internaciones.find(i => i.id === e.internacionId);
|
||||
if (!internacion) return false;
|
||||
const paciente = getPacienteById(internacion.pacienteId);
|
||||
if (!paciente) return false;
|
||||
|
||||
return !busqueda ||
|
||||
paciente.nombre.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
paciente.apellido.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
paciente.dni.includes(busqueda);
|
||||
})
|
||||
.sort((a, b) => new Date(b.fecha + 'T' + b.hora).getTime() - new Date(a.fecha + 'T' + a.hora).getTime());
|
||||
|
||||
const getSignosVitalesTexto = (sv: SignosVitales | undefined) => {
|
||||
if (!sv) return null;
|
||||
const partes: string[] = [];
|
||||
if (sv.presionSistolica && sv.presionDiastolica) partes.push(`PA: ${sv.presionSistolica}/${sv.presionDiastolica}`);
|
||||
if (sv.frecuenciaCardiaca) partes.push(`FC: ${sv.frecuenciaCardiaca}`);
|
||||
if (sv.frecuenciaRespiratoria) partes.push(`FR: ${sv.frecuenciaRespiratoria}`);
|
||||
if (sv.temperatura) partes.push(`T: ${sv.temperatura}°C`);
|
||||
if (sv.saturacionO2) partes.push(`SatO2: ${sv.saturacionO2}%`);
|
||||
return partes.join(' | ');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Evoluciones Diarias</h1>
|
||||
<p className="text-gray-500">Registro de evoluciones y signos vitales</p>
|
||||
</div>
|
||||
<Dialog open={dialogoAbierto} onOpenChange={setDialogoAbierto}>
|
||||
<DialogTrigger asChild>
|
||||
<Button onClick={resetFormulario}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Nueva Evolución
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-3xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{evolucionEditando ? 'Editar Evolución' : 'Nueva Evolución'}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
{!evolucionEditando && (
|
||||
<div>
|
||||
<Label>Paciente *</Label>
|
||||
<Select value={pacienteSeleccionado} onValueChange={setPacienteSeleccionado}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Seleccionar paciente internado" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{pacientesInternados.map(p => (
|
||||
<SelectItem key={p.id} value={p.id}>
|
||||
{p.apellido}, {p.nombre} - DNI: {p.dni}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Fecha *</Label>
|
||||
<Input type="date" value={fecha} onChange={(e) => setFecha(e.target.value)} />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Hora *</Label>
|
||||
<Input type="time" value={hora} onChange={(e) => setHora(e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-blue-50 p-3 rounded-lg border border-blue-200">
|
||||
<p className="text-sm font-bold text-blue-800 mb-3 flex items-center gap-2">
|
||||
<Activity className="h-4 w-4" />
|
||||
Signos Vitales
|
||||
</p>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<Label className="flex items-center gap-1">
|
||||
<Heart className="h-4 w-4" />TAS
|
||||
</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={presionSistolica}
|
||||
onChange={(e) => setPresionSistolica(e.target.value)}
|
||||
placeholder="120"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="flex items-center gap-1">
|
||||
<Heart className="h-4 w-4" />TAD
|
||||
</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={presionDiastolica}
|
||||
onChange={(e) => setPresionDiastolica(e.target.value)}
|
||||
placeholder="80"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="flex items-center gap-1">
|
||||
<Activity className="h-4 w-4" />FC
|
||||
</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={frecuenciaCardiaca}
|
||||
onChange={(e) => setFrecuenciaCardiaca(e.target.value)}
|
||||
placeholder="72"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="flex items-center gap-1">
|
||||
<Wind className="h-4 w-4" />FR
|
||||
</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={frecuenciaRespiratoria}
|
||||
onChange={(e) => setFrecuenciaRespiratoria(e.target.value)}
|
||||
placeholder="16"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="flex items-center gap-1">
|
||||
<Thermometer className="h-4 w-4" />T°
|
||||
</Label>
|
||||
<Input
|
||||
type="number"
|
||||
step="0.1"
|
||||
value={temperatura}
|
||||
onChange={(e) => setTemperatura(e.target.value)}
|
||||
placeholder="36.5"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="flex items-center gap-1">
|
||||
<Droplets className="h-4 w-4" />SatO2
|
||||
</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={saturacionO2}
|
||||
onChange={(e) => setSaturacionO2(e.target.value)}
|
||||
placeholder="98"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-green-50 p-3 rounded-lg border border-green-200">
|
||||
<p className="text-sm font-bold text-green-800 mb-3 flex items-center gap-2">
|
||||
<FileText className="h-4 w-4" />
|
||||
Examen Físico
|
||||
</p>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>SNC</Label>
|
||||
<textarea className="w-full p-2 border rounded-md text-sm min-h-[60px]" value={snc} onChange={(e) => setSnc(e.target.value)} placeholder="Estado neurológico" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Cardiovascular</Label>
|
||||
<textarea className="w-full p-2 border rounded-md text-sm min-h-[60px]" value={cardiovascular} onChange={(e) => setCardiovascular(e.target.value)} placeholder="Hallazgos cardiovasculares" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Respiratorio</Label>
|
||||
<textarea className="w-full p-2 border rounded-md text-sm min-h-[60px]" value={respiratorio} onChange={(e) => setRespiratorio(e.target.value)} placeholder="Hallazgos respiratorios" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Abdominal</Label>
|
||||
<textarea className="w-full p-2 border rounded-md text-sm min-h-[60px]" value={abdominal} onChange={(e) => setAbdominal(e.target.value)} placeholder="Hallazgos abdominales" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Genitourinario</Label>
|
||||
<textarea className="w-full p-2 border rounded-md text-sm min-h-[60px]" value={genitourinario} onChange={(e) => setGenitourinario(e.target.value)} placeholder="Hallazgos genitourinarios" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Piel y anexos</Label>
|
||||
<textarea className="w-full p-2 border rounded-md text-sm min-h-[60px]" value={pielAnexos} onChange={(e) => setPielAnexos(e.target.value)} placeholder="Estado de piel y anexos" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>SOMA</Label>
|
||||
<Input value={soma} onChange={(e) => setSoma(e.target.value)} placeholder="Estado SOMA" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Novedades</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
|
||||
value={novedades}
|
||||
onChange={(e) => setNovedades(e.target.value)}
|
||||
placeholder="Novedades..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Comentario</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
|
||||
value={comentario}
|
||||
onChange={(e) => setComentario(e.target.value)}
|
||||
placeholder="Comentarios adicionales..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Pendientes</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
|
||||
value={pendientes}
|
||||
onChange={(e) => setPendientes(e.target.value)}
|
||||
placeholder="Pendientes..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Médico *</Label>
|
||||
<Input
|
||||
value={medico}
|
||||
onChange={(e) => setMedico(e.target.value)}
|
||||
placeholder="Nombre del médico"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2 mt-4">
|
||||
<Button variant="outline" onClick={() => { resetFormulario(); setDialogoAbierto(false); }}>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleGuardar}
|
||||
disabled={!medico || (!evolucionEditando && !pacienteSeleccionado)}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Guardar Evolución
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
className="pl-10"
|
||||
placeholder="Buscar por paciente..."
|
||||
value={busqueda}
|
||||
onChange={(e) => setBusqueda(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="space-y-4">
|
||||
{evolucionesFiltradas.map((evolucion) => {
|
||||
const internacion = internaciones.find(i => i.id === evolucion.internacionId);
|
||||
const paciente = internacion ? getPacienteById(internacion.pacienteId) : null;
|
||||
const signosTexto = getSignosVitalesTexto(evolucion.signosVitales);
|
||||
const estaExpandida = evolucionExpandida === evolucion.id;
|
||||
|
||||
return (
|
||||
<Card key={evolucion.id} className="hover:shadow-md transition-shadow">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<FileText className="h-5 w-5 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-bold">
|
||||
{paciente ? `${paciente.apellido}, ${paciente.nombre}` : 'Paciente no encontrado'}
|
||||
</h3>
|
||||
<div className="flex items-center gap-3 text-sm text-gray-500">
|
||||
<span className="flex items-center gap-1">
|
||||
<Calendar className="h-3 w-3" />
|
||||
{evolucion.fecha}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
{evolucion.hora}
|
||||
</span>
|
||||
<Badge variant="outline">{evolucion.medico}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setEvolucionExpandida(estaExpandida ? null : evolucion.id)}
|
||||
>
|
||||
{estaExpandida ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
||||
</Button>
|
||||
{onActualizarEvolucion && (
|
||||
<Button size="sm" variant="outline" onClick={() => abrirEditar(evolucion)}>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-red-600 hover:bg-red-50"
|
||||
onClick={() => onEliminarEvolucion(evolucion.id)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{signosTexto && (
|
||||
<div className="bg-blue-50 p-2 rounded-lg">
|
||||
<p className="text-sm font-medium text-blue-800 flex items-center gap-2">
|
||||
<Activity className="h-4 w-4" />
|
||||
Signos Vitales: {signosTexto}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{estaExpandida && (
|
||||
<>
|
||||
{evolucion.examenFisico && (
|
||||
<div className="bg-green-50 p-3 rounded-lg border border-green-200">
|
||||
<p className="text-sm font-medium text-green-800 mb-2">Examen Físico:</p>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-4 gap-2 text-xs">
|
||||
{evolucion.examenFisico.SNC && <div><span className="font-medium">SNC:</span> {evolucion.examenFisico.SNC}</div>}
|
||||
{evolucion.examenFisico.Cardiovascular && <div><span className="font-medium">CV:</span> {evolucion.examenFisico.Cardiovascular}</div>}
|
||||
{evolucion.examenFisico.Respiratorio && <div><span className="font-medium">Resp:</span> {evolucion.examenFisico.Respiratorio}</div>}
|
||||
{evolucion.examenFisico.Abdominal && <div><span className="font-medium">Abd:</span> {evolucion.examenFisico.Abdominal}</div>}
|
||||
{evolucion.examenFisico.Genitourinario && <div><span className="font-medium">GU:</span> {evolucion.examenFisico.Genitourinario}</div>}
|
||||
{evolucion.examenFisico.PielAnexos && <div><span className="font-medium">Piel:</span> {evolucion.examenFisico.PielAnexos}</div>}
|
||||
{evolucion.examenFisico.SOMA && <div><span className="font-medium">SOMA:</span> {evolucion.examenFisico.SOMA}</div>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{evolucion.novedades && (
|
||||
<div className="bg-red-50 p-3 rounded-lg border border-red-200 mt-3">
|
||||
<p className="text-sm font-medium text-red-800 mb-1">Novedades:</p>
|
||||
<p className="text-sm text-gray-800 whitespace-pre-wrap">{evolucion.novedades}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{evolucion.comentario && (
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-700">Comentario:</p>
|
||||
<p className="text-sm text-gray-600 whitespace-pre-wrap">{evolucion.comentario}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{evolucion.pendientes && (
|
||||
<div className="bg-amber-50 p-3 rounded-lg border border-amber-200">
|
||||
<p className="text-sm font-medium text-amber-800 mb-1">Pendientes:</p>
|
||||
<p className="text-sm text-amber-700 whitespace-pre-wrap">{evolucion.pendientes}</p>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{evolucionesFiltradas.length === 0 && (
|
||||
<div className="text-center py-12 text-gray-400">
|
||||
<FileText className="h-16 w-16 mx-auto mb-4 opacity-50" />
|
||||
<p className="text-lg">
|
||||
{busqueda ? 'No se encontraron evoluciones con esa búsqueda' : 'No hay evoluciones registradas'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,459 @@
|
||||
import { useState } from 'react';
|
||||
import { ClipboardList, Plus, Search, Bed, Calendar, Stethoscope, LogOut, CheckCircle2 } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import type { Internacion, Paciente, Cama, Area, Evolucion, Laboratorio, Cultivo } from '@/types';
|
||||
|
||||
interface InternacionesProps {
|
||||
internaciones: Internacion[];
|
||||
pacientes: Paciente[];
|
||||
camas: Cama[];
|
||||
evoluciones?: Evolucion[];
|
||||
laboratorios?: Laboratorio[];
|
||||
cultivos?: Cultivo[];
|
||||
areas: Area[];
|
||||
onIniciarInternacion: (internacion: Omit<Internacion, 'id' | 'fechaIngreso' | 'activa'>) => void;
|
||||
onFinalizarInternacion: (internacionId: string, datos: {
|
||||
fechaEgreso: string;
|
||||
diagnosticoEgreso: string;
|
||||
motivoEgreso: Internacion['motivoEgreso']
|
||||
}) => void;
|
||||
getPacienteById: (id: string) => Paciente | undefined;
|
||||
getCamaById: (id: string) => Cama | undefined;
|
||||
onVerHC?: (internacionId: string) => void;
|
||||
}
|
||||
|
||||
export function Internaciones({
|
||||
internaciones,
|
||||
pacientes,
|
||||
camas,
|
||||
onIniciarInternacion,
|
||||
onFinalizarInternacion,
|
||||
getPacienteById,
|
||||
getCamaById,
|
||||
areas,
|
||||
onVerHC,
|
||||
}: InternacionesProps) {
|
||||
const [filtroEstado, setFiltroEstado] = useState<'todas' | 'activas' | 'finalizadas'>('todas');
|
||||
const [dialogoNuevaAbierto, setDialogoNuevaAbierto] = useState(false);
|
||||
const [dialogoEgresoAbierto, setDialogoEgresoAbierto] = useState(false);
|
||||
const [internacionSeleccionada, setInternacionSeleccionada] = useState<Internacion | null>(null);
|
||||
const [busqueda, setBusqueda] = useState('');
|
||||
const [pacienteSeleccionado, setPacienteSeleccionado] = useState<string>('');
|
||||
const [camaSeleccionada, setCamaSeleccionada] = useState<string>('');
|
||||
const [diagnosticoIngreso, setDiagnosticoIngreso] = useState('');
|
||||
const [enfermedadActual, setEnfermedadActual] = useState('');
|
||||
const [motivoConsulta, setMotivoConsulta] = useState('');
|
||||
const [antecedentesEnfermedadActual, setAntecedentesEnfermedadActual] = useState('');
|
||||
const [medicoIngresante, setMedicoIngresante] = useState('');
|
||||
|
||||
// Formulario nueva internación
|
||||
const [fechaEgreso, setFechaEgreso] = useState('');
|
||||
const [diagnosticoEgreso, setDiagnosticoEgreso] = useState('');
|
||||
const [motivoEgreso, setMotivoEgreso] = useState<Internacion['motivoEgreso']>('Alta médica');
|
||||
|
||||
const resetFormularioNueva = () => {
|
||||
setPacienteSeleccionado('');
|
||||
setCamaSeleccionada('');
|
||||
setDiagnosticoIngreso('');
|
||||
setEnfermedadActual('');
|
||||
setAntecedentesEnfermedadActual('');
|
||||
setMedicoIngresante('');
|
||||
};
|
||||
|
||||
const resetFormularioEgreso = () => {
|
||||
setFechaEgreso('');
|
||||
setDiagnosticoEgreso('');
|
||||
setMotivoEgreso('Alta médica');
|
||||
setInternacionSeleccionada(null);
|
||||
};
|
||||
|
||||
const handleIniciarInternacion = () => {
|
||||
if (pacienteSeleccionado && camaSeleccionada && motivoConsulta && enfermedadActual && medicoIngresante) {
|
||||
onIniciarInternacion({
|
||||
pacienteId: pacienteSeleccionado,
|
||||
camaId: camaSeleccionada,
|
||||
diagnosticoIngreso: diagnosticoIngreso || motivoConsulta,
|
||||
motivoConsulta,
|
||||
enfermedadActual,
|
||||
antecedentesEnfermedadActual: antecedentesEnfermedadActual || undefined,
|
||||
medicoIngresante,
|
||||
});
|
||||
resetFormularioNueva();
|
||||
setDialogoNuevaAbierto(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFinalizarInternacion = () => {
|
||||
if (internacionSeleccionada && fechaEgreso && diagnosticoEgreso && motivoEgreso) {
|
||||
onFinalizarInternacion(internacionSeleccionada.id, {
|
||||
fechaEgreso,
|
||||
diagnosticoEgreso,
|
||||
motivoEgreso,
|
||||
});
|
||||
resetFormularioEgreso();
|
||||
setDialogoEgresoAbierto(false);
|
||||
}
|
||||
};
|
||||
|
||||
const internacionesFiltradas = internaciones.filter(i => {
|
||||
const paciente = getPacienteById(i.pacienteId);
|
||||
const cumpleBusqueda = !busqueda ||
|
||||
(paciente && (
|
||||
paciente.nombre.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
paciente.apellido.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
paciente.dni.includes(busqueda)
|
||||
));
|
||||
|
||||
const cumpleEstado = filtroEstado === 'todas' ||
|
||||
(filtroEstado === 'activas' && i.activa) ||
|
||||
(filtroEstado === 'finalizadas' && !i.activa);
|
||||
|
||||
return cumpleBusqueda && cumpleEstado;
|
||||
}).sort((a, b) => new Date(b.fechaIngreso).getTime() - new Date(a.fechaIngreso).getTime());
|
||||
|
||||
const pacientesSinInternar = pacientes.filter(p => {
|
||||
const internacionActiva = internaciones.find(i => i.pacienteId === p.id && i.activa);
|
||||
return !internacionActiva;
|
||||
});
|
||||
const camasDisponibles = camas.filter(c => c.estado === 'Disponible');
|
||||
const getAreaName = (areaId?: string) => areas.find(a => a.id === areaId)?.nombre;
|
||||
|
||||
const abrirDialogoEgreso = (internacion: Internacion) => {
|
||||
setInternacionSeleccionada(internacion);
|
||||
setFechaEgreso(new Date().toISOString().split('T')[0]);
|
||||
setDialogoEgresoAbierto(true);
|
||||
};
|
||||
|
||||
// Ver Historia Clínica (navegar a página)
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Internaciones</h1>
|
||||
<p className="text-gray-500">Gestión de internaciones en sala</p>
|
||||
</div>
|
||||
<Dialog open={dialogoNuevaAbierto} onOpenChange={setDialogoNuevaAbierto}>
|
||||
<DialogTrigger asChild>
|
||||
<Button onClick={resetFormularioNueva}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Nuevo Ingreso
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Nuevo Ingreso</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Paciente *</Label>
|
||||
{!pacienteSeleccionado ? (
|
||||
<>
|
||||
<Input
|
||||
placeholder="Buscar por apellido, nombre o DNI"
|
||||
value={busqueda}
|
||||
onChange={(e) => setBusqueda(e.target.value)}
|
||||
className="mb-2"
|
||||
/>
|
||||
<div className="max-h-48 overflow-auto border rounded-md">
|
||||
{(() => {
|
||||
const q = busqueda.trim().toLowerCase();
|
||||
if (!q) {
|
||||
return (
|
||||
<div className="p-2 text-sm text-gray-500">Escribe apellido, nombre o DNI para buscar</div>
|
||||
);
|
||||
}
|
||||
const matches = pacientesSinInternar.filter(p => (
|
||||
p.apellido.toLowerCase().includes(q) ||
|
||||
p.nombre.toLowerCase().includes(q) ||
|
||||
p.dni.includes(q)
|
||||
));
|
||||
if (matches.length === 0) {
|
||||
return <div className="p-2 text-sm text-gray-500">No se encontraron pacientes coincidentes</div>;
|
||||
}
|
||||
return matches.map(p => (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
onClick={() => setPacienteSeleccionado(p.id)}
|
||||
className={`w-full text-left p-2 hover:bg-gray-50 ${pacienteSeleccionado === p.id ? 'bg-gray-100' : ''}`}
|
||||
>
|
||||
{p.apellido}, {p.nombre} — DNI: {p.dni}
|
||||
</button>
|
||||
));
|
||||
})()}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge className="bg-gray-100 text-gray-800 px-3 py-1">
|
||||
{(() => {
|
||||
const p = pacientes.find(x => x.id === pacienteSeleccionado);
|
||||
return p ? `${p.apellido}, ${p.nombre} — DNI: ${p.dni}` : '';
|
||||
})()}
|
||||
</Badge>
|
||||
<Button size="sm" variant="ghost" onClick={() => setPacienteSeleccionado('')}>Cambiar</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<Label>Cama *</Label>
|
||||
<Select value={camaSeleccionada} onValueChange={setCamaSeleccionada}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Seleccionar cama" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{camasDisponibles.map(c => (
|
||||
<SelectItem key={c.id} value={c.id}>
|
||||
{c.numero} - {getAreaName(c.areaId) || 'Sin área'} ({c.tipo})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Motivo de Consulta *</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
|
||||
value={motivoConsulta}
|
||||
onChange={(e) => setMotivoConsulta(e.target.value)}
|
||||
placeholder="Motivo de consulta..."
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Enfermedad Actual *</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[100px]"
|
||||
value={enfermedadActual}
|
||||
onChange={(e) => setEnfermedadActual(e.target.value)}
|
||||
placeholder="Describa la enfermedad actual..."
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Antecedentes de Enfermedad Actual</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md tex</p>
|
||||
</div>t-sm min-h-[80px]"
|
||||
value={antecedentesEnfermedadActual}
|
||||
onChange={(e) => setAntecedentesEnfermedadActual(e.target.value)}
|
||||
placeholder="Antecedentes relevantes de la enfermedad actual..."
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Médico Ingresante *</Label>
|
||||
<Input
|
||||
value={medicoIngresante}
|
||||
onChange={(e) => setMedicoIngresante(e.target.value)}
|
||||
placeholder="Nombre del médico ingresante"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
className="w-full"
|
||||
onClick={handleIniciarInternacion}
|
||||
disabled={!pacienteSeleccionado || !camaSeleccionada || !motivoConsulta || !enfermedadActual || !medicoIngresante}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Iniciar Internación
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
{/* Filtros */}
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div className="relative sm:col-span-2">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
className="pl-10"
|
||||
placeholder="Buscar paciente..."
|
||||
value={busqueda}
|
||||
onChange={(e) => setBusqueda(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Select value={filtroEstado} onValueChange={(v: 'todas' | 'activas' | 'finalizadas') => setFiltroEstado(v)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Filtrar por estado" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="todas">Todas las internaciones</SelectItem>
|
||||
<SelectItem value="activas">Internaciones activas</SelectItem>
|
||||
<SelectItem value="finalizadas">Internaciones finalizadas</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Lista de Internaciones */}
|
||||
<div className="space-y-4">
|
||||
{internacionesFiltradas.map((internacion) => {
|
||||
const paciente = getPacienteById(internacion.pacienteId);
|
||||
const cama = getCamaById(internacion.camaId);
|
||||
|
||||
return (
|
||||
<Card key={internacion.id} className="hover:shadow-md transition-shadow">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex flex-col lg:flex-row lg:items-start lg:justify-between gap-4">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className={`h-12 w-12 rounded-full flex items-center justify-center flex-shrink-0 ${
|
||||
internacion.activa ? 'bg-purple-100' : 'bg-gray-100'
|
||||
}`}>
|
||||
{internacion.activa ? (
|
||||
<ClipboardList className="h-6 w-6 text-purple-600" />
|
||||
) : (
|
||||
<CheckCircle2 className="h-6 w-6 text-gray-600" />
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<h3 className="font-bold text-lg">
|
||||
{paciente ? `${paciente.apellido}, ${paciente.nombre}` : 'Paciente no encontrado'}
|
||||
</h3>
|
||||
<Badge className={internacion.activa ? 'bg-purple-100 text-purple-800' : 'bg-gray-100 text-gray-800'}>
|
||||
{internacion.activa ? 'Activa' : 'Finalizada'}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 gap-x-4 gap-y-2 mt-3 text-sm">
|
||||
<div className="flex items-center gap-2 text-gray-600">
|
||||
<Bed className="h-4 w-4" />
|
||||
<span>Cama {cama?.numero || '-'} ({getAreaName(cama?.areaId) || 'Sin área'})
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-gray-600">
|
||||
<Calendar className="h-4 w-4" />
|
||||
<span>Ingreso: {internacion.fechaIngreso}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-gray-600">
|
||||
<Stethoscope className="h-4 w-4" />
|
||||
<span className="truncate">{internacion.medicoIngresante}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-2">
|
||||
<p className="text-sm text-gray-600">
|
||||
<span className="font-medium">Diagnóstico de ingreso:</span>{' '}
|
||||
{internacion.diagnosticoIngreso}
|
||||
</p>
|
||||
</div>
|
||||
{!internacion.activa && internacion.fechaEgreso && (
|
||||
<div className="mt-2 space-y-1">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-600">
|
||||
<LogOut className="h-4 w-4" />
|
||||
<span>Egreso: {internacion.fechaEgreso}</span>
|
||||
</div>
|
||||
<p className="text-sm text-gray-600">
|
||||
<span className="font-medium">Diagnóstico de egreso:</span>{' '}
|
||||
{internacion.diagnosticoEgreso}
|
||||
</p>
|
||||
<p className="text-sm text-gray-600">
|
||||
<span className="font-medium">Motivo:</span>{' '}
|
||||
{internacion.motivoEgreso}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{internacion.activa && (
|
||||
<Dialog open={dialogoEgresoAbierto && internacionSeleccionada?.id === internacion.id} onOpenChange={setDialogoEgresoAbierto}>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="whitespace-nowrap"
|
||||
onClick={() => abrirDialogoEgreso(internacion)}
|
||||
>
|
||||
<LogOut className="h-4 w-4 mr-2" />
|
||||
Registrar Egreso
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Dar Alta</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Paciente</Label>
|
||||
<Input
|
||||
value={paciente ? `${paciente.apellido}, ${paciente.nombre}` : ''}
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Fecha de Egreso *</Label>
|
||||
<Input
|
||||
type="date"
|
||||
value={fechaEgreso}
|
||||
onChange={(e) => setFechaEgreso(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Motivo de Egreso *</Label>
|
||||
<Select value={motivoEgreso} onValueChange={(v) => setMotivoEgreso(v as Internacion['motivoEgreso'])}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="Alta médica">Alta médica</SelectItem>
|
||||
<SelectItem value="Alta voluntaria">Alta voluntaria</SelectItem>
|
||||
<SelectItem value="Derivación">Derivación</SelectItem>
|
||||
<SelectItem value="Fallecimiento">Fallecimiento</SelectItem>
|
||||
<SelectItem value="Otro">Otro</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Diagnóstico de Egreso *</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
|
||||
value={diagnosticoEgreso}
|
||||
onChange={(e) => setDiagnosticoEgreso(e.target.value)}
|
||||
placeholder="Ingrese el diagnóstico de egreso..."
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
className="w-full"
|
||||
onClick={handleFinalizarInternacion}
|
||||
disabled={!fechaEgreso || !diagnosticoEgreso || !motivoEgreso}
|
||||
>
|
||||
<CheckCircle2 className="h-4 w-4 mr-2" />
|
||||
Confirmar Egreso
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
|
||||
<Button onClick={() => { if (typeof onVerHC === 'function') onVerHC(internacion.id); }}>Ver HC</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{internacionesFiltradas.length === 0 && (
|
||||
<div className="text-center py-12 text-gray-400">
|
||||
<ClipboardList className="h-16 w-16 mx-auto mb-4 opacity-50" />
|
||||
<p className="text-lg">
|
||||
{busqueda || filtroEstado !== 'todas'
|
||||
? 'No se encontraron internaciones con esos filtros'
|
||||
: 'No hay internaciones registradas'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{/* Historia Clínica ahora es una página separada */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Bed,
|
||||
Users,
|
||||
ClipboardList,
|
||||
FileText,
|
||||
FlaskConical,
|
||||
Activity,
|
||||
Microscope,
|
||||
Menu
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet';
|
||||
import type { Vista } from '@/types';
|
||||
|
||||
interface LayoutProps {
|
||||
children: React.ReactNode;
|
||||
vistaActual: Vista;
|
||||
onCambiarVista: (vista: Vista) => void;
|
||||
}
|
||||
|
||||
const menuItems: { vista: Vista; label: string; icon: React.ElementType }[] = [
|
||||
{ vista: 'dashboard', label: 'Dashboard', icon: LayoutDashboard },
|
||||
{ vista: 'camas', label: 'Mapa de Camas', icon: Bed },
|
||||
{ vista: 'pacientes', label: 'Pacientes', icon: Users },
|
||||
{ vista: 'internaciones', label: 'Internaciones', icon: ClipboardList },
|
||||
{ vista: 'evoluciones', label: 'Evoluciones', icon: FileText },
|
||||
//{ vista: 'laboratorios', label: 'Laboratorios', icon: FlaskConical },
|
||||
{ vista: 'acidobase', label: 'Ácido-Base', icon: Activity },
|
||||
{ vista: 'cultivos', label: 'Cultivos', icon: Microscope },
|
||||
];
|
||||
|
||||
export function Layout({ children, vistaActual, onCambiarVista }: LayoutProps) {
|
||||
const NavContent = () => (
|
||||
<nav className="flex flex-col gap-2">
|
||||
{menuItems.map((item) => {
|
||||
const Icon = item.icon;
|
||||
const isActive = vistaActual === item.vista;
|
||||
return (
|
||||
<Button
|
||||
key={item.vista}
|
||||
variant={isActive ? 'default' : 'ghost'}
|
||||
className={`justify-start gap-3 ${isActive ? 'bg-blue-600 hover:bg-blue-700' : 'hover:bg-gray-100'}`}
|
||||
onClick={() => onCambiarVista(item.vista)}
|
||||
>
|
||||
<Icon className="h-5 w-5" />
|
||||
<span>{item.label}</span>
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50 flex">
|
||||
{/* Sidebar Desktop */}
|
||||
<aside className="hidden lg:flex w-64 flex-col bg-white border-r border-gray-200 fixed h-full">
|
||||
<div className="p-6 border-b border-gray-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 bg-blue-600 rounded-lg flex items-center justify-center">
|
||||
<Activity className="h-6 w-6 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="font-bold text-lg text-gray-900 leading-tight">Gestion Historia Clinica Electronica</h1>
|
||||
<p className="text-xs text-gray-500">Servicio Clinica Medica - Hospital Santojanni</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 p-4 overflow-auto">
|
||||
<NavContent />
|
||||
</div>
|
||||
<div className="p-4 border-t border-gray-200 text-xs text-gray-400 text-center">
|
||||
v1.0.0
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* Header Mobile */}
|
||||
<header className="lg:hidden fixed top-0 left-0 right-0 h-16 bg-white border-b border-gray-200 z-50 flex items-center justify-between px-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-8 w-8 bg-blue-600 rounded-lg flex items-center justify-center">
|
||||
<Activity className="h-5 w-5 text-white" />
|
||||
</div>
|
||||
<span className="font-bold text-gray-900">Gestion Historia Clinica Electronica</span>
|
||||
</div>
|
||||
<Sheet>
|
||||
<SheetTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<Menu className="h-6 w-6" />
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="right" className="w-64 p-0">
|
||||
<div className="p-6 border-b border-gray-200">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-bold text-lg">Menú</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<NavContent />
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
</header>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="flex-1 lg:ml-64 pt-16 lg:pt-0 min-h-screen">
|
||||
<div className="p-4 lg:p-8 max-w-7xl mx-auto">
|
||||
{children}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,606 @@
|
||||
import { useState } from 'react';
|
||||
import { Bed, CheckCircle2, Clock, Wrench, User, Plus, Trash, Edit2 } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import type { Cama, Paciente, Internacion, Area } from '@/types';
|
||||
|
||||
interface MapaCamasProps {
|
||||
camas: Cama[];
|
||||
areas: Area[];
|
||||
pacientes: Paciente[];
|
||||
internaciones: Internacion[];
|
||||
onActualizarCama: (id: string, datos: Partial<Cama>) => void;
|
||||
onAgregarCama: (cama: Omit<Cama, 'id'>) => string;
|
||||
onEliminarCama: (id: string) => void;
|
||||
onIniciarInternacion: (internacion: Omit<Internacion, 'id' | 'fechaIngreso' | 'activa'>) => void;
|
||||
onAgregarArea: (area: Omit<Area, 'id'>) => string;
|
||||
onActualizarArea: (id: string, datos: Partial<Area>) => void;
|
||||
onEliminarArea: (id: string) => void;
|
||||
getPacienteById: (id: string) => Paciente | undefined;
|
||||
getInternacionById: (id: string) => Internacion | undefined;
|
||||
}
|
||||
|
||||
export function MapaCamas({
|
||||
camas,
|
||||
areas,
|
||||
pacientes,
|
||||
internaciones,
|
||||
onActualizarCama,
|
||||
onAgregarCama,
|
||||
onEliminarCama,
|
||||
onIniciarInternacion,
|
||||
onAgregarArea,
|
||||
onActualizarArea,
|
||||
onEliminarArea,
|
||||
getPacienteById,
|
||||
getInternacionById
|
||||
}: MapaCamasProps) {
|
||||
const [filtroSala, setFiltroSala] = useState<string>('todas');
|
||||
const [filtroTipo, setFiltroTipo] = useState<string>('todos');
|
||||
const [filtroEstado, setFiltroEstado] = useState<string>('todos');
|
||||
const [camaSeleccionada, setCamaSeleccionada] = useState<Cama | null>(null);
|
||||
const [pacienteSeleccionado, setPacienteSeleccionado] = useState<string>('');
|
||||
const [diagnostico, setDiagnostico] = useState('');
|
||||
const [enfermedadActual, setEnfermedadActual] = useState('');
|
||||
const [antecedentesEnfermedadActual, setAntecedentesEnfermedadActual] = useState('');
|
||||
const [medico, setMedico] = useState('');
|
||||
const [dialogoAbierto, setDialogoAbierto] = useState(false);
|
||||
// Area dialog state
|
||||
const [areaDialogOpen, setAreaDialogOpen] = useState(false);
|
||||
const [areaNombre, setAreaNombre] = useState('');
|
||||
const [editingAreaId, setEditingAreaId] = useState<string | null>(null);
|
||||
|
||||
// Cama dialog state
|
||||
const [bedDialogOpen, setBedDialogOpen] = useState(false);
|
||||
const [editingBed, setEditingBed] = useState<Cama | null>(null);
|
||||
const [bedNumero, setBedNumero] = useState('');
|
||||
const [bedTipo, setBedTipo] = useState<Cama['tipo']>('General');
|
||||
const [bedAreaId, setBedAreaId] = useState<string | undefined>(undefined);
|
||||
|
||||
const salas = Array.from(new Set(camas.map(c => c.areaId).filter(Boolean))) as string[];
|
||||
const areaById = Object.fromEntries(areas.map(a => [a.id, a.nombre]));
|
||||
const tipos = Array.from(new Set(camas.map(c => c.tipo)));
|
||||
|
||||
const camasFiltradas = camas.filter(cama => {
|
||||
if (filtroSala !== 'todas' && cama.areaId !== filtroSala) return false;
|
||||
if (filtroTipo !== 'todos' && cama.tipo !== filtroTipo) return false;
|
||||
if (filtroEstado !== 'todos' && cama.estado !== filtroEstado) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
const getEstadoColor = (cama: Cama) => {
|
||||
if (cama.estado === 'Disponible') {
|
||||
return 'bg-green-100 border-green-300 text-green-800';
|
||||
}
|
||||
if (cama.estado === 'Reservada') {
|
||||
return 'bg-orange-100 border-orange-300 text-orange-800';
|
||||
}
|
||||
if (cama.estado === 'Ocupada') {
|
||||
// Tipos de aislamiento
|
||||
const aislamientos = ['Aislamiento KPC', 'Aislamiento COVID', 'Aislamiento Clostridium', 'Aislamiento Neutropenico'];
|
||||
if (aislamientos.includes(cama.tipo)) {
|
||||
return 'bg-red-100 border-red-300 text-red-800';
|
||||
}
|
||||
return 'bg-blue-100 border-blue-300 text-blue-800';
|
||||
}
|
||||
return 'bg-amber-100 border-amber-300 text-amber-800';
|
||||
};
|
||||
|
||||
const getEstadoIcono = (cama: Cama) => {
|
||||
switch (cama.estado) {
|
||||
case 'Disponible': return <CheckCircle2 className="h-5 w-5" />;
|
||||
case 'Ocupada': return <User className="h-5 w-5" />;
|
||||
case 'Reparacion': return <Wrench className="h-5 w-5" />;
|
||||
case 'Reservada': return <Clock className="h-5 w-5" />;
|
||||
}
|
||||
};
|
||||
|
||||
const parseBedNumber = (numero: string) => {
|
||||
const match = numero.match(/^(\d{3})-(\d+)$/);
|
||||
if (!match) return { sala: 0, cama: 0 };
|
||||
return {
|
||||
sala: parseInt(match[1]),
|
||||
cama: parseInt(match[2])
|
||||
};
|
||||
};
|
||||
|
||||
const sortedCamas = [...camasFiltradas].sort((a, b) => {
|
||||
const pa = parseBedNumber(a.numero);
|
||||
const pb = parseBedNumber(b.numero);
|
||||
|
||||
if (pa.sala >= 200 && pa.sala < 300) {
|
||||
const salaImpar = [221, 217, 215, 213, 209, 205, 203, 201];
|
||||
const salaPar = [204, 214];
|
||||
|
||||
if (salaImpar.includes(pa.sala)) {
|
||||
if (salaImpar.includes(pb.sala)) {
|
||||
if (pa.sala === pb.sala) {
|
||||
return pa.cama - pb.cama;
|
||||
}
|
||||
return salaImpar.indexOf(pa.sala) - salaImpar.indexOf(pb.sala);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (salaImpar.includes(pb.sala)) return 1;
|
||||
|
||||
if (salaPar.includes(pa.sala)) {
|
||||
if (salaPar.includes(pb.sala)) {
|
||||
if (pa.sala === pb.sala) {
|
||||
return pa.cama - pb.cama;
|
||||
}
|
||||
return pa.sala - pb.sala;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (salaPar.includes(pb.sala)) return 1;
|
||||
|
||||
return pa.cama - pb.cama;
|
||||
}
|
||||
|
||||
if (pa.sala >= 300 && pa.sala < 400) {
|
||||
const salaPiso3 = [308, 310, 312];
|
||||
if (salaPiso3.includes(pa.sala)) {
|
||||
if (salaPiso3.includes(pb.sala)) {
|
||||
if (pa.sala === pb.sala) {
|
||||
return pa.cama - pb.cama;
|
||||
}
|
||||
return salaPiso3.indexOf(pa.sala) - salaPiso3.indexOf(pb.sala);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (salaPiso3.includes(pb.sala)) return 1;
|
||||
return pa.cama - pb.cama;
|
||||
}
|
||||
|
||||
return a.numero.localeCompare(b.numero);
|
||||
});
|
||||
|
||||
const handleOcuparCama = () => {
|
||||
if (camaSeleccionada && pacienteSeleccionado && diagnostico && enfermedadActual && medico) {
|
||||
onIniciarInternacion({
|
||||
pacienteId: pacienteSeleccionado,
|
||||
camaId: camaSeleccionada.id,
|
||||
diagnosticoIngreso: diagnostico,
|
||||
enfermedadActual,
|
||||
antecedentesEnfermedadActual: antecedentesEnfermedadActual || undefined,
|
||||
medicoIngresante: medico,
|
||||
});
|
||||
setDialogoAbierto(false);
|
||||
setCamaSeleccionada(null);
|
||||
setPacienteSeleccionado('');
|
||||
setDiagnostico('');
|
||||
setEnfermedadActual('');
|
||||
setAntecedentesEnfermedadActual('');
|
||||
setMedico('');
|
||||
}
|
||||
};
|
||||
|
||||
const handleCambiarEstado = (cama: Cama, nuevoEstado: Cama['estado']) => {
|
||||
onActualizarCama(cama.id, { estado: nuevoEstado });
|
||||
};
|
||||
|
||||
const pacientesSinInternar = pacientes.filter(p => {
|
||||
const internacionActiva = internaciones.find(i => i.pacienteId === p.id && i.activa);
|
||||
return !internacionActiva;
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Mapa de Camas</h1>
|
||||
<p className="text-gray-500">Gestión de camas del servicio</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="outline" className="bg-green-50 text-green-700">
|
||||
{camas.filter(c => c.estado === 'Disponible').length} Disponibles
|
||||
</Badge>
|
||||
<Badge variant="outline" className="bg-red-50 text-red-700">
|
||||
{camas.filter(c => c.estado === 'Ocupada').length} Ocupadas
|
||||
</Badge>
|
||||
<div className="ml-4 flex items-center gap-2">
|
||||
<Button onClick={() => {
|
||||
setEditingAreaId(null);
|
||||
setAreaNombre('');
|
||||
setAreaDialogOpen(true);
|
||||
}}>
|
||||
Administrar Áreas
|
||||
</Button>
|
||||
<Button onClick={() => {
|
||||
setEditingBed(null);
|
||||
setBedNumero('');
|
||||
setBedTipo('General');
|
||||
setBedAreaId(areas?.[0]?.id);
|
||||
setBedDialogOpen(true);
|
||||
}}>
|
||||
<Plus className="h-4 w-4 mr-1" />Agregar Cama
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filtros */}
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<Label className="text-xs text-gray-500 mb-1 block">Área</Label>
|
||||
<Select value={filtroSala} onValueChange={setFiltroSala}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Todas las áreas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="todas">Todas las áreas</SelectItem>
|
||||
{salas.map(sala => (
|
||||
<SelectItem key={sala} value={sala}>{areaById[sala] ?? sala}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-gray-500 mb-1 block">Tipo</Label>
|
||||
<Select value={filtroTipo} onValueChange={setFiltroTipo}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Todos los tipos" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="todos">Todos los tipos</SelectItem>
|
||||
{tipos.map(tipo => (
|
||||
<SelectItem key={tipo} value={tipo}>{tipo}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-gray-500 mb-1 block">Estado</Label>
|
||||
<Select value={filtroEstado} onValueChange={setFiltroEstado}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Todos los estados" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="todos">Todos los estados</SelectItem>
|
||||
<SelectItem value="Disponible">Disponible</SelectItem>
|
||||
<SelectItem value="Ocupada">Ocupada</SelectItem>
|
||||
<SelectItem value="Mantenimiento">Mantenimiento</SelectItem>
|
||||
<SelectItem value="Reservada">Reservada</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Mapa de Camas */}
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
|
||||
{sortedCamas.map((cama) => {
|
||||
const paciente = cama.pacienteId ? getPacienteById(cama.pacienteId) : null;
|
||||
const internacion = cama.internacionId ? getInternacionById(cama.internacionId) : null;
|
||||
|
||||
return (
|
||||
<Dialog key={cama.id}>
|
||||
<DialogTrigger asChild>
|
||||
<Card
|
||||
className={`cursor-pointer hover:shadow-md transition-shadow border-2 ${getEstadoColor(cama)}`}
|
||||
onClick={() => setCamaSeleccionada(cama)}
|
||||
>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<Bed className="h-6 w-6" />
|
||||
{getEstadoIcono(cama)}
|
||||
</div>
|
||||
<p className="font-bold text-lg">{cama.numero}</p>
|
||||
<p className="text-xs opacity-75">{cama.areaId ? areaById[cama.areaId] ?? 'Área desconocida' : 'Sin área'}</p>
|
||||
<Badge variant="outline" className="mt-2 text-xs bg-white/50">
|
||||
{cama.tipo}
|
||||
</Badge>
|
||||
{cama.estado === 'Ocupada' && paciente && (
|
||||
<div className="mt-2 pt-2 border-t border-current/20">
|
||||
<p className="text-xs font-medium truncate">
|
||||
{paciente.apellido}, {paciente.nombre}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
</CardContent>
|
||||
</Card>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Bed className="h-5 w-5" />
|
||||
Cama {cama.numero} - {cama.areaId ? areaById[cama.areaId] ?? 'Área desconocida' : 'Sin área'}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge className={getEstadoColor(cama)}>
|
||||
{cama.estado}
|
||||
</Badge>
|
||||
<Badge variant="outline">{cama.tipo}</Badge>
|
||||
</div>
|
||||
|
||||
{cama.estado === 'Ocupada' && paciente && internacion && (
|
||||
<div className="bg-gray-50 p-4 rounded-lg space-y-2">
|
||||
<p className="font-medium">Paciente:</p>
|
||||
<p className="text-lg">{paciente.apellido}, {paciente.nombre}</p>
|
||||
<p className="text-sm text-gray-500">DNI: {paciente.dni}</p>
|
||||
<p className="text-sm text-gray-500">Ingreso: {internacion.fechaIngreso}</p>
|
||||
<p className="text-sm text-gray-500">Diagnóstico: {internacion.diagnosticoIngreso}</p>
|
||||
<p className="text-sm text-gray-500">Médico: {internacion.medicoIngresante}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<p className="font-medium">Acciones:</p>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{cama.estado === 'Disponible' && (
|
||||
<Dialog open={dialogoAbierto} onOpenChange={setDialogoAbierto}>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
className="w-full"
|
||||
onClick={() => {
|
||||
setCamaSeleccionada(cama);
|
||||
setDialogoAbierto(true);
|
||||
}}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1" />
|
||||
Ocupar
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Nueva Internación - Cama {cama.numero}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Paciente *</Label>
|
||||
<Select value={pacienteSeleccionado} onValueChange={setPacienteSeleccionado}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Seleccionar paciente" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{pacientesSinInternar.map(p => (
|
||||
<SelectItem key={p.id} value={p.id}>
|
||||
{p.apellido}, {p.nombre} - DNI: {p.dni}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Diagnóstico de Ingreso *</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm"
|
||||
rows={3}
|
||||
value={diagnostico}
|
||||
onChange={(e) => setDiagnostico(e.target.value)}
|
||||
placeholder="Ingrese el diagnóstico..."
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Enfermedad Actual *</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm"
|
||||
rows={4}
|
||||
value={enfermedadActual}
|
||||
onChange={(e) => setEnfermedadActual(e.target.value)}
|
||||
placeholder="Describa la enfermedad actual..."
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Antecedentes de Enfermedad Actual</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm"
|
||||
rows={3}
|
||||
value={antecedentesEnfermedadActual}
|
||||
onChange={(e) => setAntecedentesEnfermedadActual(e.target.value)}
|
||||
placeholder="Antecedentes relevantes..."
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Médico Tratante *</Label>
|
||||
<input
|
||||
type="text"
|
||||
className="w-full p-2 border rounded-md text-sm"
|
||||
value={medico}
|
||||
onChange={(e) => setMedico(e.target.value)}
|
||||
placeholder="Nombre del médico..."
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
className="w-full"
|
||||
onClick={handleOcuparCama}
|
||||
disabled={!pacienteSeleccionado || !diagnostico || !enfermedadActual || !medico}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1" />
|
||||
Iniciar Internación
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
|
||||
{cama.estado !== 'Disponible' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={() => handleCambiarEstado(cama, 'Disponible')}
|
||||
>
|
||||
<CheckCircle2 className="h-4 w-4 mr-1" />
|
||||
Disponible
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{cama.estado !== 'Reparacion' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={() => handleCambiarEstado(cama, 'Reparacion')}
|
||||
>
|
||||
<Wrench className="h-4 w-4 mr-1" />
|
||||
Reparacion
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{cama.estado !== 'Reservada' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={() => handleCambiarEstado(cama, 'Reservada')}
|
||||
>
|
||||
<Clock className="h-4 w-4 mr-1" />
|
||||
Reservar
|
||||
</Button>
|
||||
)}
|
||||
|
||||
|
||||
<Button variant="outline" onClick={() => {
|
||||
setEditingBed(cama);
|
||||
setBedNumero(cama.numero);
|
||||
setBedTipo(cama.tipo);
|
||||
setBedAreaId(cama.areaId);
|
||||
setBedDialogOpen(true);
|
||||
}}>
|
||||
<Edit2 className="h-4 w-4 mr-1" />Editar
|
||||
</Button>
|
||||
<Button variant="destructive" onClick={() => {
|
||||
if (confirm('Eliminar esta cama?')) {
|
||||
onEliminarCama(cama.id);
|
||||
}
|
||||
}}>
|
||||
<Trash className="h-4 w-4 mr-1" />Eliminar
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Area dialog */}
|
||||
<Dialog open={areaDialogOpen} onOpenChange={setAreaDialogOpen}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editingAreaId ? 'Editar Área' : 'Nueva Área'}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Nombre</Label>
|
||||
<Input value={areaNombre} onChange={(e) => setAreaNombre(e.target.value)} />
|
||||
</div>
|
||||
<div className="flex gap-2 justify-end">
|
||||
{editingAreaId && (
|
||||
<Button variant="destructive" onClick={() => { if (confirm('Eliminar área?')) { onEliminarArea(editingAreaId); setAreaDialogOpen(false); } }}>
|
||||
Eliminar
|
||||
</Button>
|
||||
)}
|
||||
<Button onClick={() => setAreaDialogOpen(false)}>Cancelar</Button>
|
||||
<Button onClick={() => {
|
||||
if (!areaNombre.trim()) return alert('Nombre requerido');
|
||||
if (editingAreaId) onActualizarArea(editingAreaId, { nombre: areaNombre });
|
||||
else onAgregarArea({ nombre: areaNombre });
|
||||
setAreaDialogOpen(false);
|
||||
}}>Guardar</Button>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium">Áreas existentes</p>
|
||||
<div className="mt-2 space-y-2">
|
||||
{areas.map(a => (
|
||||
<div key={a.id} className="flex items-center justify-between">
|
||||
<div>{a.nombre}</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="ghost" onClick={() => { setEditingAreaId(a.id); setAreaNombre(a.nombre); }}>
|
||||
Editar
|
||||
</Button>
|
||||
<Button variant="destructive" onClick={() => { if (confirm('Eliminar área?')) onEliminarArea(a.id); }}>
|
||||
Eliminar
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Bed dialog */}
|
||||
<Dialog open={bedDialogOpen} onOpenChange={setBedDialogOpen}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editingBed ? `Editar Cama ${editingBed.numero}` : 'Nueva Cama'}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Número</Label>
|
||||
<Input value={bedNumero} onChange={(e) => setBedNumero(e.target.value)} />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Tipo</Label>
|
||||
<Select value={bedTipo} onValueChange={(v) => setBedTipo(v as Cama['tipo'])}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="General">General</SelectItem>
|
||||
<SelectItem value="Aislamiento KPC">Aislamiento KPC</SelectItem>
|
||||
<SelectItem value="Aislamiento COVID">Aislamiento COVID</SelectItem>
|
||||
<SelectItem value="Aislamiento Clostridium">Aislamiento Clostridium</SelectItem>
|
||||
<SelectItem value="Aislamiento Neutropenico">Aislamiento Neutropenico</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Área</Label>
|
||||
<Select value={bedAreaId ?? '__none'} onValueChange={(v) => setBedAreaId(v === '__none' ? undefined : v)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Seleccione área" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__none">Sin área</SelectItem>
|
||||
{areas.map(a => (
|
||||
<SelectItem key={a.id} value={a.id}>{a.nombre}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex gap-2 justify-end">
|
||||
{editingBed && (
|
||||
<Button variant="destructive" onClick={() => { if (confirm('Eliminar cama?')) { onEliminarCama(editingBed.id); setBedDialogOpen(false); } }}>
|
||||
Eliminar
|
||||
</Button>
|
||||
)}
|
||||
<Button onClick={() => setBedDialogOpen(false)}>Cancelar</Button>
|
||||
<Button onClick={() => {
|
||||
if (!bedNumero.trim()) return alert('Número requerido');
|
||||
if (editingBed) {
|
||||
onActualizarCama(editingBed.id, { numero: bedNumero, tipo: bedTipo, areaId: bedAreaId });
|
||||
} else {
|
||||
onAgregarCama({ numero: bedNumero, tipo: bedTipo, estado: 'Disponible', areaId: bedAreaId });
|
||||
}
|
||||
setBedDialogOpen(false);
|
||||
}}>Guardar</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{camasFiltradas.length === 0 && (
|
||||
<div className="text-center py-12 text-gray-400">
|
||||
<Bed className="h-16 w-16 mx-auto mb-4 opacity-50" />
|
||||
<p className="text-lg">No se encontraron camas con los filtros seleccionados</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
import { useState } from 'react';
|
||||
import { Users, Plus, Search, Edit2, Trash2, User, Calendar, Phone, Mail, Droplet, AlertTriangle } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
import type { Paciente } from '@/types';
|
||||
|
||||
interface PacientesProps {
|
||||
pacientes: Paciente[];
|
||||
internaciones: { id: string; pacienteId: string; activa: boolean }[];
|
||||
onAgregar: (paciente: Omit<Paciente, 'id' | 'fechaRegistro'>) => void;
|
||||
onActualizar: (id: string, datos: Partial<Paciente>) => void;
|
||||
onEliminar: (id: string) => void;
|
||||
}
|
||||
|
||||
export function Pacientes({
|
||||
pacientes,
|
||||
internaciones,
|
||||
onAgregar,
|
||||
onActualizar,
|
||||
onEliminar
|
||||
}: PacientesProps) {
|
||||
const [busqueda, setBusqueda] = useState('');
|
||||
const [dialogoAbierto, setDialogoAbierto] = useState(false);
|
||||
const [pacienteEditando, setPacienteEditando] = useState<Paciente | null>(null);
|
||||
|
||||
// Formulario
|
||||
const [nombre, setNombre] = useState('');
|
||||
const [apellido, setApellido] = useState('');
|
||||
const [dni, setDni] = useState('');
|
||||
const [fechaNacimiento, setFechaNacimiento] = useState('');
|
||||
const [sexo, setSexo] = useState<'M' | 'F' | 'Otro'>('M');
|
||||
const [telefono, setTelefono] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [direccion, setDireccion] = useState('');
|
||||
const [grupoSanguineo, setGrupoSanguineo] = useState('');
|
||||
const [alergias, setAlergias] = useState('');
|
||||
const [antecedentes, setAntecedentes] = useState('');
|
||||
|
||||
const resetFormulario = () => {
|
||||
setNombre('');
|
||||
setApellido('');
|
||||
setDni('');
|
||||
setFechaNacimiento('');
|
||||
setSexo('M');
|
||||
setTelefono('');
|
||||
setEmail('');
|
||||
setDireccion('');
|
||||
setGrupoSanguineo('');
|
||||
setAlergias('');
|
||||
setAntecedentes('');
|
||||
setPacienteEditando(null);
|
||||
};
|
||||
|
||||
const handleEditar = (paciente: Paciente) => {
|
||||
setPacienteEditando(paciente);
|
||||
setNombre(paciente.nombre);
|
||||
setApellido(paciente.apellido);
|
||||
setDni(paciente.dni);
|
||||
setFechaNacimiento(paciente.fechaNacimiento);
|
||||
setSexo(paciente.sexo);
|
||||
setTelefono(paciente.telefono);
|
||||
setEmail(paciente.email || '');
|
||||
setDireccion(paciente.direccion || '');
|
||||
setGrupoSanguineo(paciente.grupoSanguineo || '');
|
||||
setAlergias(paciente.alergias || '');
|
||||
setAntecedentes(paciente.antecedentes || '');
|
||||
setDialogoAbierto(true);
|
||||
};
|
||||
|
||||
const handleGuardar = () => {
|
||||
if (!nombre || !apellido || !dni || !fechaNacimiento || !telefono) return;
|
||||
|
||||
const datos = {
|
||||
nombre,
|
||||
apellido,
|
||||
dni,
|
||||
fechaNacimiento,
|
||||
sexo,
|
||||
telefono,
|
||||
email: email || undefined,
|
||||
direccion: direccion || undefined,
|
||||
grupoSanguineo: grupoSanguineo || undefined,
|
||||
alergias: alergias || undefined,
|
||||
antecedentes: antecedentes || undefined,
|
||||
};
|
||||
|
||||
if (pacienteEditando) {
|
||||
onActualizar(pacienteEditando.id, datos);
|
||||
} else {
|
||||
onAgregar(datos);
|
||||
}
|
||||
|
||||
resetFormulario();
|
||||
setDialogoAbierto(false);
|
||||
};
|
||||
|
||||
const pacientesFiltrados = pacientes.filter(p =>
|
||||
p.nombre.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
p.apellido.toLowerCase().includes(busqueda.toLowerCase()) ||
|
||||
p.dni.includes(busqueda)
|
||||
);
|
||||
|
||||
const getEdad = (fechaNacimiento: string) => {
|
||||
const hoy = new Date();
|
||||
const nacimiento = new Date(fechaNacimiento);
|
||||
let edad = hoy.getFullYear() - nacimiento.getFullYear();
|
||||
const mes = hoy.getMonth() - nacimiento.getMonth();
|
||||
if (mes < 0 || (mes === 0 && hoy.getDate() < nacimiento.getDate())) {
|
||||
edad--;
|
||||
}
|
||||
return edad;
|
||||
};
|
||||
|
||||
const estaInternado = (pacienteId: string) => {
|
||||
return internaciones.some(i => i.pacienteId === pacienteId && i.activa);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">Pacientes</h1>
|
||||
<p className="text-gray-500">Gestión de pacientes del hospital</p>
|
||||
</div>
|
||||
<Dialog open={dialogoAbierto} onOpenChange={setDialogoAbierto}>
|
||||
<DialogTrigger asChild>
|
||||
<Button onClick={resetFormulario}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Nuevo Paciente
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{pacienteEditando ? 'Editar Paciente' : 'Nuevo Paciente'}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Nombre *</Label>
|
||||
<Input
|
||||
value={nombre}
|
||||
onChange={(e) => setNombre(e.target.value)}
|
||||
placeholder="Nombre del paciente"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Apellido *</Label>
|
||||
<Input
|
||||
value={apellido}
|
||||
onChange={(e) => setApellido(e.target.value)}
|
||||
placeholder="Apellido del paciente"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>DNI *</Label>
|
||||
<Input
|
||||
value={dni}
|
||||
onChange={(e) => setDni(e.target.value)}
|
||||
placeholder="Número de DNI"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Fecha de Nacimiento *</Label>
|
||||
<Input
|
||||
type="date"
|
||||
value={fechaNacimiento}
|
||||
onChange={(e) => setFechaNacimiento(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Sexo *</Label>
|
||||
<Select value={sexo} onValueChange={(v: 'M' | 'F' | 'Otro') => setSexo(v)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="M">Masculino</SelectItem>
|
||||
<SelectItem value="F">Femenino</SelectItem>
|
||||
<SelectItem value="Otro">Otro</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Teléfono *</Label>
|
||||
<Input
|
||||
value={telefono}
|
||||
onChange={(e) => setTelefono(e.target.value)}
|
||||
placeholder="Teléfono de contacto"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Email</Label>
|
||||
<Input
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="Correo electrónico"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Dirección</Label>
|
||||
<Input
|
||||
value={direccion}
|
||||
onChange={(e) => setDireccion(e.target.value)}
|
||||
placeholder="Dirección del paciente"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Grupo Sanguíneo</Label>
|
||||
<Select value={grupoSanguineo} onValueChange={setGrupoSanguineo}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Seleccionar" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="A+">A+</SelectItem>
|
||||
<SelectItem value="A-">A-</SelectItem>
|
||||
<SelectItem value="B+">B+</SelectItem>
|
||||
<SelectItem value="B-">B-</SelectItem>
|
||||
<SelectItem value="AB+">AB+</SelectItem>
|
||||
<SelectItem value="AB-">AB-</SelectItem>
|
||||
<SelectItem value="O+">O+</SelectItem>
|
||||
<SelectItem value="O-">O-</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="sm:col-span-2">
|
||||
<Label>Alergias</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[60px]"
|
||||
value={alergias}
|
||||
onChange={(e) => setAlergias(e.target.value)}
|
||||
placeholder="Alergias conocidas..."
|
||||
/>
|
||||
</div>
|
||||
<div className="sm:col-span-2">
|
||||
<Label>Antecedentes Médicos</Label>
|
||||
<textarea
|
||||
className="w-full p-2 border rounded-md text-sm min-h-[60px]"
|
||||
value={antecedentes}
|
||||
onChange={(e) => setAntecedentes(e.target.value)}
|
||||
placeholder="Antecedentes médicos relevantes..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2 mt-4">
|
||||
<Button variant="outline" onClick={() => {
|
||||
resetFormulario();
|
||||
setDialogoAbierto(false);
|
||||
}}>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleGuardar}
|
||||
disabled={!nombre || !apellido || !dni || !fechaNacimiento || !telefono}
|
||||
>
|
||||
{pacienteEditando ? 'Guardar Cambios' : 'Crear Paciente'}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
{/* Búsqueda */}
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
className="pl-10"
|
||||
placeholder="Buscar por nombre, apellido o DNI..."
|
||||
value={busqueda}
|
||||
onChange={(e) => setBusqueda(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Lista de Pacientes */}
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
{pacientesFiltrados.map((paciente) => (
|
||||
<Card key={paciente.id} className="hover:shadow-md transition-shadow">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="h-12 w-12 bg-blue-100 rounded-full flex items-center justify-center flex-shrink-0">
|
||||
<User className="h-6 w-6 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<h3 className="font-bold text-lg">
|
||||
{paciente.apellido}, {paciente.nombre}
|
||||
</h3>
|
||||
{estaInternado(paciente.id) && (
|
||||
<Badge className="bg-purple-100 text-purple-800">
|
||||
Internado
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-4 gap-x-4 gap-y-1 mt-2 text-sm text-gray-500">
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="font-medium">DNI:</span> {paciente.dni}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="h-3 w-3" />
|
||||
{getEdad(paciente.fechaNacimiento)} años
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="font-medium">Sexo:</span> {paciente.sexo}
|
||||
</div>
|
||||
{paciente.grupoSanguineo && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Droplet className="h-3 w-3" />
|
||||
{paciente.grupoSanguineo}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-3 mt-2 text-sm text-gray-500">
|
||||
<div className="flex items-center gap-1">
|
||||
<Phone className="h-3 w-3" />
|
||||
{paciente.telefono}
|
||||
</div>
|
||||
{paciente.email && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Mail className="h-3 w-3" />
|
||||
{paciente.email}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{(paciente.alergias || paciente.antecedentes) && (
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{paciente.alergias && (
|
||||
<Badge variant="outline" className="bg-amber-50 text-amber-700 border-amber-200">
|
||||
<AlertTriangle className="h-3 w-3 mr-1" />
|
||||
Alergias
|
||||
</Badge>
|
||||
)}
|
||||
{paciente.antecedentes && (
|
||||
<Badge variant="outline" className="bg-blue-50 text-blue-700 border-blue-200">
|
||||
Antecedentes
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => handleEditar(paciente)}
|
||||
>
|
||||
<Edit2 className="h-4 w-4" />
|
||||
</Button>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="text-red-600 hover:bg-red-50">
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>¿Eliminar paciente?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Esta acción no se puede deshacer. Se eliminará permanentemente el paciente{' '}
|
||||
<strong>{paciente.apellido}, {paciente.nombre}</strong>.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => onEliminar(paciente.id)}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
>
|
||||
Eliminar
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{pacientesFiltrados.length === 0 && (
|
||||
<div className="text-center py-12 text-gray-400">
|
||||
<Users className="h-16 w-16 mx-auto mb-4 opacity-50" />
|
||||
<p className="text-lg">
|
||||
{busqueda ? 'No se encontraron pacientes con esa búsqueda' : 'No hay pacientes registrados'}
|
||||
</p>
|
||||
{!busqueda && (
|
||||
<Button className="mt-4" onClick={() => setDialogoAbierto(true)}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Agregar primer paciente
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user