Fix: Organizacion de Editar Ingreso igual a Nuevo Ingreso, corregido formato de fecha
This commit is contained in:
@@ -0,0 +1,310 @@
|
||||
import { useState, useEffect } 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 NuevoIngresoProps {
|
||||
pacientes: Paciente[];
|
||||
camas: Cama[];
|
||||
areas: Area[];
|
||||
onIniciarInternacion: (internacion: Omit<Internacion, 'id' | 'activa'>) => void;
|
||||
onVolver: () => void;
|
||||
getAreaName: (areaId: string | undefined) => string;
|
||||
}
|
||||
|
||||
export function NuevoIngreso({ pacientes, camas, areas, onIniciarInternacion, onVolver, getAreaName }: NuevoIngresoProps) {
|
||||
const [pacienteSeleccionado, setPacienteSeleccionado] = useState<string>('');
|
||||
const [busqueda, setBusqueda] = useState('');
|
||||
const [camaSeleccionada, setCamaSeleccionada] = useState('');
|
||||
const [medico, setMedico] = useState('');
|
||||
const [fechaIngresoHospital, setFechaIngresoHospital] = useState('');
|
||||
const [fechaIngresoClinica, setFechaIngresoClinica] = useState('');
|
||||
const [motivoConsulta, setMotivoConsulta] = useState('');
|
||||
const [diagnosticoIngreso, setDiagnosticoIngreso] = useState('');
|
||||
const [enfermedadActual, setEnfermedadActual] = useState('');
|
||||
const [antecedentesEnfermedadActual, setAntecedentesEnfermedadActual] = useState('');
|
||||
const [apache, setApache] = useState('');
|
||||
const [derivacion, setDerivacion] = useState('');
|
||||
|
||||
const resetFormulario = () => {
|
||||
setPacienteSeleccionado('');
|
||||
setBusqueda('');
|
||||
setCamaSeleccionada('');
|
||||
setMedico('');
|
||||
setFechaIngresoHospital('');
|
||||
setFechaIngresoClinica('');
|
||||
setMotivoConsulta('');
|
||||
setDiagnosticoIngreso('');
|
||||
setEnfermedadActual('');
|
||||
setAntecedentesEnfermedadActual('');
|
||||
setApache('');
|
||||
setDerivacion('');
|
||||
};
|
||||
|
||||
const pacientesSinInternar = pacientes;
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!pacienteSeleccionado || !camaSeleccionada || !medico || !diagnosticoIngreso || !enfermedadActual) {
|
||||
alert('Por favor complete los campos obligatorios');
|
||||
return;
|
||||
}
|
||||
|
||||
onIniciarInternacion({
|
||||
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,
|
||||
});
|
||||
|
||||
resetFormulario();
|
||||
onVolver();
|
||||
};
|
||||
|
||||
const selectedPaciente = pacientes.find(p => p.id === pacienteSeleccionado);
|
||||
const camasDisponibles = camaSeleccionada
|
||||
? []
|
||||
: camas.filter(c => c.estado === 'Disponible' && !c.pacienteId);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<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 flex items-center gap-2">
|
||||
<User className="h-6 w-6 text-blue-600" />
|
||||
Nuevo Ingreso
|
||||
</h1>
|
||||
<p className="text-gray-500">Formulario de internación</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => { resetFormulario(); 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 Ingreso
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
{/* Columna 1: Datos del Paciente, Cama y Datos Adicionales */}
|
||||
<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">
|
||||
<User className="h-4 w-4" />
|
||||
Datos del Paciente
|
||||
</h3>
|
||||
|
||||
{!pacienteSeleccionado ? (
|
||||
<>
|
||||
<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 = 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">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>
|
||||
</>
|
||||
) : (
|
||||
<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>
|
||||
<Button size="sm" variant="ghost" onClick={() => { setPacienteSeleccionado(''); setBusqueda(''); }}>
|
||||
Cambiar
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<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>
|
||||
<Label>Cama *</Label>
|
||||
<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)} ({c.tipo})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
{/* Columna 2: Fechas y Médico */}
|
||||
<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">
|
||||
<Calendar className="h-4 w-4" />
|
||||
Datos de Ingreso
|
||||
</h3>
|
||||
|
||||
<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>Apache / Mortalidad</Label>
|
||||
<Input
|
||||
placeholder="Valor Apache o riesgo"
|
||||
value={apache}
|
||||
onChange={(e) => setApache(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>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<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>
|
||||
|
||||
{/* Columna 3: Datos Clínicos */}
|
||||
<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 la 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>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user