Agregar tabla interconsultas: DB, store, UI con CRUD completo
This commit is contained in:
@@ -157,6 +157,22 @@ try {
|
||||
// La columna ya existe
|
||||
}
|
||||
|
||||
try {
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS interconsultas (
|
||||
id TEXT PRIMARY KEY,
|
||||
pacienteId TEXT NOT NULL,
|
||||
internacionId TEXT NOT NULL,
|
||||
fecha TEXT,
|
||||
servicioInterconsultado TEXT,
|
||||
realizada INTEGER DEFAULT 0,
|
||||
respuestaInterconsulta TEXT
|
||||
)
|
||||
`);
|
||||
} catch (e) {
|
||||
console.log('Tabla interconsultas ya existe o error:', e.message);
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
@@ -206,6 +222,7 @@ app.get('/api/state', (req, res) => {
|
||||
acidosBase: queryAll('SELECT * FROM acidosbase'),
|
||||
cultivos: queryAll('SELECT * FROM cultivos'),
|
||||
estudiosComplementarios: queryAll('SELECT * FROM estudiosComplementarios'),
|
||||
interconsultas: queryAll('SELECT * FROM interconsultas').map(ic => ({ ...ic, realizada: !!ic.realizada })),
|
||||
vistaActual: 'dashboard',
|
||||
currentInternacionId: null
|
||||
};
|
||||
@@ -288,6 +305,14 @@ if (state.laboratorios?.length) {
|
||||
}
|
||||
}
|
||||
|
||||
run('DELETE FROM interconsultas');
|
||||
if (state.interconsultas?.length) {
|
||||
const stmt = db.prepare('INSERT INTO interconsultas (id, pacienteId, internacionId, fecha, servicioInterconsultado, realizada, respuestaInterconsulta) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
||||
for (const ic of state.interconsultas) {
|
||||
stmt.run(ic.id, ic.pacienteId, ic.internacionId, ic.fecha, ic.servicioInterconsultado, ic.realizada ? 1 : 0, ic.respuestaInterconsulta || null);
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user