From af584bcc2692c9a30e5046a9e698ff080005e592 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 24 Jun 2026 08:44:48 -0500 Subject: [PATCH] =?UTF-8?q?feat(pacientes):=20verificar=20WhatsApp=20al=20?= =?UTF-8?q?ingresar=20tel=C3=A9fono,=20vincular=20user=5Fid=20al=20guardar?= =?UTF-8?q?=20fix(recepcion):=20mostrar=20nombre=5Fcompleto=20en=20resulta?= =?UTF-8?q?dos=20de=20b=C3=BAsqueda=20de=20paciente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- api/lab/check_whatsapp.php | 21 +++++++++++++++++++++ api/lab/save_paciente.php | 9 +++++++++ lab_pacientes.php | 26 +++++++++++++++++++++++++- modules/turnero/views/recepcion.php | 2 +- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 api/lab/check_whatsapp.php diff --git a/api/lab/check_whatsapp.php b/api/lab/check_whatsapp.php new file mode 100644 index 0000000..9029105 --- /dev/null +++ b/api/lab/check_whatsapp.php @@ -0,0 +1,21 @@ +prepare("SELECT id, name, phone_number FROM users WHERE phone_number = ? LIMIT 1"); +$stmt->execute([$phone]); +$user = $stmt->fetch(PDO::FETCH_ASSOC); + +jsonOk([ + 'found' => (bool)$user, + 'user_id' => $user ? (int)$user['id'] : null, + 'phone_number' => $user ? $user['phone_number'] : null, +]); diff --git a/api/lab/save_paciente.php b/api/lab/save_paciente.php index 731c83a..b35aa9d 100644 --- a/api/lab/save_paciente.php +++ b/api/lab/save_paciente.php @@ -51,6 +51,15 @@ try { } // ──────────────────────────────────────────────────────────────────────── + // Auto-vincular user_id por teléfono si no viene explícito + if (empty($datos['user_id']) && !empty($telVal)) { + $pdo = db(); + $stmt = $pdo->prepare("SELECT id FROM users WHERE phone_number = ? LIMIT 1"); + $stmt->execute([$telVal]); + $wid = $stmt->fetchColumn(); + if ($wid) $datos['user_id'] = (int)$wid; + } + $pac = new Paciente(); $admin = adminId(); diff --git a/lab_pacientes.php b/lab_pacientes.php index 696c161..3c95956 100644 --- a/lab_pacientes.php +++ b/lab_pacientes.php @@ -283,8 +283,11 @@ require_once __DIR__ . '/shared/components/sidebar.php'; + placeholder="3001234567" tabindex="5" style="border-radius:0 .45rem .45rem 0" + onblur="verificarWhatsapp()"> +
+
@@ -517,6 +520,27 @@ async function editarPaciente(id) { if (d.data?.[0]) abrirFormulario(d.data[0]); } +async function verificarWhatsapp() { + const prefijo = document.getElementById('pac-tel-prefijo').value || '57'; + let tel = (document.getElementById('pac-tel').value || '').replace(/[^0-9]/g, ''); + if (tel.length === 10) tel = prefijo + tel; + const badge = document.getElementById('wa-badge'); + const hiddenUid = document.getElementById('pac-user-id'); + if (!tel || tel.length < 10) { badge.innerHTML = ''; hiddenUid.value = ''; return; } + badge.innerHTML = 'Verificando WhatsApp…'; + try { + const r = await fetch(`api/lab/check_whatsapp.php?phone=${encodeURIComponent(tel)}`); + const d = await r.json(); + if (d.ok && d.data.found) { + badge.innerHTML = 'Registrado en WhatsApp'; + hiddenUid.value = d.data.user_id; + } else { + badge.innerHTML = 'Sin WhatsApp registrado'; + hiddenUid.value = ''; + } + } catch(_) { badge.innerHTML = ''; hiddenUid.value = ''; } +} + async function guardarPaciente() { const form = document.getElementById('form-paciente'); if (!form.checkValidity()) { form.reportValidity(); return; } diff --git a/modules/turnero/views/recepcion.php b/modules/turnero/views/recepcion.php index c404ff9..29d4ecc 100644 --- a/modules/turnero/views/recepcion.php +++ b/modules/turnero/views/recepcion.php @@ -908,7 +908,7 @@ async function buscarPaciente() { } lista.innerHTML = datos.map(p => `
-
${escHtml((p.full_name||p.nombre||'') + ' ' + (p.apellido||''))}
+
${escHtml(p.nombre_completo||p.full_name||p.nombre||'')}
${escHtml(p.tipo_documento||'')} ${escHtml(p.documento||p.numero_documento||'')} ${p.telefono||p.celular ? '· ' + escHtml(p.telefono||p.celular) : ''}
`).join('');