-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
679 lines (610 loc) · 26.4 KB
/
index.html
File metadata and controls
679 lines (610 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>StrokePredict - Risk Assessment</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<style>
/* General Styles */
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
margin: 0;
background-color: #f7f9fc;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
/* Navbar & Header (placeholder styles) */
.section-title {
text-align: center;
margin-bottom: 40px;
}
.section-title h2 {
font-size: 2.5rem;
color: #1e3a8a;
margin-bottom: 10px;
}
.section-title p {
font-size: 1.1rem;
color: #6b7280;
}
/* Assessment Section Layout */
.assessment-container {
display: flex;
flex-wrap: wrap;
gap: 40px;
align-items: flex-start;
justify-content: center;
}
.assessment-form, .assessment-results {
background-color: #fff;
padding: 30px;
border-radius: 15px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
flex: 1;
min-width: 300px;
}
.assessment-results {
position: relative;
}
/* Form Styling */
.assessment-form {
border: 1px solid #e5e7eb;
}
.form-row {
display: flex;
gap: 20px;
margin-bottom: 15px;
}
.form-group {
flex: 1;
display: flex;
flex-direction: column;
}
.form-group label {
font-weight: 600;
margin-bottom: 8px;
color: #4b5563;
}
.form-group input,
.form-group select {
width: 100%;
padding: 12px;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 1rem;
transition: border-color 0.3s;
}
.form-group input:focus,
.form-group select:focus {
outline: none;
border-color: #3b82f6;
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
/* Button Styles */
.btn {
padding: 12px 25px;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-flex;
align-items: center;
justify-content: center;
}
.btn-primary {
background-color: #1e3a8a;
color: #fff;
border: 1px solid #1e3a8a;
}
.btn-primary:hover {
background-color: #1f4094;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(31, 64, 148, 0.2);
}
.btn-outline {
background-color: transparent;
color: #1e3a8a;
border: 2px solid #1e3a8a;
}
.btn-outline:hover {
background-color: #1e3a8a;
color: #fff;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(31, 64, 148, 0.2);
}
.btn-block {
width: 100%;
margin-top: 20px;
}
/* Results Section */
#resultsContent {
display: none;
}
.results-placeholder {
text-align: center;
color: #9ca3af;
}
.results-placeholder i {
font-size: 3rem;
margin-bottom: 20px;
}
.risk-level h3 {
font-size: 1.5rem;
color: #1e3a8a;
}
.risk-meter {
position: relative;
height: 10px;
background-image: linear-gradient(to right, #4ade80, #facc15, #ef4444);
border-radius: 5px;
margin-top: 10px;
}
.risk-meter-indicator {
position: absolute;
top: 50%;
width: 12px;
height: 12px;
background-color: #333;
border: 2px solid #fff;
border-radius: 50%;
transform: translate(-50%, -50%);
transition: left 0.5s ease-in-out;
}
.risk-details h4 {
font-size: 1.25rem;
margin-top: 20px;
}
.comparison-table-container {
margin-top: 20px;
overflow-x: auto;
}
.comparison-table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
.comparison-table th,
.comparison-table td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #e5e7eb;
}
.comparison-table th {
background-color: #f3f4f6;
font-weight: 600;
color: #4b5563;
}
.comparison-table tbody tr:last-child td {
border-bottom: none;
}
.recommendations {
margin-top: 20px;
}
.recommendations ul {
list-style-type: disc;
padding-left: 20px;
margin: 0;
color: #4b5563;
}
.recommendations li {
margin-bottom: 10px;
}
.report-actions {
margin-top: 30px;
display: flex;
gap: 15px;
}
.report-actions .btn {
flex: 1;
}
/* Custom Modal for Alert */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
justify-content: center;
align-items: center;
}
.modal-content {
background-color: #fff;
padding: 30px;
border-radius: 15px;
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
max-width: 400px;
text-align: center;
}
.modal-header h2 {
margin-top: 0;
color: #ef4444;
}
.modal-body p {
margin: 20px 0;
}
.modal-footer .btn {
width: 100px;
}
@media (max-width: 768px) {
.assessment-container {
flex-direction: column;
}
.form-row {
flex-direction: column;
gap: 0;
}
}
</style>
</head>
<body>
{% include 'navbar.html' %}
<section class="assessment">
<div class="container">
<div class="section-title">
<h2>Stroke Risk Assessment</h2>
<p>Fill in your health details to assess your stroke risk factors and get personalized recommendations.</p>
</div>
<div class="assessment-container">
<div class="assessment-form">
<form id="riskAssessmentForm">
<div class="form-row">
<div class="form-group">
<label for="age">Age</label>
<input type="number" id="age" name="age" min="18" max="120" required>
</div>
<div class="form-group">
<label for="gender">Gender</label>
<select id="gender" name="gender" required>
<option value="">Select</option>
<option value="1">Male</option>
<option value="0">Female</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="height">Height (cm)</label>
<input type="number" id="height" name="height" min="100" max="250" step="0.1" required>
</div>
<div class="form-group">
<label for="weight">Weight (kg)</label>
<input type="number" id="weight" name="weight" min="30" max="300" step="0.1" required>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="systolic">Systolic BP (mmHg)</label>
<input type="number" id="systolic" name="systolic" min="70" max="250" required>
</div>
<div class="form-group">
<label for="diastolic">Diastolic BP (mmHg)</label>
<input type="number" id="diastolic" name="diastolic" min="40" max="150" required>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="cholesterol">Total Cholesterol (mg/dL)</label>
<input type="number" id="cholesterol" name="cholesterol" min="100" max="400" step="0.1" required>
</div>
<div class="form-group">
<label for="glucose">Glucose Level (mg/dL)</label>
<input type="number" id="glucose" name="glucose" min="50" max="300" step="0.1" required>
</div>
</div>
<div class="form-group">
<label for="smoking">Smoking Status</label>
<select id="smoking" name="smoking" required>
<option value="">Select</option>
<option value="0">Never smoked</option>
<option value="1">Former smoker</option>
<option value="2">Current smoker</option>
</select>
</div>
<div class="form-group">
<label for="activity">Physical Activity</label>
<select id="activity" name="activity" required>
<option value="">Select</option>
<option value="0">Sedentary</option>
<option value="1">Light (1-2 days/week)</option>
<option value="2">Moderate (3-5 days/week)</option>
<option value="3">Active (6-7 days/week)</option>
</select>
</div>
<div class="form-group">
<label for="history">Family History of Stroke</label>
<select id="history" name="history" required>
<option value="">Select</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
<button type="submit" class="btn btn-primary btn-block">Calculate My Risk</button>
</form>
</div>
<div class="assessment-results" id="assessmentResults">
<div class="results-placeholder" id="resultsPlaceholder">
<i class="fas fa-chart-pie"></i>
<h3>Your Results Will Appear Here</h3>
<p>Complete the assessment form to see your personalized stroke risk analysis and recommendations.</p>
</div>
<div class="results-content" id="resultsContent">
<div class="risk-level">
<h3>Your Stroke Risk Level</h3>
<div class="risk-meter">
<div class="risk-meter-indicator" id="riskMeterIndicator"></div>
</div>
<p id="riskLevelText">Moderate Risk</p>
</div>
<div class="risk-details">
<h4>Risk Factors Analysis</h4>
<p id="riskAnalysisText">Your assessment shows several moderate risk factors for stroke. The most significant factors are your blood pressure and physical activity level.</p>
</div>
<div class="comparison-table-container">
<h4>Health Metrics Comparison</h4>
<table class="comparison-table">
<thead>
<tr>
<th>Metric</th>
<th>Normal Range</th>
<th>High Risk Range</th>
<th>Your Value</th>
</tr>
</thead>
<tbody id="comparisonTableBody">
</tbody>
</table>
</div>
<div class="recommendations">
<h4>Personalized Recommendations</h4>
<ul id="recommendationsList">
</ul>
</div>
<div class="report-actions">
<button id="printReport" class="btn btn-primary">
<i class="fas fa-file-pdf"></i> Generate PDF
</button>
</div>
</div>
</div>
</div>
</div>
</section>
{% include 'footer.html' %}
{% include 'chatbot.html' %}
<div id="custom-alert-modal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Error</h2>
</div>
<div class="modal-body">
<p id="custom-alert-message">An unknown error occurred.</p>
</div>
<div class="modal-footer">
<button id="custom-alert-ok" class="btn btn-primary">OK</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const riskAssessmentForm = document.getElementById('riskAssessmentForm');
const resultsPlaceholder = document.getElementById('resultsPlaceholder');
const resultsContent = document.getElementById('resultsContent');
const riskMeterIndicator = document.getElementById('riskMeterIndicator');
const riskLevelText = document.getElementById('riskLevelText');
const riskAnalysisText = document.getElementById('riskAnalysisText');
const comparisonTableBody = document.getElementById('comparisonTableBody');
const recommendationsList = document.getElementById('recommendationsList');
const printReportBtn = document.getElementById('printReport');
const modal = document.getElementById('custom-alert-modal');
const modalMessage = document.getElementById('custom-alert-message');
const modalOkBtn = document.getElementById('custom-alert-ok');
// Function to show custom alert
function showAlert(message) {
modalMessage.textContent = message;
modal.style.display = 'flex';
}
// Close modal when OK is clicked
modalOkBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
// Initialize risk meter position
riskMeterIndicator.style.left = '50%';
riskAssessmentForm.addEventListener('submit', function(e) {
e.preventDefault();
// Show loading state
const submitButton = riskAssessmentForm.querySelector('button[type="submit"]');
const originalButtonText = submitButton.innerHTML;
submitButton.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Calculating...';
submitButton.disabled = true;
// Get form data as JSON, ensuring all fields are correctly parsed as numbers
const formData = {
age: parseInt(document.getElementById('age').value),
gender: parseInt(document.getElementById('gender').value),
height: parseFloat(document.getElementById('height').value),
weight: parseFloat(document.getElementById('weight').value),
systolic: parseInt(document.getElementById('systolic').value),
diastolic: parseInt(document.getElementById('diastolic').value),
cholesterol: parseFloat(document.getElementById('cholesterol').value),
glucose: parseFloat(document.getElementById('glucose').value),
smoking: parseInt(document.getElementById('smoking').value),
activity: parseInt(document.getElementById('activity').value),
history: parseInt(document.getElementById('history').value)
};
const apiUrl = window.location.origin + '/predict-structured';
console.log("Fetching URL:", apiUrl);
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(formData)
})
.then(async response => {
// First check if the response is JSON
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
const text = await response.text();
throw new Error(text || 'Server returned non-JSON response');
}
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Request failed');
}
return data;
})
.then(data => {
// Update UI with the received data
resultsPlaceholder.style.display = 'none';
resultsContent.style.display = 'block';
let riskPercentage;
if (data.risk_score >= 70) {
riskLevelText.textContent = "High Risk";
riskPercentage = 75 + Math.min(25, (data.risk_score - 70) / 30 * 25);
} else if (data.risk_score >= 40) {
riskLevelText.textContent = "Moderate Risk";
riskPercentage = 25 + ((data.risk_score - 40) / 30 * 50);
} else {
riskLevelText.textContent = "Low Risk";
riskPercentage = (data.risk_score / 40 * 25);
}
riskMeterIndicator.style.left = `${riskPercentage}%`;
let analysisText = `Based on your assessment (score: ${data.risk_score}): `;
if (riskLevelText.textContent === "High Risk") {
analysisText += "You have several significant risk factors for stroke. We strongly recommend consulting with a healthcare provider.";
} else if (riskLevelText.textContent === "Moderate Risk") {
analysisText += "You have some risk factors that could be improved. Consider lifestyle changes to reduce your risk further.";
} else {
analysisText += "You have relatively few stroke risk factors. Maintain your healthy habits and regular check-ups to keep your risk low.";
}
riskAnalysisText.textContent = analysisText;
// Calculate BMI for display
const bmi = (formData.weight / ((formData.height / 100) ** 2)).toFixed(1);
// Populate the comparison table
comparisonTableBody.innerHTML = `
<tr>
<td>Age</td>
<td>18-65 years</td>
<td>65+ years</td>
<td>${data.age} years</td>
</tr>
<tr>
<td>BMI</td>
<td>18.5-24.9</td>
<td>30+</td>
<td>${bmi}</td>
</tr>
<tr>
<td>Blood Pressure</td>
<td><120/80 mmHg</td>
<td>140/90+ mmHg</td>
<td>${data.bloodPressure} mmHg</td>
</tr>
<tr>
<td>Cholesterol</td>
<td><200 mg/dL</td>
<td>240+ mg/dL</td>
<td>${data.cholesterol} mg/dL</td>
</tr>
<tr>
<td>Glucose</td>
<td><100 mg/dL</td>
<td>126+ mg/dL</td>
<td>${data.glucose} mg/dL</td>
</tr>
<tr>
<td>Smoking</td>
<td>Never smoked</td>
<td>Current smoker</td>
<td>${data.smoking}</td>
</tr>
<tr>
<td>Activity</td>
<td>3-7 days/week</td>
<td>Sedentary</td>
<td>${data.activity}</td>
</tr>
<tr>
<td>History</td>
<td>No</td>
<td>Yes</td>
<td>${data.history}</td>
</tr>
`;
recommendationsList.innerHTML = '';
const recommendations = [];
if (formData.systolic >= 130 || formData.diastolic >= 80) {
recommendations.push("Monitor your blood pressure regularly and consult with a doctor about management strategies.");
}
if (formData.cholesterol >= 200) {
recommendations.push("Consider dietary changes to reduce cholesterol. Increase fiber intake and reduce saturated fats.");
}
if (formData.glucose >= 100) {
recommendations.push("Monitor your blood sugar levels. Reduce sugar intake and increase physical activity.");
}
if (formData.smoking === 2) {
recommendations.push("Quitting smoking is one of the most effective ways to reduce stroke risk. Seek support if needed.");
}
if (formData.activity === 0 || formData.activity === 1) {
recommendations.push("Aim for at least 150 minutes of moderate exercise per week, like brisk walking.");
}
if (bmi >= 25) {
recommendations.push("Aim for gradual weight loss through diet and exercise to reach a healthier BMI.");
}
if (recommendations.length === 0) {
recommendations.push("Continue with your current healthy lifestyle and maintain regular health check-ups.");
}
recommendations.forEach(rec => {
const li = document.createElement('li');
li.textContent = rec;
recommendationsList.appendChild(li);
});
// Scroll to results
document.getElementById('assessmentResults').scrollIntoView({ behavior: 'smooth' });
})
.catch(error => {
console.error('Error:', error);
// Use custom alert instead of browser's alert()
const cleanError = error.message.replace(/<[^>]*>?/gm, '');
showAlert('An error occurred: ' + cleanError);
})
.finally(() => {
// Restore button state
submitButton.innerHTML = originalButtonText;
submitButton.disabled = false;
});
});
// PDF Report Generation (same as before)
function generatePDF() {
// Your PDF generation code remains the same
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const element = document.querySelector('.assessment-results');
doc.html(element, {
callback: function (doc) {
doc.save('stroke_risk_report.pdf');
},
x: 15,
y: 15,
width: 170,
windowWidth: 650
});
}
printReportBtn.addEventListener('click', generatePDF);
});
</script>
</body>
</html>