Files
administracionHospital/src/sections/EditIngreso.tsx
T

312 lines
11 KiB
TypeScript

import { useState } from 'react';
import { ArrowLeft, Save, X, Bed, Calendar, Stethoscope, User, ClipboardList } from 'lucide-react';
import { Card, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Badge } from '@/components/ui/badge';
import type { Paciente, Cama, Area, Internacion } from '@/types';
interface EditIngresoProps {
internacion: Internacion;
paciente: Paciente;
cama: Cama | undefined;
pacientes: Paciente[];
camas: Cama[];
areas: Area[];
onActualizarInternacion: (id: string, datos: Partial<Internacion>) => void;
onVolver: () => void;
getAreaName: (areaId: string | undefined) => string;
}
export function EditIngreso({
internacion,
paciente: pacienteOriginal,
cama: camaOriginal,
pacientes,
camas,
areas,
onActualizarInternacion,
onVolver,
getAreaName
}: EditIngresoProps) {
const [pacienteSeleccionado, setPacienteSeleccionado] = useState(internacion.pacienteId);
const [busqueda, setBusqueda] = useState('');
const [camaSeleccionada, setCamaSeleccionada] = useState(internacion.camaId);
const [medico, setMedico] = useState(internacion.medicoIngresante);
const [fechaIngresoHospital, setFechaIngresoHospital] = useState(internacion.fechaIngresoHospital || '');
const [fechaIngresoClinica, setFechaIngresoClinica] = useState(internacion.fechaIngresoClinica || '');
const [motivoConsulta, setMotivoConsulta] = useState(internacion.motivoConsulta || '');
const [diagnosticoIngreso, setDiagnosticoIngreso] = useState(internacion.diagnosticoIngreso);
const [enfermedadActual, setEnfermedadActual] = useState(internacion.enfermedadActual);
const [antecedentesEnfermedadActual, setAntecedentesEnfermedadActual] = useState(internacion.antecedentesEnfermedadActual || '');
const [apache, setApache] = useState(internacion.apache || '');
const [derivacion, setDerivacion] = useState(internacion.derivacion || '');
const selectedPaciente = pacientes.find(p => p.id === pacienteSeleccionado);
const handleSubmit = () => {
if (!pacienteSeleccionado || !camaSeleccionada || !medico || !diagnosticoIngreso || !enfermedadActual) {
alert('Por favor complete los campos obligatorios');
return;
}
onActualizarInternacion(internacion.id, {
pacienteId: pacienteSeleccionado,
camaId: camaSeleccionada,
medicoIngresante: medico,
diagnosticoIngreso,
motivoConsulta: motivoConsulta || undefined,
enfermedadActual,
antecedentesEnfermedadActual: antecedentesEnfermedadActual || undefined,
fechaIngresoHospital: fechaIngresoHospital || undefined,
fechaIngresoClinica: fechaIngresoClinica || undefined,
apache: apache || undefined,
derivacion: derivacion || undefined,
});
onVolver();
};
return (
<div className="space-y-6 dark:text-white">
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<Button variant="ghost" size="icon" onClick={onVolver}>
<ArrowLeft className="h-5 w-5" />
</Button>
<div>
<h1 className="text-2xl font-bold text-gray-900 dark:text-white flex items-center gap-2">
<User className="h-6 w-6 text-blue-600" />
Editar Ingreso
</h1>
<p className="text-gray-500 dark:text-gray-400">Modificar datos de internación</p>
</div>
</div>
<div className="flex gap-2">
<Button variant="outline" onClick={() => onVolver()}>
<X className="h-4 w-4 mr-2" />
Cancelar
</Button>
<Button className="bg-blue-600 hover:bg-blue-700" onClick={handleSubmit}>
<Save className="h-4 w-4 mr-2" />
Guardar Cambios
</Button>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
{/* Columna 1: Datos del Paciente, Cama y Datos Adicionales */}
<div className="space-y-6">
<Card className="min-h-[200px]">
<CardContent className="pt-6 space-y-4">
<h3 className="font-semibold text-gray-900 flex items-center gap-2">
<User className="h-4 w-4" />
Datos del Paciente
</h3>
{selectedPaciente ? (
<div className="flex items-center gap-2 flex-wrap">
<Badge className="bg-blue-100 text-blue-800">
{selectedPaciente?.apellido}, {selectedPaciente?.nombre}
</Badge>
<Badge variant="outline">DNI: {selectedPaciente?.dni}</Badge>
</div>
) : (
<>
<Label>Buscar Paciente *</Label>
<Input
placeholder="Apellido, nombre o DNI"
value={busqueda}
onChange={(e) => setBusqueda(e.target.value)}
/>
<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">Escriba para buscar</div>;
}
const matches = pacientes.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">Sin resultados</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 text-sm"
>
{p.apellido}, {p.nombre} DNI: {p.dni}
</button>
));
})()}
</div>
</>
)}
</CardContent>
</Card>
</div>
{/* Columna 2: Cama */}
<div className="space-y-6">
<Card className="min-h-[200px]">
<CardContent className="pt-6 space-y-4">
<h3 className="font-semibold text-gray-900 flex items-center gap-2">
<Bed className="h-4 w-4" />
Asignación de Cama
</h3>
<div>
<Select value={camaSeleccionada} onValueChange={setCamaSeleccionada}>
<SelectTrigger>
<SelectValue placeholder="Seleccionar cama" />
</SelectTrigger>
<SelectContent>
{camas.map(c => (
<SelectItem key={c.id} value={c.id}>
{c.numero} - {getAreaName(c.areaId)}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</CardContent>
</Card>
</div>
</div>
<div className="space-y-6">
<Card>
<CardContent className="pt-6 space-y-4">
<h3 className="font-semibold text-gray-900 flex items-center gap-2">
<ClipboardList className="h-4 w-4" />
Datos de Ingreso
</h3>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<Label>Fecha Ingreso al Hospital</Label>
<Input
type="date"
value={fechaIngresoHospital}
onChange={(e) => setFechaIngresoHospital(e.target.value)}
/>
</div>
<div>
<Label>Fecha Ingreso a Clínica Médica</Label>
<Input
type="date"
value={fechaIngresoClinica}
onChange={(e) => setFechaIngresoClinica(e.target.value)}
/>
</div>
<div>
<Label>Derivado de</Label>
<Input
placeholder="Hospital o clínica de derivación"
value={derivacion}
onChange={(e) => setDerivacion(e.target.value)}
/>
</div>
<div>
<Label>Apache / Mortalidad</Label>
<Input
placeholder="Valor Apache o riesgo"
value={apache}
onChange={(e) => setApache(e.target.value)}
/>
</div>
</div>
</CardContent>
</Card>
</div>
<div className="space-y-6">
<Card>
<CardContent className="pt-6 space-y-4">
<h3 className="font-semibold text-gray-900">
Datos Clínicos
</h3>
<div>
<Label>Motivo de Consulta *</Label>
<textarea
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
placeholder="Motivo por el cual consulta"
value={motivoConsulta}
onChange={(e) => setMotivoConsulta(e.target.value)}
/>
</div>
<div>
<Label>Diagnóstico de Ingreso *</Label>
<textarea
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
placeholder="Diagnóstico principal"
value={diagnosticoIngreso}
onChange={(e) => setDiagnosticoIngreso(e.target.value)}
/>
</div>
<div>
<Label>Enfermedad Actual *</Label>
<textarea
className="w-full p-2 border rounded-md text-sm min-h-[100px]"
placeholder="Descripción de la enfermedad actual"
value={enfermedadActual}
onChange={(e) => setEnfermedadActual(e.target.value)}
/>
</div>
<div>
<Label>Antecedentes de Enfermedad Actual</Label>
<textarea
className="w-full p-2 border rounded-md text-sm min-h-[80px]"
placeholder="Antecedentes relevantes"
value={antecedentesEnfermedadActual}
onChange={(e) => setAntecedentesEnfermedadActual(e.target.value)}
/>
</div>
</CardContent>
</Card>
</div>
{/* Columna 4: Médico Ingresante */}
<div className="space-y-6">
<Card>
<CardContent className="pt-6 space-y-4">
<h3 className="font-semibold text-gray-900 flex items-center gap-2">
<Stethoscope className="h-4 w-4" />
Médico Ingresante
</h3>
<div>
<Label>Médico Ingresante *</Label>
<Input
placeholder="Nombre del médico"
value={medico}
onChange={(e) => setMedico(e.target.value)}
/>
</div>
</CardContent>
</Card>
</div>
</div>
);
}