Fix bed management: preserve camaId from frontend to backend
- Use camaId generated in frontend instead of generating new one in backend API - Remove patientId and internacionId from cama table (use internaciones table instead) - Fix discharge: delete cama if fuera de area, mark available otherwise - Fix MapaCamas to find patient via internaciones table
This commit is contained in:
@@ -239,7 +239,10 @@ app.put('/api/camas/:id', async (req, res) => {
|
||||
|
||||
app.post('/api/camas', async (req, res) => {
|
||||
try {
|
||||
const cama = { ...req.body, id: generateUUID() };
|
||||
const cama = req.body;
|
||||
if (!cama.id) {
|
||||
cama.id = generateUUID();
|
||||
}
|
||||
await createCama(cama);
|
||||
res.json(cama);
|
||||
} catch (err) {
|
||||
|
||||
+14
-1
@@ -1,6 +1,18 @@
|
||||
import * as mariadb from 'mariadb';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
|
||||
// UUID generator
|
||||
export function generateUUID() {
|
||||
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
// MariaDB connection pool
|
||||
const pool = mariadb.createPool({
|
||||
host: process.env.DB_HOST || '10.9.8.135',
|
||||
@@ -350,9 +362,10 @@ export async function getCamaById(id) {
|
||||
}
|
||||
|
||||
export async function createCama(cama) {
|
||||
const id = cama.id || generateUUID();
|
||||
await query(
|
||||
'INSERT INTO camas (id, numero, areaId, tipo, estado) VALUES (?, ?, ?, ?, ?)',
|
||||
[cama.id, cama.numero, cama.areaId, cama.tipo, cama.estado]
|
||||
[id, cama.numero, cama.areaId, cama.tipo, cama.estado]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user