From 111863baf2f4d0eebdb2a072e6460e2e1cbeaa70 Mon Sep 17 00:00:00 2001
From: Santiago Lavaise
Date: Tue, 14 Apr 2026 00:04:40 -0300
Subject: [PATCH] Fix: Organizacion de Editar Ingreso igual a Nuevo Ingreso,
corregido formato de fecha
---
server/server.js | 11 +-
src/App.tsx | 42 +++-
src/hooks/useHospitalStore.ts | 3 +-
src/lib/utils.ts | 8 +-
src/sections/Dashboard.tsx | 2 +-
src/sections/EditIngreso.tsx | 323 +++++++++++++++++++++++++++++++
src/sections/HistoriaClinica.tsx | 18 +-
src/sections/Internaciones.tsx | 10 +-
src/sections/MapaCamas.tsx | 4 +-
src/sections/NuevoIngreso.tsx | 310 +++++++++++++++++++++++++++++
src/types/index.ts | 7 +-
11 files changed, 708 insertions(+), 30 deletions(-)
create mode 100644 src/sections/EditIngreso.tsx
create mode 100644 src/sections/NuevoIngreso.tsx
diff --git a/server/server.js b/server/server.js
index 858e086..b71361c 100644
--- a/server/server.js
+++ b/server/server.js
@@ -47,7 +47,8 @@ db.exec(`
id TEXT PRIMARY KEY,
pacienteId TEXT NOT NULL,
camaId TEXT,
- fechaIngreso TEXT NOT NULL,
+ fechaIngresoHospital TEXT,
+ fechaIngresoClinica TEXT,
fechaEgreso TEXT,
diagnosticoIngreso TEXT,
motivoConsulta TEXT,
@@ -56,7 +57,9 @@ db.exec(`
diagnosticoEgreso TEXT,
medicoIngresante TEXT,
motivoEgreso TEXT,
- activa INTEGER DEFAULT 1
+ activa INTEGER DEFAULT 1,
+ apache TEXT,
+ derivacion TEXT
);
CREATE TABLE IF NOT EXISTS evoluciones (
@@ -200,9 +203,9 @@ app.put('/api/state', (req, res) => {
}
if (state.internaciones?.length) {
- const stmt = db.prepare('INSERT INTO internaciones (id, pacienteId, camaId, fechaIngreso, fechaEgreso, diagnosticoIngreso, motivoConsulta, enfermedadActual, antecedentesEnfermedadActual, diagnosticoEgreso, medicoIngresante, motivoEgreso, activa) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
+ const stmt = db.prepare('INSERT INTO internaciones (id, pacienteId, camaId, fechaIngresoHospital, fechaIngresoClinica, fechaEgreso, diagnosticoIngreso, motivoConsulta, enfermedadActual, antecedentesEnfermedadActual, diagnosticoEgreso, medicoIngresante, motivoEgreso, activa, apache, derivacion) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
for (const i of state.internaciones) {
- stmt.run(i.id, i.pacienteId, i.camaId, i.fechaIngreso, i.fechaEgreso || null, i.diagnosticoIngreso || null, i.motivoConsulta || null, i.enfermedadActual || null, i.antecedentesEnfermedadActual || null, i.diagnosticoEgreso || null, i.medicoIngresante || null, i.motivoEgreso || null, i.activa ? 1 : 0);
+ stmt.run(i.id, i.pacienteId, i.camaId, i.fechaIngresoHospital || null, i.fechaIngresoClinica || null, i.fechaEgreso || null, i.diagnosticoIngreso || null, i.motivoConsulta || null, i.enfermedadActual || null, i.antecedentesEnfermedadActual || null, i.diagnosticoEgreso || null, i.medicoIngresante || null, i.motivoEgreso || null, i.activa ? 1 : 0, i.apache || null, i.derivacion || null);
}
}
diff --git a/src/App.tsx b/src/App.tsx
index 3671457..4e52897 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -8,6 +8,8 @@ import { Evoluciones } from '@/sections/Evoluciones';
import { AcidoBaseSection } from '@/sections/AcidoBase';
import { Cultivos } from '@/sections/Cultivos';
import { HistoriaClinica } from '@/sections/HistoriaClinica';
+import { NuevoIngreso } from '@/sections/NuevoIngreso';
+import { EditIngreso } from '@/sections/EditIngreso';
import { Spinner } from '@/components/ui/spinner';
import { Button } from '@/components/ui/button';
@@ -77,6 +79,7 @@ function App() {
getPacienteById={store.getPacienteById}
getCamaById={store.getCamaById}
onVerHC={(id) => { store.setCurrentInternacion(id); store.setVista('historiaclinica'); }}
+ onNuevoIngreso={() => store.setVista('nuevoingreso')}
/>
);
case 'evoluciones':
@@ -152,12 +155,47 @@ function App() {
onActualizarInternacion={store.actualizarInternacion}
onActualizarCama={store.actualizarCama}
onVolver={() => store.setVista('internaciones')}
+ onEditarIngreso={() => { store.setVista('editaringreso'); }}
/>
);
}
+case 'nuevoingreso':
+ return (
+ store.setVista('internaciones')}
+ getAreaName={(areaId) => store.areas.find(a => a.id === areaId)?.nombre || ''}
+ />
+ );
-
- default:
+ case 'editaringreso': {
+ const internacion = store.getInternacionById(store.currentInternacionId || '');
+ const paciente = internacion ? store.getPacienteById(internacion.pacienteId) : undefined;
+ if (!internacion || !paciente) {
+ return (
+
+
Internación no encontrada
+
+
+ );
+ }
+ return (
+ store.setVista('historiaclinica')}
+ getAreaName={(areaId) => store.areas.find(a => a.id === areaId)?.nombre || ''}
+ />
+ );
+ }
return null;
}
};
diff --git a/src/hooks/useHospitalStore.ts b/src/hooks/useHospitalStore.ts
index 858f618..b2a994b 100644
--- a/src/hooks/useHospitalStore.ts
+++ b/src/hooks/useHospitalStore.ts
@@ -157,11 +157,10 @@ export function useHospitalStore() {
}, []);
// Acciones de internaciones
- const iniciarInternacion = useCallback((internacion: Omit) => {
+ const iniciarInternacion = useCallback((internacion: Omit) => {
const nuevaInternacion: Internacion = {
...internacion,
id: generateUUID(),
- fechaIngreso: new Date().toISOString().split('T')[0],
activa: true,
};
setState(prev => ({
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 0b799de..23d1bea 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -7,10 +7,8 @@ export function cn(...inputs: ClassValue[]) {
export function formatDateDDMMYYYY(dateString: string): string {
if (!dateString) return '';
- const date = new Date(dateString);
- if (isNaN(date.getTime())) return dateString;
- const day = String(date.getDate()).padStart(2, '0');
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const year = date.getFullYear();
+ const parts = dateString.split('-');
+ if (parts.length !== 3) return dateString;
+ const [year, month, day] = parts;
return `${day}-${month}-${year}`;
}
diff --git a/src/sections/Dashboard.tsx b/src/sections/Dashboard.tsx
index 670a714..3040c6f 100644
--- a/src/sections/Dashboard.tsx
+++ b/src/sections/Dashboard.tsx
@@ -210,7 +210,7 @@ export function Dashboard({
{paciente ? `${paciente.apellido}, ${paciente.nombre}` : 'Paciente no encontrado'}
- Ingreso: {formatDateDDMMYYYY(internacion.fechaIngreso)}
+ Ingreso: {internacion.fechaIngresoClinica ? formatDateDDMMYYYY(internacion.fechaIngresoClinica) : 'N/A'}
diff --git a/src/sections/EditIngreso.tsx b/src/sections/EditIngreso.tsx
new file mode 100644
index 0000000..7d70886
--- /dev/null
+++ b/src/sections/EditIngreso.tsx
@@ -0,0 +1,323 @@
+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) => 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 (
+
+
+
+
+
+
+
+ Editar Ingreso
+
+
Modificar datos de internación
+
+
+
+
+
+
+
+
+
+ {/* Columna 1: Datos del Paciente, Cama y Datos Adicionales */}
+
+
+
+
+
+ Datos del Paciente
+
+
+ {selectedPaciente ? (
+
+
+ {selectedPaciente?.apellido}, {selectedPaciente?.nombre}
+
+ DNI: {selectedPaciente?.dni}
+
+ ) : (
+ <>
+
+ setBusqueda(e.target.value)}
+ />
+
+ {(() => {
+ const q = busqueda.trim().toLowerCase();
+ if (!q) {
+ return
Escriba para buscar
;
+ }
+ const matches = pacientes.filter(p =>
+ p.apellido.toLowerCase().includes(q) ||
+ p.nombre.toLowerCase().includes(q) ||
+ p.dni.includes(q)
+ );
+ if (matches.length === 0) {
+ return
Sin resultados
;
+ }
+ return matches.map(p => (
+
+ ));
+ })()}
+
+ >
+ )}
+
+
+
+
+
+
+
+ Asignación de Cama
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Datos Adicionales
+
+
+
+
+ setApache(e.target.value)}
+ />
+
+
+
+ setDerivacion(e.target.value)}
+ />
+
+
+
+
+
+ {/* Columna 2: Datos de Ingreso */}
+
+
+ {/* Columna 3: Datos Clínicos */}
+
+
+
+
+ Datos Clínicos
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/sections/HistoriaClinica.tsx b/src/sections/HistoriaClinica.tsx
index f3e5449..68bdb44 100644
--- a/src/sections/HistoriaClinica.tsx
+++ b/src/sections/HistoriaClinica.tsx
@@ -58,6 +58,7 @@ interface HistoriaClinicaProps {
onActualizarInternacion: (id: string, datos: Partial) => void;
onActualizarCama: (id: string, datos: Partial) => void;
onVolver: () => void;
+ onEditarIngreso?: () => void;
}
const PARAMETROS_COMUNES: Record = {
@@ -154,11 +155,12 @@ export function HistoriaClinica({
onActualizarInternacion,
onActualizarCama,
onVolver,
+ onEditarIngreso,
}: HistoriaClinicaProps) {
const [tabActivo, setTabActivo] = useState('evoluciones');
const [detalleExpandido, setDetalleExpandido] = useState(false);
const [editIngresoDialog, setEditIngresoDialog] = useState(false);
- const [editFechaIngreso, setEditFechaIngreso] = useState(internacion.fechaIngreso);
+ const [editFechaIngreso, setEditFechaIngreso] = useState(internacion.fechaIngresoClinica);
const [editMotivoConsulta, setEditMotivoConsulta] = useState(internacion.motivoConsulta || '');
const [editDiagnostico, setEditDiagnostico] = useState(internacion.diagnosticoIngreso || '');
const [editEnfermedadActual, setEditEnfermedadActual] = useState(internacion.enfermedadActual || '');
@@ -192,7 +194,7 @@ export function HistoriaClinica({
onActualizarCama(editCamaId, { estado: 'Ocupada', pacienteId: paciente.id, internacionId: internacion.id });
}
onActualizarInternacion(internacion.id, {
- fechaIngreso: editFechaIngreso,
+ fechaIngresoClinica: editFechaIngreso,
motivoConsulta: editMotivoConsulta,
diagnosticoIngreso: editDiagnostico,
enfermedadActual: editEnfermedadActual,
@@ -222,7 +224,7 @@ export function HistoriaClinica({
Volver
-