Refactor tratamientos and login logic