Renombrar 'Areas' a 'Grupos' y actualizar dependencias

This commit is contained in:
2026-08-09 20:05:08 +00:00
parent 91cde0e5d9
commit dc108a9699
12 changed files with 421 additions and 342 deletions
+26 -18
View File
@@ -3,7 +3,7 @@ import cors from 'cors';
import {
getDb, getValue, setValue, getUsuarioByDni, getUsuarioById, getAllUsuarios, createUsuario, updateUsuario, deleteUsuario, verifyPassword, hashPassword,
getAllPacientes, createPaciente, updatePaciente, deletePaciente,
getAllAreas, createArea, updateArea, deleteArea,
getAllGrupos, createGrupo, updateGrupo, deleteGrupo,
getAllCamas, createCama, updateCama, deleteCama,
getAllInternaciones, createInternacion, updateInternacion, deleteInternacion,
getAllEvoluciones, createEvolucion, updateEvolucion, deleteEvolucion,
@@ -27,9 +27,11 @@ const STORAGE_KEY = 'hospital-data-v1';
app.get('/api/state', (req, res) => {
try {
const gruposList = getAllGrupos();
const state = {
pacientes: getAllPacientes(),
areas: getAllAreas(),
grupos: gruposList,
areas: gruposList,
camas: getAllCamas(),
internaciones: getAllInternaciones(),
evoluciones: getAllEvoluciones(),
@@ -66,6 +68,7 @@ app.put('/api/state', (req, res) => {
db.prepare('DELETE FROM glucemias').run();
db.prepare('DELETE FROM internaciones').run();
db.prepare('DELETE FROM camas').run();
db.prepare('DELETE FROM grupos').run();
db.prepare('DELETE FROM areas').run();
db.prepare('DELETE FROM pacientes').run();
db.prepare('DELETE FROM estudiosComplementarios').run();
@@ -81,24 +84,29 @@ app.put('/api/state', (req, res) => {
}
}
if (state.areas?.length) {
const stmt = db.prepare('INSERT INTO areas (id, nombre) VALUES (?, ?)');
for (const a of state.areas) {
stmt.run(a.id, a.nombre);
const gruposData = state.grupos?.length ? state.grupos : state.areas;
if (gruposData?.length) {
const stmtG = db.prepare('INSERT OR IGNORE INTO grupos (id, nombre) VALUES (?, ?)');
const stmtA = db.prepare('INSERT OR IGNORE INTO areas (id, nombre) VALUES (?, ?)');
for (const g of gruposData) {
stmtG.run(g.id, g.nombre);
stmtA.run(g.id, g.nombre);
}
}
if (state.camas?.length) {
const stmt = db.prepare('INSERT OR IGNORE INTO camas (id, numero, areaId, tipo, estado) VALUES (?, ?, ?, ?, ?)');
const stmt = db.prepare('INSERT OR IGNORE INTO camas (id, numero, grupoId, areaId, tipo, estado) VALUES (?, ?, ?, ?, ?, ?)');
for (const c of state.camas) {
stmt.run(c.id, c.numero, c.areaId, c.tipo, c.estado);
const gId = c.grupoId || c.areaId || null;
stmt.run(c.id, c.numero, gId, gId, c.tipo, c.estado);
}
}
if (state.internaciones?.length) {
const stmt = db.prepare('INSERT OR IGNORE INTO internaciones (id, pacienteId, camaId, areaId, fechaIngresoHospital, fechaIngresoClinica, fechaEgreso, diagnosticoIngreso, motivoConsulta, enfermedadActual, antecedentesEnfermedadActual, diagnosticoEgreso, medicoIngresante, motivoEgreso, activa, apache, derivacion) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
const stmt = db.prepare('INSERT OR IGNORE INTO internaciones (id, pacienteId, camaId, grupoId, areaId, 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.areaId || null, 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);
const gId = i.grupoId || i.areaId || null;
stmt.run(i.id, i.pacienteId, i.camaId, gId, gId, 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);
}
}
@@ -326,9 +334,9 @@ app.put('/api/auth/update-email', (req, res) => {
// === GESTIÓN DE USUARIOS (ADMIN) ===
app.get('/api/areas', (req, res) => {
app.get('/api/grupos', (req, res) => {
try {
const areas = getAllAreas();
const areas = getAllGrupos();
res.json(areas);
} catch (err) {
console.error(err);
@@ -463,18 +471,18 @@ app.delete('/api/pacientes/:id', (req, res) => {
});
// ========== AREAS ==========
app.post('/api/areas', (req, res) => {
app.post('/api/grupos', (req, res) => {
try {
const area = { ...req.body, id: req.body.id || generateUUID() };
createArea(area);
createGrupo(area);
res.json(area);
} catch (err) { res.status(500).json({ error: err.message }); }
});
app.put('/api/areas/:id', (req, res) => {
try { updateArea(req.params.id, req.body); res.json({ ok: true }); } catch (err) { res.status(500).json({ error: err.message }); }
app.put('/api/grupos/:id', (req, res) => {
try { updateGrupo(req.params.id, req.body); res.json({ ok: true }); } catch (err) { res.status(500).json({ error: err.message }); }
});
app.delete('/api/areas/:id', (req, res) => {
try { deleteArea(req.params.id); res.json({ ok: true }); } catch (err) { res.status(500).json({ error: err.message }); }
app.delete('/api/grupos/:id', (req, res) => {
try { deleteGrupo(req.params.id); res.json({ ok: true }); } catch (err) { res.status(500).json({ error: err.message }); }
});
// ========== CAMAS ==========