Update app.py
Browse files
app.py
CHANGED
|
@@ -5,26 +5,23 @@ import joblib
|
|
| 5 |
import pickle
|
| 6 |
from PIL import Image
|
| 7 |
import io
|
| 8 |
-
import cv2
|
| 9 |
import os
|
| 10 |
import plotly.graph_objects as go
|
| 11 |
import plotly.express as px
|
| 12 |
from datetime import datetime
|
| 13 |
-
import requests
|
| 14 |
-
import json
|
| 15 |
import base64
|
| 16 |
from fpdf import FPDF
|
| 17 |
import tempfile
|
| 18 |
|
| 19 |
# Set page config first
|
| 20 |
st.set_page_config(
|
| 21 |
-
page_title="
|
| 22 |
page_icon="🏥",
|
| 23 |
layout="wide",
|
| 24 |
initial_sidebar_state="collapsed"
|
| 25 |
)
|
| 26 |
|
| 27 |
-
# Professional CSS Styling
|
| 28 |
def local_css():
|
| 29 |
st.markdown("""
|
| 30 |
<style>
|
|
@@ -34,21 +31,21 @@ def local_css():
|
|
| 34 |
text-align: center;
|
| 35 |
margin-bottom: 0.5rem;
|
| 36 |
font-weight: 800;
|
| 37 |
-
background: linear-gradient(135deg, #
|
| 38 |
-webkit-background-clip: text;
|
| 39 |
-webkit-text-fill-color: transparent;
|
| 40 |
text-shadow: 0px 4px 8px rgba(0,0,0,0.2);
|
| 41 |
font-family: 'Arial', sans-serif;
|
| 42 |
}
|
| 43 |
.quote-section {
|
| 44 |
-
background: linear-gradient(135deg, #
|
| 45 |
color: white;
|
| 46 |
padding: 25px;
|
| 47 |
border-radius: 20px;
|
| 48 |
text-align: center;
|
| 49 |
margin: 20px 0;
|
| 50 |
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
|
| 51 |
-
border: 3px solid #
|
| 52 |
}
|
| 53 |
.quote-text {
|
| 54 |
font-size: 1.4rem;
|
|
@@ -74,7 +71,7 @@ def local_css():
|
|
| 74 |
transform: translateY(-2px);
|
| 75 |
}
|
| 76 |
.metric-card {
|
| 77 |
-
background: linear-gradient(135deg, #
|
| 78 |
color: white;
|
| 79 |
padding: 25px;
|
| 80 |
border-radius: 15px;
|
|
@@ -111,7 +108,7 @@ def local_css():
|
|
| 111 |
box-shadow: 0 6px 15px rgba(40,167,69,0.4);
|
| 112 |
}
|
| 113 |
.priority-box {
|
| 114 |
-
border: 4px solid #
|
| 115 |
padding: 30px;
|
| 116 |
border-radius: 20px;
|
| 117 |
margin: 20px 0;
|
|
@@ -120,7 +117,7 @@ def local_css():
|
|
| 120 |
}
|
| 121 |
.stButton button {
|
| 122 |
width: 100%;
|
| 123 |
-
background: linear-gradient(45deg, #
|
| 124 |
color: white;
|
| 125 |
font-weight: bold;
|
| 126 |
border: none;
|
|
@@ -128,12 +125,12 @@ def local_css():
|
|
| 128 |
border-radius: 12px;
|
| 129 |
font-size: 1.2rem;
|
| 130 |
transition: all 0.3s ease;
|
| 131 |
-
box-shadow: 0 6px 15px rgba(
|
| 132 |
}
|
| 133 |
.stButton button:hover {
|
| 134 |
transform: translateY(-3px);
|
| 135 |
-
box-shadow: 0 10px 25px rgba(
|
| 136 |
-
background: linear-gradient(45deg, #
|
| 137 |
}
|
| 138 |
.chat-message {
|
| 139 |
padding: 15px;
|
|
@@ -142,7 +139,7 @@ def local_css():
|
|
| 142 |
border: 2px solid #e0e0e0;
|
| 143 |
}
|
| 144 |
.user-message {
|
| 145 |
-
background: linear-gradient(135deg, #
|
| 146 |
color: white;
|
| 147 |
margin-left: 20%;
|
| 148 |
text-align: right;
|
|
@@ -158,6 +155,14 @@ def local_css():
|
|
| 158 |
right: 20px;
|
| 159 |
z-index: 1000;
|
| 160 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
</style>
|
| 162 |
""", unsafe_allow_html=True)
|
| 163 |
|
|
@@ -177,29 +182,29 @@ def init_session_state():
|
|
| 177 |
# Healthcare quotes database
|
| 178 |
HEALTHCARE_QUOTES = [
|
| 179 |
{
|
| 180 |
-
'english': "
|
| 181 |
-
'urdu': "
|
| 182 |
-
'author': "
|
| 183 |
},
|
| 184 |
{
|
| 185 |
-
'english': "
|
| 186 |
-
'urdu': "
|
| 187 |
-
'author': "
|
| 188 |
},
|
| 189 |
{
|
| 190 |
-
'english': "
|
| 191 |
-
'urdu': "
|
| 192 |
-
'author': "
|
| 193 |
},
|
| 194 |
{
|
| 195 |
-
'english': "
|
| 196 |
-
'urdu': "
|
| 197 |
-
'author': "
|
| 198 |
},
|
| 199 |
{
|
| 200 |
-
'english': "
|
| 201 |
-
'urdu': "
|
| 202 |
-
'author': "
|
| 203 |
}
|
| 204 |
]
|
| 205 |
|
|
@@ -207,226 +212,379 @@ class HealthcareChatbot:
|
|
| 207 |
def __init__(self):
|
| 208 |
self.medical_knowledge_base = {
|
| 209 |
'heart_disease': {
|
| 210 |
-
'symptoms': ["Chest pain", "Shortness of breath", "
|
| 211 |
-
'risk_factors': ["High blood pressure", "High cholesterol", "Smoking", "Diabetes", "Obesity", "Family history"],
|
| 212 |
-
'prevention': ["Healthy diet", "Regular exercise", "No smoking", "Weight management", "Stress management"],
|
| 213 |
-
'emergency_signs': ["Severe chest pain", "Difficulty breathing", "Fainting", "Rapid heartbeat"]
|
| 214 |
},
|
| 215 |
'diabetes': {
|
| 216 |
-
'symptoms': ["Increased thirst", "Frequent urination", "Fatigue", "Blurred vision", "Slow healing"],
|
| 217 |
-
'risk_factors': ["Family history", "
|
| 218 |
-
'prevention': ["
|
| 219 |
-
'emergency_signs': ["
|
| 220 |
},
|
| 221 |
'hypertension': {
|
| 222 |
-
'symptoms': ["Headaches", "Dizziness", "Blurred vision", "Shortness of breath", "Chest pain"],
|
| 223 |
-
'risk_factors': ["Family history", "Age", "Obesity", "High salt intake", "Stress", "Alcohol"],
|
| 224 |
-
'prevention': ["
|
| 225 |
-
'emergency_signs': ["Severe headache", "Chest pain", "Difficulty breathing", "Vision changes"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
}
|
| 227 |
}
|
| 228 |
|
| 229 |
def get_response(self, user_input, language='English'):
|
| 230 |
-
user_input = user_input.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
# Heart disease related queries
|
| 233 |
-
if any(word in user_input for word in ['heart', 'cardiac', 'chest pain', 'cholesterol']):
|
| 234 |
return self._format_heart_response(language)
|
| 235 |
|
| 236 |
# Diabetes related queries
|
| 237 |
-
elif any(word in user_input for word in ['diabetes', 'sugar', 'glucose', 'insulin']):
|
| 238 |
return self._format_diabetes_response(language)
|
| 239 |
|
| 240 |
# Hypertension related queries
|
| 241 |
-
elif any(word in user_input for word in ['blood pressure', 'hypertension', 'bp']):
|
| 242 |
return self._format_hypertension_response(language)
|
| 243 |
|
| 244 |
-
#
|
| 245 |
-
elif any(word in user_input for word in ['
|
| 246 |
-
return self.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
# Symptoms assessment
|
| 249 |
-
elif any(word in user_input for word in ['symptom', 'pain', 'fever', 'headache']):
|
| 250 |
return self._format_symptoms_response(language)
|
| 251 |
|
| 252 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
else:
|
| 254 |
return self._format_default_response(language)
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
def _format_heart_response(self, language):
|
|
|
|
| 257 |
if language == 'English':
|
| 258 |
return f"""
|
| 259 |
-
**❤️ Heart Health Information**
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
-
|
| 262 |
-
{chr(10).join(['• ' +
|
| 263 |
|
| 264 |
-
|
| 265 |
-
{chr(10).join(['• ' +
|
| 266 |
|
| 267 |
-
|
| 268 |
-
{chr(10).join(['• ' +
|
| 269 |
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
-
|
| 274 |
"""
|
| 275 |
else:
|
| 276 |
return f"""
|
| 277 |
-
**❤️ دل کی صحت کی معلومات**
|
| 278 |
|
| 279 |
-
|
| 280 |
-
{chr(10).join(['• ' + symptom for symptom in ['سینے میں درد', 'سانس لینے میں دشواری', '
|
| 281 |
|
| 282 |
-
|
| 283 |
-
{chr(10).join(['• ' + factor for factor in ['ہائی بلڈ پریشر', 'ہائی کولیسٹرول', 'سگریٹ نوشی', 'ذیابیطس', 'موٹاپا', 'خاندانی تاریخ']])}
|
| 284 |
|
| 285 |
-
|
| 286 |
-
{chr(10).join(['• ' + tip for tip in ['صحت مند غذا', 'باقاعدہ ورزش', 'سگریٹ نوشی سے پرہیز', 'وزن کا انتظام', 'تناؤ کا انتظام']])}
|
| 287 |
|
| 288 |
-
|
| 289 |
-
{chr(10).join(['• ' + sign for sign in ['شدید سینے میں درد', 'سانس لینے میں شدید دشواری', 'بیہوش ہونا', 'تیز دل کی دھڑکن']])}
|
| 290 |
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
"""
|
| 293 |
|
| 294 |
def _format_diabetes_response(self, language):
|
|
|
|
| 295 |
if language == 'English':
|
| 296 |
return f"""
|
| 297 |
-
**🩺 Diabetes Information**
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
-
|
| 300 |
-
{chr(10).join(['• ' +
|
| 301 |
|
| 302 |
-
|
| 303 |
-
{chr(10).join(['• ' +
|
| 304 |
|
| 305 |
-
|
| 306 |
-
{chr(10).join(['• ' +
|
| 307 |
|
| 308 |
-
|
| 309 |
-
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
-
|
| 312 |
"""
|
| 313 |
else:
|
| 314 |
return f"""
|
| 315 |
-
**🩺 ذیابیطس کی معلومات**
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
-
|
| 318 |
-
{chr(10).join(['• ' +
|
| 319 |
|
| 320 |
-
|
| 321 |
-
{chr(10).join(['• ' +
|
| 322 |
|
| 323 |
-
|
| 324 |
-
{chr(10).join(['• ' +
|
| 325 |
|
| 326 |
-
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
| 328 |
|
| 329 |
-
|
| 330 |
"""
|
| 331 |
|
| 332 |
def _format_hypertension_response(self, language):
|
|
|
|
| 333 |
if language == 'English':
|
| 334 |
return f"""
|
| 335 |
-
**💓 Blood Pressure Information**
|
| 336 |
|
| 337 |
-
|
| 338 |
-
{chr(10).join(['• ' + symptom for symptom in
|
| 339 |
|
| 340 |
-
|
| 341 |
-
{chr(10).join(['• ' + factor for factor in
|
| 342 |
|
| 343 |
-
|
| 344 |
-
{chr(10).join(['• ' + tip for tip in
|
| 345 |
|
| 346 |
-
|
| 347 |
-
{chr(10).join(['• ' + sign for sign in
|
| 348 |
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
"""
|
| 351 |
else:
|
| 352 |
return f"""
|
| 353 |
-
**💓 بلڈ پریشر کی معلومات**
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
-
|
| 356 |
-
{chr(10).join(['• ' +
|
| 357 |
|
| 358 |
-
|
| 359 |
-
{chr(10).join(['• ' +
|
| 360 |
|
| 361 |
-
|
| 362 |
-
{chr(10).join(['• ' +
|
| 363 |
|
| 364 |
-
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
-
|
| 368 |
"""
|
| 369 |
|
| 370 |
-
def
|
|
|
|
| 371 |
if language == 'English':
|
| 372 |
-
return """
|
| 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 |
-
• Practice good hygiene
|
| 398 |
-
|
| 399 |
-
*Remember: Small consistent changes lead to big health improvements!*
|
| 400 |
"""
|
| 401 |
else:
|
| 402 |
-
return """
|
| 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 |
def _format_symptoms_response(self, language):
|
|
@@ -434,118 +592,348 @@ class HealthcareChatbot:
|
|
| 434 |
return """
|
| 435 |
**🔍 Symptom Assessment Guidance**
|
| 436 |
|
| 437 |
-
|
| 438 |
• Persistent fever above 103°F (39.4°C)
|
| 439 |
• Difficulty breathing or chest pain
|
| 440 |
• Severe abdominal pain
|
| 441 |
-
• Sudden dizziness or confusion
|
| 442 |
-
• Unexplained weight loss
|
| 443 |
• Symptoms lasting more than 2 weeks
|
|
|
|
| 444 |
|
| 445 |
-
|
| 446 |
-
• Rest and
|
| 447 |
-
• Monitor symptoms and temperature
|
| 448 |
• Use over-the-counter medications as directed
|
| 449 |
-
• Apply cold/heat packs as
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
•
|
| 454 |
-
•
|
| 455 |
-
•
|
| 456 |
-
•
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
| 459 |
"""
|
| 460 |
else:
|
| 461 |
return """
|
| 462 |
**🔍 علامات کی تشخیص کی رہنمائی**
|
| 463 |
|
| 464 |
-
|
| 465 |
• 103°F (39.4°C) سے اوپر مستقل بخار
|
| 466 |
• سانس لینے میں دشواری یا سینے میں درد
|
| 467 |
• شدید پیٹ کا درد
|
| 468 |
-
• اچانک چکر
|
| 469 |
-
• بے وجہ وزن میں کمی
|
| 470 |
• 2 ہفتے سے زیادہ علامات برقرار رہنا
|
|
|
|
| 471 |
|
| 472 |
-
|
| 473 |
-
• آرام
|
| 474 |
-
• علامات اور درجہ حرارت کی نگرانی
|
| 475 |
• ہدایت کے مطابق اوور دی کاؤنٹر ادویات استعمال کریں
|
| 476 |
-
• حسب
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
|
| 478 |
-
|
| 479 |
-
•
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
• سینے میں درد یا دباؤ
|
|
|
|
| 481 |
• شدید خون بہنا
|
| 482 |
-
• اچانک
|
| 483 |
-
•
|
| 484 |
-
|
| 485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
"""
|
| 487 |
|
| 488 |
-
def
|
|
|
|
| 489 |
if language == 'English':
|
| 490 |
-
return """
|
| 491 |
-
|
| 492 |
|
| 493 |
-
|
| 494 |
-
•
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
•
|
| 498 |
-
• Symptom assessment guidance
|
| 499 |
|
| 500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
|
| 502 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
"""
|
| 504 |
else:
|
| 505 |
-
return """
|
| 506 |
-
|
| 507 |
|
| 508 |
-
|
| 509 |
-
•
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
•
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
| 515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
|
| 517 |
-
*یاد رکھیں:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 518 |
"""
|
| 519 |
|
| 520 |
class PDFReportGenerator:
|
| 521 |
def __init__(self):
|
| 522 |
self.pdf = FPDF()
|
| 523 |
-
|
|
|
|
| 524 |
def generate_report(self, patient_data, risk_scores, language='English'):
|
| 525 |
self.pdf.add_page()
|
| 526 |
|
| 527 |
# Title
|
| 528 |
self.pdf.set_font('Arial', 'B', 16)
|
| 529 |
if language == 'English':
|
| 530 |
-
self.pdf.cell(0, 10, 'MEDICAL ASSESSMENT REPORT', 0, 1, 'C')
|
| 531 |
else:
|
| 532 |
-
|
|
|
|
| 533 |
|
| 534 |
self.pdf.ln(10)
|
| 535 |
|
| 536 |
# Patient Information
|
| 537 |
self.pdf.set_font('Arial', 'B', 12)
|
| 538 |
-
|
| 539 |
-
self.pdf.cell(0, 10, 'Patient Information:', 0, 1)
|
| 540 |
-
else:
|
| 541 |
-
self.pdf.cell(0, 10, 'مریض کی معلومات:', 0, 1)
|
| 542 |
|
| 543 |
self.pdf.set_font('Arial', '', 10)
|
| 544 |
patient_info = [
|
| 545 |
-
f"Name: {patient_data.get('name', 'Not provided')}",
|
| 546 |
f"Age: {patient_data.get('age', 'Not provided')} years",
|
| 547 |
-
f"Gender: {patient_data.get('gender', 'Not provided')}",
|
| 548 |
-
f"Contact: {patient_data.get('contact', 'Not provided')}"
|
| 549 |
]
|
| 550 |
|
| 551 |
for info in patient_info:
|
|
@@ -555,10 +943,7 @@ class PDFReportGenerator:
|
|
| 555 |
|
| 556 |
# Clinical Parameters
|
| 557 |
self.pdf.set_font('Arial', 'B', 12)
|
| 558 |
-
|
| 559 |
-
self.pdf.cell(0, 10, 'Clinical Parameters:', 0, 1)
|
| 560 |
-
else:
|
| 561 |
-
self.pdf.cell(0, 10, 'کلینیکل پیرامیٹرز:', 0, 1)
|
| 562 |
|
| 563 |
self.pdf.set_font('Arial', '', 10)
|
| 564 |
clinical_info = [
|
|
@@ -574,12 +959,29 @@ class PDFReportGenerator:
|
|
| 574 |
|
| 575 |
self.pdf.ln(5)
|
| 576 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
# Risk Assessment
|
| 578 |
self.pdf.set_font('Arial', 'B', 12)
|
| 579 |
-
|
| 580 |
-
self.pdf.cell(0, 10, 'Risk Assessment:', 0, 1)
|
| 581 |
-
else:
|
| 582 |
-
self.pdf.cell(0, 10, 'خطرے کی تشخیص:', 0, 1)
|
| 583 |
|
| 584 |
self.pdf.set_font('Arial', '', 10)
|
| 585 |
risk_info = [
|
|
@@ -596,25 +998,81 @@ class PDFReportGenerator:
|
|
| 596 |
|
| 597 |
# Recommendation
|
| 598 |
self.pdf.set_font('Arial', 'B', 12)
|
| 599 |
-
|
| 600 |
-
self.pdf.cell(0, 10, 'Clinical Recommendation:', 0, 1)
|
| 601 |
-
else:
|
| 602 |
-
self.pdf.cell(0, 10, 'کلینیکل سفارش:', 0, 1)
|
| 603 |
|
| 604 |
self.pdf.set_font('Arial', '', 10)
|
| 605 |
-
recommendation = risk_scores.get('recommendation', 'No recommendation available')
|
| 606 |
self.pdf.multi_cell(0, 8, recommendation)
|
| 607 |
|
| 608 |
self.pdf.ln(10)
|
| 609 |
|
| 610 |
# Footer
|
| 611 |
self.pdf.set_font('Arial', 'I', 8)
|
| 612 |
-
|
| 613 |
-
self.pdf.cell(0, 10, f'Generated on: {datetime.now().strftime("%Y-%m-%d %H:%M")}', 0, 1, 'C')
|
| 614 |
-
else:
|
| 615 |
-
self.pdf.cell(0, 10, f'تاریخ پیدائش: {datetime.now().strftime("%Y-%m-%d %H:%M")}', 0, 1, 'C')
|
| 616 |
|
| 617 |
-
return self.pdf.output(dest='S').encode('latin1')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
|
| 619 |
def calculate_priority_score(heart_risk, diabetes_risk, hypertension_risk):
|
| 620 |
"""Calculate integrated priority score with clinical weighting"""
|
|
@@ -660,89 +1118,153 @@ def validate_patient_data(age, bp_systolic, bp_diastolic, heart_rate):
|
|
| 660 |
|
| 661 |
return errors
|
| 662 |
|
| 663 |
-
def
|
| 664 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
|
| 666 |
-
#
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
|
| 671 |
-
#
|
| 672 |
-
if
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
hypertension_risk += 0.12
|
| 676 |
-
elif age > 40:
|
| 677 |
-
heart_risk += 0.10
|
| 678 |
-
diabetes_risk += 0.07
|
| 679 |
-
hypertension_risk += 0.08
|
| 680 |
-
elif age > 30:
|
| 681 |
-
heart_risk += 0.05
|
| 682 |
-
diabetes_risk += 0.04
|
| 683 |
-
hypertension_risk += 0.05
|
| 684 |
|
| 685 |
-
#
|
| 686 |
-
if
|
| 687 |
-
|
| 688 |
-
hypertension_risk += 0.30
|
| 689 |
-
elif bp_systolic > 130 or bp_diastolic > 85:
|
| 690 |
-
heart_risk += 0.15
|
| 691 |
-
hypertension_risk += 0.20
|
| 692 |
|
| 693 |
-
#
|
| 694 |
-
if
|
| 695 |
-
|
| 696 |
-
elif
|
| 697 |
-
heart_risk += 0.12
|
| 698 |
|
| 699 |
-
# Glucose
|
| 700 |
-
if glucose >
|
| 701 |
-
|
| 702 |
-
heart_risk += 0.15
|
| 703 |
-
elif glucose > 100: # Pre-diabetic range
|
| 704 |
-
diabetes_risk += 0.20
|
| 705 |
-
heart_risk += 0.08
|
| 706 |
|
| 707 |
-
#
|
| 708 |
-
if
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
|
| 717 |
# Symptom factors
|
| 718 |
-
if symptoms['
|
| 719 |
-
|
| 720 |
-
if symptoms['shortness_breath']:
|
| 721 |
-
heart_risk += 0.15
|
| 722 |
-
hypertension_risk += 0.10
|
| 723 |
-
if symptoms['palpitations']:
|
| 724 |
-
heart_risk += 0.10
|
| 725 |
-
hypertension_risk += 0.08
|
| 726 |
-
if symptoms['fatigue']:
|
| 727 |
-
diabetes_risk += 0.12
|
| 728 |
-
heart_risk += 0.08
|
| 729 |
-
if symptoms['dizziness']:
|
| 730 |
-
hypertension_risk += 0.15
|
| 731 |
-
if symptoms['blurred_vision']:
|
| 732 |
-
diabetes_risk += 0.10
|
| 733 |
-
hypertension_risk += 0.08
|
| 734 |
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
|
| 740 |
-
#
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
|
|
|
|
|
|
|
|
|
| 744 |
|
| 745 |
-
return
|
| 746 |
|
| 747 |
def create_download_link(pdf_data, filename, text):
|
| 748 |
"""Create a download link for PDF"""
|
|
@@ -755,21 +1277,26 @@ def main():
|
|
| 755 |
local_css()
|
| 756 |
init_session_state()
|
| 757 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
# Initialize chatbot
|
| 759 |
chatbot = HealthcareChatbot()
|
| 760 |
|
| 761 |
-
# Language selector at top right
|
| 762 |
col_lang, col_space = st.columns([1, 5])
|
| 763 |
with col_lang:
|
|
|
|
| 764 |
language = st.selectbox("Language", ["English", "Urdu"], key="language_selector", label_visibility="collapsed")
|
| 765 |
st.session_state.current_language = language
|
| 766 |
|
| 767 |
-
# Main header
|
| 768 |
-
st.markdown('<h1 class="main-header">🏥
|
| 769 |
if language == "English":
|
| 770 |
-
st.markdown('<h3 style="text-align: center; color: #
|
| 771 |
else:
|
| 772 |
-
st.markdown('<h3 style="text-align: center; color: #
|
| 773 |
|
| 774 |
# Display random healthcare quote
|
| 775 |
import random
|
|
@@ -796,10 +1323,10 @@ def main():
|
|
| 796 |
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 797 |
|
| 798 |
if language == "English":
|
| 799 |
-
st.markdown('<h2 style="color: #
|
| 800 |
st.write("Complete the following form for comprehensive patient risk assessment and priority scoring")
|
| 801 |
else:
|
| 802 |
-
st.markdown('<h2 style="color: #
|
| 803 |
st.write("جامع مریض کے خطرے کی تشخیص اور ترجیحی اسکورنگ کے لیے درج ذیل فارم کو مکمل کریں")
|
| 804 |
|
| 805 |
with st.form("patient_assessment_form"):
|
|
@@ -924,14 +1451,15 @@ def main():
|
|
| 924 |
'symptoms': symptoms_dict
|
| 925 |
}
|
| 926 |
|
| 927 |
-
#
|
| 928 |
-
|
| 929 |
-
age, bp_systolic, bp_diastolic,
|
|
|
|
| 930 |
)
|
| 931 |
|
| 932 |
# Calculate integrated priority score
|
| 933 |
priority_score = calculate_priority_score(
|
| 934 |
-
|
| 935 |
)
|
| 936 |
|
| 937 |
priority_level, recommendation, risk_class = get_priority_recommendation(
|
|
@@ -940,9 +1468,9 @@ def main():
|
|
| 940 |
|
| 941 |
# Store results
|
| 942 |
st.session_state.risk_scores = {
|
| 943 |
-
'heart':
|
| 944 |
-
'diabetes':
|
| 945 |
-
'hypertension':
|
| 946 |
'priority': priority_score,
|
| 947 |
'recommendation': recommendation,
|
| 948 |
'level': priority_level
|
|
@@ -968,9 +1496,9 @@ def main():
|
|
| 968 |
col5, col6, col7, col8 = st.columns(4)
|
| 969 |
|
| 970 |
risk_metrics = [
|
| 971 |
-
(
|
| 972 |
-
(
|
| 973 |
-
(
|
| 974 |
(priority_score, "Priority Score", "🎯", "#96CEB4")
|
| 975 |
]
|
| 976 |
|
|
@@ -1040,10 +1568,10 @@ def main():
|
|
| 1040 |
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1041 |
|
| 1042 |
if language == "English":
|
| 1043 |
-
st.markdown('<h2 style="color: #
|
| 1044 |
st.write("Ask health-related questions and get instant, reliable medical information")
|
| 1045 |
else:
|
| 1046 |
-
st.markdown('<h2 style="color: #
|
| 1047 |
st.write("صحت سے متعلق سوالات پوچھیں اور فوری، قابل اعتماد طبی معلومات حاصل کریں")
|
| 1048 |
|
| 1049 |
# Display chat history
|
|
@@ -1084,7 +1612,7 @@ def main():
|
|
| 1084 |
if st.button("❤️ Heart Health", use_container_width=True):
|
| 1085 |
st.session_state.chat_history.append({
|
| 1086 |
"role": "user",
|
| 1087 |
-
"content": "Tell me about heart
|
| 1088 |
})
|
| 1089 |
st.rerun()
|
| 1090 |
|
|
@@ -1092,7 +1620,7 @@ def main():
|
|
| 1092 |
if st.button("🩺 Diabetes", use_container_width=True):
|
| 1093 |
st.session_state.chat_history.append({
|
| 1094 |
"role": "user",
|
| 1095 |
-
"content": "What are diabetes symptoms and management?"
|
| 1096 |
})
|
| 1097 |
st.rerun()
|
| 1098 |
|
|
@@ -1100,15 +1628,50 @@ def main():
|
|
| 1100 |
if st.button("💓 Blood Pressure", use_container_width=True):
|
| 1101 |
st.session_state.chat_history.append({
|
| 1102 |
"role": "user",
|
| 1103 |
-
"content": "How to control high blood pressure?"
|
| 1104 |
})
|
| 1105 |
st.rerun()
|
| 1106 |
|
| 1107 |
with col_qa4:
|
| 1108 |
-
if st.button("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1109 |
st.session_state.chat_history.append({
|
| 1110 |
"role": "user",
|
| 1111 |
-
"content": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1112 |
})
|
| 1113 |
st.rerun()
|
| 1114 |
|
|
@@ -1119,10 +1682,10 @@ def main():
|
|
| 1119 |
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1120 |
|
| 1121 |
if language == "English":
|
| 1122 |
-
st.markdown('<h2 style="color: #
|
| 1123 |
st.write("Download comprehensive medical reports and view assessment analytics")
|
| 1124 |
else:
|
| 1125 |
-
st.markdown('<h2 style="color: #
|
| 1126 |
st.write("جامع طبی رپورٹس ڈاؤن لوڈ کریں اور تشخیص کے تجزیات دیکھیں")
|
| 1127 |
|
| 1128 |
if st.session_state.assessment_history:
|
|
@@ -1143,9 +1706,9 @@ def main():
|
|
| 1143 |
)
|
| 1144 |
|
| 1145 |
if language == "English":
|
| 1146 |
-
st.markdown(create_download_link(pdf_data, "
|
| 1147 |
else:
|
| 1148 |
-
st.markdown(create_download_link(pdf_data, "
|
| 1149 |
|
| 1150 |
# Analytics Section
|
| 1151 |
if language == "English":
|
|
@@ -1188,7 +1751,12 @@ def main():
|
|
| 1188 |
])
|
| 1189 |
|
| 1190 |
fig = px.line(risk_data, x='Assessment', y=['Heart Risk', 'Diabetes Risk', 'Hypertension Risk'],
|
| 1191 |
-
title="Risk Trend Analysis" if language == "English" else "خطرے کے رجحان کا تجزیہ"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1192 |
st.plotly_chart(fig, use_container_width=True)
|
| 1193 |
|
| 1194 |
else:
|
|
|
|
| 5 |
import pickle
|
| 6 |
from PIL import Image
|
| 7 |
import io
|
|
|
|
| 8 |
import os
|
| 9 |
import plotly.graph_objects as go
|
| 10 |
import plotly.express as px
|
| 11 |
from datetime import datetime
|
|
|
|
|
|
|
| 12 |
import base64
|
| 13 |
from fpdf import FPDF
|
| 14 |
import tempfile
|
| 15 |
|
| 16 |
# Set page config first
|
| 17 |
st.set_page_config(
|
| 18 |
+
page_title="SehatAI - Smart Healthcare Triage",
|
| 19 |
page_icon="🏥",
|
| 20 |
layout="wide",
|
| 21 |
initial_sidebar_state="collapsed"
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Professional CSS Styling with Pakistan theme colors
|
| 25 |
def local_css():
|
| 26 |
st.markdown("""
|
| 27 |
<style>
|
|
|
|
| 31 |
text-align: center;
|
| 32 |
margin-bottom: 0.5rem;
|
| 33 |
font-weight: 800;
|
| 34 |
+
background: linear-gradient(135deg, #00401A, #00612A, #008000);
|
| 35 |
-webkit-background-clip: text;
|
| 36 |
-webkit-text-fill-color: transparent;
|
| 37 |
text-shadow: 0px 4px 8px rgba(0,0,0,0.2);
|
| 38 |
font-family: 'Arial', sans-serif;
|
| 39 |
}
|
| 40 |
.quote-section {
|
| 41 |
+
background: linear-gradient(135deg, #00401A 0%, #00612A 100%);
|
| 42 |
color: white;
|
| 43 |
padding: 25px;
|
| 44 |
border-radius: 20px;
|
| 45 |
text-align: center;
|
| 46 |
margin: 20px 0;
|
| 47 |
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
|
| 48 |
+
border: 3px solid #008000;
|
| 49 |
}
|
| 50 |
.quote-text {
|
| 51 |
font-size: 1.4rem;
|
|
|
|
| 71 |
transform: translateY(-2px);
|
| 72 |
}
|
| 73 |
.metric-card {
|
| 74 |
+
background: linear-gradient(135deg, #00401A 0%, #00612A 100%);
|
| 75 |
color: white;
|
| 76 |
padding: 25px;
|
| 77 |
border-radius: 15px;
|
|
|
|
| 108 |
box-shadow: 0 6px 15px rgba(40,167,69,0.4);
|
| 109 |
}
|
| 110 |
.priority-box {
|
| 111 |
+
border: 4px solid #00612A;
|
| 112 |
padding: 30px;
|
| 113 |
border-radius: 20px;
|
| 114 |
margin: 20px 0;
|
|
|
|
| 117 |
}
|
| 118 |
.stButton button {
|
| 119 |
width: 100%;
|
| 120 |
+
background: linear-gradient(45deg, #00401A, #00612A);
|
| 121 |
color: white;
|
| 122 |
font-weight: bold;
|
| 123 |
border: none;
|
|
|
|
| 125 |
border-radius: 12px;
|
| 126 |
font-size: 1.2rem;
|
| 127 |
transition: all 0.3s ease;
|
| 128 |
+
box-shadow: 0 6px 15px rgba(0,64,26,0.4);
|
| 129 |
}
|
| 130 |
.stButton button:hover {
|
| 131 |
transform: translateY(-3px);
|
| 132 |
+
box-shadow: 0 10px 25px rgba(0,64,26,0.5);
|
| 133 |
+
background: linear-gradient(45deg, #00612A, #00401A);
|
| 134 |
}
|
| 135 |
.chat-message {
|
| 136 |
padding: 15px;
|
|
|
|
| 139 |
border: 2px solid #e0e0e0;
|
| 140 |
}
|
| 141 |
.user-message {
|
| 142 |
+
background: linear-gradient(135deg, #00401A, #00612A);
|
| 143 |
color: white;
|
| 144 |
margin-left: 20%;
|
| 145 |
text-align: right;
|
|
|
|
| 155 |
right: 20px;
|
| 156 |
z-index: 1000;
|
| 157 |
}
|
| 158 |
+
.pakistan-flag {
|
| 159 |
+
background: linear-gradient(135deg, #00401A, #00612A, #FFFFFF);
|
| 160 |
+
padding: 5px 15px;
|
| 161 |
+
border-radius: 20px;
|
| 162 |
+
color: white;
|
| 163 |
+
font-weight: bold;
|
| 164 |
+
margin: 0 10px;
|
| 165 |
+
}
|
| 166 |
</style>
|
| 167 |
""", unsafe_allow_html=True)
|
| 168 |
|
|
|
|
| 182 |
# Healthcare quotes database
|
| 183 |
HEALTHCARE_QUOTES = [
|
| 184 |
{
|
| 185 |
+
'english': "Health is the crown on the well person's head that only the ill can see.",
|
| 186 |
+
'urdu': "صحت ایک تاج ہے جو تندرست انسان کے سر پر ہوتا ہے جسے صرف بیمار ہی دیکھ سکتے ہیں۔",
|
| 187 |
+
'author': "Robin Sharma"
|
| 188 |
},
|
| 189 |
{
|
| 190 |
+
'english': "The first wealth is health. Take care of your body, it's the only place you have to live.",
|
| 191 |
+
'urdu': "پہلی دولت صحت ہے۔ اپنے جسم کا خیال رکھیں، یہ وہ واحد جگہ ہے جہاں آپ کو رہنا ہے۔",
|
| 192 |
+
'author': "Ralph Waldo Emerson"
|
| 193 |
},
|
| 194 |
{
|
| 195 |
+
'english': "A healthy outside starts from the inside. Prevention is better than cure.",
|
| 196 |
+
'urdu': "ایک صحت مند باہر کی طرف اندر سے شروع ہوتی ہے۔ بچاؤ علاج سے بہتر ہے۔",
|
| 197 |
+
'author': "Robert Urich"
|
| 198 |
},
|
| 199 |
{
|
| 200 |
+
'english': "Your body hears everything your mind says. Stay positive for better health.",
|
| 201 |
+
'urdu': "آپ کا جسم وہ سب کچھ سنتا ہے جو آپ کا دماغ کہتا ہے۔ بہتر صحت کے لیے مثبت رہیں۔",
|
| 202 |
+
'author': "Naomi Judd"
|
| 203 |
},
|
| 204 |
{
|
| 205 |
+
'english': "The greatest of follies is to sacrifice health for any other kind of happiness.",
|
| 206 |
+
'urdu': "سب سے بڑی بیوقوفی صحت کو کسی دوسری قسم کی خوشی کے لیے قربان کرنا ہے۔",
|
| 207 |
+
'author': "Arthur Schopenhauer"
|
| 208 |
}
|
| 209 |
]
|
| 210 |
|
|
|
|
| 212 |
def __init__(self):
|
| 213 |
self.medical_knowledge_base = {
|
| 214 |
'heart_disease': {
|
| 215 |
+
'symptoms': ["Chest pain or discomfort", "Shortness of breath", "Pain in arms, neck, jaw", "Nausea", "Fatigue", "Dizziness"],
|
| 216 |
+
'risk_factors': ["High blood pressure", "High cholesterol", "Smoking", "Diabetes", "Obesity", "Family history", "Physical inactivity"],
|
| 217 |
+
'prevention': ["Healthy diet low in saturated fats", "Regular exercise 30 mins daily", "No smoking", "Weight management", "Stress management", "Regular check-ups"],
|
| 218 |
+
'emergency_signs': ["Severe chest pain", "Difficulty breathing", "Fainting", "Rapid heartbeat", "Pain spreading to arms/shoulders"]
|
| 219 |
},
|
| 220 |
'diabetes': {
|
| 221 |
+
'symptoms': ["Increased thirst and hunger", "Frequent urination", "Fatigue", "Blurred vision", "Slow healing wounds", "Unexplained weight loss"],
|
| 222 |
+
'risk_factors': ["Family history", "Overweight (BMI > 25)", "High blood pressure", "Physical inactivity", "Age over 45", "Gestational diabetes history"],
|
| 223 |
+
'prevention': ["Balanced diet with controlled carbs", "Regular physical activity", "Weight management", "Blood sugar monitoring", "Regular health screenings"],
|
| 224 |
+
'emergency_signs': ["Blood sugar >300 mg/dL or <70 mg/dL", "Confusion or disorientation", "Fruity breath odor", "Rapid breathing", "Loss of consciousness"]
|
| 225 |
},
|
| 226 |
'hypertension': {
|
| 227 |
+
'symptoms': ["Headaches", "Dizziness", "Blurred vision", "Shortness of breath", "Chest pain", "Nosebleeds"],
|
| 228 |
+
'risk_factors': ["Family history", "Age over 65", "Obesity", "High salt intake", "Stress", "Alcohol consumption", "Smoking"],
|
| 229 |
+
'prevention': ["DASH diet (low sodium)", "Regular aerobic exercise", "Weight management", "Stress reduction", "Limit alcohol", "No smoking"],
|
| 230 |
+
'emergency_signs': ["Severe headache", "Chest pain", "Difficulty breathing", "Vision changes", "Confusion", "Seizures"]
|
| 231 |
+
},
|
| 232 |
+
'general_health': {
|
| 233 |
+
'nutrition': ["Eat 5-9 servings of fruits/vegetables daily", "Choose whole grains over refined", "Include lean proteins", "Stay hydrated (8-10 glasses water)", "Limit processed foods and sugar"],
|
| 234 |
+
'exercise': ["150 mins moderate exercise weekly", "Strength training 2x weekly", "Stay active throughout day", "Include flexibility exercises", "Get adequate rest between workouts"],
|
| 235 |
+
'lifestyle': ["7-9 hours quality sleep nightly", "Stress management techniques", "No smoking", "Limit alcohol to 1-2 drinks/day", "Regular health check-ups"],
|
| 236 |
+
'prevention': ["Annual physical exams", "Vaccinations up to date", "Regular hand washing", "Sun protection", "Mental health care"]
|
| 237 |
}
|
| 238 |
}
|
| 239 |
|
| 240 |
def get_response(self, user_input, language='English'):
|
| 241 |
+
user_input = user_input.lower().strip()
|
| 242 |
+
|
| 243 |
+
# Greeting patterns
|
| 244 |
+
if any(word in user_input for word in ['hello', 'hi', 'hey', 'salam', 'السلام علیکم']):
|
| 245 |
+
return self._format_greeting_response(language)
|
| 246 |
|
| 247 |
# Heart disease related queries
|
| 248 |
+
if any(word in user_input for word in ['heart', 'cardiac', 'chest pain', 'cholesterol', 'دل', 'سینے میں درد']):
|
| 249 |
return self._format_heart_response(language)
|
| 250 |
|
| 251 |
# Diabetes related queries
|
| 252 |
+
elif any(word in user_input for word in ['diabetes', 'sugar', 'glucose', 'insulin', 'ذیابیطس', 'شوگر']):
|
| 253 |
return self._format_diabetes_response(language)
|
| 254 |
|
| 255 |
# Hypertension related queries
|
| 256 |
+
elif any(word in user_input for word in ['blood pressure', 'hypertension', 'bp', 'بلڈ پریشر', 'ہائی بلڈ پریشر']):
|
| 257 |
return self._format_hypertension_response(language)
|
| 258 |
|
| 259 |
+
# Nutrition and diet
|
| 260 |
+
elif any(word in user_input for word in ['diet', 'nutrition', 'food', 'eating', 'غذا', 'کھانا']):
|
| 261 |
+
return self._format_nutrition_response(language)
|
| 262 |
+
|
| 263 |
+
# Exercise and fitness
|
| 264 |
+
elif any(word in user_input for word in ['exercise', 'workout', 'fitness', 'gym', 'ورزش', 'جم']):
|
| 265 |
+
return self._format_exercise_response(language)
|
| 266 |
|
| 267 |
# Symptoms assessment
|
| 268 |
+
elif any(word in user_input for word in ['symptom', 'pain', 'fever', 'headache', 'علامت', 'درد']):
|
| 269 |
return self._format_symptoms_response(language)
|
| 270 |
|
| 271 |
+
# Medication queries
|
| 272 |
+
elif any(word in user_input for word in ['medicine', 'medication', 'drug', 'treatment', 'دوا', 'علاج']):
|
| 273 |
+
return self._format_medication_response(language)
|
| 274 |
+
|
| 275 |
+
# Emergency situations
|
| 276 |
+
elif any(word in user_input for word in ['emergency', 'urgent', 'help', 'ہنگامی', 'فوری']):
|
| 277 |
+
return self._format_emergency_response(language)
|
| 278 |
+
|
| 279 |
+
# General health queries
|
| 280 |
+
elif any(word in user_input for word in ['health', 'wellness', 'prevention', 'صحت', 'تندرستی']):
|
| 281 |
+
return self._format_general_health_response(language)
|
| 282 |
+
|
| 283 |
+
# Default response for unknown queries
|
| 284 |
else:
|
| 285 |
return self._format_default_response(language)
|
| 286 |
|
| 287 |
+
def _format_greeting_response(self, language):
|
| 288 |
+
if language == 'English':
|
| 289 |
+
return """
|
| 290 |
+
**🤖 Welcome to SehatAI Health Assistant!**
|
| 291 |
+
|
| 292 |
+
I'm here to help you with:
|
| 293 |
+
• Heart health and cardiovascular diseases
|
| 294 |
+
• Diabetes and blood sugar management
|
| 295 |
+
• Blood pressure and hypertension
|
| 296 |
+
• Nutrition and diet advice
|
| 297 |
+
• Exercise and fitness guidance
|
| 298 |
+
• Symptom assessment
|
| 299 |
+
• General health and wellness
|
| 300 |
+
|
| 301 |
+
Please ask me specific health-related questions, and I'll provide detailed, helpful information.
|
| 302 |
+
|
| 303 |
+
*Note: I'm an AI assistant. For serious medical concerns, always consult a qualified healthcare professional.*
|
| 304 |
+
"""
|
| 305 |
+
else:
|
| 306 |
+
return """
|
| 307 |
+
**🤖 سیحت اے آئی ہیلتھ اسسٹنٹ میں خوش آمدید!**
|
| 308 |
+
|
| 309 |
+
میں آپ کی مدد کے لیے یہاں ہوں:
|
| 310 |
+
• دل کی صحت اور قلبی امراض
|
| 311 |
+
• ذیابیطس اور بلڈ شوگر مینجمنٹ
|
| 312 |
+
• بلڈ پریشر اور ہائی بلڈ پریشر
|
| 313 |
+
• غذائیت اور غذا کے مشورے
|
| 314 |
+
• ور��ش اور فٹنس گائیڈنس
|
| 315 |
+
• علامات کی تشخیص
|
| 316 |
+
• عام صحت اور تندرستی
|
| 317 |
+
|
| 318 |
+
براہ کرم مجھ سے مخصوص صحت سے متعلق سوالات پوچھیں، اور میں تفصیلی، مددگار معلومات فراہم کروں گا۔
|
| 319 |
+
|
| 320 |
+
*نوٹ: میں ایک AI اسسٹنٹ ہوں۔ سنگین طبی مسائل کے لیے، ہمیشہ کوالیفائیڈ ہیلتھ کیئر پروفیشنل سے مشورہ کریں۔*
|
| 321 |
+
"""
|
| 322 |
+
|
| 323 |
def _format_heart_response(self, language):
|
| 324 |
+
knowledge = self.medical_knowledge_base['heart_disease']
|
| 325 |
if language == 'English':
|
| 326 |
return f"""
|
| 327 |
+
**❤️ Comprehensive Heart Health Information**
|
| 328 |
+
|
| 329 |
+
**🚨 Common Symptoms:**
|
| 330 |
+
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 331 |
|
| 332 |
+
**⚠️ Risk Factors:**
|
| 333 |
+
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 334 |
|
| 335 |
+
**🛡️ Prevention Strategies:**
|
| 336 |
+
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 337 |
|
| 338 |
+
**🚑 Emergency Warning Signs (Seek Immediate Care):**
|
| 339 |
+
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 340 |
|
| 341 |
+
**📊 Recommended Monitoring:**
|
| 342 |
+
• Regular blood pressure checks
|
| 343 |
+
• Cholesterol levels annually if high risk
|
| 344 |
+
• ECG if symptoms present
|
| 345 |
+
• Stress test if recommended by doctor
|
| 346 |
|
| 347 |
+
*🔬 Clinical Note: Early detection saves lives. Regular check-ups are crucial for heart health.*
|
| 348 |
"""
|
| 349 |
else:
|
| 350 |
return f"""
|
| 351 |
+
**❤️ دل کی صحت کی جامع معلومات**
|
| 352 |
|
| 353 |
+
**🚨 عام علامات:**
|
| 354 |
+
{chr(10).join(['• ' + symptom for symptom in ['سینے میں درد یا بے چینی', 'سانس لینے میں دشواری', 'بازوؤں، گردن، جبڑے میں درد', 'متلی', 'تھکاوٹ', 'چکر آنا']])}
|
| 355 |
|
| 356 |
+
**⚠️ خطرے کے عوامل:**
|
| 357 |
+
{chr(10).join(['• ' + factor for factor in ['ہائی بلڈ پریشر', 'ہائی کولیسٹرول', 'سگریٹ نوشی', 'ذیابیطس', 'موٹاپا', 'خاندانی تاریخ', 'جسمانی غیر فعالیت']])}
|
| 358 |
|
| 359 |
+
**🛡️ بچاؤ کی حکمت عملی:**
|
| 360 |
+
{chr(10).join(['• ' + tip for tip in ['سیر شدہ چکنائی سے پاک صحت مند غذا', 'روزانہ 30 منٹ باقاعدہ ورزش', 'سگریٹ نوشی سے پرہیز', 'وزن کا انتظام', 'تناؤ کا انتظام', 'باقاعدہ چیک اپ']])}
|
| 361 |
|
| 362 |
+
**🚑 ہنگامی انتباہی علامات (فوری علاج حاصل کریں):**
|
| 363 |
+
{chr(10).join(['• ' + sign for sign in ['شدید سینے میں درد', 'سانس لینے میں شدید دشواری', 'بیہوش ہونا', 'تیز دل کی دھڑکن', 'بازو/کندھوں میں پھیلنے والا درد']])}
|
| 364 |
|
| 365 |
+
**📊 تجویز کردہ نگرانی:**
|
| 366 |
+
• بلڈ پریشر کی باقاعدہ جانچ
|
| 367 |
+
• اگر خطرہ زیادہ ہو تو سالانہ کولیسٹرول کی سطح
|
| 368 |
+
• اگر علامات موجود ہوں تو ECG
|
| 369 |
+
• اگر ڈاکٹر تجویز کرے تو اسٹریس ٹیسٹ
|
| 370 |
+
|
| 371 |
+
*🔬 کلینیکل نوٹ: ابتدائی تشخیص جان بچاتی ہے۔ دل کی صحت کے لیے باقاعدہ چیک اپ بہت ضروری ہیں۔*
|
| 372 |
"""
|
| 373 |
|
| 374 |
def _format_diabetes_response(self, language):
|
| 375 |
+
knowledge = self.medical_knowledge_base['diabetes']
|
| 376 |
if language == 'English':
|
| 377 |
return f"""
|
| 378 |
+
**🩺 Comprehensive Diabetes Information**
|
| 379 |
+
|
| 380 |
+
**🚨 Common Symptoms:**
|
| 381 |
+
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 382 |
|
| 383 |
+
**⚠️ Risk Factors:**
|
| 384 |
+
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 385 |
|
| 386 |
+
**🛡️ Prevention & Management:**
|
| 387 |
+
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 388 |
|
| 389 |
+
**🚑 Emergency Signs (Seek Immediate Care):**
|
| 390 |
+
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 391 |
|
| 392 |
+
**📊 Monitoring Guidelines:**
|
| 393 |
+
• Fasting blood sugar: 80-130 mg/dL
|
| 394 |
+
• Post-meal blood sugar: <180 mg/dL
|
| 395 |
+
• HbA1c: <7.0% (quarterly if uncontrolled)
|
| 396 |
+
• Regular foot and eye examinations
|
| 397 |
|
| 398 |
+
*🔬 Clinical Note: Consistent monitoring and lifestyle management are key to diabetes control.*
|
| 399 |
"""
|
| 400 |
else:
|
| 401 |
return f"""
|
| 402 |
+
**🩺 ذیابیطس کی جامع معلومات**
|
| 403 |
+
|
| 404 |
+
**🚨 عام علامات:**
|
| 405 |
+
{chr(10).join(['• ' + symptom for symptom in ['زیادہ پیاس اور بھوک لگنا', 'بار بار پیشاب آنا', 'تھکاوٹ', 'دھندلا نظر آنا', 'زخموں کا دیر سے بھرنا', 'بے وجہ وزن میں کمی']])}
|
| 406 |
|
| 407 |
+
**⚠️ خطرے کے عوامل:**
|
| 408 |
+
{chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', 'وزن زیادہ ہونا (BMI > 25)', 'ہائی بلڈ پریشر', 'جسمانی غیر فعالیت', '45 سال سے زیادہ عمر', 'حمل کی ذیابیطس کی تاریخ']])}
|
| 409 |
|
| 410 |
+
**🛡️ بچاؤ اور انتظام:**
|
| 411 |
+
{chr(10).join(['• ' + tip for tip in ['کنٹرول کاربوہائیڈریٹ کے ساتھ متوازن غذا', 'باقاعدہ جسمانی سرگرمی', 'وزن کا انتظام', 'بلڈ شوگر مانیٹرنگ', 'باقاعدہ صحت کی اسکریننگ']])}
|
| 412 |
|
| 413 |
+
**🚑 ہنگامی علامات (فوری علاج حاصل کریں):**
|
| 414 |
+
{chr(10).join(['• ' + sign for sign in ['بلڈ شوگر >300 mg/dL یا <70 mg/dL', 'الجھن یا بے ترتیبی', 'پھل کی سی بو والی سانس', 'تیز سانس لینا', 'ہوش کا ضیاع']])}
|
| 415 |
|
| 416 |
+
**📊 نگرانی کے رہنما اصول:**
|
| 417 |
+
• فاسٹنگ بلڈ شوگر: 80-130 mg/dL
|
| 418 |
+
• کھانے کے بعد بلڈ شوگر: <180 mg/dL
|
| 419 |
+
• HbA1c: <7.0% (اگر کنٹرول نہ ہو تو سہ ماہی)
|
| 420 |
+
• پاؤں اور آنکھوں کا باقاعدہ معائنہ
|
| 421 |
|
| 422 |
+
*🔬 کلینیکل نوٹ: مستقل نگرانی اور طرز زندگی کا انتظام ذیابیطس کے کنٹرول کی کلید ہے۔*
|
| 423 |
"""
|
| 424 |
|
| 425 |
def _format_hypertension_response(self, language):
|
| 426 |
+
knowledge = self.medical_knowledge_base['hypertension']
|
| 427 |
if language == 'English':
|
| 428 |
return f"""
|
| 429 |
+
**💓 Comprehensive Blood Pressure Information**
|
| 430 |
|
| 431 |
+
**🚨 Common Symptoms:**
|
| 432 |
+
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 433 |
|
| 434 |
+
**⚠️ Risk Factors:**
|
| 435 |
+
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 436 |
|
| 437 |
+
**���️ Prevention & Control:**
|
| 438 |
+
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 439 |
|
| 440 |
+
**🚑 Hypertensive Emergency Signs:**
|
| 441 |
+
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 442 |
|
| 443 |
+
**📊 Blood Pressure Classification:**
|
| 444 |
+
• Normal: <120/80 mmHg
|
| 445 |
+
• Elevated: 120-129/<80 mmHg
|
| 446 |
+
• Stage 1 Hypertension: 130-139/80-89 mmHg
|
| 447 |
+
• Stage 2 Hypertension: ≥140/90 mmHg
|
| 448 |
+
|
| 449 |
+
*🔬 Clinical Note: Silent killer - often no symptoms. Regular monitoring is essential.*
|
| 450 |
"""
|
| 451 |
else:
|
| 452 |
return f"""
|
| 453 |
+
**💓 بلڈ پریشر کی جامع معلومات**
|
| 454 |
+
|
| 455 |
+
**🚨 عام علامات:**
|
| 456 |
+
{chr(10).join(['• ' + symptom for symptom in ['سر درد', 'چکر آنا', 'دھندلا نظر آنا', 'سانس لینے میں دشواری', 'سینے میں درد', 'ناک سے خون آنا']])}
|
| 457 |
|
| 458 |
+
**⚠️ خطرے کے عوامل:**
|
| 459 |
+
{chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', '65 سال سے زیادہ عمر', 'موٹاپا', 'زیادہ نمک کا استعمال', 'تناؤ', 'شراب کا استعمال', 'سگریٹ نوشی']])}
|
| 460 |
|
| 461 |
+
**🛡️ بچاؤ اور کنٹرول:**
|
| 462 |
+
{chr(10).join(['• ' + tip for tip in ['ڈیش ڈائٹ (کم سوڈیم)', 'باقاعدہ ایروبک ورزش', 'وزن کا انتظام', 'تناؤ میں کمی', 'شراب کو محدود کریں', 'سگریٹ نوشی سے پرہیز']])}
|
| 463 |
|
| 464 |
+
**🚑 ہائی بلڈ پریشر کی ہنگامی علامات:**
|
| 465 |
+
{chr(10).join(['• ' + sign for sign in ['شدید سر درد', 'سینے میں درد', 'سانس لینے میں دشواری', 'بینائی میں تبدیلی', 'الجھن', 'دورے']])}
|
| 466 |
|
| 467 |
+
**📊 بلڈ پریشر کی درجہ بندی:**
|
| 468 |
+
• نارمل: <120/80 mmHg
|
| 469 |
+
• بلند: 120-129/<80 mmHg
|
| 470 |
+
• اسٹیج 1 ہائی بلڈ پریشر: 130-139/80-89 mmHg
|
| 471 |
+
• اسٹیج 2 ہائی بلڈ پریشر: ≥140/90 mmHg
|
| 472 |
|
| 473 |
+
*🔬 کلینیکل نوٹ: خاموش قاتل - اکثر کوئی علامات نہیں ہوتیں۔ باقاعدہ نگرانی ضروری ہے۔*
|
| 474 |
"""
|
| 475 |
|
| 476 |
+
def _format_nutrition_response(self, language):
|
| 477 |
+
knowledge = self.medical_knowledge_base['general_health']
|
| 478 |
if language == 'English':
|
| 479 |
+
return f"""
|
| 480 |
+
**🍎 Comprehensive Nutrition Guide**
|
| 481 |
+
|
| 482 |
+
**🥦 Healthy Eating Principles:**
|
| 483 |
+
{chr(10).join(['• ' + tip for tip in knowledge['nutrition']])}
|
| 484 |
+
|
| 485 |
+
**🎯 Specific Recommendations:**
|
| 486 |
+
• **Heart Health**: Mediterranean diet, omega-3 rich foods
|
| 487 |
+
• **Diabetes**: Controlled carb intake, high fiber
|
| 488 |
+
• **Hypertension**: Low sodium (<2300mg/day), potassium-rich foods
|
| 489 |
+
• **Weight Management**: Calorie control, portion management
|
| 490 |
+
|
| 491 |
+
**🚫 Foods to Limit:**
|
| 492 |
+
• Processed and packaged foods
|
| 493 |
+
• Sugary drinks and sweets
|
| 494 |
+
• High sodium snacks
|
| 495 |
+
• Saturated and trans fats
|
| 496 |
+
|
| 497 |
+
**💡 Pakistani Dietary Adaptations:**
|
| 498 |
+
• Choose whole wheat chapati over refined flour
|
| 499 |
+
• Include lentils (daal) and legumes regularly
|
| 500 |
+
• Use healthy cooking oils (canola, olive)
|
| 501 |
+
• Limit ghee and butter usage
|
| 502 |
+
|
| 503 |
+
*Remember: Balanced nutrition is foundation of good health.*
|
|
|
|
|
|
|
|
|
|
| 504 |
"""
|
| 505 |
else:
|
| 506 |
+
return f"""
|
| 507 |
+
**🍎 غذائیت کی جامع گائیڈ**
|
| 508 |
+
|
| 509 |
+
**🥦 صحت مند کھانے کے اصول:**
|
| 510 |
+
{chr(10).join(['• ' + tip for tip in ['روزانہ 5-9 سرونگ پھل/سبزیاں کھائیں', 'ریفائنڈ کی بجائے سارا اناج منتخب کریں', 'لیان پروٹین شامل کریں', 'ہائیڈریٹ رہیں (8-10 گلاس پانی)', 'پراسیسڈ فوڈز اور چینی کو محدود کریں']])}
|
| 511 |
+
|
| 512 |
+
**🎯 مخصوص سفارشات:**
|
| 513 |
+
• **دل کی صحت**: بحیرہ روم کی غذا، اومیگا 3 سے بھرپور غذائیں
|
| 514 |
+
• **ذیابیطس**: کنٹرول کاربوہائیڈریٹ انٹیک، زیادہ فائبر
|
| 515 |
+
• **ہائی بلڈ پریشر**: کم سوڈیم (<2300mg/day)، پوٹاشیم سے بھرپور غذائیں
|
| 516 |
+
• **وزن کا انتظام**: کیلوری کنٹرول، حصے کا انتظام
|
| 517 |
+
|
| 518 |
+
**🚫 محدود کرنے والی غذائیں:**
|
| 519 |
+
• پراسیسڈ اور پیکجڈ فوڈز
|
| 520 |
+
• میٹھے مشروبات اور مٹھائیاں
|
| 521 |
+
• ہائی سوڈیم اسنیکس
|
| 522 |
+
• سیر شدہ اور ٹرانس فیٹس
|
| 523 |
+
|
| 524 |
+
**💡 پاکستانی غذائی موافقت:**
|
| 525 |
+
• ریفائنڈ آٹے کی بجائے whole wheat چپاتی منتخب کریں
|
| 526 |
+
• دالوں اور پھلیوں کو باقاعدہ شامل کریں
|
| 527 |
+
• صحت مند ککنگ آئلز (کینولا، زیتون) استعمال کریں
|
| 528 |
+
• گھی اور مکھن کے استعمال کو محدود کریں
|
| 529 |
+
|
| 530 |
+
*یاد رکھیں: متوازن غذائیت اچھی صحت کی بنیاد ہے۔*
|
| 531 |
+
"""
|
| 532 |
+
|
| 533 |
+
def _format_exercise_response(self, language):
|
| 534 |
+
knowledge = self.medical_knowledge_base['general_health']
|
| 535 |
+
if language == 'English':
|
| 536 |
+
return f"""
|
| 537 |
+
**💪 Comprehensive Exercise Guide**
|
| 538 |
+
|
| 539 |
+
**🏃♂️ Exercise Recommendations:**
|
| 540 |
+
{chr(10).join(['• ' + tip for tip in knowledge['exercise']])}
|
| 541 |
+
|
| 542 |
+
**🎯 Disease-Specific Exercise:**
|
| 543 |
+
• **Heart Health**: 30 mins moderate cardio daily
|
| 544 |
+
• **Diabetes**: Combination of cardio and strength training
|
| 545 |
+
• **Hypertension**: Regular aerobic exercise
|
| 546 |
+
• **Weight Management**: 300+ mins moderate exercise weekly
|
| 547 |
+
|
| 548 |
+
**🌞 Pakistani Climate Considerations:**
|
| 549 |
+
• Exercise in cooler morning/evening hours
|
| 550 |
+
• Stay hydrated with water and electrolytes
|
| 551 |
+
• Wear light, breathable clothing
|
| 552 |
+
• Listen to your body in hot weather
|
| 553 |
+
|
| 554 |
+
**🔄 Exercise Types:**
|
| 555 |
+
• **Cardio**: Walking, jogging, cycling, swimming
|
| 556 |
+
• **Strength**: Weight training, resistance bands
|
| 557 |
+
• **Flexibility**: Yoga, stretching
|
| 558 |
+
• **Balance**: Tai chi, balance exercises
|
| 559 |
+
|
| 560 |
+
*Important: Consult doctor before starting new exercise program.*
|
| 561 |
+
"""
|
| 562 |
+
else:
|
| 563 |
+
return f"""
|
| 564 |
+
**💪 ورزش کی جامع گائیڈ**
|
| 565 |
+
|
| 566 |
+
**🏃♂️ ورزش کی سفارشات:**
|
| 567 |
+
{chr(10).join(['• ' + tip for tip in ['ہفتے میں 150 منٹ اعتدال پسند ورزش', 'ہفتے میں 2 بار طاقت کی تربیت', 'پورے دن متحرک رہیں', 'لچک کی ورزشیں شامل کریں', 'ورک آؤٹس کے درمیان مناسب آرام حاصل کریں']])}
|
| 568 |
+
|
| 569 |
+
**🎯 بیماری کی مخصوص ورزش:**
|
| 570 |
+
• **دل کی صحت**: روزانہ 30 منٹ اعتدال پسند کارڈیو
|
| 571 |
+
• **ذیابیطس**: کارڈیو اور طاقت کی تربیت کا مجموعہ
|
| 572 |
+
• **ہائی بلڈ پریشر**: باقاعدہ ایروبک ورزش
|
| 573 |
+
• **وزن کا انتظام**: ہفتے میں 300+ منٹ اعتدال پسند ورزش
|
| 574 |
+
|
| 575 |
+
**🌞 پاکستانی آب و ہوا کے تحفظات:**
|
| 576 |
+
• ٹھنڈے صبح/شام کے اوقات میں ورزش کریں
|
| 577 |
+
• پانی اور الیکٹرولائٹس کے ساتھ ہائیڈریٹ رہیں
|
| 578 |
+
• ہلکے، ہوا دار کپڑے پہنیں
|
| 579 |
+
• گرم موسم میں اپنے جسم کی بات سنیں
|
| 580 |
+
|
| 581 |
+
**🔄 ورزش کی اقسام:**
|
| 582 |
+
• **کارڈیو**: چہل قدمی، جاگنگ، سائیکل چلانا، تیراکی
|
| 583 |
+
• **طاقت**: وزن کی تربیت، مزاحمتی بینڈ
|
| 584 |
+
• **لچک**: یوگا، اسٹریچنگ
|
| 585 |
+
• **توازن**: تائی چی، توازن کی ورزشیں
|
| 586 |
+
|
| 587 |
+
*اہم: نئی ورزش پروگرام شروع کرنے سے پہلے ڈاکٹر سے مشورہ کریں۔*
|
| 588 |
"""
|
| 589 |
|
| 590 |
def _format_symptoms_response(self, language):
|
|
|
|
| 592 |
return """
|
| 593 |
**🔍 Symptom Assessment Guidance**
|
| 594 |
|
| 595 |
+
**🩺 When to Seek Medical Care:**
|
| 596 |
• Persistent fever above 103°F (39.4°C)
|
| 597 |
• Difficulty breathing or chest pain
|
| 598 |
• Severe abdominal pain
|
| 599 |
+
• Sudden dizziness, weakness, or confusion
|
| 600 |
+
• Unexplained weight loss (>10% body weight)
|
| 601 |
• Symptoms lasting more than 2 weeks
|
| 602 |
+
• Worsening of chronic conditions
|
| 603 |
|
| 604 |
+
**🏠 Self-Care Tips:**
|
| 605 |
+
• Rest and adequate hydration
|
| 606 |
+
• Monitor symptoms and temperature regularly
|
| 607 |
• Use over-the-counter medications as directed
|
| 608 |
+
• Apply cold/heat packs as appropriate
|
| 609 |
+
• Maintain proper nutrition
|
| 610 |
+
|
| 611 |
+
**🚨 Emergency Warning Signs (Go to ER):**
|
| 612 |
+
• Difficulty breathing or shortness of breath
|
| 613 |
+
• Chest pain or pressure lasting >5 minutes
|
| 614 |
+
• Severe bleeding that doesn't stop
|
| 615 |
+
• Sudden severe pain anywhere in body
|
| 616 |
+
• Loss of consciousness or fainting
|
| 617 |
+
• Sudden vision changes
|
| 618 |
+
• Difficulty speaking or confusion
|
| 619 |
+
|
| 620 |
+
*⚠️ Important: This is general guidance. Always consult healthcare professional for proper diagnosis.*
|
| 621 |
"""
|
| 622 |
else:
|
| 623 |
return """
|
| 624 |
**🔍 علامات کی تشخیص کی رہنمائی**
|
| 625 |
|
| 626 |
+
**🩺 طبی دیکھ بھال کب حاصل کریں:**
|
| 627 |
• 103°F (39.4°C) سے اوپر مستقل بخار
|
| 628 |
• سانس لینے میں دشواری یا سینے میں درد
|
| 629 |
• شدید پیٹ کا درد
|
| 630 |
+
• اچانک چکر آنا، کمزوری، یا الجھن
|
| 631 |
+
• بے وجہ وزن میں کمی (>10% جسمانی وزن)
|
| 632 |
• 2 ہفتے سے زیادہ علامات برقرار رہنا
|
| 633 |
+
• دائمی حالات کا بگڑنا
|
| 634 |
|
| 635 |
+
**🏠 خود کی دیکھ بھال کے نکات:**
|
| 636 |
+
• آرام اور مناسب ہائیڈریشن
|
| 637 |
+
• علامات اور درجہ حرارت کی باقاعدہ نگرانی
|
| 638 |
• ہدایت کے مطابق اوور دی کاؤنٹر ادویات استعمال کریں
|
| 639 |
+
• حسب مناسب کولڈ/ہیٹ پیکس لگائیں
|
| 640 |
+
• مناسب غذائیت برقرار رکھیں
|
| 641 |
+
|
| 642 |
+
**🚨 ہنگامی انتباہی علامات (ایمرجنسی روم جائیں):**
|
| 643 |
+
• سانس لینے میں دشواری یا سانس کی قلت
|
| 644 |
+
• 5 منٹ سے زیادہ سینے میں درد یا دباؤ
|
| 645 |
+
• شدید خون بہنا جو رک نہیں رہا
|
| 646 |
+
• جسم میں کہیں بھی اچانک شدید درد
|
| 647 |
+
• ہوش کا ضیاع یا بیہوشی
|
| 648 |
+
• اچانک بینائی میں تبدیلی
|
| 649 |
+
• بولنے میں دشواری یا الجھن
|
| 650 |
+
|
| 651 |
+
*⚠️ اہم: یہ عام رہنمائی ہے۔ مناسب تشخیص کے لیے ہمیشہ ہیلتھ کیئر پروفیشنل سے مشورہ کریں۔*
|
| 652 |
+
"""
|
| 653 |
+
|
| 654 |
+
def _format_medication_response(self, language):
|
| 655 |
+
if language == 'English':
|
| 656 |
+
return """
|
| 657 |
+
**💊 Medication Safety & Information**
|
| 658 |
+
|
| 659 |
+
**📋 General Medication Guidelines:**
|
| 660 |
+
• Take medications exactly as prescribed
|
| 661 |
+
• Never share prescriptions with others
|
| 662 |
+
• Keep updated medication list with you
|
| 663 |
+
• Inform all doctors about all medications
|
| 664 |
+
• Understand purpose and side effects of each medicine
|
| 665 |
+
|
| 666 |
+
**⚠️ Common Medication Categories:**
|
| 667 |
+
• **Heart**: Beta-blockers, ACE inhibitors, statins
|
| 668 |
+
• **Diabetes**: Metformin, insulin, SGLT2 inhibitors
|
| 669 |
+
• **Hypertension**: Diuretics, calcium channel blockers
|
| 670 |
+
• **Pain**: NSAIDs, acetaminophen (use cautiously)
|
| 671 |
+
|
| 672 |
+
**🚨 Medication Warning Signs:**
|
| 673 |
+
• Severe allergic reactions (rash, swelling)
|
| 674 |
+
• Difficulty breathing after taking medicine
|
| 675 |
+
• Severe stomach pain or vomiting
|
| 676 |
+
• Unusual bleeding or bruising
|
| 677 |
+
• Confusion or hallucinations
|
| 678 |
+
|
| 679 |
+
**💡 Important Reminders:**
|
| 680 |
+
• Don't stop medications without doctor's advice
|
| 681 |
+
• Report side effects to your doctor
|
| 682 |
+
• Keep medications in original containers
|
| 683 |
+
• Check expiration dates regularly
|
| 684 |
+
|
| 685 |
+
*Note: Always follow your healthcare provider's specific instructions.*
|
| 686 |
+
"""
|
| 687 |
+
else:
|
| 688 |
+
return """
|
| 689 |
+
**💊 دوائیوں کی حفاظت اور معلومات**
|
| 690 |
+
|
| 691 |
+
**📋 عام دوائیوں کے رہنما اصول:**
|
| 692 |
+
• دوائیں بالکل تجویز کردہ طریقے سے لیں
|
| 693 |
+
• کبھی بھی دوسروں کے ساتھ نسخے شیئر نہ کریں
|
| 694 |
+
• اپنے ساتھ اپ ڈیٹ شدہ دوائیوں کی فہرست رکھیں
|
| 695 |
+
• تمام ڈاکٹروں کو تمام دوائیوں کے بارے میں بتائیں
|
| 696 |
+
• ہر دوا کے مقصد اور مضر اثرات کو سمجھیں
|
| 697 |
+
|
| 698 |
+
**⚠️ عام دوائیوں کی اقسام:**
|
| 699 |
+
• **دل**: بیٹا بلاکرز، ACE inhibitors، statins
|
| 700 |
+
• **ذیابیطس**: میٹفارمن، انسولین، SGLT2 inhibitors
|
| 701 |
+
• **ہائی بلڈ پریشر**: ڈائیوریٹکس، کیلشیم چینل بلاکرز
|
| 702 |
+
• **درد**: NSAIDs، acetaminophen (احتیاط سے استعمال کریں)
|
| 703 |
+
|
| 704 |
+
**🚨 دوائیوں کی انتباہی علامات:**
|
| 705 |
+
• شدید الرجک رد عمل (خارش، سوجن)
|
| 706 |
+
• دوا لینے کے بعد سانس لینے میں دشواری
|
| 707 |
+
• شدید پیٹ میں درد یا الٹی
|
| 708 |
+
• غیر معمولی خون بہنا یا چوٹ لگنا
|
| 709 |
+
• الجھن یا توہمات
|
| 710 |
+
|
| 711 |
+
**💡 اہم یاد دہانیاں:**
|
| 712 |
+
• ڈاکٹر کے مشورے کے بغیر دوائیں بند نہ کریں
|
| 713 |
+
• اپنے ڈاکٹر کو مضر اثرات کی رپورٹ کریں
|
| 714 |
+
• دوائیں اصل کنٹینرز میں رکھیں
|
| 715 |
+
• میعاد ختم ہونے کی تاریخوں کو باقاعدگی سے چیک کریں
|
| 716 |
+
|
| 717 |
+
*نوٹ: ہمیشہ اپنے ہیلتھ کیئر فراہم کرنے والے کی مخصوص ہدایات پر عمل کریں۔*
|
| 718 |
+
"""
|
| 719 |
+
|
| 720 |
+
def _format_emergency_response(self, language):
|
| 721 |
+
if language == 'English':
|
| 722 |
+
return """
|
| 723 |
+
**🚨 EMERGENCY MEDICAL GUIDANCE**
|
| 724 |
|
| 725 |
+
**📞 Immediate Actions Required:**
|
| 726 |
+
• Call emergency services (1122 in Pakistan)
|
| 727 |
+
• Don't drive yourself to hospital
|
| 728 |
+
• Keep patient calm and comfortable
|
| 729 |
+
• Have medical information ready
|
| 730 |
+
• Don't give food or drink
|
| 731 |
+
|
| 732 |
+
**🏥 When to Go to Emergency Room:**
|
| 733 |
+
• Chest pain or pressure
|
| 734 |
+
• Difficulty breathing
|
| 735 |
+
• Severe bleeding
|
| 736 |
+
• Sudden weakness or paralysis
|
| 737 |
+
• Severe burns
|
| 738 |
+
• Poisoning or overdose
|
| 739 |
+
• Seizures
|
| 740 |
+
• Severe allergic reactions
|
| 741 |
+
|
| 742 |
+
**🆘 First Aid Basics:**
|
| 743 |
+
• **CPR**: Start if no breathing/pulse (30 compressions: 2 breaths)
|
| 744 |
+
• **Bleeding**: Apply direct pressure
|
| 745 |
+
• **Choking**: Perform Heimlich maneuver
|
| 746 |
+
• **Burns**: Cool with running water
|
| 747 |
+
• **Fainting**: Lay flat, elevate legs
|
| 748 |
+
|
| 749 |
+
**📋 Emergency Preparedness:**
|
| 750 |
+
• Keep emergency numbers handy
|
| 751 |
+
• Know location of nearest hospital
|
| 752 |
+
• Have medical history documented
|
| 753 |
+
• Keep medications list updated
|
| 754 |
+
|
| 755 |
+
*⚠️ THIS IS EMERGENCY GUIDANCE ONLY. SEEK PROFESSIONAL MEDICAL HELP IMMEDIATELY.*
|
| 756 |
+
"""
|
| 757 |
+
else:
|
| 758 |
+
return """
|
| 759 |
+
**🚨 ہنگامی طبی رہنمائی**
|
| 760 |
+
|
| 761 |
+
**📞 فوری کارروائی کی ضرورت ہے:**
|
| 762 |
+
• ہنگامی خدمات کو کال کریں (پاکستان میں 1122)
|
| 763 |
+
• خود ہسپتال نہ جائیں
|
| 764 |
+
• مریض کو پرسکون اور آرام دہ رکھیں
|
| 765 |
+
• طبی معلومات تیار رکھیں
|
| 766 |
+
• کھانا یا پانی نہ دیں
|
| 767 |
+
|
| 768 |
+
**🏥 ایمرجنسی روم کب جائیں:**
|
| 769 |
• سینے میں درد یا دباؤ
|
| 770 |
+
• سانس لینے میں دشواری
|
| 771 |
• شدید خون بہنا
|
| 772 |
+
• اچانک کمزوری یا فالج
|
| 773 |
+
• شدید جلنے
|
| 774 |
+
• زہر یا اوور ڈوز
|
| 775 |
+
• دورے
|
| 776 |
+
• شدید الرجک رد عمل
|
| 777 |
+
|
| 778 |
+
**🆘 فرسٹ ایڈ کی بنیادی باتیں:**
|
| 779 |
+
• **CPR**: اگر سانس/پلس نہ ہو تو شروع کریں (30 کمپریشن: 2 سانس)
|
| 780 |
+
• **خون بہنا**: براہ راست دباؤ ڈالیں
|
| 781 |
+
• **گلا گھٹنا**: ہیملک مانور انجام دیں
|
| 782 |
+
• **جلنے**: پانی سے ٹھنڈا کریں
|
| 783 |
+
• **بیہوشی**: سیدھا لیٹائیں، ٹانگیں اونچی کریں
|
| 784 |
+
|
| 785 |
+
**📋 ہنگامی تیاری:**
|
| 786 |
+
• ہنگامی نمبرز ہاتھ میں رکھیں
|
| 787 |
+
• قریبی ہسپتال کا مقام جانیں
|
| 788 |
+
• طبی تاریخ دستاویزی شکل میں رکھ��ں
|
| 789 |
+
• دوائیوں کی فہرست اپ ڈیٹ رکھیں
|
| 790 |
+
|
| 791 |
+
*⚠️ یہ صرف ہنگامی رہنمائی ہے۔ فوری طور پر پیشہ ورانہ طبی مدد حاصل کریں۔*
|
| 792 |
"""
|
| 793 |
|
| 794 |
+
def _format_general_health_response(self, language):
|
| 795 |
+
knowledge = self.medical_knowledge_base['general_health']
|
| 796 |
if language == 'English':
|
| 797 |
+
return f"""
|
| 798 |
+
**🌿 Comprehensive Health & Wellness Guide**
|
| 799 |
|
| 800 |
+
**💚 Lifestyle Recommendations:**
|
| 801 |
+
{chr(10).join(['• ' + tip for tip in knowledge['lifestyle']])}
|
| 802 |
+
|
| 803 |
+
**🛡️ Preventive Healthcare:**
|
| 804 |
+
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
|
|
|
| 805 |
|
| 806 |
+
**🎯 Health Monitoring Schedule:**
|
| 807 |
+
• **Daily**: Blood pressure (if hypertensive), blood sugar (if diabetic)
|
| 808 |
+
• **Weekly**: Weight, exercise minutes
|
| 809 |
+
• **Monthly**: Self-examinations (skin, breasts, testicles)
|
| 810 |
+
• **Annual**: Complete physical, blood tests, dental checkup
|
| 811 |
+
• **As recommended**: Cancer screenings, vision/hearing tests
|
| 812 |
|
| 813 |
+
**🌟 Healthy Habits for Pakistan:**
|
| 814 |
+
• Drink filtered/boiled water
|
| 815 |
+
• Eat fresh, locally available fruits and vegetables
|
| 816 |
+
• Practice good food hygiene
|
| 817 |
+
• Get adequate sunlight exposure (vitamin D)
|
| 818 |
+
• Maintain social connections and mental wellbeing
|
| 819 |
+
|
| 820 |
+
*Remember: Small consistent changes lead to lasting health improvements!*
|
| 821 |
"""
|
| 822 |
else:
|
| 823 |
+
return f"""
|
| 824 |
+
**🌿 صحت اور تندرستی کی جامع گائیڈ**
|
| 825 |
|
| 826 |
+
**💚 طرز زندگی کی سفارشات:**
|
| 827 |
+
{chr(10).join(['• ' + tip for tip in ['رات میں 7-9 گھنٹے معیاری نیند', 'تناؤ کے انتظام کی تکنیکیں', 'سگریٹ نوشی سے پرہیز', 'شراب کو 1-2 ڈرنکس/دن تک محدود کریں', 'باقاعدہ صحت کی جانچ']])}
|
| 828 |
+
|
| 829 |
+
**🛡️ احتیاطی ہیلتھ کیئر:**
|
| 830 |
+
{chr(10).join(['• ' + tip for tip in ['سالانہ جسمانی امتحانات', 'ویکسینیشن اپ ڈیٹ', 'باقاعدہ ہاتھ دھونا', 'سورج سے تحفظ', 'ذہنی صحت کی دیکھ بھال']])}
|
| 831 |
+
|
| 832 |
+
**🎯 صحت کی نگرانی کا شیڈول:**
|
| 833 |
+
• **روزانہ**: بلڈ پریشر (اگر ہائی بلڈ پریشر ہو)، بلڈ شوگر (اگر ذیابیطس ہو)
|
| 834 |
+
• **ہفتہ وار**: وزن، ورزش کے منٹ
|
| 835 |
+
• **ماہانہ**: خود معائنہ (جلد، چھاتی، خصیے)
|
| 836 |
+
• **سالانہ**: مکمل جسمانی، خون کے ٹیسٹ، دانتوں کا چیک اپ
|
| 837 |
+
• **جیسا کہ تجویز کیا گیا ہے**: کینسر کی اسکریننگ، بینائی/سماعت کے ٹیسٹ
|
| 838 |
|
| 839 |
+
**🌟 پاکستان کے لیے صحت مند عادات:**
|
| 840 |
+
• فلٹر/ابلا ہوا پانی پیئیں
|
| 841 |
+
• تازہ، مقامی طور پر دستیاب پھل اور سبزیاں کھائیں
|
| 842 |
+
• اچھی غذا کی حفظان صحت کی مشق کریں
|
| 843 |
+
• مناسب سورج کی روشنی (وٹامن ڈی) حاصل کریں
|
| 844 |
+
• سماجی رابطے اور ذہنی تندرستی برقرار رکھیں
|
| 845 |
|
| 846 |
+
*یاد رکھیں: چھوٹی مسلسل تبدیلیاں پائیدار صحت کی بہتری کا باعث بنتی ہیں!*
|
| 847 |
+
"""
|
| 848 |
+
|
| 849 |
+
def _format_default_response(self, language):
|
| 850 |
+
if language == 'English':
|
| 851 |
+
return """
|
| 852 |
+
**🤖 SehatAI Health Assistant**
|
| 853 |
+
|
| 854 |
+
I understand you're asking about health topics. I'm specially trained to help with:
|
| 855 |
+
|
| 856 |
+
**💚 Common Health Areas:**
|
| 857 |
+
• Heart disease and cardiovascular health
|
| 858 |
+
• Diabetes management and prevention
|
| 859 |
+
• Blood pressure control
|
| 860 |
+
• Nutrition and dietary guidance
|
| 861 |
+
• Exercise and physical activity
|
| 862 |
+
• Symptom assessment
|
| 863 |
+
• Medication information
|
| 864 |
+
• Emergency situations
|
| 865 |
+
• General wellness and prevention
|
| 866 |
+
|
| 867 |
+
**💡 How to Get Better Answers:**
|
| 868 |
+
Please ask specific questions like:
|
| 869 |
+
• "What are the symptoms of heart disease?"
|
| 870 |
+
• "How to manage diabetes?"
|
| 871 |
+
• "What foods help lower blood pressure?"
|
| 872 |
+
• "Exercise recommendations for beginners"
|
| 873 |
+
• "When to go to emergency room?"
|
| 874 |
+
|
| 875 |
+
I'll provide detailed, accurate medical information to help you make informed health decisions.
|
| 876 |
+
|
| 877 |
+
*⚠️ Remember: I'm an AI assistant. For personal medical advice, always consult qualified healthcare professionals.*
|
| 878 |
+
"""
|
| 879 |
+
else:
|
| 880 |
+
return """
|
| 881 |
+
**🤖 سیحت اے آئی ہیلتھ اسسٹنٹ**
|
| 882 |
+
|
| 883 |
+
میں سمجھتا ہوں کہ آپ صحت کے موضوعات کے بارے میں پوچھ رہے ہیں۔ میں خاص طور پر مدد کے لیے تربیت یافتہ ہوں:
|
| 884 |
+
|
| 885 |
+
**💚 عام صحت کے شعبے:**
|
| 886 |
+
• دل کی بیماری اور قلبی صحت
|
| 887 |
+
• ذیابیطس کا انتظام اور روک تھام
|
| 888 |
+
• بلڈ پریشر کنٹرول
|
| 889 |
+
• غذائیت اور غذائی رہنمائی
|
| 890 |
+
• ورزش اور جسمانی سرگرمی
|
| 891 |
+
• علامات کی تشخیص
|
| 892 |
+
• دوائیوں کی معلومات
|
| 893 |
+
• ہنگامی حالات
|
| 894 |
+
• عام تندرستی اور روک تھام
|
| 895 |
+
|
| 896 |
+
**💡 بہتر جوابات کیسے حاصل کریں:**
|
| 897 |
+
براہ کرم مخصوص سوالات پوچھیں جیسے:
|
| 898 |
+
• "دل کی بیماری کی علامات کیا ہیں؟"
|
| 899 |
+
• "ذیابیطس کا انتظام کیسے کریں؟"
|
| 900 |
+
• "کون سی غذائیں بلڈ پریشر کم کرنے میں مدد کرتی ہیں؟"
|
| 901 |
+
• "ابتدائی افراد کے لیے ورزش کی سفارشات"
|
| 902 |
+
• "ایمرجنسی روم کب جائیں؟"
|
| 903 |
+
|
| 904 |
+
میں آپ کو معلوماتی صحت کے فیصلے کرنے میں مدد کے لیے تفصیلی، درست طبی معلومات فراہم کروں گا۔
|
| 905 |
+
|
| 906 |
+
*⚠️ یاد رکھیں: میں ایک AI اسسٹنٹ ہوں۔ ذاتی طبی مشورے کے لیے، ہمیشہ کوالیفائیڈ ہیلتھ کیئر پروفیشنلز سے مشورہ کریں۔*
|
| 907 |
"""
|
| 908 |
|
| 909 |
class PDFReportGenerator:
|
| 910 |
def __init__(self):
|
| 911 |
self.pdf = FPDF()
|
| 912 |
+
self.pdf.set_auto_page_break(auto=True, margin=15)
|
| 913 |
+
|
| 914 |
def generate_report(self, patient_data, risk_scores, language='English'):
|
| 915 |
self.pdf.add_page()
|
| 916 |
|
| 917 |
# Title
|
| 918 |
self.pdf.set_font('Arial', 'B', 16)
|
| 919 |
if language == 'English':
|
| 920 |
+
self.pdf.cell(0, 10, 'SEHATAI MEDICAL ASSESSMENT REPORT', 0, 1, 'C')
|
| 921 |
else:
|
| 922 |
+
# For Urdu, we'll use English to avoid encoding issues
|
| 923 |
+
self.pdf.cell(0, 10, 'SEHATAI MEDICAL ASSESSMENT REPORT', 0, 1, 'C')
|
| 924 |
|
| 925 |
self.pdf.ln(10)
|
| 926 |
|
| 927 |
# Patient Information
|
| 928 |
self.pdf.set_font('Arial', 'B', 12)
|
| 929 |
+
self.pdf.cell(0, 10, 'Patient Information:', 0, 1)
|
|
|
|
|
|
|
|
|
|
| 930 |
|
| 931 |
self.pdf.set_font('Arial', '', 10)
|
| 932 |
patient_info = [
|
| 933 |
+
f"Name: {self._safe_encode(patient_data.get('name', 'Not provided'))}",
|
| 934 |
f"Age: {patient_data.get('age', 'Not provided')} years",
|
| 935 |
+
f"Gender: {self._safe_encode(patient_data.get('gender', 'Not provided'))}",
|
| 936 |
+
f"Contact: {self._safe_encode(patient_data.get('contact', 'Not provided'))}"
|
| 937 |
]
|
| 938 |
|
| 939 |
for info in patient_info:
|
|
|
|
| 943 |
|
| 944 |
# Clinical Parameters
|
| 945 |
self.pdf.set_font('Arial', 'B', 12)
|
| 946 |
+
self.pdf.cell(0, 10, 'Clinical Parameters:', 0, 1)
|
|
|
|
|
|
|
|
|
|
| 947 |
|
| 948 |
self.pdf.set_font('Arial', '', 10)
|
| 949 |
clinical_info = [
|
|
|
|
| 959 |
|
| 960 |
self.pdf.ln(5)
|
| 961 |
|
| 962 |
+
# Symptoms
|
| 963 |
+
self.pdf.set_font('Arial', 'B', 12)
|
| 964 |
+
self.pdf.cell(0, 10, 'Reported Symptoms:', 0, 1)
|
| 965 |
+
|
| 966 |
+
self.pdf.set_font('Arial', '', 10)
|
| 967 |
+
symptoms = patient_data.get('symptoms', {})
|
| 968 |
+
symptom_list = [
|
| 969 |
+
f"Chest Pain: {'Yes' if symptoms.get('chest_pain') else 'No'}",
|
| 970 |
+
f"Shortness of Breath: {'Yes' if symptoms.get('shortness_breath') else 'No'}",
|
| 971 |
+
f"Palpitations: {'Yes' if symptoms.get('palpitations') else 'No'}",
|
| 972 |
+
f"Fatigue: {'Yes' if symptoms.get('fatigue') else 'No'}",
|
| 973 |
+
f"Dizziness: {'Yes' if symptoms.get('dizziness') else 'No'}",
|
| 974 |
+
f"Blurred Vision: {'Yes' if symptoms.get('blurred_vision') else 'No'}"
|
| 975 |
+
]
|
| 976 |
+
|
| 977 |
+
for symptom in symptom_list:
|
| 978 |
+
self.pdf.cell(0, 8, symptom, 0, 1)
|
| 979 |
+
|
| 980 |
+
self.pdf.ln(5)
|
| 981 |
+
|
| 982 |
# Risk Assessment
|
| 983 |
self.pdf.set_font('Arial', 'B', 12)
|
| 984 |
+
self.pdf.cell(0, 10, 'Risk Assessment Results:', 0, 1)
|
|
|
|
|
|
|
|
|
|
| 985 |
|
| 986 |
self.pdf.set_font('Arial', '', 10)
|
| 987 |
risk_info = [
|
|
|
|
| 998 |
|
| 999 |
# Recommendation
|
| 1000 |
self.pdf.set_font('Arial', 'B', 12)
|
| 1001 |
+
self.pdf.cell(0, 10, 'Clinical Recommendation:', 0, 1)
|
|
|
|
|
|
|
|
|
|
| 1002 |
|
| 1003 |
self.pdf.set_font('Arial', '', 10)
|
| 1004 |
+
recommendation = self._safe_encode(risk_scores.get('recommendation', 'No recommendation available'))
|
| 1005 |
self.pdf.multi_cell(0, 8, recommendation)
|
| 1006 |
|
| 1007 |
self.pdf.ln(10)
|
| 1008 |
|
| 1009 |
# Footer
|
| 1010 |
self.pdf.set_font('Arial', 'I', 8)
|
| 1011 |
+
self.pdf.cell(0, 10, f'Generated by SehatAI on: {datetime.now().strftime("%Y-%m-%d %H:%M")}', 0, 1, 'C')
|
|
|
|
|
|
|
|
|
|
| 1012 |
|
| 1013 |
+
return self.pdf.output(dest='S').encode('latin1', 'replace')
|
| 1014 |
+
|
| 1015 |
+
def _safe_encode(self, text):
|
| 1016 |
+
"""Safely encode text for PDF generation"""
|
| 1017 |
+
if text is None:
|
| 1018 |
+
return ""
|
| 1019 |
+
try:
|
| 1020 |
+
return str(text)
|
| 1021 |
+
except:
|
| 1022 |
+
return "Encoding error"
|
| 1023 |
+
|
| 1024 |
+
# Load ML models with error handling
|
| 1025 |
+
@st.cache_resource(show_spinner=False)
|
| 1026 |
+
def load_models():
|
| 1027 |
+
models = {}
|
| 1028 |
+
scalers = {}
|
| 1029 |
+
|
| 1030 |
+
try:
|
| 1031 |
+
# Load heart disease model
|
| 1032 |
+
if os.path.exists('heart_model.pkl'):
|
| 1033 |
+
models['heart'] = joblib.load('heart_model.pkl')
|
| 1034 |
+
st.success("✅ Heart disease model loaded successfully")
|
| 1035 |
+
else:
|
| 1036 |
+
st.warning("⚠️ Heart model file not found, using rule-based assessment")
|
| 1037 |
+
models['heart'] = None
|
| 1038 |
+
except Exception as e:
|
| 1039 |
+
st.warning(f"⚠️ Error loading heart model: {str(e)}")
|
| 1040 |
+
models['heart'] = None
|
| 1041 |
+
|
| 1042 |
+
try:
|
| 1043 |
+
# Load diabetes model
|
| 1044 |
+
if os.path.exists('diabeties_model.pkl'):
|
| 1045 |
+
models['diabetes'] = joblib.load('diabeties_model.pkl')
|
| 1046 |
+
st.success("✅ Diabetes model loaded successfully")
|
| 1047 |
+
else:
|
| 1048 |
+
st.warning("⚠️ Diabetes model file not found, using rule-based assessment")
|
| 1049 |
+
models['diabetes'] = None
|
| 1050 |
+
except Exception as e:
|
| 1051 |
+
st.warning(f"⚠️ Error loading diabetes model: {str(e)}")
|
| 1052 |
+
models['diabetes'] = None
|
| 1053 |
+
|
| 1054 |
+
try:
|
| 1055 |
+
# Load hypertension model
|
| 1056 |
+
if os.path.exists('hypertension_model.pkl'):
|
| 1057 |
+
models['hypertension'] = joblib.load('hypertension_model.pkl')
|
| 1058 |
+
st.success("✅ Hypertension model loaded successfully")
|
| 1059 |
+
else:
|
| 1060 |
+
st.warning("⚠️ Hypertension model file not found, using rule-based assessment")
|
| 1061 |
+
models['hypertension'] = None
|
| 1062 |
+
except Exception as e:
|
| 1063 |
+
st.warning(f"⚠️ Error loading hypertension model: {str(e)}")
|
| 1064 |
+
models['hypertension'] = None
|
| 1065 |
+
|
| 1066 |
+
# Load scalers
|
| 1067 |
+
try:
|
| 1068 |
+
if os.path.exists('scaler.pkl'):
|
| 1069 |
+
scalers['default'] = joblib.load('scaler.pkl')
|
| 1070 |
+
st.success("✅ Scaler loaded successfully")
|
| 1071 |
+
except:
|
| 1072 |
+
st.warning("⚠️ Scaler not available, using standard scaling")
|
| 1073 |
+
scalers['default'] = None
|
| 1074 |
+
|
| 1075 |
+
return models, scalers
|
| 1076 |
|
| 1077 |
def calculate_priority_score(heart_risk, diabetes_risk, hypertension_risk):
|
| 1078 |
"""Calculate integrated priority score with clinical weighting"""
|
|
|
|
| 1118 |
|
| 1119 |
return errors
|
| 1120 |
|
| 1121 |
+
def predict_with_models(age, bp_systolic, bp_diastolic, heart_rate, cholesterol, glucose, bmi, symptoms, models, scalers):
|
| 1122 |
+
"""Predict risks using loaded ML models"""
|
| 1123 |
+
heart_risk, diabetes_risk, hypertension_risk = 0.0, 0.0, 0.0
|
| 1124 |
+
|
| 1125 |
+
try:
|
| 1126 |
+
# Prepare features for heart model
|
| 1127 |
+
if models['heart'] is not None:
|
| 1128 |
+
heart_features = np.array([[
|
| 1129 |
+
age, bp_systolic, cholesterol, heart_rate,
|
| 1130 |
+
symptoms['chest_pain'], symptoms['shortness_breath'],
|
| 1131 |
+
symptoms['palpitations'], bmi, glucose
|
| 1132 |
+
]])
|
| 1133 |
+
|
| 1134 |
+
if scalers.get('default') is not None:
|
| 1135 |
+
heart_features = scalers['default'].transform(heart_features)
|
| 1136 |
+
|
| 1137 |
+
heart_risk = models['heart'].predict_proba(heart_features)[0][1]
|
| 1138 |
+
else:
|
| 1139 |
+
heart_risk = predict_risk_rule_based_heart(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1140 |
+
|
| 1141 |
+
except Exception as e:
|
| 1142 |
+
heart_risk = predict_risk_rule_based_heart(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1143 |
+
|
| 1144 |
+
try:
|
| 1145 |
+
# Prepare features for diabetes model
|
| 1146 |
+
if models['diabetes'] is not None:
|
| 1147 |
+
diabetes_features = np.array([[
|
| 1148 |
+
age, glucose, bmi, cholesterol,
|
| 1149 |
+
symptoms['fatigue'], symptoms['blurred_vision'],
|
| 1150 |
+
bp_systolic, heart_rate
|
| 1151 |
+
]])
|
| 1152 |
+
|
| 1153 |
+
if scalers.get('default') is not None:
|
| 1154 |
+
diabetes_features = scalers['default'].transform(diabetes_features)
|
| 1155 |
+
|
| 1156 |
+
diabetes_risk = models['diabetes'].predict_proba(diabetes_features)[0][1]
|
| 1157 |
+
else:
|
| 1158 |
+
diabetes_risk = predict_risk_rule_based_diabetes(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1159 |
+
|
| 1160 |
+
except Exception as e:
|
| 1161 |
+
diabetes_risk = predict_risk_rule_based_diabetes(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1162 |
+
|
| 1163 |
+
try:
|
| 1164 |
+
# Prepare features for hypertension model
|
| 1165 |
+
if models['hypertension'] is not None:
|
| 1166 |
+
hypertension_features = np.array([[
|
| 1167 |
+
age, bp_systolic, bp_diastolic, bmi,
|
| 1168 |
+
symptoms['dizziness'], symptoms['palpitations'],
|
| 1169 |
+
heart_rate, cholesterol
|
| 1170 |
+
]])
|
| 1171 |
+
|
| 1172 |
+
if scalers.get('default') is not None:
|
| 1173 |
+
hypertension_features = scalers['default'].transform(hypertension_features)
|
| 1174 |
+
|
| 1175 |
+
hypertension_risk = models['hypertension'].predict_proba(hypertension_features)[0][1]
|
| 1176 |
+
else:
|
| 1177 |
+
hypertension_risk = predict_risk_rule_based_hypertension(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1178 |
+
|
| 1179 |
+
except Exception as e:
|
| 1180 |
+
hypertension_risk = predict_risk_rule_based_hypertension(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1181 |
+
|
| 1182 |
+
return heart_risk, diabetes_risk, hypertension_risk
|
| 1183 |
+
|
| 1184 |
+
def predict_risk_rule_based_heart(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms):
|
| 1185 |
+
"""Rule-based heart risk prediction"""
|
| 1186 |
+
risk = 0.0
|
| 1187 |
|
| 1188 |
+
# Age factor
|
| 1189 |
+
if age > 60: risk += 0.25
|
| 1190 |
+
elif age > 45: risk += 0.15
|
| 1191 |
+
elif age > 30: risk += 0.05
|
| 1192 |
|
| 1193 |
+
# Blood pressure factor
|
| 1194 |
+
if bp_systolic > 180 or bp_diastolic > 120: risk += 0.30
|
| 1195 |
+
elif bp_systolic > 140 or bp_diastolic > 90: risk += 0.20
|
| 1196 |
+
elif bp_systolic > 130 or bp_diastolic > 85: risk += 0.10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1197 |
|
| 1198 |
+
# Cholesterol factor
|
| 1199 |
+
if cholesterol > 240: risk += 0.20
|
| 1200 |
+
elif cholesterol > 200: risk += 0.10
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1201 |
|
| 1202 |
+
# BMI factor
|
| 1203 |
+
if bmi > 35: risk += 0.15
|
| 1204 |
+
elif bmi > 30: risk += 0.10
|
| 1205 |
+
elif bmi > 25: risk += 0.05
|
|
|
|
| 1206 |
|
| 1207 |
+
# Glucose factor
|
| 1208 |
+
if glucose > 200: risk += 0.10
|
| 1209 |
+
elif glucose > 126: risk += 0.05
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1210 |
|
| 1211 |
+
# Symptom factors
|
| 1212 |
+
if symptoms['chest_pain']: risk += 0.25
|
| 1213 |
+
if symptoms['shortness_breath']: risk += 0.15
|
| 1214 |
+
if symptoms['palpitations']: risk += 0.10
|
| 1215 |
+
|
| 1216 |
+
return min(0.95, risk)
|
| 1217 |
+
|
| 1218 |
+
def predict_risk_rule_based_diabetes(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms):
|
| 1219 |
+
"""Rule-based diabetes risk prediction"""
|
| 1220 |
+
risk = 0.0
|
| 1221 |
+
|
| 1222 |
+
# Age factor
|
| 1223 |
+
if age > 50: risk += 0.20
|
| 1224 |
+
elif age > 40: risk += 0.10
|
| 1225 |
+
elif age > 30: risk += 0.05
|
| 1226 |
+
|
| 1227 |
+
# Glucose factor (most important)
|
| 1228 |
+
if glucose > 200: risk += 0.40
|
| 1229 |
+
elif glucose > 126: risk += 0.30
|
| 1230 |
+
elif glucose > 100: risk += 0.15
|
| 1231 |
+
|
| 1232 |
+
# BMI factor
|
| 1233 |
+
if bmi > 35: risk += 0.25
|
| 1234 |
+
elif bmi > 30: risk += 0.15
|
| 1235 |
+
elif bmi > 25: risk += 0.08
|
| 1236 |
+
|
| 1237 |
+
# Blood pressure factor
|
| 1238 |
+
if bp_systolic > 140 or bp_diastolic > 90: risk += 0.10
|
| 1239 |
|
| 1240 |
# Symptom factors
|
| 1241 |
+
if symptoms['fatigue']: risk += 0.10
|
| 1242 |
+
if symptoms['blurred_vision']: risk += 0.08
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1243 |
|
| 1244 |
+
return min(0.95, risk)
|
| 1245 |
+
|
| 1246 |
+
def predict_risk_rule_based_hypertension(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms):
|
| 1247 |
+
"""Rule-based hypertension risk prediction"""
|
| 1248 |
+
risk = 0.0
|
| 1249 |
+
|
| 1250 |
+
# Blood pressure factor (most important)
|
| 1251 |
+
if bp_systolic > 180 or bp_diastolic > 120: risk += 0.50
|
| 1252 |
+
elif bp_systolic > 140 or bp_diastolic > 90: risk += 0.35
|
| 1253 |
+
elif bp_systolic > 130 or bp_diastolic > 85: risk += 0.20
|
| 1254 |
+
|
| 1255 |
+
# Age factor
|
| 1256 |
+
if age > 60: risk += 0.15
|
| 1257 |
+
elif age > 45: risk += 0.08
|
| 1258 |
|
| 1259 |
+
# BMI factor
|
| 1260 |
+
if bmi > 30: risk += 0.15
|
| 1261 |
+
elif bmi > 25: risk += 0.08
|
| 1262 |
+
|
| 1263 |
+
# Symptom factors
|
| 1264 |
+
if symptoms['dizziness']: risk += 0.10
|
| 1265 |
+
if symptoms['palpitations']: risk += 0.08
|
| 1266 |
|
| 1267 |
+
return min(0.95, risk)
|
| 1268 |
|
| 1269 |
def create_download_link(pdf_data, filename, text):
|
| 1270 |
"""Create a download link for PDF"""
|
|
|
|
| 1277 |
local_css()
|
| 1278 |
init_session_state()
|
| 1279 |
|
| 1280 |
+
# Load ML models
|
| 1281 |
+
with st.spinner("🔄 Loading AI models..."):
|
| 1282 |
+
models, scalers = load_models()
|
| 1283 |
+
|
| 1284 |
# Initialize chatbot
|
| 1285 |
chatbot = HealthcareChatbot()
|
| 1286 |
|
| 1287 |
+
# Language selector at top right with Pakistan flag colors
|
| 1288 |
col_lang, col_space = st.columns([1, 5])
|
| 1289 |
with col_lang:
|
| 1290 |
+
st.markdown('<div class="pakistan-flag">🇵🇰</div>', unsafe_allow_html=True)
|
| 1291 |
language = st.selectbox("Language", ["English", "Urdu"], key="language_selector", label_visibility="collapsed")
|
| 1292 |
st.session_state.current_language = language
|
| 1293 |
|
| 1294 |
+
# Main header with new name
|
| 1295 |
+
st.markdown('<h1 class="main-header">🏥 SehatAI</h1>', unsafe_allow_html=True)
|
| 1296 |
if language == "English":
|
| 1297 |
+
st.markdown('<h3 style="text-align: center; color: #00612A; margin-bottom: 20px;">Smart Healthcare Triage & Risk Assessment System</h3>', unsafe_allow_html=True)
|
| 1298 |
else:
|
| 1299 |
+
st.markdown('<h3 style="text-align: center; color: #00612A; margin-bottom: 20px;">ذہین ہیلتھ کیئر ٹریج اور خطرے کی تشخیص کا نظام</h3>', unsafe_allow_html=True)
|
| 1300 |
|
| 1301 |
# Display random healthcare quote
|
| 1302 |
import random
|
|
|
|
| 1323 |
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1324 |
|
| 1325 |
if language == "English":
|
| 1326 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">👨⚕️ Comprehensive Patient Assessment</h2>', unsafe_allow_html=True)
|
| 1327 |
st.write("Complete the following form for comprehensive patient risk assessment and priority scoring")
|
| 1328 |
else:
|
| 1329 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">👨⚕️ جامع مریض تشخیص</h2>', unsafe_allow_html=True)
|
| 1330 |
st.write("جامع مریض کے خطرے کی تشخیص اور ترجیحی اسکورنگ کے لیے درج ذیل فارم کو مکمل کریں")
|
| 1331 |
|
| 1332 |
with st.form("patient_assessment_form"):
|
|
|
|
| 1451 |
'symptoms': symptoms_dict
|
| 1452 |
}
|
| 1453 |
|
| 1454 |
+
# Predict risks using ML models
|
| 1455 |
+
heart_risk, diabetes_risk, hypertension_risk = predict_with_models(
|
| 1456 |
+
age, bp_systolic, bp_diastolic, heart_rate,
|
| 1457 |
+
cholesterol, glucose, bmi, symptoms_dict, models, scalers
|
| 1458 |
)
|
| 1459 |
|
| 1460 |
# Calculate integrated priority score
|
| 1461 |
priority_score = calculate_priority_score(
|
| 1462 |
+
heart_risk, diabetes_risk, hypertension_risk
|
| 1463 |
)
|
| 1464 |
|
| 1465 |
priority_level, recommendation, risk_class = get_priority_recommendation(
|
|
|
|
| 1468 |
|
| 1469 |
# Store results
|
| 1470 |
st.session_state.risk_scores = {
|
| 1471 |
+
'heart': heart_risk,
|
| 1472 |
+
'diabetes': diabetes_risk,
|
| 1473 |
+
'hypertension': hypertension_risk,
|
| 1474 |
'priority': priority_score,
|
| 1475 |
'recommendation': recommendation,
|
| 1476 |
'level': priority_level
|
|
|
|
| 1496 |
col5, col6, col7, col8 = st.columns(4)
|
| 1497 |
|
| 1498 |
risk_metrics = [
|
| 1499 |
+
(heart_risk, "Heart Disease", "❤️", "#FF6B6B"),
|
| 1500 |
+
(diabetes_risk, "Diabetes", "🩺", "#4ECDC4"),
|
| 1501 |
+
(hypertension_risk, "Hypertension", "💓", "#45B7D1"),
|
| 1502 |
(priority_score, "Priority Score", "🎯", "#96CEB4")
|
| 1503 |
]
|
| 1504 |
|
|
|
|
| 1568 |
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1569 |
|
| 1570 |
if language == "English":
|
| 1571 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">💬 SehatAI Health Assistant</h2>', unsafe_allow_html=True)
|
| 1572 |
st.write("Ask health-related questions and get instant, reliable medical information")
|
| 1573 |
else:
|
| 1574 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">💬 سیحت اے آئی ہیلتھ اسسٹنٹ</h2>', unsafe_allow_html=True)
|
| 1575 |
st.write("صحت سے متعلق سوالات پوچھیں اور فوری، قابل اعتماد طبی معلومات حاصل کریں")
|
| 1576 |
|
| 1577 |
# Display chat history
|
|
|
|
| 1612 |
if st.button("❤️ Heart Health", use_container_width=True):
|
| 1613 |
st.session_state.chat_history.append({
|
| 1614 |
"role": "user",
|
| 1615 |
+
"content": "Tell me about heart disease symptoms and prevention"
|
| 1616 |
})
|
| 1617 |
st.rerun()
|
| 1618 |
|
|
|
|
| 1620 |
if st.button("🩺 Diabetes", use_container_width=True):
|
| 1621 |
st.session_state.chat_history.append({
|
| 1622 |
"role": "user",
|
| 1623 |
+
"content": "What are diabetes symptoms and management strategies?"
|
| 1624 |
})
|
| 1625 |
st.rerun()
|
| 1626 |
|
|
|
|
| 1628 |
if st.button("💓 Blood Pressure", use_container_width=True):
|
| 1629 |
st.session_state.chat_history.append({
|
| 1630 |
"role": "user",
|
| 1631 |
+
"content": "How to control high blood pressure naturally?"
|
| 1632 |
})
|
| 1633 |
st.rerun()
|
| 1634 |
|
| 1635 |
with col_qa4:
|
| 1636 |
+
if st.button("🍎 Nutrition", use_container_width=True):
|
| 1637 |
+
st.session_state.chat_history.append({
|
| 1638 |
+
"role": "user",
|
| 1639 |
+
"content": "What is a healthy diet for heart health?"
|
| 1640 |
+
})
|
| 1641 |
+
st.rerun()
|
| 1642 |
+
|
| 1643 |
+
# Additional quick actions
|
| 1644 |
+
col_qa5, col_qa6, col_qa7, col_qa8 = st.columns(4)
|
| 1645 |
+
|
| 1646 |
+
with col_qa5:
|
| 1647 |
+
if st.button("💪 Exercise", use_container_width=True):
|
| 1648 |
+
st.session_state.chat_history.append({
|
| 1649 |
+
"role": "user",
|
| 1650 |
+
"content": "Exercise recommendations for beginners"
|
| 1651 |
+
})
|
| 1652 |
+
st.rerun()
|
| 1653 |
+
|
| 1654 |
+
with col_qa6:
|
| 1655 |
+
if st.button("🔍 Symptoms", use_container_width=True):
|
| 1656 |
st.session_state.chat_history.append({
|
| 1657 |
"role": "user",
|
| 1658 |
+
"content": "When should I seek emergency medical care?"
|
| 1659 |
+
})
|
| 1660 |
+
st.rerun()
|
| 1661 |
+
|
| 1662 |
+
with col_qa7:
|
| 1663 |
+
if st.button("💊 Medications", use_container_width=True):
|
| 1664 |
+
st.session_state.chat_history.append({
|
| 1665 |
+
"role": "user",
|
| 1666 |
+
"content": "General medication safety guidelines"
|
| 1667 |
+
})
|
| 1668 |
+
st.rerun()
|
| 1669 |
+
|
| 1670 |
+
with col_qa8:
|
| 1671 |
+
if st.button("🚨 Emergency", use_container_width=True):
|
| 1672 |
+
st.session_state.chat_history.append({
|
| 1673 |
+
"role": "user",
|
| 1674 |
+
"content": "What are emergency warning signs?"
|
| 1675 |
})
|
| 1676 |
st.rerun()
|
| 1677 |
|
|
|
|
| 1682 |
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1683 |
|
| 1684 |
if language == "English":
|
| 1685 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">📋 Medical Reports & Analytics</h2>', unsafe_allow_html=True)
|
| 1686 |
st.write("Download comprehensive medical reports and view assessment analytics")
|
| 1687 |
else:
|
| 1688 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">📋 طبی رپورٹس اور تجزیات</h2>', unsafe_allow_html=True)
|
| 1689 |
st.write("جامع طبی رپورٹس ڈاؤن لوڈ کریں اور تشخیص کے تجزیات دیکھیں")
|
| 1690 |
|
| 1691 |
if st.session_state.assessment_history:
|
|
|
|
| 1706 |
)
|
| 1707 |
|
| 1708 |
if language == "English":
|
| 1709 |
+
st.markdown(create_download_link(pdf_data, "sehatai_medical_report.pdf", "📥 Download Medical Report (PDF)"), unsafe_allow_html=True)
|
| 1710 |
else:
|
| 1711 |
+
st.markdown(create_download_link(pdf_data, "sehatai_medical_report.pdf", "📥 طبی رپورٹ ڈاؤن لوڈ کریں (PDF)"), unsafe_allow_html=True)
|
| 1712 |
|
| 1713 |
# Analytics Section
|
| 1714 |
if language == "English":
|
|
|
|
| 1751 |
])
|
| 1752 |
|
| 1753 |
fig = px.line(risk_data, x='Assessment', y=['Heart Risk', 'Diabetes Risk', 'Hypertension Risk'],
|
| 1754 |
+
title="Risk Trend Analysis" if language == "English" else "خطرے کے رجحان کا تجزیہ",
|
| 1755 |
+
color_discrete_map={
|
| 1756 |
+
'Heart Risk': '#FF6B6B',
|
| 1757 |
+
'Diabetes Risk': '#4ECDC4',
|
| 1758 |
+
'Hypertension Risk': '#45B7D1'
|
| 1759 |
+
})
|
| 1760 |
st.plotly_chart(fig, use_container_width=True)
|
| 1761 |
|
| 1762 |
else:
|