Add Indicaciones backend - types, DB table, store, API
This commit is contained in:
@@ -208,6 +208,35 @@ try {
|
||||
console.log('Error tabla atb:', e.message);
|
||||
}
|
||||
|
||||
try {
|
||||
const existingIndicaciones = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='indicaciones'").get();
|
||||
if (!existingIndicaciones) {
|
||||
db.exec(`
|
||||
CREATE TABLE indicaciones (
|
||||
id TEXT PRIMARY KEY,
|
||||
internacionId TEXT NOT NULL,
|
||||
tipo TEXT NOT NULL,
|
||||
droga TEXT,
|
||||
dosis TEXT,
|
||||
frecuenciaHoras INTEGER,
|
||||
via TEXT,
|
||||
descripcion TEXT,
|
||||
tipoPlan TEXT,
|
||||
cantidadMl INTEGER,
|
||||
tiempoHoras INTEGER,
|
||||
estado TEXT DEFAULT 'Activa',
|
||||
medicoCrea TEXT,
|
||||
fechaCrea TEXT,
|
||||
medicoSuspende TEXT,
|
||||
fechaSuspension TEXT
|
||||
)
|
||||
`);
|
||||
console.log('Tabla indicaciones creada');
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error tabla indicaciones:', e.message);
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
@@ -259,6 +288,7 @@ app.get('/api/state', (req, res) => {
|
||||
estudiosComplementarios: queryAll('SELECT * FROM estudiosComplementarios'),
|
||||
interconsultas: queryAll('SELECT * FROM interconsultas').map(ic => ({ ...ic, realizada: !!ic.realizada })),
|
||||
atb: queryAll('SELECT * FROM atb'),
|
||||
indicaciones: queryAll('SELECT * FROM indicaciones'),
|
||||
vistaActual: 'dashboard',
|
||||
currentInternacionId: null
|
||||
};
|
||||
@@ -357,6 +387,14 @@ if (state.laboratorios?.length) {
|
||||
}
|
||||
}
|
||||
|
||||
run('DELETE FROM indicaciones');
|
||||
if (state.indicaciones?.length) {
|
||||
const stmt = db.prepare('INSERT INTO indicaciones (id, internacionId, tipo, droga, dosis, frecuenciaHoras, via, descripcion, tipoPlan, cantidadMl, tiempoHoras, estado, medicoCrea, fechaCrea, medicoSuspende, fechaSuspension) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
for (const ind of state.indicaciones) {
|
||||
stmt.run(ind.id, ind.internacionId, ind.tipo, ind.droga || null, ind.dosis || null, ind.frecuenciaHoras || null, ind.via || null, ind.descripcion || null, ind.tipoPlan || null, ind.cantidadMl || null, ind.tiempoHoras || null, ind.estado, ind.medicoCrea, ind.fechaCrea, ind.medicoSuspende || null, ind.fechaSuspension || null);
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user