diff --git a/susconecta/app/laudos/[id]/page.tsx b/susconecta/app/laudos/[id]/page.tsx index 4677027..2d62bb4 100644 --- a/susconecta/app/laudos/[id]/page.tsx +++ b/susconecta/app/laudos/[id]/page.tsx @@ -96,6 +96,136 @@ export default function LaudoPage() { window.print() } + const handleDownloadPDF = async () => { + if (!report) return + + try { + // Para simplificar, vamos usar jsPDF com html2canvas para capturar o conteúdo + const { jsPDF } = await import('jspdf') + const html2canvas = await import('html2canvas').then((m) => m.default) + + // Criar um elemento temporário com o conteúdo + const element = document.createElement('div') + element.style.position = 'absolute' + element.style.left = '-9999px' + element.style.width = '210mm' // A4 width + element.style.padding = '20mm' + element.style.backgroundColor = 'white' + element.style.fontFamily = 'Arial, sans-serif' + + // Extrair informações + const reportDate = new Date(report.report_date || report.created_at || Date.now()).toLocaleDateString('pt-BR') + const cid = report.cid ?? report.cid_code ?? report.cidCode ?? report.cie ?? '' + const exam = report.exam ?? report.exame ?? report.especialidade ?? report.report_type ?? '' + const diagnosis = report.diagnosis ?? report.diagnostico ?? report.diagnosis_text ?? report.diagnostico_text ?? '' + const conclusion = report.conclusion ?? report.conclusao ?? report.conclusion_text ?? report.conclusao_text ?? '' + const notesText = report.content ?? report.body ?? report.conteudo ?? report.notes ?? report.observacoes ?? '' + + // Extrair nome do médico + let doctorName = '' + if (doctor) { + doctorName = doctor.full_name || doctor.name || doctor.fullName || doctor.doctor_name || '' + } + if (!doctorName) { + const rd = report as any + const tryKeys = [ + 'doctor_name', 'doctor_full_name', 'doctorFullName', 'doctorName', + 'requested_by_name', 'requested_by', 'requester_name', 'requester', + 'created_by_name', 'created_by', 'executante', 'executante_name', + ] + for (const k of tryKeys) { + const v = rd[k] + if (v !== undefined && v !== null && String(v).trim() !== '') { + doctorName = String(v) + break + } + } + } + + // Montar HTML do documento + element.innerHTML = ` +
Data: ${reportDate}
+ ${doctorName ? `Profissional: ${doctorName}
` : ''} +CID
${cid}
EXAME / TIPO
${exam}
${diagnosis}
+${conclusion}
+${notesText}
+