From 1b441461ad4611c3074e54c79550451f34fd1d18 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 18 Apr 2026 13:10:47 -0500 Subject: [PATCH] up --- classes/lab/Paciente.php | 24 +++++++++++++++++++++++- enfermero_portal.php | 16 +++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/classes/lab/Paciente.php b/classes/lab/Paciente.php index e2daed7..a3b54ea 100644 --- a/classes/lab/Paciente.php +++ b/classes/lab/Paciente.php @@ -240,6 +240,28 @@ class Paciente { 'fecha_nacimiento', 'genero', 'direccion', 'ciudad', 'barrio', 'eps', 'notas_admin', 'is_active', ]; - return array_intersect_key($datos, array_flip($permitidos)); + $campos = array_intersect_key($datos, array_flip($permitidos)); + if (!empty($campos['telefono'])) { + $campos['telefono'] = $this->normalizarTelefono($campos['telefono']); + } + return $campos; + } + + /** + * Normaliza un número de teléfono colombiano al formato 57XXXXXXXXXX. + * - Elimina espacios, guiones y paréntesis. + * - Si empieza por +57 → quita el +. + * - Si tiene 10 dígitos empezando por 3 → antepone 57. + * - Cualquier otro caso lo devuelve limpio de caracteres no numéricos. + */ + private function normalizarTelefono(string $tel): string { + $tel = preg_replace('/[^0-9+]/', '', $tel); + if (str_starts_with($tel, '+')) { + $tel = ltrim($tel, '+'); + } + if (strlen($tel) === 10 && str_starts_with($tel, '3')) { + $tel = '57' . $tel; + } + return $tel; } } diff --git a/enfermero_portal.php b/enfermero_portal.php index 1ca2271..313be38 100644 --- a/enfermero_portal.php +++ b/enfermero_portal.php @@ -1419,6 +1419,20 @@ const formVer = { // ═══════════════════════════════════════════════════════ // agendaNueva — Agendar domicilio desde el portal enfermero // ═══════════════════════════════════════════════════════ + +/** + * Normaliza un teléfono colombiano a 573XXXXXXXXX (sin +). + * - 10 dígitos empezando por 3 → antepone 57 + * - +57XXXXXXXXXX → quita el + + * - Cualquier otro valor → solo dígitos + */ +function normalizarTelefono(val) { + let t = (val || '').replace(/[^0-9+]/g, ''); + if (t.startsWith('+')) t = t.slice(1); + if (t.length === 10 && t.startsWith('3')) t = '57' + t; + return t || null; +} + const agendaNueva = { _modal: null, _buscarTimer: null, @@ -1667,7 +1681,7 @@ const agendaNueva = { tipo_documento: document.getElementById('na-np-tipo-doc').value, numero_documento: documento, eps: document.getElementById('na-np-eps').value.trim() || null, - telefono: document.getElementById('na-np-telefono').value.trim() || null, + telefono: normalizarTelefono(document.getElementById('na-np-telefono').value), fecha_nacimiento: document.getElementById('na-np-fnac').value || null, email: document.getElementById('na-np-email').value.trim() || null, }),