feat: sistema de notas clínicas para enfermero (ficha + notas libres) y fix lab_reportes métricas
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* POST /api/lab/delete_nota_domicilio.php
|
||||
* Elimina una nota libre de domicilio.
|
||||
* Las notas tipo='clinica' NO se pueden eliminar (solo editar/vaciar).
|
||||
*
|
||||
* Body JSON: { id }
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireMethod('POST');
|
||||
|
||||
try {
|
||||
$datos = inputJson();
|
||||
$id = (int)($datos['id'] ?? 0);
|
||||
if (!$id) jsonError('id requerido');
|
||||
|
||||
$db = Database::getInstance();
|
||||
$nota = $db->fetch('SELECT * FROM lab_domicilio_notas WHERE id = ?', [$id]);
|
||||
if (!$nota) jsonError('Nota no encontrada', 404);
|
||||
|
||||
if ($nota['tipo'] === 'clinica') {
|
||||
jsonError('La ficha clínica no puede eliminarse, solo editarse');
|
||||
}
|
||||
|
||||
// Solo el dueño o admin puede borrar
|
||||
if (userRole() === 'enfermero' && (int)$nota['enfermera_id'] !== enfermeraId()) {
|
||||
jsonError('Sin permiso para eliminar esta nota', 403);
|
||||
}
|
||||
|
||||
// Eliminar imagen adjunta si existe
|
||||
if (!empty($nota['imagen_path'])) {
|
||||
$imgPath = realpath(__DIR__ . '/../../uploads/media/' . $nota['imagen_path']);
|
||||
if ($imgPath && file_exists($imgPath)) {
|
||||
@unlink($imgPath);
|
||||
}
|
||||
}
|
||||
|
||||
$db->delete('lab_domicilio_notas', 'id = ?', [$id]);
|
||||
jsonOk(['id' => $id], 'Nota eliminada');
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log('[delete_nota_domicilio] ' . $e->getMessage());
|
||||
jsonError($e->getMessage(), 500);
|
||||
}
|
||||
Reference in New Issue
Block a user