File: /var/www/vhost/disk-apps/dev-telemedicina.teky.com.co/public/js/clinic_document/user_info.js
$(function () {
$("#documento").autocomplete({
source: "/pacientes/autocomplete",
minLength: 3,
select: function (event, ui) {
$('#guest_id').val(ui.item.id);
$("#documento").val(ui.item.value);
$('#nombre1').val(ui.item.nombre1);
$('#nombre2').val(ui.item.nombre2);
$('#apellido1').val(ui.item.apellido1);
$('#apellido2').val(ui.item.apellido2);
$('#direccion').val(ui.item.direccion);
$('#tipo_documento').val(ui.item.tipo_documento);
$('#country_id').val(ui.item.country_id)
setCity(ui.item.country_id, ui.item.department_id, ui.item.city_id);
$('#telefono').val(ui.item.telefono);
$('#aseguradora').val(ui.item.aseguradora);
$('#sexo').val(ui.item.sexo);
$('#email').val(ui.item.email);
if (ui.item.fecha_nacimiento) {
var d = ui.item.fecha_nacimiento;
d = d.split('-');
d = d[2] + '/' + d[1] + '/' + d[0];
$('#fecha_nacimiento').val(d);
_calculateAge();
}
/// set select de municipios
valor = ui.item.department_id;
if(!valor){
$('#city_id').empty();
var sel = '<option value="">-- Select</option>';
$('#city_id').append(sel);
return;
}
$.ajax({
url: "/city/get/" + valor,
type: "GET",
contentType: 'application/json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
'Content-Type': 'application/json'
},
success: function (r) {
if (r[0]["respuesta"]) {
var cities = r[0]["cities"];
$('#city_id').empty();
var sel = '<option value="">-- Select</option>';
$('#city_id').append(sel);
for (var i in cities) {
if(cities[i].id==ui.item.city_id){
var row = '<option value="' + cities[i].id + '" selected="selected">' + cities[i].name + '</option>';
}else{
var row = '<option value="' + cities[i].id + '">' + cities[i].name + '</option>';
}
$('#city_id').append(row);
}
} else {
$('#city_id').empty();
}
},
error: function(err){
}
});
}
});
});
$('#country_id').change(function () {
valor = $(this).val();
if(!valor){
$('#department_id').empty();
$('#city_id').empty();
return;
}
$('#modalLoader').modal('show');
$.ajax({
url: "/states/get/" + valor,
type: "GET",
contentType: 'application/json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
'Content-Type': 'application/json'
},
success: function (r) {
if (r[0]["respuesta"]) {
$('#modalLoader').modal('hide');
var states = r[0]["states"];
$('#department_id').empty();
var sel = '<option value="">-- Select</option>';
$('#department_id').append(sel);
for (var i in states) {
var row = '<option value="' + states[i].id + '">' + states[i].name + '</option>';
$('#department_id').append(row);
}
} else {
$('#department_id').empty();
$('#city_id').empty();
}
},
error: function(err){
$('#modalLoader').modal('hide');
}
});
});
$('#department_id').change(function () {
valor = $(this).val();
if(!valor){
$('#city_id').empty();
return;
}
$('#modalLoader').modal('show');
$.ajax({
url: "/city/get/" + valor,
type: "GET",
contentType: 'application/json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
'Content-Type': 'application/json'
},
success: function (r) {
if (r[0]["respuesta"]) {
$('#modalLoader').modal('hide');
var cities = r[0]["cities"];
$('#city_id').empty();
var sel = '<option value="">-- Select</option>';
$('#city_id').append(sel);
for (var i in cities) {
var row = '<option value="' + cities[i].id + '">' + cities[i].name + '</option>';
$('#city_id').append(row);
}
} else {
$('#city_id').empty();
}
},
error: function(err){
$('#modalLoader').modal('hide');
}
});
});