Update web/index.html
Browse files- web/index.html +45 -15
web/index.html
CHANGED
|
@@ -829,19 +829,25 @@
|
|
| 829 |
console.log('Respuesta del backend:', response);
|
| 830 |
|
| 831 |
if (response && response.success && response.consultations.length > 0) {
|
| 832 |
-
// Agrupar consultas por fecha
|
| 833 |
const grouped = {};
|
| 834 |
response.consultations.forEach(c => {
|
| 835 |
-
const
|
|
|
|
|
|
|
|
|
|
| 836 |
if (!grouped[d]) grouped[d] = {total:0, pos:0, neg:0};
|
| 837 |
grouped[d].total++;
|
| 838 |
if (c.diabeticRetinopathy) grouped[d].pos++; else grouped[d].neg++;
|
| 839 |
});
|
| 840 |
const dates = Object.keys(grouped).sort();
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
|
|
|
|
|
|
|
|
|
| 845 |
} else {
|
| 846 |
createEmptyChart();
|
| 847 |
}
|
|
@@ -1519,17 +1525,41 @@
|
|
| 1519 |
function loadAgeRangesData() {
|
| 1520 |
console.log('Cargando datos de rangos de edad...');
|
| 1521 |
|
| 1522 |
-
api.
|
| 1523 |
-
|
| 1524 |
-
|
| 1525 |
-
if (response && response.success) {
|
| 1526 |
-
currentAgeData = response;
|
| 1527 |
-
updateAgeRangesChart(response);
|
| 1528 |
-
updateAgeStatistics(response);
|
| 1529 |
-
} else {
|
| 1530 |
-
console.error('Error cargando datos de edad:', response?.error);
|
| 1531 |
showEmptyAgeChart();
|
|
|
|
| 1532 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1533 |
});
|
| 1534 |
}
|
| 1535 |
|
|
|
|
| 829 |
console.log('Respuesta del backend:', response);
|
| 830 |
|
| 831 |
if (response && response.success && response.consultations.length > 0) {
|
| 832 |
+
// Agrupar consultas por fecha — parsear correctamente
|
| 833 |
const grouped = {};
|
| 834 |
response.consultations.forEach(c => {
|
| 835 |
+
const raw = c.consultationDate || '';
|
| 836 |
+
// Soporta "2026-03-17 23:05:12" y "2026-03-17T23:05:12"
|
| 837 |
+
const d = raw.replace('T', ' ').substring(0, 10);
|
| 838 |
+
if (!d || d === '0000-00-00') return;
|
| 839 |
if (!grouped[d]) grouped[d] = {total:0, pos:0, neg:0};
|
| 840 |
grouped[d].total++;
|
| 841 |
if (c.diabeticRetinopathy) grouped[d].pos++; else grouped[d].neg++;
|
| 842 |
});
|
| 843 |
const dates = Object.keys(grouped).sort();
|
| 844 |
+
if (dates.length === 0) { createEmptyChart(); return; }
|
| 845 |
+
createOrUpdateChart(
|
| 846 |
+
dates,
|
| 847 |
+
dates.map(d => grouped[d].total),
|
| 848 |
+
dates.map(d => grouped[d].pos),
|
| 849 |
+
dates.map(d => grouped[d].neg)
|
| 850 |
+
);
|
| 851 |
} else {
|
| 852 |
createEmptyChart();
|
| 853 |
}
|
|
|
|
| 1525 |
function loadAgeRangesData() {
|
| 1526 |
console.log('Cargando datos de rangos de edad...');
|
| 1527 |
|
| 1528 |
+
api.getPatients('').then(function(response) {
|
| 1529 |
+
if (!response || !response.success || !response.patients.length) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1530 |
showEmptyAgeChart();
|
| 1531 |
+
return;
|
| 1532 |
}
|
| 1533 |
+
|
| 1534 |
+
const patients = response.patients.filter(p => p.birthDate);
|
| 1535 |
+
if (!patients.length) { showEmptyAgeChart(); return; }
|
| 1536 |
+
|
| 1537 |
+
// Calcular rangos de edad
|
| 1538 |
+
const ranges = {'0-20': 0, '21-40': 0, '41-60': 0, '61-80': 0, '80+': 0};
|
| 1539 |
+
let totalAge = 0, minAge = 999, maxAge = 0;
|
| 1540 |
+
|
| 1541 |
+
patients.forEach(p => {
|
| 1542 |
+
const age = moment().diff(moment(p.birthDate), 'years');
|
| 1543 |
+
totalAge += age;
|
| 1544 |
+
if (age < minAge) minAge = age;
|
| 1545 |
+
if (age > maxAge) maxAge = age;
|
| 1546 |
+
if (age <= 20) ranges['0-20']++;
|
| 1547 |
+
else if (age <= 40) ranges['21-40']++;
|
| 1548 |
+
else if (age <= 60) ranges['41-60']++;
|
| 1549 |
+
else if (age <= 80) ranges['61-80']++;
|
| 1550 |
+
else ranges['80+']++;
|
| 1551 |
+
});
|
| 1552 |
+
|
| 1553 |
+
const labels = Object.keys(ranges).filter(k => ranges[k] > 0);
|
| 1554 |
+
const data = labels.map(k => ranges[k]);
|
| 1555 |
+
|
| 1556 |
+
const chartData = { labels, data, total: patients.length };
|
| 1557 |
+
const avgAge = Math.round(totalAge / patients.length);
|
| 1558 |
+
|
| 1559 |
+
updateAgeRangesChart({ chart_data: chartData });
|
| 1560 |
+
$('#avgAge').text(avgAge);
|
| 1561 |
+
$('#ageRange').text(minAge + '-' + maxAge);
|
| 1562 |
+
$('#totalPatientsAge').text(patients.length);
|
| 1563 |
});
|
| 1564 |
}
|
| 1565 |
|