fix: parsear d.data[] de la API de notas (no d.clinica/d.libres inexistentes)

This commit is contained in:
Lizandro Guarnizo
2026-03-25 14:21:17 -05:00
parent 921c6abd8c
commit 7917f4852e
2 changed files with 11 additions and 6 deletions
+5 -2
View File
@@ -1641,11 +1641,14 @@ const notasManager = {
async _cargar(domId) {
const r = await fetch(`api/lab/get_notas_domicilio.php?domicilio_id=${domId}`);
const d = await r.json();
const notas = d.success ? (d.data || []) : [];
const clinica = notas.find(n => n.tipo === 'clinica') || null;
const libres = notas.filter(n => n.tipo === 'libre');
this._cache[domId] = d.success
? { clinica: d.clinica || null, libres: d.libres || [] }
? { clinica, libres }
: { clinica: null, libres: [] };
// Actualizar badge
const total = (d.libres || []).length + (d.clinica ? 1 : 0);
const total = libres.length + (clinica ? 1 : 0);
const badge = document.getElementById(`nota-count-${domId}`);
if (badge) {
badge.textContent = total;
+6 -4
View File
@@ -830,8 +830,9 @@ async function cargarNotasDetalle(domId) {
const r = await fetch(`api/lab/get_notas_domicilio.php?domicilio_id=${domId}`);
const d = await r.json();
if (!d.success) return;
const c = d.clinica || {};
const libres = d.libres || [];
const notas = d.data || [];
const c = notas.find(n => n.tipo === 'clinica') || {};
const libres = notas.filter(n => n.tipo === 'libre');
const hayFicha = c.antecedentes || c.medicamentos || c.acudiente_nombre;
const hayLibres = libres.length > 0;
if (!hayFicha && !hayLibres) return;
@@ -898,8 +899,9 @@ async function verInformeDom() {
try {
const r = await fetch(`api/lab/get_notas_domicilio.php?domicilio_id=${dom.id}`);
const d = await r.json();
const c = d.success ? (d.clinica||{}) : {};
const libres = d.success ? (d.libres||[]) : [];
const notas = d.success ? (d.data || []) : [];
const c = notas.find(n => n.tipo === 'clinica') || {};
const libres = notas.filter(n => n.tipo === 'libre');
document.getElementById('inf-antecedentes').textContent = c.antecedentes || '—';
document.getElementById('inf-medicamentos').textContent = c.medicamentos || '—';