174 lines
5.9 KiB
JavaScript
174 lines
5.9 KiB
JavaScript
async function recuperarCantidadGenero(tipoConsulta, filtros = {}) {
|
|
try {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
|
});
|
|
const data = await response.json();
|
|
return data.cantidad || 0;
|
|
} catch (error) {
|
|
console.error("Error al recuperar datos:", error);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
async function recuperarCantidadEdad(tipoConsulta, filtros = {}) {
|
|
try {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
|
});
|
|
const data = await response.json();
|
|
return data.cantidad || 0;
|
|
} catch (error) {
|
|
console.error("Error al recuperar datos:", error);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
async function recuperarCantidadEstado(tipoConsulta, filtros = {}) {
|
|
try {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
|
});
|
|
const data = await response.json();
|
|
if (!Array.isArray(data)) throw new Error("La respuesta del backend no es un array.");
|
|
return data;
|
|
} catch (error) {
|
|
console.error("Error al recuperar datos de estados:", error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
async function recuperarCantidadExamen(tipoConsulta, filtros = {}) {
|
|
try {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
|
});
|
|
const data = await response.json();
|
|
if (!Array.isArray(data)) throw new Error("La respuesta del backend no es un array");
|
|
return data;
|
|
} catch (error) {
|
|
console.error("Error al recuperar datos de examenes:", error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
async function recuperarCantidadFecha(tipoConsulta, filtros = {}) {
|
|
try {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta, ...filtros }),
|
|
});
|
|
const data = await response.json();
|
|
if (!Array.isArray(data)) throw new Error("La respuesta del backend no es un array.");
|
|
return data;
|
|
} catch (error) {
|
|
console.error("Error al recuperar datos de fechas:", error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
let filtroActivo = null; // Puede ser 'id_rango_edad', 'id_genero', 'id_examen', 'fechas' o null
|
|
|
|
function getFiltrosSeleccionados() {
|
|
const id_rango_edad = document.getElementById('id_rango_edad')?.value || "NULL";
|
|
const id_genero = document.getElementById('id_genero')?.value || "NULL";
|
|
const id_examen = document.getElementById('id_examen')?.value || "NULL";
|
|
const fechaInicio = document.getElementById('date1')?.value || "";
|
|
const fechaFin = document.getElementById('date2')?.value || "";
|
|
|
|
if (filtroActivo === 'id_rango_edad' && id_rango_edad !== "NULL") {
|
|
return { id_rango_edad };
|
|
}
|
|
if (filtroActivo === 'id_genero' && id_genero !== "NULL") {
|
|
return { id_genero };
|
|
}
|
|
if (filtroActivo === 'id_examen' && id_examen !== "NULL") {
|
|
return { id_examen };
|
|
}
|
|
if (filtroActivo === 'fechas' && fechaInicio && fechaFin) {
|
|
return { fechaInicio, fechaFin };
|
|
}
|
|
return {}; // Sin filtros
|
|
}
|
|
|
|
function setFiltroActivo(tipo) {
|
|
filtroActivo = tipo;
|
|
}
|
|
function getFiltroActivo() {
|
|
return filtroActivo;
|
|
}
|
|
|
|
async function obtenerDatosGeneros(filtros = {}) {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta: "Generos", ...filtros }),
|
|
});
|
|
return await response.json();
|
|
}
|
|
|
|
async function obtenerDatosEdades(filtros = {}) {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta: "Edades", ...filtros }),
|
|
});
|
|
return await response.json();
|
|
}
|
|
|
|
async function obtenerDatosEstados(filtros = {}) {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta: "Estados", ...filtros }),
|
|
});
|
|
return await response.json();
|
|
}
|
|
|
|
async function obtenerDatosExamenes(filtros = {}) {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta: "Examenes", ...filtros }),
|
|
});
|
|
return await response.json();
|
|
}
|
|
|
|
async function obtenerDatosFechas(filtros = {}) {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta: "Fechas", ...filtros }),
|
|
});
|
|
return await response.json();
|
|
}
|
|
|
|
async function obtenerResumenGenero(filtros = {}) {
|
|
const response = await fetch("../controllers/graficos.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ tipoConsulta: "ResumenGenero", ...filtros }),
|
|
});
|
|
return await response.json();
|
|
}
|
|
|
|
export {
|
|
obtenerDatosGeneros,
|
|
obtenerDatosEdades,
|
|
obtenerDatosEstados,
|
|
obtenerDatosExamenes,
|
|
obtenerDatosFechas,
|
|
getFiltrosSeleccionados,
|
|
setFiltroActivo,
|
|
getFiltroActivo,
|
|
obtenerResumenGenero // <-- Exporta la nueva función
|
|
}; |