SAFER-DAPT / index.html
AndreaImperatore04's picture
Update index.html
c2460f2 verified
Raw History Blame Contribute Delete
31.3 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SAFER-DAPT</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.plot.ly/plotly-2.27.0.min.js"></script>
<!-- Librerie per il PDF come nel tuo esempio funzionante -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<style>
:root {
--academic-blue: #0056b3;
--academic-dark: #1a202c;
--border-color: #dee2e6;
--bg-light: #f4f6f8;
}
body {
background-color: #ffffff;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
color: #333333;
font-size: 14px;
}
.academic-header {
background-color: var(--academic-blue);
color: white;
padding: 15px 0;
border-bottom: 4px solid #e9ecef;
}
.academic-header h1 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: 0.5px; }
.academic-header .subtitle { font-size: 13px; color: #e2e8f0; margin-top: 4px; }
.main-container { max-width: 1200px; margin: 20px auto; padding: 0 15px; }
.academic-panel {
border: 1px solid var(--border-color);
border-radius: 2px;
background-color: #ffffff;
margin-bottom: 20px;
}
.academic-panel-header {
background-color: var(--bg-light);
border-bottom: 1px solid var(--border-color);
padding: 10px 15px;
font-size: 15px;
font-weight: bold;
color: var(--academic-blue);
text-transform: uppercase;
display: flex;
justify-content: space-between;
align-items: center;
}
.academic-panel-body { padding: 15px; }
.form-label { font-size: 12px; font-weight: bold; color: #495057; margin-bottom: 4px; display: inline-flex; align-items: center; gap: 5px; }
.help-icon {
display: inline-block;
background-color: #e9ecef;
color: #6c757d;
border-radius: 50%;
width: 14px;
height: 14px;
text-align: center;
font-size: 10px;
line-height: 14px;
cursor: help;
font-weight: normal;
}
.form-control, .form-select {
border-radius: 2px;
border: 1px solid #ced4da;
padding: 4px 8px;
font-size: 13px;
height: 30px;
}
.form-control:focus, .form-select:focus { border-color: var(--academic-blue); box-shadow: none; }
.input-group-text, .input-group .form-control, .input-group .form-select { border-radius: 2px; }
.form-section-title {
font-size: 13px;
font-weight: bold;
color: #6c757d;
border-bottom: 1px solid #e9ecef;
padding-bottom: 5px;
margin-bottom: 15px;
margin-top: 5px;
}
.btn-compute {
background-color: var(--academic-blue);
color: white;
border: 1px solid #004085;
border-radius: 2px;
padding: 8px 24px;
font-size: 14px;
font-weight: bold;
transition: background-color 0.2s;
}
.btn-compute:hover { background-color: #004085; color: white; }
.btn-reset {
background-color: #f8f9fa;
color: #495057;
border: 1px solid #ced4da;
border-radius: 2px;
padding: 8px 16px;
font-size: 14px;
font-weight: bold;
margin-right: 10px;
transition: background-color 0.2s;
}
.btn-reset:hover { background-color: #e2e6ea; }
.btn-print, .btn-download {
background-color: #ffffff;
color: #495057;
border: 1px solid #ced4da;
border-radius: 2px;
padding: 4px 12px;
font-size: 12px;
font-weight: bold;
cursor: pointer;
margin-right: 5px;
}
.btn-download { background-color: var(--academic-blue); color: #ffffff; border-color: #004085; }
.btn-print:hover { background-color: #f4f6f8; }
.btn-download:hover { background-color: #004085; }
.result-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.result-table th, .result-table td { border: 1px solid var(--border-color); padding: 8px 12px; text-align: left; font-size: 14px; }
.result-table th { background-color: var(--bg-light); color: #495057; width: 35%; font-weight: bold; }
.result-table td.value-base { font-weight: bold; color: var(--academic-blue); }
.recommendation-box {
border-left: 4px solid var(--academic-blue);
background-color: #f8f9fa;
padding: 15px;
margin-bottom: 20px;
}
.recommendation-title { font-weight: bold; font-size: 15px; margin-bottom: 8px; color: var(--academic-dark); }
.recommendation-text { font-size: 14px; color: #333; margin: 0; }
.math-box {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 13px;
color: #d63384;
background-color: #f8f9fa;
border: 1px solid #e9ecef;
padding: 6px 10px;
border-radius: 2px;
display: inline-block;
margin: 4px 0;
white-space: nowrap;
overflow-x: auto;
max-width: 100%;
}
.doc-list { font-size: 13px; padding-left: 20px; margin-top: 10px; }
.doc-list li { margin-bottom: 8px; }
.nav-tabs .nav-link { border-radius: 2px 2px 0 0; color: #495057; font-size: 13px; font-weight: bold; padding: 8px 16px; }
.nav-tabs .nav-link.active { color: var(--academic-blue); border-top: 3px solid var(--academic-blue); }
.hidden { display: none !important; }
.alert-custom {
font-size: 13px;
padding: 10px;
border-radius: 2px;
margin-bottom: 20px;
}
@media print {
body { background-color: #ffffff; padding: 0; margin: 0; }
.academic-header, #inputPanel, .nav-tabs, #actionButtons, .help-icon { display: none !important; }
.main-container { width: 100%; max-width: 100%; margin: 0; padding: 0; }
.academic-panel { border: none; margin: 0; box-shadow: none; page-break-inside: avoid; }
.academic-panel-header { background-color: transparent; border-bottom: 2px solid #000; color: #000; padding: 0 0 10px 0; margin-bottom: 15px; }
.result-table th { background-color: #f8f9fa !important; -webkit-print-color-adjust: exact; }
.col-lg-5, .col-lg-7 { width: 100%; padding: 0; }
#tab3d { display: none !important; }
.recommendation-box { border-left-color: #000 !important; -webkit-print-color-adjust: exact; }
}
</style>
</head>
<body>
<header class="academic-header">
<div class="main-container m-0 mx-auto py-0">
<h1>SAFER-DAPT</h1>
<div class="subtitle">SAFINOUS-Assisted Framework for Evaluating Risk during Dual Antiplatelet Therapy.</div>
</div>
</header>
<div class="main-container">
<div id="validationAlert" class="alert alert-danger alert-custom hidden" role="alert"></div>
<!-- INSERIMENTO DATI -->
<div class="academic-panel" id="inputPanel">
<div class="academic-panel-header">Data Entry Form</div>
<div class="academic-panel-body">
<form id="patientForm">
<div class="row g-4">
<div class="col-lg-4">
<div class="form-section-title">Baseline & Laboratory</div>
<div class="row g-2 mb-2">
<div class="col-6">
<label class="form-label">Age</label>
<input type="number" class="form-control" id="Age" value="65">
</div>
<div class="col-6">
<label class="form-label">Sex</label>
<select class="form-select" id="Sex">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<label class="form-label mt-2">Hemoglobin</label>
<div class="input-group mb-2">
<input type="number" step="0.1" class="form-control" id="Hb" value="10.3">
<select class="form-select" id="HbUnit" style="max-width: 90px;">
<option value="g/dL">g/dL</option>
<option value="g/L">g/L</option>
<option value="mmol/L">mmol</option>
</select>
</div>
<label class="form-label mt-2">WBC Count</label>
<div class="input-group mb-2">
<input type="number" step="0.1" class="form-control" id="WBC" value="7.9">
<select class="form-select" id="WBCUnit" style="max-width: 100px;">
<option value="x10^3/uL">x10³/µL</option>
<option value="cells/uL">cells/µL</option>
</select>
</div>
<div class="row g-2 mt-2">
<div class="col-5">
<label class="form-label">CrCl <span class="help-icon" data-bs-toggle="tooltip" title="Estimated Creatinine Clearance (e.g. Cockcroft-Gault)">?</span></label>
<input type="number" class="form-control" id="CrCl" value="85">
</div>
<div class="col-7">
<label class="form-label">Creatinine</label>
<div class="input-group">
<input type="number" step="0.1" class="form-control" id="Creatinine" value="1.2">
<select class="form-select" id="CrUnit" style="padding-left:4px; padding-right:4px;">
<option value="mg/dL">mg/dL</option>
<option value="umol/L">µmol/L</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="form-section-title">Clinical History</div>
<label class="form-label">Prior Bleed <span class="help-icon" data-bs-toggle="tooltip" title="Previous spontaneous bleeding requiring hospitalization or blood transfusion">?</span></label>
<select class="form-select mb-3" id="PriorBleed"><option value="0">No Prior Bleeding</option><option value="1">Yes, Prior Bleeding</option></select>
<label class="form-label">Diabetes</label>
<select class="form-select mb-3" id="Diabetes"><option value="0">No</option><option value="1">Yes</option></select>
<label class="form-label">Active Smoker</label>
<select class="form-select mb-3" id="Smoking"><option value="0">No</option><option value="1">Yes</option></select>
<label class="form-label">Dyslipidemia</label>
<select class="form-select mb-3" id="Dyslipidemia"><option value="0">No</option><option value="1">Yes</option></select>
<label class="form-label">Hypertension</label>
<select class="form-select" id="Hypertension"><option value="0">No</option><option value="1">Yes</option></select>
</div>
<div class="col-lg-4">
<div class="form-section-title">Operative Details</div>
<label class="form-label">EVH <span class="help-icon" data-bs-toggle="tooltip" title="Endoscopic Vein Harvest technique used for SVG retrieval">?</span></label>
<select class="form-select mb-3" id="EVH"><option value="0">No</option><option value="1">Yes</option></select>
<label class="form-label">Complex Grafts <span class="help-icon" data-bs-toggle="tooltip" title="E.g. sequential grafts, Y-grafts, or concomitant endarterectomy">?</span></label>
<select class="form-select mb-3" id="ComplexGrafts"><option value="0">No</option><option value="1">Yes</option></select>
<label class="form-label">Number of SVG</label>
<select class="form-select mb-3" id="NSVG"><option value="1">1</option><option value="2" selected>2</option><option value="3">3</option><option value="4">4</option></select>
<label class="form-label">Graft Targets</label>
<div class="d-flex gap-2">
<select class="form-select" id="GraftDiag"><option value="0">No Diag</option><option value="1">Diag</option></select>
<select class="form-select" id="GraftLCx"><option value="0">No LCx/OM</option><option value="1">LCx/OM</option></select>
<select class="form-select" id="GraftRCA"><option value="0">No RCA</option><option value="1">RCA</option></select>
</div>
</div>
</div>
<hr class="mt-4 mb-3">
<div class="text-right d-flex justify-content-end">
<button type="button" class="btn-reset" onclick="resetForm()">Clear Form</button>
<button type="button" class="btn-compute" onclick="calculateRisk()">Run Risk Analysis</button>
</div>
</form>
</div>
</div>
<!-- SEZIONE RISULTATI -->
<div id="resultsSection" class="hidden">
<div class="row g-4" id="reportContent">
<div class="col-lg-5">
<div class="academic-panel">
<div class="academic-panel-header">
Clinical Report
<div id="actionButtons">
<button class="btn-print" onclick="window.print()">Print</button>
<button class="btn-download" onclick="downloadPDF()">Download PDF</button>
</div>
</div>
<div class="academic-panel-body">
<table class="result-table">
<tbody>
<tr>
<th>SAFINOUS Score</th>
<td id="valSafinous">0.0</td>
</tr>
<tr>
<th>PRECISE-DAPT</th>
<td id="valPrecise">0.0</td>
</tr>
<tr>
<th>CDRS+ Score</th>
<td class="value-base" id="valCDRS">0.0</td>
</tr>
<tr>
<th>CRI Index</th>
<td class="value-base" id="valCRI">0.0%</td>
</tr>
</tbody>
</table>
<div class="recommendation-box" id="trajectoryBox">
<div class="recommendation-title" id="valTrajectory">Trajectory</div>
<p class="recommendation-text" id="valRecommendation">Recommendation details.</p>
</div>
<div class="form-section-title mt-4">Continuous Metrics Formulas</div>
<div class="math-box text-nowrap">CDRS+ = max(0, 3·SAFINOUS - 2·PRECISE_DAPT + 100)</div><br>
<div class="math-box text-nowrap mt-1">CRI% = [ (P(Isch) - P(Bleed) + 1.0) / 2.0 ] × 100%</div>
<div class="form-section-title mt-4">Clinical Thresholds</div>
<ul class="doc-list">
<li><strong>High Ischemic:</strong> CDRS+ ≥ 65 (Prolonged DAPT)</li>
<li><strong>Balanced Risk:</strong> 40 ≤ CDRS+ < 65 (Short DAPT)</li>
<li><strong>High Bleeding:</strong> CDRS+ < 40 (Aspirin Mono)</li>
</ul>
</div>
</div>
</div>
<div class="col-lg-7">
<div class="academic-panel">
<div class="academic-panel-header">Data Visualization</div>
<div class="academic-panel-body p-0">
<ul class="nav nav-tabs px-3 pt-3" id="myTab" role="tablist">
<li class="nav-item" role="presentation"><button class="nav-link active" data-bs-toggle="tab" data-bs-target="#tab2d" type="button">2D Map</button></li>
<li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#tab3d" type="button">3D Map</button></li>
<li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#tabimpact" type="button">Feature Impact</button></li>
</ul>
<div class="tab-content p-3" id="myTabContent">
<div class="tab-pane fade show active" id="tab2d"><div id="plot2d" style="height: 480px; width:100%;"></div></div>
<div class="tab-pane fade" id="tab3d"><div id="plot3d" style="height: 480px; width:100%;"></div></div>
<div class="tab-pane fade" id="tabimpact">
<div id="plotDynamicImpactSaf" style="height: 240px; width:100%;"></div>
<div id="plotDynamicImpactPrec" style="height: 240px; width:100%; margin-top: 15px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(){
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
});
const plotlyBaseLayout = {
font: { family: 'Arial, sans-serif', color: '#333', size: 12 },
plot_bgcolor: '#ffffff',
paper_bgcolor: '#ffffff',
margin: { t: 40, b: 40, l: 50, r: 20 }
};
const bg_data = { p_isch: [], p_bleed: [], cri_pct: [] };
for(let i=0; i<84; i++) {
let p_i = Math.random() * 0.8 + 0.1;
let p_b = Math.random() * 0.8 + 0.1;
bg_data.p_isch.push(p_i);
bg_data.p_bleed.push(p_b);
bg_data.cri_pct.push(((p_i - p_b + 1.0) / 2.0) * 100.0);
}
function resetForm() {
document.getElementById("patientForm").reset();
document.getElementById("resultsSection").classList.add("hidden");
document.getElementById("validationAlert").classList.add("hidden");
window.scrollTo({ top: 0, behavior: 'smooth' });
}
function validateInputs(Age, Hb, WBC, CrCl, Creatinine) {
let errors = [];
if(isNaN(Age) || Age < 18 || Age > 110) errors.push("Age must be between 18 and 110 years.");
if(isNaN(Hb) || Hb < 3 || Hb > 25) errors.push("Hemoglobin value is outside expected clinical limits.");
if(isNaN(WBC) || WBC < 0.1 || WBC > 100) errors.push("WBC Count is outside expected clinical limits.");
if(isNaN(CrCl) || CrCl < 1 || CrCl > 250) errors.push("CrCl must be between 1 and 250 mL/min.");
if(isNaN(Creatinine) || Creatinine < 0.1 || Creatinine > 20) errors.push("Serum Creatinine is outside expected limits.");
return errors;
}
function calculateRisk() {
const alertBox = document.getElementById("validationAlert");
alertBox.classList.add("hidden");
alertBox.innerHTML = "";
const Age = parseFloat(document.getElementById('Age').value);
const SexFemale = document.getElementById('Sex').value === 'Female' ? 1 : 0;
let Hb = parseFloat(document.getElementById('Hb').value);
const HbUnit = document.getElementById('HbUnit').value;
if (HbUnit === 'g/L') Hb /= 10.0;
else if (HbUnit === 'mmol/L') Hb *= 1.611;
let WBC = parseFloat(document.getElementById('WBC').value);
const WBCUnit = document.getElementById('WBCUnit').value;
if (WBCUnit === 'cells/uL') WBC /= 1000.0;
const CrCl = parseFloat(document.getElementById('CrCl').value);
let Creatinine = parseFloat(document.getElementById('Creatinine').value);
const CrUnit = document.getElementById('CrUnit').value;
if (CrUnit === 'umol/L') Creatinine /= 88.4;
const validationErrors = validateInputs(Age, Hb, WBC, CrCl, Creatinine);
if(validationErrors.length > 0) {
alertBox.innerHTML = "<strong>Data Entry Error:</strong><br>" + validationErrors.join("<br>");
alertBox.classList.remove("hidden");
document.getElementById("resultsSection").classList.add("hidden");
window.scrollTo({ top: 0, behavior: 'smooth' });
return;
}
const PriorBleed = parseInt(document.getElementById('PriorBleed').value);
const Diabetes = parseInt(document.getElementById('Diabetes').value);
const Smoking = parseInt(document.getElementById('Smoking').value);
const Dyslipidemia = parseInt(document.getElementById('Dyslipidemia').value);
const EVH = parseInt(document.getElementById('EVH').value);
const ComplexGrafts = parseInt(document.getElementById('ComplexGrafts').value);
const NSVG = parseInt(document.getElementById('NSVG').value);
const GraftDiag = parseInt(document.getElementById('GraftDiag').value);
const GraftLCx = parseInt(document.getElementById('GraftLCx').value);
const GraftRCA = parseInt(document.getElementById('GraftRCA').value);
const CreaScore = Creatinine > 1.2 ? 1 : 0;
const Safinous = 0.1*(Age-55) - 3.0*(1-SexFemale) + 1.0*Dyslipidemia + 3.0*Diabetes +
3.0*Smoking + 2.0*CreaScore - 3.0*EVH + 4.0*ComplexGrafts +
2.0*(NSVG-1) + 4.0*GraftDiag + 4.0*GraftLCx + 3.0*GraftRCA;
let Precise = 0.3*Age - 1.5*Hb + 0.8*WBC - 0.15*CrCl + 15.0*PriorBleed + 35.0;
if (Precise < 5) Precise = 5;
if (Precise > 60) Precise = 60;
const raw_cdrs = (3.0 * Safinous) - (2.0 * Precise) + 100.0;
const CDRS_positive = Math.max(0.0, raw_cdrs);
const p_isch = 1.0 / (1.0 + Math.exp(-Safinous / 3.5));
const p_bleed = 1.0 / (1.0 + Math.exp(-(Precise - 25.0) / 5.0));
const CRI_pct = ((p_isch - p_bleed + 1.0) / 2.0) * 100.0;
let traj = "", rec = "", color = "", border_color = "";
if (CDRS_positive >= 65.0) {
traj = "High Ischemic Dominance";
rec = "Prolonged DAPT (6-12 months or longer) to maximize saphenous vein graft patency.";
color = "#0056b3"; border_color = "#0056b3";
} else if (CDRS_positive >= 40.0 && CDRS_positive < 65.0) {
traj = "Balanced Competing Risk (Grey Zone)";
rec = "Individualized, Short DAPT (1-3 months) combined with enhanced clinical surveillance.";
color = "#dc3545"; border_color = "#dc3545";
} else {
traj = "High Bleeding Dominance";
rec = "Aspirin Monotherapy (100 mg/day) to minimize hemorrhagic hazard.";
color = "#fd7e14"; border_color = "#fd7e14";
}
const resSection = document.getElementById('resultsSection');
resSection.classList.remove('hidden');
document.getElementById('valSafinous').innerText = Safinous.toFixed(1);
document.getElementById('valPrecise').innerText = Precise.toFixed(1);
document.getElementById('valCDRS').innerText = CDRS_positive.toFixed(1);
document.getElementById('valCRI').innerText = CRI_pct.toFixed(1) + "%";
document.getElementById('trajectoryBox').style.borderLeftColor = border_color;
const trajSpan = document.getElementById('valTrajectory');
trajSpan.innerText = traj;
trajSpan.style.color = color;
document.getElementById('valRecommendation').innerText = rec;
resSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
draw2DPlot(p_isch, p_bleed);
draw3DPlot(p_isch, p_bleed, CRI_pct);
drawDynamicFeatureImpact(Age, SexFemale, Dyslipidemia, Diabetes, Smoking, CreaScore, EVH, ComplexGrafts, NSVG, GraftDiag, GraftLCx, GraftRCA, Hb, WBC, CrCl, PriorBleed);
}
function draw2DPlot(px, py) {
const traceBg = { x: bg_data.p_isch, y: bg_data.p_bleed, mode: 'markers', name: 'Cohort', marker: {color: '#adb5bd', size: 6, opacity: 0.6}, type: 'scatter' };
const tracePt = { x: [px], y: [py], mode: 'markers+text', name: 'Patient', text: ['Patient'], textposition: 'top right', textfont: {family: 'Arial', weight: 'bold', color: '#000'}, marker: {color: '#dc3545', size: 10, symbol: 'square', line: {width: 1, color: '#000'}}, type: 'scatter' };
const layout = { ...plotlyBaseLayout, title: {text: 'Probability Distribution', font: {size: 14, weight: 'bold'}}, xaxis: {title: 'P(Ischemia)', gridcolor: '#e9ecef', zeroline: false}, yaxis: {title: 'P(Bleeding)', gridcolor: '#e9ecef', zeroline: false}, shapes: [ {type: 'line', x0: 0.5, y0: 0, x1: 0.5, y1: 1, line: {dash: 'dot', color: '#6c757d'}}, {type: 'line', x0: 0, y0: 0.5, x1: 1, y1: 0.5, line: {dash: 'dot', color: '#6c757d'}} ], showlegend: false };
Plotly.newPlot('plot2d', [traceBg, tracePt], layout, {responsive: true, displayModeBar: false});
}
function draw3DPlot(px, py, pz) {
const traceBg = { x: bg_data.p_isch, y: bg_data.p_bleed, z: bg_data.cri_pct, mode: 'markers', name: 'Cohort', marker: {color: '#adb5bd', size: 3, opacity: 0.5}, type: 'scatter3d' };
const tracePt = { x: [px], y: [py], z: [pz], mode: 'markers+text', name: 'Patient', text: ['Patient'], textposition: 'top center', marker: {color: '#dc3545', size: 5, symbol: 'square'}, type: 'scatter3d' };
const layout = { ...plotlyBaseLayout, scene: {xaxis: {title: 'P(Isch)', backgroundcolor: '#ffffff', gridcolor:'#e9ecef'}, yaxis: {title: 'P(Bleed)', backgroundcolor: '#ffffff', gridcolor:'#e9ecef'}, zaxis: {title: 'CRI %', backgroundcolor: '#ffffff', gridcolor:'#e9ecef'}}, margin: {t:0, b:0, l:0, r:0}, showlegend: false };
Plotly.newPlot('plot3d', [traceBg, tracePt], layout, {responsive: true, displayModeBar: false});
}
function drawDynamicFeatureImpact(Age, SexFemale, Dyslipidemia, Diabetes, Smoking, CreaScore, EVH, ComplexGrafts, NSVG, GraftDiag, GraftLCx, GraftRCA, Hb, WBC, CrCl, PriorBleed) {
let safData = [
{name: 'Age', val: 0.1 * (Age - 55)}, {name: 'Male', val: -3.0 * (1 - SexFemale)}, {name: 'Dyslipidemia', val: 1.0 * Dyslipidemia},
{name: 'Diabetes', val: 3.0 * Diabetes}, {name: 'Smoking', val: 3.0 * Smoking}, {name: 'Cr > 1.2', val: 2.0 * CreaScore},
{name: 'EVH', val: -3.0 * EVH}, {name: 'Complex Graft', val: 4.0 * ComplexGrafts}, {name: 'N. SVG', val: 2.0 * (NSVG - 1)},
{name: 'Diag', val: 4.0 * GraftDiag}, {name: 'LCx/OM', val: 4.0 * GraftLCx}, {name: 'RCA', val: 3.0 * GraftRCA}
].filter(d => d.val !== 0).sort((a,b) => Math.abs(a.val) - Math.abs(b.val));
let precData = [
{name: 'Age', val: 0.3 * Age}, {name: 'Hb', val: -1.5 * Hb}, {name: 'WBC', val: 0.8 * WBC},
{name: 'CrCl', val: -0.15 * CrCl}, {name: 'Prior Bleed', val: 15.0 * PriorBleed}
].filter(d => d.val !== 0).sort((a,b) => Math.abs(a.val) - Math.abs(b.val));
const drawStyledPlot = (data, divId, titleText) => {
const trace = { x: data.map(d => d.val), y: data.map(d => d.name), type: 'bar', orientation: 'h', marker: { color: '#0056b3' } };
const layout = { ...plotlyBaseLayout, title: { text: titleText, font: { size: 13, weight: 'bold' } }, xaxis: { showgrid: true, gridcolor: '#e9ecef', zeroline: true, zerolinecolor: '#6c757d', zerolinewidth: 1, tickfont: {size: 11} }, yaxis: { showgrid: false, tickfont: {size: 11} }, margin: { t: 30, b: 20, l: 100, r: 10 }, height: 240 };
Plotly.newPlot(divId, [trace], layout, {responsive: true, displayModeBar: false});
};
drawStyledPlot(safData, 'plotDynamicImpactSaf', 'SAFINOUS Impact Points');
drawStyledPlot(precData, 'plotDynamicImpactPrec', 'PRECISE-DAPT Impact Points');
}
// Funzione Download PDF basata esattamente sulla logica pulita del tuo esempio
async function downloadPDF() {
const buttons = document.getElementById('actionButtons');
buttons.style.display = 'none';
try {
const { jsPDF } = window.jspdf;
const element = document.getElementById('reportContent');
const canvas = await html2canvas(element, {
scale: 2,
useCORS: true,
backgroundColor: '#ffffff'
});
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF('p', 'mm', 'a4');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 10, pdfWidth, pdfHeight);
pdf.save('SAFER-DAPT_Clinical_Report.pdf');
} catch (error) {
console.error("PDF generation failed:", error);
alert("Failed to export PDF.");
} finally {
buttons.style.display = 'block';
}
}
document.querySelectorAll('button[data-bs-toggle="tab"]').forEach(el => {
el.addEventListener('shown.bs.tab', () => { window.dispatchEvent(new Event('resize')); });
});
</script>
</body>
</html>