51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* POST /modules/turnero/api/firmar_profesional_consentimiento.php
|
|
* Guarda la firma del enfermero/profesional en un consentimiento del turnero.
|
|
*
|
|
* Body JSON:
|
|
* turno_id int requerido
|
|
* formulario_id int requerido
|
|
* svg string requerido (data URI SVG o PNG base64)
|
|
*/
|
|
require_once __DIR__ . '/_helpers.php';
|
|
requireMethod('POST');
|
|
requireTurnero();
|
|
|
|
$body = inputJson();
|
|
$turnoId = (int)($body['turno_id'] ?? 0);
|
|
$formularioId = (int)($body['formulario_id'] ?? 0);
|
|
$svg = $body['svg'] ?? '';
|
|
|
|
if (!$turnoId) jsonError('turno_id requerido.');
|
|
if (!$formularioId) jsonError('formulario_id requerido.');
|
|
if (strlen($svg) < 100) jsonError('Firma requerida.');
|
|
if (!preg_match('/^data:image\/(svg\+xml|png|jpeg|webp);base64,/i', $svg)) {
|
|
jsonError('Formato de firma no válido.');
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
$stmt = $pdo->prepare(
|
|
"SELECT tc.id, tc.estado, t.sesion_id
|
|
FROM turnero_consentimientos tc
|
|
JOIN turnero_turnos t ON t.id = tc.turno_id
|
|
WHERE tc.turno_id = ? AND tc.formulario_id = ?"
|
|
);
|
|
$stmt->execute([$turnoId, $formularioId]);
|
|
$tc = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$tc) jsonError('Consentimiento no encontrado.', 404);
|
|
if ($tc['estado'] !== 'firmado') jsonError('El paciente debe firmar primero antes de que el profesional pueda firmar.');
|
|
|
|
$stmt = $pdo->prepare(
|
|
"UPDATE turnero_consentimientos
|
|
SET firma_profesional_svg = ?, firmado_profesional_at = NOW()
|
|
WHERE turno_id = ? AND formulario_id = ?"
|
|
);
|
|
$stmt->execute([$svg, $turnoId, $formularioId]);
|
|
|
|
notificarSSE((int)$tc['sesion_id']);
|
|
|
|
jsonOk(['mensaje' => 'Firma del profesional guardada correctamente.']);
|