Fix professional signature row only showing when form schema requires it

Only display the 'Falta firma enfermero' row and button when the assigned
consent form actually contains a firma_profesional field in its esquema.
get_consentimientos.php now computes requiere_firma_profesional from the
JSON schema and recepcion.php gates the row on that flag.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-03 11:55:20 -05:00
co-authored by Claude Sonnet 4.6
parent 05c7230eda
commit 2dec300f3a
2 changed files with 36 additions and 4 deletions
+34 -2
View File
@@ -37,7 +37,8 @@ $stmt = $pdo->prepare(
tc.firmado_at,
(tc.firma_profesional_svg IS NOT NULL) AS tiene_firma_profesional,
tc.firmado_profesional_at,
f.nombre AS formulario_nombre
f.nombre AS formulario_nombre,
f.esquema AS formulario_esquema
FROM turnero_consentimientos tc
LEFT JOIN lab_formularios f ON f.id = tc.formulario_id
WHERE tc.turno_id = ?
@@ -46,6 +47,22 @@ $stmt = $pdo->prepare(
$stmt->execute([$turnoId]);
$consentimientos = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Compute requiere_firma_profesional from schema; strip raw esquema from response
foreach ($consentimientos as &$c) {
$esquema = $c['formulario_esquema'] ?? null;
$campos = [];
if ($esquema) {
$decoded = json_decode($esquema, true);
$campos = is_array($decoded) ? $decoded : ($decoded['campos'] ?? []);
}
$c['requiere_firma_profesional'] = !empty(array_filter(
$campos,
fn($f) => ($f['tipo'] ?? '') === 'firma_profesional'
));
unset($c['formulario_esquema']);
}
unset($c);
$respuesta = [
'turno_id' => $turnoId,
'turno_estado' => $turno['estado'],
@@ -171,7 +188,8 @@ if ($incluirSolicitud) {
tc.estado, tc.enviado_at, tc.firmado_at,
(tc.firma_profesional_svg IS NOT NULL) AS tiene_firma_profesional,
tc.firmado_profesional_at,
f.nombre AS formulario_nombre
f.nombre AS formulario_nombre,
f.esquema AS formulario_esquema
FROM turnero_consentimientos tc
LEFT JOIN lab_formularios f ON f.id = tc.formulario_id
WHERE tc.turno_id = ?
@@ -179,6 +197,20 @@ if ($incluirSolicitud) {
);
$stmtC->execute([$turnoId]);
$consentimientos = $stmtC->fetchAll(PDO::FETCH_ASSOC);
foreach ($consentimientos as &$c) {
$esquema = $c['formulario_esquema'] ?? null;
$campos = [];
if ($esquema) {
$decoded = json_decode($esquema, true);
$campos = is_array($decoded) ? $decoded : ($decoded['campos'] ?? []);
}
$c['requiere_firma_profesional'] = !empty(array_filter(
$campos,
fn($f) => ($f['tipo'] ?? '') === 'firma_profesional'
));
unset($c['formulario_esquema']);
}
unset($c);
$respuesta['consentimientos'] = $consentimientos;
}
}
+2 -2
View File
@@ -1441,9 +1441,9 @@ function renderConsentimientos(lista) {
<i class="fab fa-whatsapp"></i> WhatsApp
</button>`;
// Fila de firma del profesional (solo visible si el paciente ya firmó)
// Fila de firma del profesional (solo si el formulario la requiere y el paciente ya firmó)
let profRow = '';
if (c.estado === 'firmado') {
if (c.estado === 'firmado' && c.requiere_firma_profesional) {
const tienePro = c.tiene_firma_profesional == 1 || c.tiene_firma_profesional === true;
if (tienePro) {
profRow = `<div class="consent-prof-row">