feat: implement remote CRUD for patients and update version
continuous-integration/webhook Deploy concluído (VPS4)
continuous-integration/webhook Deploy concluído (VPS4)
This commit is contained in:
@@ -207,6 +207,48 @@ router.get('/by-patient', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
// POST /api/images/patients - Criar paciente
|
||||
// Insere um registro "fantasma" (enabled=0) para manter os dados
|
||||
// ================================================================
|
||||
router.post('/patients', async (req, res) => {
|
||||
try {
|
||||
const { firstName, lastName, doctor, birthday, gender, phone, remark } = req.body;
|
||||
const fullName = `${firstName || ''} ${lastName || ''}`.trim();
|
||||
if (!fullName) return res.status(400).json({ error: 'Nome obrigatório' });
|
||||
|
||||
const crypto = require('crypto');
|
||||
const dummyGuid = crypto.randomUUID();
|
||||
|
||||
await db.run(
|
||||
`INSERT INTO images (
|
||||
image_guid, patient_name, doctor, remark, enabled, filename, original_filename
|
||||
) VALUES ($1, $2, $3, $4, 0, $5, $6)`,
|
||||
[
|
||||
dummyGuid,
|
||||
fullName,
|
||||
doctor || null,
|
||||
remark || null,
|
||||
'dummy_patient_record',
|
||||
'dummy_patient_record'
|
||||
]
|
||||
);
|
||||
|
||||
const io = req.app.get('io') || global.io;
|
||||
if (io) {
|
||||
io.emit('remote-crud-patient', {
|
||||
action: 'create',
|
||||
patient: { id: dummyGuid, firstName, lastName, doctor, birthday, gender, phone, remark, fullName }
|
||||
});
|
||||
}
|
||||
|
||||
res.json({ success: true, message: 'Paciente criado com sucesso' });
|
||||
} catch (error) {
|
||||
console.error('Erro ao criar paciente:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
// PUT /api/images/patients/:name - Editar dados de um paciente
|
||||
// Atualiza patient_name, doctor e remark em todas as imagens do paciente.
|
||||
@@ -243,6 +285,15 @@ router.put('/patients/:name', async (req, res) => {
|
||||
params
|
||||
);
|
||||
|
||||
const io = req.app.get('io') || global.io;
|
||||
if (io) {
|
||||
io.emit('remote-crud-patient', {
|
||||
action: 'update',
|
||||
oldName: oldName,
|
||||
patient: { newName: newName?.trim(), doctor, remark }
|
||||
});
|
||||
}
|
||||
|
||||
res.json({ success: true, updated: result.changes });
|
||||
} catch (error) {
|
||||
console.error('Erro ao editar paciente:', error);
|
||||
@@ -265,6 +316,12 @@ router.delete('/by-patient', async (req, res) => {
|
||||
}
|
||||
|
||||
await db.run('DELETE FROM images WHERE patient_name = $1', [patientName]);
|
||||
|
||||
const io = req.app.get('io') || global.io;
|
||||
if (io) {
|
||||
io.emit('remote-crud-patient', { action: 'delete', patientName });
|
||||
}
|
||||
|
||||
res.json({ success: true, count: images.length });
|
||||
} catch (error) {
|
||||
console.error('Erro ao excluir imagens do paciente:', error);
|
||||
|
||||
Reference in New Issue
Block a user