documents/generate: debug log em loadAllVariables
User reportou que mesmo com profile/paciente/clinica preenchidos os campos do dialog continuam vazios. Pra diagnosticar: - Promise.all -> Promise.allSettled: nao mascara falha individual - console.error por source que falhou (patient/session/therapist/clinic) - console.log com payload completo em dev mode (ownerId, tenantId, patientId, agendaEventoId, valores carregados, errors) Depois de identificar a causa esses logs ficam ou viram telemetria estruturada. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -243,12 +243,30 @@ export async function loadAllVariables(patientId, agendaEventoId = null, extras
|
|||||||
const ownerId = await getOwnerId();
|
const ownerId = await getOwnerId();
|
||||||
const tenantId = await getActiveTenantId(ownerId);
|
const tenantId = await getActiveTenantId(ownerId);
|
||||||
|
|
||||||
const [patient, session, therapist, clinic] = await Promise.all([
|
// Promise.allSettled pra nao mascarar falha individual: se uma source
|
||||||
|
// falhar, as outras ainda preenchem e a gente loga qual quebrou.
|
||||||
|
const results = await Promise.allSettled([
|
||||||
loadPatientData(patientId),
|
loadPatientData(patientId),
|
||||||
loadSessionData(agendaEventoId),
|
loadSessionData(agendaEventoId),
|
||||||
loadTherapistData(),
|
loadTherapistData(),
|
||||||
loadClinicData(tenantId)
|
loadClinicData(tenantId)
|
||||||
]);
|
]);
|
||||||
|
const labels = ['patient', 'session', 'therapist', 'clinic'];
|
||||||
|
const errors = [];
|
||||||
|
results.forEach((r, i) => {
|
||||||
|
if (r.status === 'rejected') {
|
||||||
|
errors.push({ source: labels[i], err: r.reason });
|
||||||
|
console.error(`[loadAllVariables] falha em ${labels[i]}:`, r.reason);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const [patient, session, therapist, clinic] = results.map(r => r.status === 'fulfilled' ? r.value : {});
|
||||||
|
if (import.meta?.env?.DEV) {
|
||||||
|
console.log('[loadAllVariables] resultados:', {
|
||||||
|
patient, session, therapist, clinic,
|
||||||
|
ownerId, tenantId, patientId, agendaEventoId,
|
||||||
|
errors
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve valor numérico (extras tem prioridade sobre session)
|
// Resolve valor numérico (extras tem prioridade sobre session)
|
||||||
const valorNum = extras.valor != null
|
const valorNum = extras.valor != null
|
||||||
|
|||||||
Reference in New Issue
Block a user