up
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user