From 0b77297c3d7b6dc38d3af70f78e51d5921e35ce5 Mon Sep 17 00:00:00 2001 From: Sergio Nicolas Lavaise Date: Thu, 16 Apr 2026 01:28:31 -0300 Subject: [PATCH] =?UTF-8?q?Agregar=20FiO2=20y=20edici=C3=B3n=20en=20gasome?= =?UTF-8?q?tr=C3=ADas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Agregar campo fio2 en interface AcidoBase - Agregar columna fio2 en SQLite - Nuevo campo FiO2 en modal nueva gasometría - Mostrar FiO2 en lista de gasometrías - Agregar botón edición (lápiz) en registros - Agregar función actualizarAcidoBase en store --- server/server.js | 11 ++++- src/App.tsx | 1 + src/hooks/useHospitalStore.ts | 8 ++++ src/sections/HistoriaClinica.tsx | 71 +++++++++++++++++++++++++++++--- src/types/index.ts | 1 + 5 files changed, 84 insertions(+), 8 deletions(-) diff --git a/server/server.js b/server/server.js index ecd5eae..a8d3ef6 100644 --- a/server/server.js +++ b/server/server.js @@ -104,6 +104,7 @@ db.exec(` be REAL, sato2 REAL, lactato REAL, + fio2 REAL, interpretacion TEXT ); @@ -144,6 +145,12 @@ try { // La columna ya existe } +try { + db.exec("ALTER TABLE acidosbase ADD COLUMN fio2 REAL"); +} catch (e) { + // La columna ya existe +} + const app = express(); app.use(cors()); app.use(express.json({ limit: '50mb' })); @@ -254,9 +261,9 @@ app.put('/api/state', (req, res) => { } if (state.acidosBase?.length) { - const stmt = db.prepare('INSERT INTO acidosbase (id, pacienteId, fecha, hora, ph, pco2, po2, hco3, be, statO2, lactato, interpretacion) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); + const stmt = db.prepare('INSERT INTO acidosbase (id, pacienteId, fecha, hora, ph, pco2, po2, hco3, be, sato2, lactato, fio2, interpretacion) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); for (const a of state.acidosBase) { - stmt.run(a.id, a.pacienteId, a.fecha, a.hora, a.ph, a.pco2, a.po2, a.hco3, a.be, a.sato2, a.lactato, a.interpretacion); + stmt.run(a.id, a.pacienteId, a.fecha, a.hora, a.ph, a.pco2, a.po2, a.hco3, a.be, a.sato2, a.lactato || null, a.fio2 || null, a.interpretacion); } } diff --git a/src/App.tsx b/src/App.tsx index a0345d4..d309ff0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -151,6 +151,7 @@ function AppContent() { onActualizarLaboratorio={store.actualizarLaboratorio} onEliminarLaboratorio={store.eliminarLaboratorio} onAgregarAcidoBase={(a) => store.agregarAcidoBase({ ...a, internacionId: internacion.id })} + onActualizarAcidoBase={store.actualizarAcidoBase} onEliminarAcidoBase={store.eliminarAcidoBase} onAgregarCultivo={(c) => store.agregarCultivo({ ...c, internacionId: internacion.id })} onActualizarCultivo={store.actualizarCultivo} diff --git a/src/hooks/useHospitalStore.ts b/src/hooks/useHospitalStore.ts index 685f573..4007457 100644 --- a/src/hooks/useHospitalStore.ts +++ b/src/hooks/useHospitalStore.ts @@ -281,6 +281,13 @@ const finalizarInternacion = useCallback((internacionId: string, datos: { return nuevoAcidoBase.id; }, []); + const actualizarAcidoBase = useCallback((id: string, datos: Partial) => { + setState(prev => ({ + ...prev, + acidosBase: prev.acidosBase.map(a => a.id === id ? { ...a, ...datos } : a), + })); + }, []); + const eliminarAcidoBase = useCallback((id: string) => { setState(prev => ({ ...prev, @@ -457,6 +464,7 @@ const getEstadisticas = useCallback(() => { agregarLaboratorio, eliminarLaboratorio, agregarAcidoBase, + actualizarAcidoBase, eliminarAcidoBase, agregarCultivo, actualizarCultivo, diff --git a/src/sections/HistoriaClinica.tsx b/src/sections/HistoriaClinica.tsx index 192eead..4b2798c 100644 --- a/src/sections/HistoriaClinica.tsx +++ b/src/sections/HistoriaClinica.tsx @@ -59,6 +59,7 @@ interface HistoriaClinicaProps { onActualizarLaboratorio: (id: string, datos: Partial) => void; onEliminarLaboratorio: (id: string) => void; onAgregarAcidoBase: (acidoBase: Omit) => void; + onActualizarAcidoBase: (id: string, datos: Partial) => void; onEliminarAcidoBase: (id: string) => void; onAgregarCultivo: (cultivo: Omit) => void; onActualizarCultivo: (id: string, datos: Partial) => void; @@ -159,6 +160,7 @@ export function HistoriaClinica({ onActualizarLaboratorio, onEliminarLaboratorio, onAgregarAcidoBase, + onActualizarAcidoBase, onEliminarAcidoBase, onAgregarCultivo, onActualizarCultivo, @@ -532,7 +534,7 @@ export function HistoriaClinica({ - + @@ -1295,13 +1297,16 @@ function SeccionEvoluciones({ evos, internacionId, add, update, del }: { ); } -function SeccionAcidosBase({ ab, patientId, add, del }: { +function SeccionAcidosBase({ ab, patientId, add, update, del }: { ab: AcidoBase[]; patientId: string; add: (a: Omit) => void; + update: (id: string, datos: Partial) => void; del: (id: string) => void; }) { const [dialog, setDialog] = useState(false); + const [editDialog, setEditDialog] = useState(false); + const [selected, setSelected] = useState(null); const [fecha, setFecha] = useState(new Date().toISOString().split('T')[0]); const [hora, setHora] = useState(new Date().toTimeString().slice(0, 5)); const [ph, setPh] = useState(''); @@ -1311,12 +1316,30 @@ function SeccionAcidosBase({ ab, patientId, add, del }: { const [be, setBe] = useState(''); const [sato2, setSato2] = useState(''); const [lactato, setLactato] = useState(''); + const [fio2, setFio2] = useState(''); const [interpretacion, setInterpretacion] = useState(''); const reset = () => { setFecha(new Date().toISOString().split('T')[0]); setHora(new Date().toTimeString().slice(0, 5)); - setPh(''); setPco2(''); setPo2(''); setHco3(''); setBe(''); setSato2(''); setLactato(''); setInterpretacion(''); + setPh(''); setPco2(''); setPo2(''); setHco3(''); setBe(''); setSato2(''); setLactato(''); setFio2(''); setInterpretacion(''); + setSelected(null); + }; + + const loadEdit = (a: AcidoBase) => { + setSelected(a); + setFecha(a.fecha); + setHora(a.hora); + setPh(String(a.ph)); + setPco2(String(a.pco2)); + setPo2(String(a.po2)); + setHco3(String(a.hco3)); + setBe(String(a.be)); + setSato2(String(a.sato2)); + setLactato(a.lactato ? String(a.lactato) : ''); + setFio2(a.fio2 ? String(a.fio2) : ''); + setInterpretacion(a.interpretacion || ''); + setEditDialog(true); }; const abFiltered = ab.filter(a => a.pacienteId === patientId).sort((a, b) => new Date(b.fecha + 'T' + b.hora).getTime() - new Date(a.fecha + 'T' + a.hora).getTime()); @@ -1350,11 +1373,19 @@ function SeccionAcidosBase({ ab, patientId, add, del }: { const handle = () => { if (!ph || !pco2 || !po2 || !hco3 || !be || !sato2) return; const interpretacionAuto = interpretarGasometria(); - add({ pacienteId: patientId, 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 }); + add({ pacienteId: patientId, 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, fio2: fio2 ? parseFloat(fio2) : undefined, interpretacion: interpretacion || interpretacionAuto }); setDialog(false); reset(); }; + const handleEdit = () => { + if (!selected || !ph || !pco2 || !po2 || !hco3 || !be || !sato2) return; + const interpretacionAuto = interpretarGasometria(); + update(selected.id, { 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, fio2: fio2 ? parseFloat(fio2) : undefined, interpretacion: interpretacion || interpretacionAuto }); + setEditDialog(false); + reset(); + }; + return (
@@ -1368,7 +1399,7 @@ function SeccionAcidosBase({ ab, patientId, add, del }: {
setFecha(e.target.value)} />
setHora(e.target.value)} />
-
+
setPh(e.target.value)} placeholder="7.40" />
setPco2(e.target.value)} placeholder="40" />
setPo2(e.target.value)} placeholder="85" />
@@ -1376,6 +1407,7 @@ function SeccionAcidosBase({ ab, patientId, add, del }: {
setBe(e.target.value)} placeholder="0" />
setSato2(e.target.value)} placeholder="97" />
setLactato(e.target.value)} placeholder="1.0" />
+
setFio2(e.target.value)} placeholder="21" />
{ph && pco2 && hco3 &&

Interpretación automática: {interpretarGasometria()}

}