feat(pacientes): verificar WhatsApp al ingresar teléfono, vincular user_id al guardar
fix(recepcion): mostrar nombre_completo en resultados de búsqueda de paciente Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
018d445846
commit
af584bcc26
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* GET /api/lab/check_whatsapp.php?phone=573001234567
|
||||
* Verifica si un número de teléfono está registrado en WhatsApp (tabla users).
|
||||
*/
|
||||
require_once __DIR__ . '/_helpers.php';
|
||||
requireAuth();
|
||||
|
||||
$phone = trim($_GET['phone'] ?? '');
|
||||
if (!$phone) { jsonError('phone requerido', 400); }
|
||||
|
||||
$pdo = db();
|
||||
$stmt = $pdo->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,
|
||||
]);
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user