fix: signature fields deduplicate and share across same-type fields
- PHP pre-computes one shared SVG per type (firma/firma_profesional) - Schema loop skips duplicate firma fields of same type already rendered - Patient signature from turnero widget propagates to all 'firma' schema fields - firmar_profesional.php saves nurse signature to ALL firma_profesional fields Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
8a5b4eef1e
commit
d7b1aea5a4
@@ -69,9 +69,13 @@ if (!$campoDef || ($campoDef['tipo'] ?? '') !== 'firma_profesional') {
|
||||
err('El campo no es una firma_profesional');
|
||||
}
|
||||
|
||||
// ── Actualizar datos_cliente ─────────────────────────────────────────
|
||||
// ── Actualizar datos_cliente: guardar en TODOS los campos firma_profesional ──
|
||||
$datos = json_decode($envio['datos_cliente'] ?? '{}', true) ?? [];
|
||||
$datos[$campoId . '_svg'] = $svg;
|
||||
foreach ($esquema as $c) {
|
||||
if (($c['tipo'] ?? '') === 'firma_profesional' && !empty($c['id'])) {
|
||||
$datos[$c['id'] . '_svg'] = $svg;
|
||||
}
|
||||
}
|
||||
|
||||
$nuevosDatos = json_encode($datos, JSON_UNESCAPED_UNICODE);
|
||||
$nuevoEstado = $envio['estado'] === 'firmado' ? 'firmado' : 'firmado';
|
||||
|
||||
@@ -421,6 +421,22 @@ function esc2(mixed $v): string {
|
||||
<?php
|
||||
$paciente = $datosPrefilled['__paciente'] ?? [];
|
||||
|
||||
// ── Pre-computar firma compartida por tipo ──────────────────────────
|
||||
// Si el paciente firmó una vez (cualquier campo o via turnero widget),
|
||||
// esa firma se usa en TODOS los campos firma del mismo tipo.
|
||||
$firmaSharedPaciente = $envio['firma_svg'] ?? null; // turnero widget
|
||||
$firmaSharedProfesional = null;
|
||||
foreach ($esquema as $_c) {
|
||||
$_t = $_c['tipo'] ?? '';
|
||||
$_id = $_c['id'] ?? null;
|
||||
if (!$_id) continue;
|
||||
if ($_t === 'firma' && !$firmaSharedPaciente) $firmaSharedPaciente = $datosCliente[$_id . '_svg'] ?? null;
|
||||
if ($_t === 'firma_profesional' && !$firmaSharedProfesional) $firmaSharedProfesional = $datosCliente[$_id . '_svg'] ?? null;
|
||||
}
|
||||
// Rastrear si ya renderizamos el widget de cada tipo para no duplicar el canvas
|
||||
$_renderedFirmaPaciente = false;
|
||||
$_renderedFirmaProfesional = false;
|
||||
|
||||
foreach ($esquema as $campo):
|
||||
$tipo = $campo['tipo'] ?? '';
|
||||
if ($tipo === 'separador'): ?>
|
||||
@@ -431,13 +447,21 @@ function esc2(mixed $v): string {
|
||||
if ($tipo === 'firma' || $tipo === 'firma_profesional'):
|
||||
$cid = $campo['id'] ?? null;
|
||||
if (!$cid) continue;
|
||||
$fSvg = $datosCliente[$cid . '_svg'] ?? null;
|
||||
$fFoto = $datosCliente[$cid . '_foto'] ?? null;
|
||||
$isPro = ($tipo === 'firma_profesional');
|
||||
// Usar firma compartida del tipo correspondiente
|
||||
$fSvg = $isPro ? $firmaSharedProfesional : $firmaSharedPaciente;
|
||||
$fFoto = $datosCliente[$cid . '_foto'] ?? null;
|
||||
$fIcon = $isPro ? 'fa-user-md' : 'fa-signature';
|
||||
$fColor = $isPro ? '#198754' : '#1565c0';
|
||||
$fLabel = htmlspecialchars($campo['label'] ?? ($isPro ? 'Firma profesional' : 'Firma paciente'));
|
||||
// Firma paciente sin contenido: omitir
|
||||
|
||||
// Si ya renderizamos la firma de este tipo, omitir duplicado
|
||||
if (!$isPro && $_renderedFirmaPaciente) { continue; }
|
||||
if ($isPro && $_renderedFirmaProfesional) { continue; }
|
||||
if (!$isPro) $_renderedFirmaPaciente = true;
|
||||
if ($isPro) $_renderedFirmaProfesional = true;
|
||||
|
||||
// Firma paciente sin contenido y sin widget turnero: omitir
|
||||
if (!$isPro && !$fSvg && !$fFoto) continue;
|
||||
?>
|
||||
<div class="section-title mt-3" style="color:<?= $fColor ?>">
|
||||
@@ -453,7 +477,7 @@ function esc2(mixed $v): string {
|
||||
</div>
|
||||
<?php elseif ($isPro): ?>
|
||||
<?php if (!$modoPublico): ?>
|
||||
<!-- Canvas para que el profesional firme ahora (solo sesión activa) -->
|
||||
<!-- Canvas para que el profesional firme (se replica en todos los campos firma_profesional) -->
|
||||
<div class="firma-pro-widget no-print" id="fpw-<?= htmlspecialchars($cid) ?>"
|
||||
data-envio="<?= (int)$envio['id'] ?>" data-campo="<?= htmlspecialchars($cid) ?>">
|
||||
<p class="text-muted small mb-2"><i class="fas fa-pen me-1"></i>Dibuje su firma en el recuadro:</p>
|
||||
|
||||
Reference in New Issue
Block a user