This commit is contained in:
Lizandro Guarnizo
2026-06-16 16:05:04 -05:00
parent 9e79b8ff56
commit 62c4e7a18c
2 changed files with 89 additions and 37 deletions
-36
View File
@@ -616,42 +616,6 @@ async function cargarFichaSolicitud(turnoId) {
listaEx.innerHTML = '<span class="text-muted small">Sin exámenes registrados</span>';
}
// Auto-crear tokens para formularios del lugar que aún no tengan registro
if (lugarId) {
const resF = await fetch(`${API}get_lugar_formularios.php?lugar_id=${lugarId}`);
const jsonF = await resF.json();
const forms = (jsonF.ok && jsonF.formularios) ? jsonF.formularios : [];
const existIds = new Set(consts.map(c => parseInt(c.formulario_id)));
const faltantes = forms.filter(f => !existIds.has(parseInt(f.id)));
if (faltantes.length > 0) {
await Promise.all(faltantes.map(f =>
fetch(API + 'create_consent_token.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ turno_id: turnoId, formulario_id: f.id }),
}).catch(() => {})
));
// Recargar consents tras la creación
const res2 = await fetch(`${API}get_consentimientos.php?turno_id=${turnoId}`);
const json2 = await res2.json();
if (json2.ok) consts = json2.consentimientos || [];
// Si alguno no se pudo crear (sin paciente), mostrarlo igual como pendiente visual
const createdIds = new Set(consts.map(c => parseInt(c.formulario_id)));
faltantes.forEach(f => {
if (!createdIds.has(parseInt(f.id))) {
consts.push({
id: null, turno_id: turnoId,
formulario_id: f.id, formulario_nombre: f.nombre,
estado: 'pendiente', token: null,
});
}
});
}
}
// Consentimientos
renderConsentimientos(consts);