${escapeHTML(data.studyTitle)}
1. Study & Researcher Details
Affiliation: ${escapeHTML(data.institution)}
Principal Researcher: ${escapeHTML(data.researcher)}
Statement Date: ${escapeHTML(data.date)}
2. Informed Consent & Voluntary Participation
Consent Process:
${formatText(data.consentProcess)}
Voluntary Nature & Withdrawal:
${formatText(data.voluntary)}
3. Data Protection and Risk Management
Confidentiality & Storage:
${formatText(data.confidentiality)}
Anticipated Risks & Mitigation:
${formatText(data.risks)}
4. Oversight and Communication
IRB/Ethics Status: ${escapeHTML(data.irbStatus)}
IRB Reference Number: ${escapeHTML(data.irbRef)}
Debriefing & Results Sharing:
${formatText(data.debriefing)}
`;
};
const downloadTxt = () => {
const data = getData();
let content = `RESEARCH ETHICS STATEMENT\n`;
content += "========================================================\n";
content += `Study Title: ${data.studyTitle}\n`;
content += `Researcher: ${data.researcher}\n`;
content += `Institution: ${data.institution}\n`;
content += `Date: ${data.date}\n\n`;
content += "1. INFORMED CONSENT & VOLUNTARY PARTICIPATION\n";
content += "----------------------------------------------\n";
content += `Consent Process: ${data.consentProcess}\n\n`;
content += `Voluntary Participation & Withdrawal: ${data.voluntary}\n\n`;
content += "2. DATA PROTECTION & RISK MANAGEMENT\n";
content += "--------------------------------------\n";
content += `Confidentiality & Storage: ${data.confidentiality}\n\n`;
content += `Anticipated Risks & Mitigation: ${data.risks}\n\n`;
content += "3. OVERSIGHT AND COMMUNICATION\n";
content += "------------------------------\n";
content += `IRB Status: ${data.irbStatus}\n`;
content += `IRB Reference: ${data.irbRef}\n`;
content += `Debriefing & Results Sharing: ${data.debriefing}\n`;
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `ethics_statement_${data.researcher.replace(/ /g, '_')}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
};
const downloadPDF = () => {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert('Error: jsPDF library not loaded.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const data = getData();
const margin = 20;
const pageWidth = doc.internal.pageSize.getWidth();
const usableWidth = pageWidth - (margin * 2);
let yPos = 20;
const addTitle = (text, isMain = false) => {
if (yPos > 270) { doc.addPage(); yPos = 20; }
yPos += 5;
doc.setFontSize(isMain ? 16 : 14);
doc.setFont(undefined, 'bold');
doc.setTextColor(isMain ? 44 : 39, isMain ? 62 : 174, isMain ? 80 : 96); // Main dark, Section green
doc.text(text, margin, yPos);
doc.setDrawColor(224, 224, 224);
doc.line(margin, yPos + 1, pageWidth - margin, yPos + 1);
yPos += isMain ? 8 : 6;
};
const addText = (text, isParagraph = false, isBold = false) => {
if (yPos > 280) { doc.addPage(); yPos = 20; }
doc.setFontSize(10);
doc.setFont(undefined, isBold ? 'bold' : 'normal');
doc.setTextColor(52, 73, 94);
const lines = isParagraph ? doc.splitTextToSize(text, usableWidth) : text.split('\n');
if (lines.length * 6 + yPos > 285) { doc.addPage(); yPos = 20; }
lines.forEach(line => {
doc.text(line, margin, yPos);
yPos += 6;
});
yPos += isParagraph ? 2 : 1;
};
const addLabelValue = (label, value) => {
doc.setFontSize(10);
doc.setFont(undefined, 'bold');
doc.setTextColor(44, 62, 80);
doc.text(label, margin, yPos);
doc.setFont(undefined, 'normal');
doc.setTextColor(52, 73, 94);
doc.text(value, margin + 40, yPos); // Indent value
yPos += 6;
};
// --- Build PDF Document ---
// Header
doc.setFontSize(18);
doc.setFont(undefined, 'bold');
doc.setTextColor(44, 62, 80);
doc.text("Research Ethics Statement", pageWidth / 2, yPos, { align: 'center' });
yPos += 8;
doc.setFontSize(12);
doc.setFont(undefined, 'normal');
doc.text(data.studyTitle, pageWidth / 2, yPos, { align: 'center' });
yPos += 10;
// 1. Study Details
addTitle("1. Study & Researcher Details", false);
addLabelValue("Affiliation:", data.institution);
addLabelValue("Researcher:", data.researcher);
addLabelValue("Date:", data.date);
yPos += 5;
// 2. Consent & Withdrawal
addTitle("2. Informed Consent & Voluntary Participation", false);
addText("Consent Process:", false, true);
addText(data.consentProcess, true);
addText("Voluntary Participation & Withdrawal:", false, true);
addText(data.voluntary, true);
yPos += 5;
// 3. Confidentiality & Risk
addTitle("3. Data Protection and Risk Management", false);
addText("Confidentiality & Storage:", false, true);
addText(data.confidentiality, true);
addText("Anticipated Risks & Mitigation:", false, true);
addText(data.risks, true);
yPos += 5;
// 4. IRB & Debriefing
addTitle("4. Oversight and Communication", false);
addLabelValue("IRB Status:", data.irbStatus);
addLabelValue("IRB Reference:", data.irbRef);
addText("Debriefing & Results Sharing:", false, true);
addText(data.debriefing, true);
doc.save(`ethics_statement_${data.researcher.replace(/ /g, '_')}.pdf`);
};
// --- Event Listeners ---
// Tab Buttons
tabButtons.forEach((btn, index) => {
btn.addEventListener('click', () => showTab(index + 1));
});
// Next/Prev Navigation
nextBtn.addEventListener('click', () => showTab(currentTab + 1));
prevBtn.addEventListener('click', () => showTab(currentTab - 1));
// Tab 5 Actions
downloadPdfBtn.addEventListener('click', downloadPDF);
downloadTxtBtn.addEventListener('click', downloadTxt);
// --- Initialization ---
showTab(1);
});