Update app.py
Browse files
app.py
CHANGED
|
@@ -286,24 +286,21 @@ class HealthcareChatbot:
|
|
| 286 |
return self._get_rule_based_response(user_input, language)
|
| 287 |
|
| 288 |
def _get_groq_response(self, user_input, language):
|
| 289 |
-
system_prompt = """You are
|
| 290 |
-
Provide accurate,
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
4. Provide detailed medical explanations, practical advice, and when to seek help
|
| 297 |
-
5. Be empathetic but professional and authoritative
|
| 298 |
-
6. Focus on the specific medical issue the user is asking about
|
| 299 |
-
7. If it's a greeting, respond professionally and ask how you can help with their health concerns
|
| 300 |
-
|
| 301 |
-
Format your response as a medical professional would speak to a patient."""
|
| 302 |
|
| 303 |
if language == 'Urdu':
|
| 304 |
-
system_prompt += " Respond in Urdu with
|
| 305 |
else:
|
| 306 |
-
system_prompt += " Respond in English with professional medical advice.
|
| 307 |
|
| 308 |
messages = [
|
| 309 |
{"role": "system", "content": system_prompt},
|
|
@@ -330,7 +327,10 @@ class HealthcareChatbot:
|
|
| 330 |
def _get_rule_based_response(self, user_input, language):
|
| 331 |
user_input = user_input.lower().strip()
|
| 332 |
|
| 333 |
-
#
|
|
|
|
|
|
|
|
|
|
| 334 |
# Heart disease related queries
|
| 335 |
if any(word in user_input for word in ['heart', 'cardiac', 'chest pain', 'cholesterol', 'دل', 'سینے میں درد']):
|
| 336 |
return self._format_heart_response(language)
|
|
@@ -367,41 +367,42 @@ class HealthcareChatbot:
|
|
| 367 |
elif any(word in user_input for word in ['health', 'wellness', 'prevention', 'صحت', 'تندرستی']):
|
| 368 |
return self._format_general_health_response(language)
|
| 369 |
|
| 370 |
-
#
|
| 371 |
else:
|
| 372 |
-
return self.
|
| 373 |
|
| 374 |
-
def
|
| 375 |
-
"""Professional response for greetings and general queries"""
|
| 376 |
if language == 'English':
|
| 377 |
-
return
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
As your medical AI assistant, I'm here to provide specific, professional healthcare guidance. Could you please tell me more about your specific health concern so I can give you the most accurate and helpful medical advice?
|
| 381 |
|
| 382 |
-
I
|
| 383 |
-
•
|
| 384 |
-
• Diabetes
|
| 385 |
-
• Blood pressure
|
| 386 |
-
•
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
-
Please
|
| 389 |
|
| 390 |
*Note: I'm an AI assistant. For serious medical concerns, always consult a qualified healthcare professional.*
|
| 391 |
"""
|
| 392 |
else:
|
| 393 |
-
return
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
آپ کے میڈیکل AI اسسٹنٹ کے طور پر، میں مخصوص، پیشہ ورانہ ہیلتھ کیئر رہنمائی فراہم کرنے کے لیے یہاں ہوں۔ براہ کرم مجھے اپنے مخصوص صحت کے مسئلے کے بارے میں مزید بتائیں تاکہ میں آپ کو سب سے درست اور مددگار طبی مشورہ دے سکوں۔
|
| 397 |
|
| 398 |
-
میں
|
| 399 |
-
•
|
| 400 |
-
• ذیابیطس
|
| 401 |
-
• بلڈ پریشر
|
| 402 |
-
•
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
-
براہ کرم
|
| 405 |
|
| 406 |
*نوٹ: میں ایک AI اسسٹنٹ ہوں۔ سنگین طبی مسائل کے لیے، ہمیشہ کوالیفائیڈ ہیلتھ کیئر پروفیشنل سے مشورہ کریں۔*
|
| 407 |
"""
|
|
@@ -410,501 +411,1275 @@ Please share more details about your specific symptoms or health questions, and
|
|
| 410 |
knowledge = self.medical_knowledge_base['heart_disease']
|
| 411 |
if language == 'English':
|
| 412 |
return f"""
|
| 413 |
-
|
| 414 |
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
**Cardiac Symptoms to Monitor:**
|
| 418 |
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 419 |
|
| 420 |
-
|
| 421 |
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 422 |
|
| 423 |
-
|
| 424 |
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 425 |
|
| 426 |
-
|
| 427 |
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 428 |
|
| 429 |
-
|
| 430 |
-
• Regular
|
| 431 |
-
•
|
| 432 |
-
• ECG if
|
| 433 |
-
• Stress
|
| 434 |
|
| 435 |
-
|
| 436 |
"""
|
| 437 |
else:
|
| 438 |
return f"""
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
دل کی صحت کے بارے میں آپ کے سوال کی بنیاد پر، یہ میرا پیشہ ورانہ جائزہ ہے:
|
| 442 |
|
| 443 |
-
|
| 444 |
{chr(10).join(['• ' + symptom for symptom in ['سینے میں درد یا بے چینی', 'سانس لینے میں دشواری', 'بازوؤں، گردن، جبڑے میں درد', 'متلی', 'تھکاوٹ', 'چکر آنا']])}
|
| 445 |
|
| 446 |
-
|
| 447 |
{chr(10).join(['• ' + factor for factor in ['ہائی بلڈ پریشر', 'ہائی کولیسٹرول', 'سگریٹ نوشی', 'ذیابیطس', 'موٹاپا', 'خاندانی تاریخ', 'جسمانی غیر فعالیت']])}
|
| 448 |
|
| 449 |
-
|
| 450 |
{chr(10).join(['• ' + tip for tip in ['سیر شدہ چکنائی سے پاک صحت مند غذا', 'روزانہ 30 منٹ باقاعدہ ورزش', 'سگریٹ نوشی سے پرہیز', 'وزن کا انتظام', 'تنا�� کا انتظام', 'باقاعدہ چیک اپ']])}
|
| 451 |
|
| 452 |
-
|
| 453 |
{chr(10).join(['• ' + sign for sign in ['شدید سینے میں درد', 'سانس لینے میں شدید دشواری', 'بیہوش ہونا', 'تیز دل کی دھڑکن', 'بازو/کندھوں میں پھیلنے والا درد']])}
|
| 454 |
|
| 455 |
-
|
| 456 |
"""
|
| 457 |
|
| 458 |
def _format_diabetes_response(self, language):
|
| 459 |
knowledge = self.medical_knowledge_base['diabetes']
|
| 460 |
if language == 'English':
|
| 461 |
return f"""
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
Regarding your diabetes inquiry, here's my clinical perspective:
|
| 465 |
|
| 466 |
-
|
| 467 |
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 468 |
|
| 469 |
-
|
| 470 |
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 471 |
|
| 472 |
-
|
| 473 |
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 474 |
|
| 475 |
-
|
| 476 |
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 477 |
|
| 478 |
-
|
| 479 |
-
• Fasting
|
| 480 |
-
•
|
| 481 |
-
• HbA1c: <7.0% (
|
| 482 |
-
• Regular
|
| 483 |
-
• Annual foot examination
|
| 484 |
|
| 485 |
-
|
| 486 |
"""
|
| 487 |
else:
|
| 488 |
return f"""
|
| 489 |
-
|
| 490 |
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
**عام ذیابیطس کی علامات:**
|
| 494 |
{chr(10).join(['• ' + symptom for symptom in ['زیادہ پیاس اور بھوک لگنا', 'بار بار پیشاب آنا', 'تھکاوٹ', 'دھندلا نظر آنا', 'زخموں کا دیر سے بھرنا', 'بے وجہ وزن میں کمی']])}
|
| 495 |
|
| 496 |
-
|
| 497 |
{chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', 'وزن زیادہ ہونا (BMI > 25)', 'ہائی بلڈ پریشر', 'جسمانی غیر فعالیت', '45 سال سے زیادہ عمر', 'حمل کی ذیابیطس کی تاریخ']])}
|
| 498 |
|
| 499 |
-
|
| 500 |
{chr(10).join(['• ' + tip for tip in ['کنٹرول کاربوہائیڈریٹ کے ساتھ متوازن غذا', 'باقاعدہ جسمانی سرگرمی', 'وزن کا انتظام', 'بلڈ شوگر مانیٹرنگ', 'باقاعدہ صحت کی اسکریننگ']])}
|
| 501 |
|
| 502 |
-
|
| 503 |
{chr(10).join(['• ' + sign for sign in ['بلڈ شوگر >300 mg/dL یا <70 mg/dL', 'الجھن یا بے ترتیبی', 'پھل کی سی بو والی سانس', 'تیز سانس لینا', 'ہوش کا ضیاع']])}
|
| 504 |
|
| 505 |
-
|
| 506 |
"""
|
| 507 |
|
| 508 |
def _format_hypertension_response(self, language):
|
| 509 |
knowledge = self.medical_knowledge_base['hypertension']
|
| 510 |
if language == 'English':
|
| 511 |
return f"""
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
Regarding your blood pressure concerns, here's my medical assessment:
|
| 515 |
|
| 516 |
-
|
| 517 |
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 518 |
|
| 519 |
-
|
| 520 |
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 521 |
|
| 522 |
-
|
| 523 |
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 524 |
|
| 525 |
-
|
| 526 |
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 527 |
|
| 528 |
-
|
| 529 |
-
• Normal: <120
|
| 530 |
• Elevated: 120-129/<80 mmHg
|
| 531 |
-
• Stage 1
|
| 532 |
-
• Stage 2
|
| 533 |
-
• Hypertensive Crisis: >180/>120 mmHg
|
| 534 |
|
| 535 |
-
|
| 536 |
"""
|
| 537 |
else:
|
| 538 |
return f"""
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
بلڈ پریشر کے بارے میں آپ کی تشویش کے حوالے سے، یہ میری طبی تشخیص ہے:
|
| 542 |
|
| 543 |
-
|
| 544 |
{chr(10).join(['• ' + symptom for symptom in ['سر درد', 'چکر آنا', 'دھندلا نظر آنا', 'سانس لینے میں دشواری', 'سینے میں درد', 'ناک سے خون آنا']])}
|
| 545 |
|
| 546 |
-
|
| 547 |
{chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', '65 سال سے زیادہ عمر', 'موٹاپا', 'زیادہ نمک کا استعمال', 'تناؤ', 'شراب کا استعمال', 'سگریٹ نوشی']])}
|
| 548 |
|
| 549 |
-
|
| 550 |
{chr(10).join(['• ' + tip for tip in ['ڈیش ڈائٹ (کم سوڈیم)', 'باقاعدہ ایروبک ورزش', 'وزن کا انتظام', 'تناؤ میں کمی', 'شراب کو محدود کریں', 'سگریٹ نوشی سے پرہیز']])}
|
| 551 |
|
| 552 |
-
|
| 553 |
{chr(10).join(['• ' + sign for sign in ['شدید سر درد', 'سینے میں درد', 'سانس لینے میں دشواری', 'بینائی میں تبدیلی', 'الجھن', 'دورے']])}
|
| 554 |
|
| 555 |
-
|
| 556 |
"""
|
| 557 |
|
| 558 |
def _format_nutrition_response(self, language):
|
| 559 |
if language == 'English':
|
| 560 |
return """
|
| 561 |
-
|
| 562 |
|
| 563 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 564 |
|
| 565 |
-
|
| 566 |
-
•
|
| 567 |
-
•
|
| 568 |
-
•
|
| 569 |
-
• Maintain hydration (2-3 liters daily)
|
| 570 |
-
• Minimize processed foods and added sugars
|
| 571 |
|
| 572 |
-
|
| 573 |
-
• **Cardiac Health**: Mediterranean diet, omega-3 fatty acids
|
| 574 |
-
• **Diabetes**: Controlled carbohydrate intake, high fiber
|
| 575 |
-
• **Hypertension**: DASH diet (<2300mg sodium/day), potassium-rich foods
|
| 576 |
-
|
| 577 |
-
**Cultural Dietary Adaptations for Pakistan:**
|
| 578 |
• Choose whole wheat chapati over refined flour
|
| 579 |
-
•
|
| 580 |
-
•
|
| 581 |
-
• Limit ghee and
|
| 582 |
|
| 583 |
-
*
|
| 584 |
"""
|
| 585 |
else:
|
| 586 |
return """
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
آپ کی غذائی استفسار کی بنیاد پر، یہ ثبوت پر مبنی غذائی سفارشات ہیں:
|
| 590 |
|
| 591 |
-
|
| 592 |
• روزانہ 5-9 سرونگ پھل/سبزیاں کھائیں
|
| 593 |
-
• ریفائنڈ
|
| 594 |
-
• لیان پروٹین
|
| 595 |
-
•
|
| 596 |
-
• پراسیسڈ فوڈز اور
|
| 597 |
|
| 598 |
-
|
| 599 |
-
•
|
| 600 |
• **ذیابیطس**: کنٹرول کاربوہائیڈریٹ انٹیک، زیادہ فائبر
|
| 601 |
-
• **ہائی بلڈ پریشر**:
|
| 602 |
|
| 603 |
-
|
| 604 |
-
• ریفائنڈ آٹے
|
| 605 |
• دالوں اور پھلیوں کو باقاعدہ شامل کریں
|
| 606 |
-
• صحت مند ککنگ آئلز (کینولا،
|
| 607 |
-
• گھی اور
|
| 608 |
|
| 609 |
-
|
| 610 |
"""
|
| 611 |
|
| 612 |
def _format_exercise_response(self, language):
|
| 613 |
if language == 'English':
|
| 614 |
return """
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
•
|
| 621 |
-
•
|
| 622 |
-
•
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
**
|
| 627 |
-
• **
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
•
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
• Monitor for heat-related illness symptoms
|
| 636 |
-
|
| 637 |
-
*Exercise Physiology Note: Regular physical activity is potent medicine for chronic disease prevention and management.*
|
| 638 |
"""
|
| 639 |
else:
|
| 640 |
return """
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
جسمانی سرگرمی کے بارے میں، یہ میری ورزش کی نسخہ ہے:
|
| 644 |
|
| 645 |
-
|
| 646 |
-
• ہفتے میں 150 منٹ اعتدال پسند
|
| 647 |
-
• ہفتے میں 2
|
| 648 |
-
•
|
| 649 |
-
• لچک
|
| 650 |
-
•
|
| 651 |
|
| 652 |
-
|
| 653 |
-
•
|
| 654 |
-
•
|
| 655 |
-
• **ہائی بلڈ
|
| 656 |
|
| 657 |
-
|
| 658 |
• ٹھنڈے صبح/شام کے اوقات میں ورزش کریں
|
| 659 |
-
•
|
| 660 |
-
•
|
| 661 |
-
• گرمی سے متعلق بیماری کی علامات کی نگرانی کریں
|
| 662 |
|
| 663 |
-
|
| 664 |
"""
|
| 665 |
|
| 666 |
def _format_symptoms_response(self, language):
|
| 667 |
if language == 'English':
|
| 668 |
return """
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
•
|
| 675 |
-
•
|
| 676 |
-
•
|
| 677 |
-
•
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
•
|
| 683 |
-
•
|
| 684 |
-
•
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
• Seizure activity
|
| 688 |
-
|
| 689 |
-
**Clinical Assessment Protocol:**
|
| 690 |
-
• Comprehensive history taking
|
| 691 |
-
• Vital signs assessment
|
| 692 |
-
• Systematic physical examination
|
| 693 |
-
• Appropriate diagnostic testing
|
| 694 |
-
• Specialist referral when indicated
|
| 695 |
-
|
| 696 |
-
*Medical Note: Symptom assessment requires professional medical evaluation for accurate diagnosis and treatment.*
|
| 697 |
"""
|
| 698 |
else:
|
| 699 |
return """
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
•
|
| 706 |
-
•
|
| 707 |
-
•
|
| 708 |
-
•
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
• شدید
|
| 714 |
-
•
|
| 715 |
-
•
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
• دورے کی سرگرمی
|
| 719 |
-
|
| 720 |
-
**کلینیکل تشخیص پروٹوکول:**
|
| 721 |
-
• جامع تاریخ لینا
|
| 722 |
-
• اہم علامات کی تشخیص
|
| 723 |
-
• نظامی جسمانی معائنہ
|
| 724 |
-
• مناسب تشخیصی ٹیسٹنگ
|
| 725 |
-
• اشارہ کردہ ہو تو ماہر کی رجوع
|
| 726 |
-
|
| 727 |
-
*طبی نوٹ: علامات کی تشخیص کے لیے درست تشخیص اور علاج کے لیے پیشہ ورانہ طبی تشخیص کی ضرورت ہوتی ہے۔*
|
| 728 |
"""
|
| 729 |
|
| 730 |
def _format_medication_response(self, language):
|
| 731 |
if language == 'English':
|
| 732 |
return """
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
•
|
| 739 |
-
•
|
| 740 |
-
•
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
•
|
| 746 |
-
•
|
| 747 |
-
•
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
**Medication Management Principles:**
|
| 752 |
-
• Regular medication reconciliation
|
| 753 |
-
• Adherence assessment at each visit
|
| 754 |
-
• Monitoring for drug interactions
|
| 755 |
-
• Appropriate storage and disposal
|
| 756 |
-
• Understanding administration techniques
|
| 757 |
-
|
| 758 |
-
*Pharmacology Note: Medication management requires ongoing professional supervision for optimal therapeutic outcomes.*
|
| 759 |
"""
|
| 760 |
else:
|
| 761 |
return """
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
•
|
| 768 |
-
•
|
| 769 |
-
•
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
•
|
| 775 |
-
•
|
| 776 |
-
•
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
**دوائیوں کے انتظام کے اصول:**
|
| 781 |
-
• باقاعدہ دوائیوں کی مطابقت پذیری
|
| 782 |
-
• ہر وزٹ پر پابندی کی تشخیص
|
| 783 |
-
• دوائیوں کے تعاملات کی نگرانی
|
| 784 |
-
• مناسب اسٹوریج اور ضائع
|
| 785 |
-
• انتظامیہ کی تکنیکوں کو سمجھنا
|
| 786 |
-
|
| 787 |
-
*فارماکالوجی نوٹ: دوائیوں کے انتظام کے لیے بہترین علاج کے نتائج کے لیے مسلسل پیشہ ورانہ نگرانی کی ضرورت ہوتی ہے۔*
|
| 788 |
"""
|
| 789 |
|
| 790 |
def _format_emergency_response(self, language):
|
| 791 |
if language == 'English':
|
| 792 |
return """
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
•
|
| 799 |
-
•
|
| 800 |
-
•
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
•
|
| 806 |
-
•
|
| 807 |
-
•
|
| 808 |
-
•
|
| 809 |
-
•
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
**Pre-Hospital Management:**
|
| 814 |
-
• Ensure scene safety
|
| 815 |
-
• Basic life support if trained
|
| 816 |
-
• Continuous monitoring of vital signs
|
| 817 |
-
• Preparation for EMS arrival
|
| 818 |
-
• Documentation of event timeline
|
| 819 |
-
|
| 820 |
-
**⚠️ CRITICAL: This constitutes emergency medical guidance only. Seek immediate professional medical evaluation.**
|
| 821 |
"""
|
| 822 |
else:
|
| 823 |
return """
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
•
|
| 830 |
-
•
|
| 831 |
-
•
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
• شدید
|
| 837 |
-
•
|
| 838 |
-
•
|
| 839 |
-
•
|
| 840 |
-
•
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
**ہسپتال سے پہلے کے انتظام:**
|
| 845 |
-
• منظر کی حفاظت کو یقینی بنائیں
|
| 846 |
-
• اگر تربیت یافتہ ہوں تو بنیادی زندگی کی حمایت
|
| 847 |
-
• اہم علامات کی مسلسل نگرانی
|
| 848 |
-
• EMS کی آمد کی تیاری
|
| 849 |
-
• واقعہ کی ٹائم لائن کی دستاویزات
|
| 850 |
-
|
| 851 |
-
**⚠️ اہم: یہ صرف ہنگامی طبی رہنمائی پر مشتمل ہے۔ فوری پیشہ ورانہ طبی تشخیص حاصل کریں۔**
|
| 852 |
"""
|
| 853 |
|
| 854 |
def _format_general_health_response(self, language):
|
| 855 |
if language == 'English':
|
| 856 |
return """
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
•
|
| 863 |
-
•
|
| 864 |
-
•
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
•
|
| 870 |
-
•
|
| 871 |
-
•
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
•
|
| 877 |
-
•
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
*Preventive Medicine Insight: Sustainable health improvements result from consistent lifestyle modifications and regular preventive care.*
|
| 882 |
"""
|
| 883 |
else:
|
| 884 |
return """
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
•
|
| 891 |
-
•
|
| 892 |
-
•
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
•
|
| 898 |
-
•
|
| 899 |
-
•
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
•
|
| 905 |
-
•
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
return self._get_rule_based_response(user_input, language)
|
| 287 |
|
| 288 |
def _get_groq_response(self, user_input, language):
|
| 289 |
+
system_prompt = """You are SehatAI, a professional healthcare assistant designed for Pakistani patients.
|
| 290 |
+
Provide accurate, culturally appropriate medical advice in a compassionate manner.
|
| 291 |
+
Focus on preventive care, symptom explanation, and when to seek medical attention.
|
| 292 |
+
Always emphasize that you are an AI assistant and recommend consulting healthcare professionals for serious conditions.
|
| 293 |
+
Be specific, practical, and provide actionable advice.
|
| 294 |
|
| 295 |
+
IMPORTANT: Provide detailed, specific answers directly related to the user's query.
|
| 296 |
+
Do not give generic responses - tailor your answer specifically to what the user is asking.
|
| 297 |
+
If they ask about specific symptoms, conditions, or treatments, provide comprehensive information about that topic.
|
| 298 |
+
Use your medical knowledge to give practical, actionable advice."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
if language == 'Urdu':
|
| 301 |
+
system_prompt += " Respond in Urdu with proper medical terminology and cultural sensitivity. Provide detailed, specific answers in Urdu."
|
| 302 |
else:
|
| 303 |
+
system_prompt += " Respond in English with clear, professional medical advice. Provide detailed, specific answers in English."
|
| 304 |
|
| 305 |
messages = [
|
| 306 |
{"role": "system", "content": system_prompt},
|
|
|
|
| 327 |
def _get_rule_based_response(self, user_input, language):
|
| 328 |
user_input = user_input.lower().strip()
|
| 329 |
|
| 330 |
+
# Greeting patterns
|
| 331 |
+
if any(word in user_input for word in ['hello', 'hi', 'hey', 'salam', 'السلام علیکم']):
|
| 332 |
+
return self._format_greeting_response(language)
|
| 333 |
+
|
| 334 |
# Heart disease related queries
|
| 335 |
if any(word in user_input for word in ['heart', 'cardiac', 'chest pain', 'cholesterol', 'دل', 'سینے میں درد']):
|
| 336 |
return self._format_heart_response(language)
|
|
|
|
| 367 |
elif any(word in user_input for word in ['health', 'wellness', 'prevention', 'صحت', 'تندرستی']):
|
| 368 |
return self._format_general_health_response(language)
|
| 369 |
|
| 370 |
+
# Default response for unknown queries
|
| 371 |
else:
|
| 372 |
+
return self._format_default_response(language)
|
| 373 |
|
| 374 |
+
def _format_greeting_response(self, language):
|
|
|
|
| 375 |
if language == 'English':
|
| 376 |
+
return """
|
| 377 |
+
**🤖 Welcome to SehatAI Health Assistant!**
|
|
|
|
|
|
|
| 378 |
|
| 379 |
+
I'm here to help you with:
|
| 380 |
+
• Heart health and cardiovascular diseases
|
| 381 |
+
• Diabetes and blood sugar management
|
| 382 |
+
• Blood pressure and hypertension
|
| 383 |
+
• Nutrition and diet advice
|
| 384 |
+
• Exercise and fitness guidance
|
| 385 |
+
• Symptom assessment
|
| 386 |
+
• General health and wellness
|
| 387 |
|
| 388 |
+
Please ask me specific health-related questions, and I'll provide detailed, helpful information.
|
| 389 |
|
| 390 |
*Note: I'm an AI assistant. For serious medical concerns, always consult a qualified healthcare professional.*
|
| 391 |
"""
|
| 392 |
else:
|
| 393 |
+
return """
|
| 394 |
+
**🤖 سیحت اے آئی ہیلتھ اسسٹنٹ میں خوش آمدید!**
|
|
|
|
|
|
|
| 395 |
|
| 396 |
+
میں آپ کی مدد کے لیے یہاں ہوں:
|
| 397 |
+
• دل کی صحت اور قلبی امراض
|
| 398 |
+
• ذیابیطس اور بلڈ شوگر مینجمنٹ
|
| 399 |
+
• بلڈ پریشر اور ہائی بلڈ پریشر
|
| 400 |
+
• غذائیت اور غذا کے مشورے
|
| 401 |
+
• ورزش اور فٹنس گائیڈنس
|
| 402 |
+
• علامات کی تشخیص
|
| 403 |
+
• عام صحت اور تندرستی
|
| 404 |
|
| 405 |
+
براہ کرم مجھ سے مخصوص صحت سے متعلق سوالات پوچھیں، اور میں تفصیلی، مددگار معلومات فراہم کروں گا۔
|
| 406 |
|
| 407 |
*نوٹ: میں ایک AI اسسٹنٹ ہوں۔ سنگین طبی مسائل کے لیے، ہمیشہ کوالیفائیڈ ہیلتھ کیئر پروفیشنل سے مشورہ کریں۔*
|
| 408 |
"""
|
|
|
|
| 411 |
knowledge = self.medical_knowledge_base['heart_disease']
|
| 412 |
if language == 'English':
|
| 413 |
return f"""
|
| 414 |
+
**❤️ Comprehensive Heart Health Information**
|
| 415 |
|
| 416 |
+
**🚨 Common Symptoms:**
|
|
|
|
|
|
|
| 417 |
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 418 |
|
| 419 |
+
**⚠️ Risk Factors:**
|
| 420 |
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 421 |
|
| 422 |
+
**🛡️ Prevention Strategies:**
|
| 423 |
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 424 |
|
| 425 |
+
**🚑 Emergency Warning Signs (Seek Immediate Care):**
|
| 426 |
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 427 |
|
| 428 |
+
**📊 Recommended Monitoring:**
|
| 429 |
+
• Regular blood pressure checks
|
| 430 |
+
• Cholesterol levels annually if high risk
|
| 431 |
+
• ECG if symptoms present
|
| 432 |
+
• Stress test if recommended by doctor
|
| 433 |
|
| 434 |
+
*🔬 Clinical Note: Early detection saves lives. Regular check-ups are crucial for heart health.*
|
| 435 |
"""
|
| 436 |
else:
|
| 437 |
return f"""
|
| 438 |
+
**❤️ دل کی صحت کی جامع معلومات**
|
|
|
|
|
|
|
| 439 |
|
| 440 |
+
**🚨 عام علامات:**
|
| 441 |
{chr(10).join(['• ' + symptom for symptom in ['سینے میں درد یا بے چینی', 'سانس لینے میں دشواری', 'بازوؤں، گردن، جبڑے میں درد', 'متلی', 'تھکاوٹ', 'چکر آنا']])}
|
| 442 |
|
| 443 |
+
**⚠️ خطرے کے عوامل:**
|
| 444 |
{chr(10).join(['• ' + factor for factor in ['ہائی بلڈ پریشر', 'ہائی کولیسٹرول', 'سگریٹ نوشی', 'ذیابیطس', 'موٹاپا', 'خاندانی تاریخ', 'جسمانی غیر فعالیت']])}
|
| 445 |
|
| 446 |
+
**🛡️ بچاؤ کی حکمت عملی:**
|
| 447 |
{chr(10).join(['• ' + tip for tip in ['سیر شدہ چکنائی سے پاک صحت مند غذا', 'روزانہ 30 منٹ باقاعدہ ورزش', 'سگریٹ نوشی سے پرہیز', 'وزن کا انتظام', 'تنا�� کا انتظام', 'باقاعدہ چیک اپ']])}
|
| 448 |
|
| 449 |
+
**🚑 ہنگامی انتباہی علامات (فوری علاج حاصل کریں):**
|
| 450 |
{chr(10).join(['• ' + sign for sign in ['شدید سینے میں درد', 'سانس لینے میں شدید دشواری', 'بیہوش ہونا', 'تیز دل کی دھڑکن', 'بازو/کندھوں میں پھیلنے والا درد']])}
|
| 451 |
|
| 452 |
+
*🔬 کلینیکل نوٹ: ابتدائی تشخیص جان بچاتی ہے۔ دل کی صحت کے لیے باقاعدہ چیک اپ بہت ضروری ہیں۔*
|
| 453 |
"""
|
| 454 |
|
| 455 |
def _format_diabetes_response(self, language):
|
| 456 |
knowledge = self.medical_knowledge_base['diabetes']
|
| 457 |
if language == 'English':
|
| 458 |
return f"""
|
| 459 |
+
**🩺 Comprehensive Diabetes Information**
|
|
|
|
|
|
|
| 460 |
|
| 461 |
+
**🚨 Common Symptoms:**
|
| 462 |
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 463 |
|
| 464 |
+
**⚠️ Risk Factors:**
|
| 465 |
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 466 |
|
| 467 |
+
**🛡️ Prevention & Management:**
|
| 468 |
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 469 |
|
| 470 |
+
**🚑 Emergency Signs (Seek Immediate Care):**
|
| 471 |
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 472 |
|
| 473 |
+
**📊 Monitoring Guidelines:**
|
| 474 |
+
• Fasting blood sugar: 80-130 mg/dL
|
| 475 |
+
• Post-meal blood sugar: <180 mg/dL
|
| 476 |
+
• HbA1c: <7.0% (quarterly if uncontrolled)
|
| 477 |
+
• Regular foot and eye examinations
|
|
|
|
| 478 |
|
| 479 |
+
*🔬 Clinical Note: Consistent monitoring and lifestyle management are key to diabetes control.*
|
| 480 |
"""
|
| 481 |
else:
|
| 482 |
return f"""
|
| 483 |
+
**🩺 ذیابیطس کی جامع معلومات**
|
| 484 |
|
| 485 |
+
**🚨 عام علامات:**
|
|
|
|
|
|
|
| 486 |
{chr(10).join(['• ' + symptom for symptom in ['زیادہ پیاس اور بھوک لگنا', 'بار بار پیشاب آنا', 'تھکاوٹ', 'دھندلا نظر آنا', 'زخموں کا دیر سے بھرنا', 'بے وجہ وزن میں کمی']])}
|
| 487 |
|
| 488 |
+
**⚠️ خطرے کے عوامل:**
|
| 489 |
{chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', 'وزن زیادہ ہونا (BMI > 25)', 'ہائی بلڈ پریشر', 'جسمانی غیر فعالیت', '45 سال سے زیادہ عمر', 'حمل کی ذیابیطس کی تاریخ']])}
|
| 490 |
|
| 491 |
+
**🛡️ بچاؤ اور انتظام:**
|
| 492 |
{chr(10).join(['• ' + tip for tip in ['کنٹرول کاربوہائیڈریٹ کے ساتھ متوازن غذا', 'باقاعدہ جسمانی سرگرمی', 'وزن کا انتظام', 'بلڈ شوگر مانیٹرنگ', 'باقاعدہ صحت کی اسکریننگ']])}
|
| 493 |
|
| 494 |
+
**🚑 ہنگامی علامات (فوری علاج حاصل کریں):**
|
| 495 |
{chr(10).join(['• ' + sign for sign in ['بلڈ شوگر >300 mg/dL یا <70 mg/dL', 'الجھن یا بے ترتیبی', 'پھل کی سی بو والی سانس', 'تیز سانس لینا', 'ہوش کا ضیاع']])}
|
| 496 |
|
| 497 |
+
*🔬 کلینیکل نوٹ: مستقل نگرانی اور طرز زندگی کا انتظام ذیابیطس کے کنٹرول کی کلید ہے۔*
|
| 498 |
"""
|
| 499 |
|
| 500 |
def _format_hypertension_response(self, language):
|
| 501 |
knowledge = self.medical_knowledge_base['hypertension']
|
| 502 |
if language == 'English':
|
| 503 |
return f"""
|
| 504 |
+
**💓 Comprehensive Blood Pressure Information**
|
|
|
|
|
|
|
| 505 |
|
| 506 |
+
**🚨 Common Symptoms:**
|
| 507 |
{chr(10).join(['• ' + symptom for symptom in knowledge['symptoms']])}
|
| 508 |
|
| 509 |
+
**⚠️ Risk Factors:**
|
| 510 |
{chr(10).join(['• ' + factor for factor in knowledge['risk_factors']])}
|
| 511 |
|
| 512 |
+
**🛡️ Prevention & Control:**
|
| 513 |
{chr(10).join(['• ' + tip for tip in knowledge['prevention']])}
|
| 514 |
|
| 515 |
+
**🚑 Hypertensive Emergency Signs:**
|
| 516 |
{chr(10).join(['• ' + sign for sign in knowledge['emergency_signs']])}
|
| 517 |
|
| 518 |
+
**📊 Blood Pressure Classification:**
|
| 519 |
+
• Normal: <120/80 mmHg
|
| 520 |
• Elevated: 120-129/<80 mmHg
|
| 521 |
+
• Stage 1 Hypertension: 130-139/80-89 mmHg
|
| 522 |
+
• Stage 2 Hypertension: ≥140/90 mmHg
|
|
|
|
| 523 |
|
| 524 |
+
*🔬 Clinical Note: Silent killer - often no symptoms. Regular monitoring is essential.*
|
| 525 |
"""
|
| 526 |
else:
|
| 527 |
return f"""
|
| 528 |
+
**💓 بلڈ پریشر کی جامع معلومات**
|
|
|
|
|
|
|
| 529 |
|
| 530 |
+
**🚨 عام علامات:**
|
| 531 |
{chr(10).join(['• ' + symptom for symptom in ['سر درد', 'چکر آنا', 'دھندلا نظر آنا', 'سانس لینے میں دشواری', 'سینے میں درد', 'ناک سے خون آنا']])}
|
| 532 |
|
| 533 |
+
**⚠️ خطرے کے عوامل:**
|
| 534 |
{chr(10).join(['• ' + factor for factor in ['خاندانی تاریخ', '65 سال سے زیادہ عمر', 'موٹاپا', 'زیادہ نمک کا استعمال', 'تناؤ', 'شراب کا استعمال', 'سگریٹ نوشی']])}
|
| 535 |
|
| 536 |
+
**🛡️ بچاؤ اور کنٹرول:**
|
| 537 |
{chr(10).join(['• ' + tip for tip in ['ڈیش ڈائٹ (کم سوڈیم)', 'باقاعدہ ایروبک ورزش', 'وزن کا انتظام', 'تناؤ میں کمی', 'شراب کو محدود کریں', 'سگریٹ نوشی سے پرہیز']])}
|
| 538 |
|
| 539 |
+
**🚑 ہائی بلڈ پریشر کی ہنگامی علامات:**
|
| 540 |
{chr(10).join(['• ' + sign for sign in ['شدید سر درد', 'سینے میں درد', 'سانس لینے میں دشواری', 'بینائی میں تبدیلی', 'الجھن', 'دورے']])}
|
| 541 |
|
| 542 |
+
*🔬 کلینیکل نوٹ: خاموش قاتل - اکثر کوئی علامات نہیں ہوتیں۔ باقاعدہ نگرانی ضروری ہے۔*
|
| 543 |
"""
|
| 544 |
|
| 545 |
def _format_nutrition_response(self, language):
|
| 546 |
if language == 'English':
|
| 547 |
return """
|
| 548 |
+
**🍎 Comprehensive Nutrition Guide**
|
| 549 |
|
| 550 |
+
**🥦 Healthy Eating Principles:**
|
| 551 |
+
• Eat 5-9 servings of fruits/vegetables daily
|
| 552 |
+
• Choose whole grains over refined
|
| 553 |
+
• Include lean proteins
|
| 554 |
+
• Stay hydrated (8-10 glasses water)
|
| 555 |
+
• Limit processed foods and sugar
|
| 556 |
|
| 557 |
+
**🎯 Specific Recommendations:**
|
| 558 |
+
• **Heart Health**: Mediterranean diet, omega-3 rich foods
|
| 559 |
+
• **Diabetes**: Controlled carb intake, high fiber
|
| 560 |
+
• **Hypertension**: Low sodium (<2300mg/day), potassium-rich foods
|
|
|
|
|
|
|
| 561 |
|
| 562 |
+
**💡 Pakistani Dietary Adaptations:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
• Choose whole wheat chapati over refined flour
|
| 564 |
+
• Include lentils (daal) and legumes regularly
|
| 565 |
+
• Use healthy cooking oils (canola, olive)
|
| 566 |
+
• Limit ghee and butter usage
|
| 567 |
|
| 568 |
+
*Remember: Balanced nutrition is foundation of good health.*
|
| 569 |
"""
|
| 570 |
else:
|
| 571 |
return """
|
| 572 |
+
**🍎 غذائیت کی جامع گائیڈ**
|
|
|
|
|
|
|
| 573 |
|
| 574 |
+
**🥦 صحت مند کھانے کے اصول:**
|
| 575 |
• روزانہ 5-9 سرونگ پھل/سبزیاں کھائیں
|
| 576 |
+
• ریفائنڈ کی بجائے سارا اناج منتخب کریں
|
| 577 |
+
• لیان پروٹین شامل کریں
|
| 578 |
+
• ہائیڈریٹ رہیں (8-10 گلاس پانی)
|
| 579 |
+
• پراسیسڈ فوڈز اور چینی کو محدود کریں
|
| 580 |
|
| 581 |
+
**🎯 مخصوص سفارشات:**
|
| 582 |
+
• **دل کی صحت**: بحیرہ روم کی غذا، اومیگا 3 سے بھرپور غذائیں
|
| 583 |
• **ذیابیطس**: کنٹرول کاربوہائیڈریٹ انٹیک، زیادہ فائبر
|
| 584 |
+
• **ہائی بلڈ پریشر**: کم سوڈیم (<2300mg/day)، پوٹاشیم سے بھرپور غذائیں
|
| 585 |
|
| 586 |
+
**💡 پاکستانی غذائی موافقت:**
|
| 587 |
+
• ریفائنڈ آٹے کی بجائے whole wheat چپاتی منتخب کریں
|
| 588 |
• دالوں اور پھلیوں کو باقاعدہ شامل کریں
|
| 589 |
+
• صحت مند ککنگ آئلز (کینولا، زیتون) استعمال کریں
|
| 590 |
+
• گھی اور مکھن کے استعمال کو محدود کریں
|
| 591 |
|
| 592 |
+
*یاد رکھیں: متوازن غذائیت اچھی صحت کی بنیاد ہے۔*
|
| 593 |
"""
|
| 594 |
|
| 595 |
def _format_exercise_response(self, language):
|
| 596 |
if language == 'English':
|
| 597 |
return """
|
| 598 |
+
**💪 Comprehensive Exercise Guide**
|
| 599 |
+
|
| 600 |
+
**🏃♂️ Exercise Recommendations:**
|
| 601 |
+
• 150 mins moderate exercise weekly
|
| 602 |
+
• Strength training 2x weekly
|
| 603 |
+
• Stay active throughout day
|
| 604 |
+
• Include flexibility exercises
|
| 605 |
+
• Get adequate rest between workouts
|
| 606 |
+
|
| 607 |
+
**🎯 Disease-Specific Exercise:**
|
| 608 |
+
• **Heart Health**: 30 mins moderate cardio daily
|
| 609 |
+
• **Diabetes**: Combination of cardio and strength training
|
| 610 |
+
• **Hypertension**: Regular aerobic exercise
|
| 611 |
+
|
| 612 |
+
**🌞 Pakistani Climate Considerations:**
|
| 613 |
+
• Exercise in cooler morning/evening hours
|
| 614 |
+
• Stay hydrated with water and electrolytes
|
| 615 |
+
• Wear light, breathable clothing
|
| 616 |
+
|
| 617 |
+
*Important: Consult doctor before starting new exercise program.*
|
|
|
|
|
|
|
|
|
|
| 618 |
"""
|
| 619 |
else:
|
| 620 |
return """
|
| 621 |
+
**💪 ورزش کی جامع گائیڈ**
|
|
|
|
|
|
|
| 622 |
|
| 623 |
+
**🏃♂️ ورزش کی سفارشات:**
|
| 624 |
+
• ہفتے میں 150 منٹ اعتدال پسند ورزش
|
| 625 |
+
• ہفتے میں 2 بار طاقت کی تربیت
|
| 626 |
+
• پورے دن متحرک رہیں
|
| 627 |
+
• لچک کی ورزشیں شامل کریں
|
| 628 |
+
• ورک آؤٹس کے درمیان مناسب آرام حاصل کریں
|
| 629 |
|
| 630 |
+
**🎯 بیماری کی مخصوص ورزش:**
|
| 631 |
+
• **دل کی صحت**: روزانہ 30 منٹ اعتدال پسند کارڈیو
|
| 632 |
+
• **ذیابیطس**: کارڈیو اور طاقت کی تربیت کا مجموعہ
|
| 633 |
+
• **ہائی بلڈ پریشر**: باقاعدہ ایروبک ورزش
|
| 634 |
|
| 635 |
+
**🌞 پاکستانی آب و ہوا کے تحفظات:**
|
| 636 |
• ٹھنڈے صبح/شام کے اوقات میں ورزش کریں
|
| 637 |
+
• پانی اور الیکٹرولائٹس کے ساتھ ہائیڈریٹ رہیں
|
| 638 |
+
• ہلکے، ہوا دار کپڑے پہنیں
|
|
|
|
| 639 |
|
| 640 |
+
*اہم: نئی ورزش پروگرام شروع کرنے سے پہلے ڈاکٹر سے مشورہ کریں۔*
|
| 641 |
"""
|
| 642 |
|
| 643 |
def _format_symptoms_response(self, language):
|
| 644 |
if language == 'English':
|
| 645 |
return """
|
| 646 |
+
**🔍 Symptom Assessment Guidance**
|
| 647 |
+
|
| 648 |
+
**🩺 When to Seek Medical Care:**
|
| 649 |
+
• Persistent fever above 103°F (39.4°C)
|
| 650 |
+
• Difficulty breathing or chest pain
|
| 651 |
+
• Severe abdominal pain
|
| 652 |
+
• Sudden dizziness, weakness, or confusion
|
| 653 |
+
• Unexplained weight loss (>10% body weight)
|
| 654 |
+
• Symptoms lasting more than 2 weeks
|
| 655 |
+
|
| 656 |
+
**🚨 Emergency Warning Signs (Go to ER):**
|
| 657 |
+
• Difficulty breathing or shortness of breath
|
| 658 |
+
• Chest pain or pressure lasting >5 minutes
|
| 659 |
+
• Severe bleeding that doesn't stop
|
| 660 |
+
• Sudden severe pain anywhere in body
|
| 661 |
+
• Loss of consciousness or fainting
|
| 662 |
+
|
| 663 |
+
*⚠️ Important: This is general guidance. Always consult healthcare professional for proper diagnosis.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
"""
|
| 665 |
else:
|
| 666 |
return """
|
| 667 |
+
**🔍 علامات کی تشخیص کی رہنمائی**
|
| 668 |
+
|
| 669 |
+
**🩺 طبی دیکھ بھال کب حاصل کریں:**
|
| 670 |
+
• 103°F (39.4°C) سے اوپر مستقل بخار
|
| 671 |
+
• سانس لینے میں دشواری یا سینے میں درد
|
| 672 |
+
• شدید پیٹ کا درد
|
| 673 |
+
• اچانک چکر آنا، کمزوری، یا الجھن
|
| 674 |
+
• بے وجہ وزن میں کمی (>10% جسمانی وزن)
|
| 675 |
+
• 2 ہفتے سے زیادہ علامات برقرار رہنا
|
| 676 |
+
|
| 677 |
+
**🚨 ہنگامی انتباہی علامات (ایمرجنسی روم جائیں):**
|
| 678 |
+
• سانس لینے میں دشواری یا سانس کی قلت
|
| 679 |
+
• 5 منٹ سے زیادہ سینے میں درد یا دباؤ
|
| 680 |
+
• شدید خون بہنا جو رک نہیں رہا
|
| 681 |
+
• جسم میں کہیں بھی اچانک شدید درد
|
| 682 |
+
• ہوش کا ضیاع یا بیہوشی
|
| 683 |
+
|
| 684 |
+
*⚠️ اہم: یہ عام رہنمائی ہے۔ مناسب تشخیص کے لیے ہمیشہ ہیلتھ کیئر پروفیشنل سے مشورہ کریں۔*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
"""
|
| 686 |
|
| 687 |
def _format_medication_response(self, language):
|
| 688 |
if language == 'English':
|
| 689 |
return """
|
| 690 |
+
**💊 Medication Safety & Information**
|
| 691 |
+
|
| 692 |
+
**📋 General Medication Guidelines:**
|
| 693 |
+
• Take medications exactly as prescribed
|
| 694 |
+
• Never share prescriptions with others
|
| 695 |
+
• Keep updated medication list with you
|
| 696 |
+
• Inform all doctors about all medications
|
| 697 |
+
• Understand purpose and side effects of each medicine
|
| 698 |
+
|
| 699 |
+
**🚨 Medication Warning Signs:**
|
| 700 |
+
• Severe allergic reactions (rash, swelling)
|
| 701 |
+
• Difficulty breathing after taking medicine
|
| 702 |
+
• Severe stomach pain or vomiting
|
| 703 |
+
• Unusual bleeding or bruising
|
| 704 |
+
• Confusion or hallucinations
|
| 705 |
+
|
| 706 |
+
*Note: Always follow your healthcare provider's specific instructions.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
"""
|
| 708 |
else:
|
| 709 |
return """
|
| 710 |
+
**💊 دوائیوں کی حفاظت اور معلومات**
|
| 711 |
+
|
| 712 |
+
**📋 عام دوائیوں کے رہنما اصول:**
|
| 713 |
+
• دوائیں بالکل تجویز کردہ طریقے سے لیں
|
| 714 |
+
• کبھی بھی دوسروں کے ساتھ نسخے شیئر نہ کریں
|
| 715 |
+
• اپنے ساتھ اپ ڈیٹ شدہ دوائیوں کی فہرست رکھیں
|
| 716 |
+
• تمام ڈاکٹروں کو تمام دوائیوں کے بارے میں بتائیں
|
| 717 |
+
• ہر دوا کے مقصد اور مضر اثرات کو سمجھیں
|
| 718 |
+
|
| 719 |
+
**🚨 دوائیوں کی انتباہی علامات:**
|
| 720 |
+
• شدید الرجک رد عمل (خارش، سوجن)
|
| 721 |
+
• دوا لینے کے بعد سانس لینے میں دشواری
|
| 722 |
+
• شدید پیٹ میں درد یا الٹی
|
| 723 |
+
• غیر معمولی خون بہنا یا چوٹ لگنا
|
| 724 |
+
• الجھن یا توہمات
|
| 725 |
+
|
| 726 |
+
*نوٹ: ہمیشہ اپنے ہیلتھ کیئر فراہم کرنے والے کی مخصوص ہدایات پر عمل کریں۔*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 727 |
"""
|
| 728 |
|
| 729 |
def _format_emergency_response(self, language):
|
| 730 |
if language == 'English':
|
| 731 |
return """
|
| 732 |
+
**🚨 EMERGENCY MEDICAL GUIDANCE**
|
| 733 |
+
|
| 734 |
+
**📞 Immediate Actions Required:**
|
| 735 |
+
• Call emergency services (1122 in Pakistan)
|
| 736 |
+
• Don't drive yourself to hospital
|
| 737 |
+
• Keep patient calm and comfortable
|
| 738 |
+
• Have medical information ready
|
| 739 |
+
• Don't give food or drink
|
| 740 |
+
|
| 741 |
+
**🏥 When to Go to Emergency Room:**
|
| 742 |
+
• Chest pain or pressure
|
| 743 |
+
• Difficulty breathing
|
| 744 |
+
• Severe bleeding
|
| 745 |
+
• Sudden weakness or paralysis
|
| 746 |
+
• Severe burns
|
| 747 |
+
• Poisoning or overdose
|
| 748 |
+
• Seizures
|
| 749 |
+
|
| 750 |
+
*⚠️ THIS IS EMERGENCY GUIDANCE ONLY. SEEK PROFESSIONAL MEDICAL HELP IMMEDIATELY.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 751 |
"""
|
| 752 |
else:
|
| 753 |
return """
|
| 754 |
+
**🚨 ہنگامی طبی رہنمائی**
|
| 755 |
+
|
| 756 |
+
**📞 فوری کارروائی کی ضرورت ہے:**
|
| 757 |
+
• ہنگامی خدمات کو کال کریں (پاکستان میں 1122)
|
| 758 |
+
• خود ہسپتال نہ جائیں
|
| 759 |
+
• مریض کو پرسکون اور آرام دہ رکھیں
|
| 760 |
+
• طبی معلومات تیار رکھیں
|
| 761 |
+
• کھانا یا پانی نہ دیں
|
| 762 |
+
|
| 763 |
+
**🏥 ایمرجنسی روم کب جائیں:**
|
| 764 |
+
• سینے میں درد یا دباؤ
|
| 765 |
+
• سانس لینے میں دشواری
|
| 766 |
+
• شدید خون بہنا
|
| 767 |
+
• اچانک کمزوری یا فالج
|
| 768 |
+
• شدید جلنے
|
| 769 |
+
• زہر یا اوور ڈوز
|
| 770 |
+
• دورے
|
| 771 |
+
|
| 772 |
+
*⚠️ یہ صرف ہنگامی رہنمائی ہے۔ فوری طور پر پیشہ ورانہ طبی مدد حاصل کریں۔*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 773 |
"""
|
| 774 |
|
| 775 |
def _format_general_health_response(self, language):
|
| 776 |
if language == 'English':
|
| 777 |
return """
|
| 778 |
+
**🌿 Comprehensive Health & Wellness Guide**
|
| 779 |
+
|
| 780 |
+
**💚 Lifestyle Recommendations:**
|
| 781 |
+
• 7-9 hours quality sleep nightly
|
| 782 |
+
• Stress management techniques
|
| 783 |
+
• No smoking
|
| 784 |
+
• Limit alcohol to 1-2 drinks/day
|
| 785 |
+
• Regular health check-ups
|
| 786 |
+
|
| 787 |
+
**🛡️ Preventive Healthcare:**
|
| 788 |
+
• Annual physical exams
|
| 789 |
+
• Vaccinations up to date
|
| 790 |
+
• Regular hand washing
|
| 791 |
+
• Sun protection
|
| 792 |
+
• Mental health care
|
| 793 |
+
|
| 794 |
+
**🌟 Healthy Habits for Pakistan:**
|
| 795 |
+
• Drink filtered/boiled water
|
| 796 |
+
• Eat fresh, locally available fruits and vegetables
|
| 797 |
+
• Practice good food hygiene
|
| 798 |
+
• Get adequate sunlight exposure (vitamin D)
|
| 799 |
+
|
| 800 |
+
*Remember: Small consistent changes lead to lasting health improvements!*
|
|
|
|
|
|
|
| 801 |
"""
|
| 802 |
else:
|
| 803 |
return """
|
| 804 |
+
**🌿 صحت اور تندرستی کی جامع گائیڈ**
|
| 805 |
+
|
| 806 |
+
**💚 طرز زندگی کی سفارشات:**
|
| 807 |
+
• رات میں 7-9 گھنٹے معیاری نیند
|
| 808 |
+
• تناؤ کے انتظام کی تکنیکیں
|
| 809 |
+
• سگریٹ نوشی سے پرہیز
|
| 810 |
+
• شراب کو 1-2 ڈرنکس/دن تک محدود کریں
|
| 811 |
+
• باقاعدہ صحت کی جانچ
|
| 812 |
+
|
| 813 |
+
**🛡️ احتیاطی ہیلتھ کیئر:**
|
| 814 |
+
• سالانہ جسمانی امتحانات
|
| 815 |
+
• ویکسینیشن اپ ڈیٹ
|
| 816 |
+
• باقاعدہ ہاتھ دھونا
|
| 817 |
+
• سورج سے تحفظ
|
| 818 |
+
• ذہنی صحت کی دیکھ بھال
|
| 819 |
+
|
| 820 |
+
**🌟 پاکستان کے لیے صحت مند عادات:**
|
| 821 |
+
• فلٹر/ابلا ہوا پانی پیئیں
|
| 822 |
+
• تازہ، مقامی طور پر دستیاب پھل اور سبزیاں کھائیں
|
| 823 |
+
• اچھی غذا کی حفظان صحت کی مشق کریں
|
| 824 |
+
• مناسب سورج کی روشنی (وٹامن ڈی) حاصل کریں
|
| 825 |
+
|
| 826 |
+
*یاد رکھیں: چھوٹی مسلسل تبدیلیاں پائیدار صحت کی بہتری کا باعث بنتی ہیں!*
|
| 827 |
+
"""
|
| 828 |
+
|
| 829 |
+
def _format_default_response(self, language):
|
| 830 |
+
if language == 'English':
|
| 831 |
+
return """
|
| 832 |
+
**🤖 SehatAI Health Assistant**
|
| 833 |
+
|
| 834 |
+
I understand you're asking about health topics. I'm specially trained to help with:
|
| 835 |
+
|
| 836 |
+
**💚 Common Health Areas:**
|
| 837 |
+
• Heart disease and cardiovascular health
|
| 838 |
+
• Diabetes management and prevention
|
| 839 |
+
• Blood pressure control
|
| 840 |
+
• Nutrition and dietary guidance
|
| 841 |
+
• Exercise and physical activity
|
| 842 |
+
• Symptom assessment
|
| 843 |
+
• Medication information
|
| 844 |
+
• Emergency situations
|
| 845 |
+
• General wellness and prevention
|
| 846 |
+
|
| 847 |
+
Please ask specific questions for detailed medical information.
|
| 848 |
+
|
| 849 |
+
*⚠️ Remember: I'm an AI assistant. For personal medical advice, always consult qualified healthcare professionals.*
|
| 850 |
+
"""
|
| 851 |
+
else:
|
| 852 |
+
return """
|
| 853 |
+
**🤖 سیحت اے آئی ہیلتھ اسسٹنٹ**
|
| 854 |
+
|
| 855 |
+
میں سمجھتا ہوں کہ آپ صحت کے موضوعات کے بارے میں پوچھ رہے ہیں۔ میں خاص طور پر مدد کے لیے تربیت یافتہ ہوں:
|
| 856 |
+
|
| 857 |
+
**💚 عام صحت کے شعبے:**
|
| 858 |
+
• دل کی بیماری اور قلبی صحت
|
| 859 |
+
• ذیابیطس کا انتظام اور روک تھام
|
| 860 |
+
• بلڈ پریشر کنٹرول
|
| 861 |
+
• غذائیت اور غذائی رہنمائی
|
| 862 |
+
• ورزش اور جسمانی سرگرمی
|
| 863 |
+
• علامات کی تشخیص
|
| 864 |
+
• دوائ��وں کی معلومات
|
| 865 |
+
• ہنگامی حالات
|
| 866 |
+
• عام تندرستی اور روک تھام
|
| 867 |
+
|
| 868 |
+
براہ کرم تفصیلی طبی معلومات کے لیے مخصوص سوالات پوچھیں۔
|
| 869 |
+
|
| 870 |
+
*⚠️ یاد رکھیں: میں ایک AI اسسٹنٹ ہوں۔ ذاتی طبی مشورے کے لیے، ہمیشہ کوالیفائیڈ ہیلتھ کیئر پروفیشنلز سے مشورہ کریں۔*
|
| 871 |
+
"""
|
| 872 |
+
|
| 873 |
+
class PDFReportGenerator:
|
| 874 |
+
def __init__(self):
|
| 875 |
+
self.pdf = FPDF()
|
| 876 |
+
self.pdf.set_auto_page_break(auto=True, margin=15)
|
| 877 |
+
|
| 878 |
+
def generate_report(self, patient_data, risk_scores, language='English'):
|
| 879 |
+
self.pdf.add_page()
|
| 880 |
+
|
| 881 |
+
# Title
|
| 882 |
+
self.pdf.set_font('Arial', 'B', 16)
|
| 883 |
+
if language == 'English':
|
| 884 |
+
self.pdf.cell(0, 10, 'SEHATAI MEDICAL ASSESSMENT REPORT', 0, 1, 'C')
|
| 885 |
+
else:
|
| 886 |
+
self.pdf.cell(0, 10, 'SEHATAI MEDICAL ASSESSMENT REPORT', 0, 1, 'C')
|
| 887 |
+
|
| 888 |
+
self.pdf.ln(10)
|
| 889 |
+
|
| 890 |
+
# Patient Information
|
| 891 |
+
self.pdf.set_font('Arial', 'B', 12)
|
| 892 |
+
self.pdf.cell(0, 10, 'Patient Information:', 0, 1)
|
| 893 |
+
|
| 894 |
+
self.pdf.set_font('Arial', '', 10)
|
| 895 |
+
patient_info = [
|
| 896 |
+
f"Name: {self._safe_encode(patient_data.get('name', 'Not provided'))}",
|
| 897 |
+
f"Age: {patient_data.get('age', 'Not provided')} years",
|
| 898 |
+
f"Gender: {self._safe_encode(patient_data.get('gender', 'Not provided'))}",
|
| 899 |
+
f"Contact: {self._safe_encode(patient_data.get('contact', 'Not provided'))}"
|
| 900 |
+
]
|
| 901 |
+
|
| 902 |
+
for info in patient_info:
|
| 903 |
+
self.pdf.cell(0, 8, info, 0, 1)
|
| 904 |
+
|
| 905 |
+
self.pdf.ln(5)
|
| 906 |
+
|
| 907 |
+
# Clinical Parameters
|
| 908 |
+
self.pdf.set_font('Arial', 'B', 12)
|
| 909 |
+
self.pdf.cell(0, 10, 'Clinical Parameters:', 0, 1)
|
| 910 |
+
|
| 911 |
+
self.pdf.set_font('Arial', '', 10)
|
| 912 |
+
clinical_info = [
|
| 913 |
+
f"Blood Pressure: {patient_data.get('bp_systolic', 'N/A')}/{patient_data.get('bp_diastolic', 'N/A')} mmHg",
|
| 914 |
+
f"Heart Rate: {patient_data.get('heart_rate', 'N/A')} bpm",
|
| 915 |
+
f"Cholesterol: {patient_data.get('cholesterol', 'N/A')} mg/dL",
|
| 916 |
+
f"Glucose: {patient_data.get('glucose', 'N/A')} mg/dL",
|
| 917 |
+
f"BMI: {patient_data.get('bmi', 'N/A')}"
|
| 918 |
+
]
|
| 919 |
+
|
| 920 |
+
for info in clinical_info:
|
| 921 |
+
self.pdf.cell(0, 8, info, 0, 1)
|
| 922 |
+
|
| 923 |
+
self.pdf.ln(5)
|
| 924 |
+
|
| 925 |
+
# Symptoms
|
| 926 |
+
self.pdf.set_font('Arial', 'B', 12)
|
| 927 |
+
self.pdf.cell(0, 10, 'Reported Symptoms:', 0, 1)
|
| 928 |
+
|
| 929 |
+
self.pdf.set_font('Arial', '', 10)
|
| 930 |
+
symptoms = patient_data.get('symptoms', {})
|
| 931 |
+
symptom_list = [
|
| 932 |
+
f"Chest Pain: {'Yes' if symptoms.get('chest_pain') else 'No'}",
|
| 933 |
+
f"Shortness of Breath: {'Yes' if symptoms.get('shortness_breath') else 'No'}",
|
| 934 |
+
f"Palpitations: {'Yes' if symptoms.get('palpitations') else 'No'}",
|
| 935 |
+
f"Fatigue: {'Yes' if symptoms.get('fatigue') else 'No'}",
|
| 936 |
+
f"Dizziness: {'Yes' if symptoms.get('dizziness') else 'No'}",
|
| 937 |
+
f"Blurred Vision: {'Yes' if symptoms.get('blurred_vision') else 'No'}"
|
| 938 |
+
]
|
| 939 |
+
|
| 940 |
+
for symptom in symptom_list:
|
| 941 |
+
self.pdf.cell(0, 8, symptom, 0, 1)
|
| 942 |
+
|
| 943 |
+
self.pdf.ln(5)
|
| 944 |
+
|
| 945 |
+
# Risk Assessment
|
| 946 |
+
self.pdf.set_font('Arial', 'B', 12)
|
| 947 |
+
self.pdf.cell(0, 10, 'Risk Assessment Results:', 0, 1)
|
| 948 |
+
|
| 949 |
+
self.pdf.set_font('Arial', '', 10)
|
| 950 |
+
risk_info = [
|
| 951 |
+
f"Heart Disease Risk: {risk_scores.get('heart', 0):.1%}",
|
| 952 |
+
f"Diabetes Risk: {risk_scores.get('diabetes', 0):.1%}",
|
| 953 |
+
f"Hypertension Risk: {risk_scores.get('hypertension', 0):.1%}",
|
| 954 |
+
f"Overall Priority Score: {risk_scores.get('priority', 0):.1%}"
|
| 955 |
+
]
|
| 956 |
+
|
| 957 |
+
for info in risk_info:
|
| 958 |
+
self.pdf.cell(0, 8, info, 0, 1)
|
| 959 |
+
|
| 960 |
+
self.pdf.ln(5)
|
| 961 |
+
|
| 962 |
+
# Recommendation
|
| 963 |
+
self.pdf.set_font('Arial', 'B', 12)
|
| 964 |
+
self.pdf.cell(0, 10, 'Clinical Recommendation:', 0, 1)
|
| 965 |
+
|
| 966 |
+
self.pdf.set_font('Arial', '', 10)
|
| 967 |
+
recommendation = self._safe_encode(risk_scores.get('recommendation', 'No recommendation available'))
|
| 968 |
+
self.pdf.multi_cell(0, 8, recommendation)
|
| 969 |
+
|
| 970 |
+
self.pdf.ln(10)
|
| 971 |
+
|
| 972 |
+
# Footer
|
| 973 |
+
self.pdf.set_font('Arial', 'I', 8)
|
| 974 |
+
self.pdf.cell(0, 10, f'Generated by SehatAI on: {datetime.now().strftime("%Y-%m-%d %H:%M")}', 0, 1, 'C')
|
| 975 |
+
|
| 976 |
+
# Return the PDF as bytes
|
| 977 |
+
return self.pdf.output()
|
| 978 |
+
|
| 979 |
+
def _safe_encode(self, text):
|
| 980 |
+
"""Safely encode text for PDF generation"""
|
| 981 |
+
if text is None:
|
| 982 |
+
return ""
|
| 983 |
+
try:
|
| 984 |
+
return str(text)
|
| 985 |
+
except:
|
| 986 |
+
return "Encoding error"
|
| 987 |
+
|
| 988 |
+
# Load ML models with enhanced error handling
|
| 989 |
+
@st.cache_resource(show_spinner=False)
|
| 990 |
+
def load_models():
|
| 991 |
+
models = {}
|
| 992 |
+
|
| 993 |
+
# Try multiple approaches to load models
|
| 994 |
+
model_files = {
|
| 995 |
+
'heart': ['heart_model.pkl', 'heart_disease_model.pkl', 'models/heart_model.pkl'],
|
| 996 |
+
'diabetes': ['diabetes_model.pkl', 'diabetes_model.pkl', 'models/diabetes_model.pkl'],
|
| 997 |
+
'hypertension': ['hypertension_model.pkl', 'models/hypertension_model.pkl']
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
def try_load_model(model_name, file_list):
|
| 1001 |
+
for file_path in file_list:
|
| 1002 |
+
if os.path.exists(file_path):
|
| 1003 |
+
try:
|
| 1004 |
+
model = joblib.load(file_path)
|
| 1005 |
+
# Success message removed from interface as requested
|
| 1006 |
+
return model
|
| 1007 |
+
except Exception as e:
|
| 1008 |
+
continue
|
| 1009 |
+
return None
|
| 1010 |
+
|
| 1011 |
+
models['heart'] = try_load_model("Heart Disease", model_files['heart'])
|
| 1012 |
+
models['diabetes'] = try_load_model("Diabetes", model_files['diabetes'])
|
| 1013 |
+
models['hypertension'] = try_load_model("Hypertension", model_files['hypertension'])
|
| 1014 |
+
|
| 1015 |
+
# If no models found, use rule-based
|
| 1016 |
+
if not any(models.values()):
|
| 1017 |
+
st.info("🔍 Using advanced rule-based assessment (no ML models found)")
|
| 1018 |
+
|
| 1019 |
+
return models
|
| 1020 |
+
|
| 1021 |
+
def calculate_priority_score(heart_risk, diabetes_risk, hypertension_risk):
|
| 1022 |
+
"""Calculate integrated priority score with clinical weighting"""
|
| 1023 |
+
# Clinical severity weighting
|
| 1024 |
+
priority = (
|
| 1025 |
+
heart_risk * 0.45 + # Highest weight for cardiac issues
|
| 1026 |
+
diabetes_risk * 0.25 + # Medium weight for diabetes
|
| 1027 |
+
hypertension_risk * 0.30 # Medium weight for hypertension
|
| 1028 |
+
)
|
| 1029 |
+
|
| 1030 |
+
return min(1.0, priority) # Cap at 1.0
|
| 1031 |
+
|
| 1032 |
+
def get_priority_recommendation(priority_score, language='English'):
|
| 1033 |
+
"""Get priority-based recommendation with clinical thresholds"""
|
| 1034 |
+
if priority_score >= 0.75:
|
| 1035 |
+
if language == 'Urdu':
|
| 1036 |
+
return "EMERGENCY_CARE", "اعلی ترجیح - فوری ہنگامی علاج کی ضرورت", "risk-high"
|
| 1037 |
+
else:
|
| 1038 |
+
return "EMERGENCY_CARE", "High Priority - Immediate Emergency Care Required", "risk-high"
|
| 1039 |
+
elif priority_score >= 0.55:
|
| 1040 |
+
if language == 'Urdu':
|
| 1041 |
+
return "SAME_DAY_CONSULT", "درمیانی ترجیح - اسی دن مشورہ ضروری", "risk-medium"
|
| 1042 |
+
else:
|
| 1043 |
+
return "SAME_DAY_CONSULT", "Medium Priority - Same Day Consultation Required", "risk-medium"
|
| 1044 |
+
else:
|
| 1045 |
+
if language == 'Urdu':
|
| 1046 |
+
return "ROUTINE_APPOINTMENT", "کم ترجیح - روٹین اپائنٹمنٹ", "risk-low"
|
| 1047 |
+
else:
|
| 1048 |
+
return "ROUTINE_APPOINTMENT", "Low Priority - Routine Appointment", "risk-low"
|
| 1049 |
+
|
| 1050 |
+
def validate_patient_data(age, bp_systolic, bp_diastolic, heart_rate):
|
| 1051 |
+
"""Validate patient data for realistic clinical values"""
|
| 1052 |
+
errors = []
|
| 1053 |
+
|
| 1054 |
+
if age < 1 or age > 120:
|
| 1055 |
+
errors.append("Age must be between 1 and 120 years")
|
| 1056 |
+
if bp_systolic < 70 or bp_systolic > 250:
|
| 1057 |
+
errors.append("Systolic BP must be between 70 and 250 mmHg")
|
| 1058 |
+
if bp_diastolic < 40 or bp_diastolic > 150:
|
| 1059 |
+
errors.append("Diastolic BP must be between 40 and 150 mmHg")
|
| 1060 |
+
if heart_rate < 30 or heart_rate > 200:
|
| 1061 |
+
errors.append("Heart rate must be between 30 and 200 bpm")
|
| 1062 |
+
|
| 1063 |
+
return errors
|
| 1064 |
+
|
| 1065 |
+
def predict_with_models(age, bp_systolic, bp_diastolic, heart_rate, cholesterol, glucose, bmi, symptoms, models):
|
| 1066 |
+
"""Predict risks using loaded ML models with fallback to rule-based"""
|
| 1067 |
+
heart_risk, diabetes_risk, hypertension_risk = 0.0, 0.0, 0.0
|
| 1068 |
+
|
| 1069 |
+
# Heart disease prediction
|
| 1070 |
+
if models.get('heart') is not None:
|
| 1071 |
+
try:
|
| 1072 |
+
heart_features = np.array([[
|
| 1073 |
+
age, bp_systolic, cholesterol, heart_rate,
|
| 1074 |
+
symptoms['chest_pain'], symptoms['shortness_breath'],
|
| 1075 |
+
symptoms['palpitations'], bmi, glucose
|
| 1076 |
+
]])
|
| 1077 |
+
heart_risk = models['heart'].predict_proba(heart_features)[0][1]
|
| 1078 |
+
except Exception as e:
|
| 1079 |
+
heart_risk = predict_risk_rule_based_heart(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1080 |
+
else:
|
| 1081 |
+
heart_risk = predict_risk_rule_based_heart(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1082 |
+
|
| 1083 |
+
# Diabetes prediction
|
| 1084 |
+
if models.get('diabetes') is not None:
|
| 1085 |
+
try:
|
| 1086 |
+
diabetes_features = np.array([[
|
| 1087 |
+
age, glucose, bmi, cholesterol,
|
| 1088 |
+
symptoms['fatigue'], symptoms['blurred_vision'],
|
| 1089 |
+
bp_systolic, heart_rate
|
| 1090 |
+
]])
|
| 1091 |
+
diabetes_risk = models['diabetes'].predict_proba(diabetes_features)[0][1]
|
| 1092 |
+
except Exception as e:
|
| 1093 |
+
diabetes_risk = predict_risk_rule_based_diabetes(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1094 |
+
else:
|
| 1095 |
+
diabetes_risk = predict_risk_rule_based_diabetes(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1096 |
+
|
| 1097 |
+
# Hypertension prediction
|
| 1098 |
+
if models.get('hypertension') is not None:
|
| 1099 |
+
try:
|
| 1100 |
+
hypertension_features = np.array([[
|
| 1101 |
+
age, bp_systolic, bp_diastolic, bmi,
|
| 1102 |
+
symptoms['dizziness'], symptoms['palpitations'],
|
| 1103 |
+
heart_rate, cholesterol
|
| 1104 |
+
]])
|
| 1105 |
+
hypertension_risk = models['hypertension'].predict_proba(hypertension_features)[0][1]
|
| 1106 |
+
except Exception as e:
|
| 1107 |
+
hypertension_risk = predict_risk_rule_based_hypertension(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1108 |
+
else:
|
| 1109 |
+
hypertension_risk = predict_risk_rule_based_hypertension(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms)
|
| 1110 |
+
|
| 1111 |
+
return heart_risk, diabetes_risk, hypertension_risk
|
| 1112 |
+
|
| 1113 |
+
def predict_risk_rule_based_heart(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms):
|
| 1114 |
+
"""Advanced rule-based heart risk prediction"""
|
| 1115 |
+
risk = 0.0
|
| 1116 |
+
|
| 1117 |
+
# Age factor
|
| 1118 |
+
if age > 60: risk += 0.25
|
| 1119 |
+
elif age > 45: risk += 0.15
|
| 1120 |
+
elif age > 30: risk += 0.05
|
| 1121 |
+
|
| 1122 |
+
# Blood pressure factor
|
| 1123 |
+
if bp_systolic > 180 or bp_diastolic > 120: risk += 0.30
|
| 1124 |
+
elif bp_systolic > 140 or bp_diastolic > 90: risk += 0.20
|
| 1125 |
+
elif bp_systolic > 130 or bp_diastolic > 85: risk += 0.10
|
| 1126 |
+
|
| 1127 |
+
# Cholesterol factor
|
| 1128 |
+
if cholesterol > 240: risk += 0.20
|
| 1129 |
+
elif cholesterol > 200: risk += 0.10
|
| 1130 |
+
|
| 1131 |
+
# BMI factor
|
| 1132 |
+
if bmi > 35: risk += 0.15
|
| 1133 |
+
elif bmi > 30: risk += 0.10
|
| 1134 |
+
elif bmi > 25: risk += 0.05
|
| 1135 |
+
|
| 1136 |
+
# Glucose factor
|
| 1137 |
+
if glucose > 200: risk += 0.10
|
| 1138 |
+
elif glucose > 126: risk += 0.05
|
| 1139 |
+
|
| 1140 |
+
# Symptom factors
|
| 1141 |
+
if symptoms['chest_pain']: risk += 0.25
|
| 1142 |
+
if symptoms['shortness_breath']: risk += 0.15
|
| 1143 |
+
if symptoms['palpitations']: risk += 0.10
|
| 1144 |
+
|
| 1145 |
+
return min(0.95, max(0.05, risk))
|
| 1146 |
+
|
| 1147 |
+
def predict_risk_rule_based_diabetes(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms):
|
| 1148 |
+
"""Advanced rule-based diabetes risk prediction"""
|
| 1149 |
+
risk = 0.0
|
| 1150 |
+
|
| 1151 |
+
# Age factor
|
| 1152 |
+
if age > 50: risk += 0.20
|
| 1153 |
+
elif age > 40: risk += 0.10
|
| 1154 |
+
elif age > 30: risk += 0.05
|
| 1155 |
+
|
| 1156 |
+
# Glucose factor (most important)
|
| 1157 |
+
if glucose > 200: risk += 0.40
|
| 1158 |
+
elif glucose > 126: risk += 0.30
|
| 1159 |
+
elif glucose > 100: risk += 0.15
|
| 1160 |
+
|
| 1161 |
+
# BMI factor
|
| 1162 |
+
if bmi > 35: risk += 0.25
|
| 1163 |
+
elif bmi > 30: risk += 0.15
|
| 1164 |
+
elif bmi > 25: risk += 0.08
|
| 1165 |
+
|
| 1166 |
+
# Blood pressure factor
|
| 1167 |
+
if bp_systolic > 140 or bp_diastolic > 90: risk += 0.10
|
| 1168 |
+
|
| 1169 |
+
# Symptom factors
|
| 1170 |
+
if symptoms['fatigue']: risk += 0.10
|
| 1171 |
+
if symptoms['blurred_vision']: risk += 0.08
|
| 1172 |
+
|
| 1173 |
+
return min(0.95, max(0.05, risk))
|
| 1174 |
+
|
| 1175 |
+
def predict_risk_rule_based_hypertension(age, bp_systolic, bp_diastolic, cholesterol, glucose, bmi, symptoms):
|
| 1176 |
+
"""Advanced rule-based hypertension risk prediction"""
|
| 1177 |
+
risk = 0.0
|
| 1178 |
+
|
| 1179 |
+
# Blood pressure factor (most important)
|
| 1180 |
+
if bp_systolic > 180 or bp_diastolic > 120: risk += 0.50
|
| 1181 |
+
elif bp_systolic > 140 or bp_diastolic > 90: risk += 0.35
|
| 1182 |
+
elif bp_systolic > 130 or bp_diastolic > 85: risk += 0.20
|
| 1183 |
+
|
| 1184 |
+
# Age factor
|
| 1185 |
+
if age > 60: risk += 0.15
|
| 1186 |
+
elif age > 45: risk += 0.08
|
| 1187 |
+
|
| 1188 |
+
# BMI factor
|
| 1189 |
+
if bmi > 30: risk += 0.15
|
| 1190 |
+
elif bmi > 25: risk += 0.08
|
| 1191 |
+
|
| 1192 |
+
# Symptom factors
|
| 1193 |
+
if symptoms['dizziness']: risk += 0.10
|
| 1194 |
+
if symptoms['palpitations']: risk += 0.08
|
| 1195 |
+
|
| 1196 |
+
return min(0.95, max(0.05, risk))
|
| 1197 |
+
|
| 1198 |
+
def create_download_link(pdf_bytes, filename, text):
|
| 1199 |
+
"""Create a download link for PDF"""
|
| 1200 |
+
b64 = base64.b64encode(pdf_bytes).decode()
|
| 1201 |
+
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">{text}</a>'
|
| 1202 |
+
return href
|
| 1203 |
+
|
| 1204 |
+
def main():
|
| 1205 |
+
# Load custom CSS
|
| 1206 |
+
local_css()
|
| 1207 |
+
init_session_state()
|
| 1208 |
+
|
| 1209 |
+
# Load ML models in background without showing messages
|
| 1210 |
+
if not st.session_state.models_loaded:
|
| 1211 |
+
with st.spinner("🔄 Loading AI models..."):
|
| 1212 |
+
models = load_models()
|
| 1213 |
+
st.session_state.models = models
|
| 1214 |
+
st.session_state.models_loaded = True
|
| 1215 |
+
|
| 1216 |
+
models = st.session_state.models
|
| 1217 |
+
|
| 1218 |
+
# Language selector at top right with Pakistan flag colors
|
| 1219 |
+
col_lang, col_space = st.columns([1, 5])
|
| 1220 |
+
with col_lang:
|
| 1221 |
+
st.markdown('<div class="pakistan-flag">🇵🇰</div>', unsafe_allow_html=True)
|
| 1222 |
+
language = st.selectbox("Language", ["English", "Urdu"], key="language_selector", label_visibility="collapsed")
|
| 1223 |
+
st.session_state.current_language = language
|
| 1224 |
+
|
| 1225 |
+
# Main header with new name
|
| 1226 |
+
st.markdown('<h1 class="main-header">🏥 SehatAI</h1>', unsafe_allow_html=True)
|
| 1227 |
+
if language == "English":
|
| 1228 |
+
st.markdown('<h3 style="text-align: center; color: #00612A; margin-bottom: 20px;">Smart Healthcare Triage & Risk Assessment System</h3>', unsafe_allow_html=True)
|
| 1229 |
+
else:
|
| 1230 |
+
st.markdown('<h3 style="text-align: center; color: #00612A; margin-bottom: 20px;">ذہین ہیلتھ کیئر ٹریج اور خطرے کی تشخیص کا نظام</h3>', unsafe_allow_html=True)
|
| 1231 |
+
|
| 1232 |
+
# Display random healthcare quote
|
| 1233 |
+
import random
|
| 1234 |
+
quote = random.choice(HEALTHCARE_QUOTES)
|
| 1235 |
+
|
| 1236 |
+
st.markdown(f'''
|
| 1237 |
+
<div class="quote-section">
|
| 1238 |
+
<div class="quote-text">"{quote['english']}"</div>
|
| 1239 |
+
<div class="quote-text">"{quote['urdu']}"</div>
|
| 1240 |
+
<div class="quote-author">- {quote['author']}</div>
|
| 1241 |
+
</div>
|
| 1242 |
+
''', unsafe_allow_html=True)
|
| 1243 |
+
|
| 1244 |
+
# Create tabs
|
| 1245 |
+
if language == "English":
|
| 1246 |
+
tab_names = ["Patient Assessment", "Health Assistant", "Medical Reports"]
|
| 1247 |
+
else:
|
| 1248 |
+
tab_names = ["مریض تشخیص", "ہیلتھ اسسٹنٹ", "طبی رپورٹس"]
|
| 1249 |
+
|
| 1250 |
+
tab1, tab2, tab3 = st.tabs(tab_names)
|
| 1251 |
+
|
| 1252 |
+
with tab1:
|
| 1253 |
+
# Patient Assessment Form
|
| 1254 |
+
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1255 |
+
|
| 1256 |
+
if language == "English":
|
| 1257 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">👨⚕️ Comprehensive Patient Assessment</h2>', unsafe_allow_html=True)
|
| 1258 |
+
st.write("Complete the following form for comprehensive patient risk assessment and priority scoring")
|
| 1259 |
+
else:
|
| 1260 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">👨⚕️ جامع مریض تشخیص</h2>', unsafe_allow_html=True)
|
| 1261 |
+
st.write("جامع مریض کے خطرے کی تشخیص اور ترجیحی اسکورنگ کے لیے درج ذیل فارم کو مکمل کریں")
|
| 1262 |
+
|
| 1263 |
+
with st.form("patient_assessment_form"):
|
| 1264 |
+
col1, col2 = st.columns(2)
|
| 1265 |
+
|
| 1266 |
+
with col1:
|
| 1267 |
+
# Basic Information
|
| 1268 |
+
if language == "English":
|
| 1269 |
+
st.subheader("Personal Information")
|
| 1270 |
+
name = st.text_input("Full Name", placeholder="Enter patient's full name")
|
| 1271 |
+
age = st.number_input("Age", min_value=1, max_value=120, value=45,
|
| 1272 |
+
help="Patient's age in years")
|
| 1273 |
+
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
| 1274 |
+
contact = st.text_input("Contact Number", placeholder="03XX-XXXXXXX")
|
| 1275 |
+
else:
|
| 1276 |
+
st.subheader("ذاتی معلومات")
|
| 1277 |
+
name = st.text_input("مکمل نام", placeholder="مریض کا مکمل نام درج کریں")
|
| 1278 |
+
age = st.number_input("عمر", min_value=1, max_value=120, value=45,
|
| 1279 |
+
help="مریض کی عمر سالوں میں")
|
| 1280 |
+
gender = st.selectbox("جنس", ["مرد", "عورت", "دیگر"])
|
| 1281 |
+
contact = st.text_input("رابطہ نمبر", placeholder="03XX-XXXXXXX")
|
| 1282 |
+
|
| 1283 |
+
with col2:
|
| 1284 |
+
# Vital Signs
|
| 1285 |
+
if language == "English":
|
| 1286 |
+
st.subheader("Clinical Parameters")
|
| 1287 |
+
bp_systolic = st.slider("Blood Pressure (systolic)",
|
| 1288 |
+
min_value=70, max_value=250, value=120,
|
| 1289 |
+
help="Systolic blood pressure in mmHg")
|
| 1290 |
+
bp_diastolic = st.slider("Blood Pressure (diastolic)",
|
| 1291 |
+
min_value=40, max_value=150, value=80,
|
| 1292 |
+
help="Diastolic blood pressure in mmHg")
|
| 1293 |
+
heart_rate = st.slider("Heart Rate (bpm)",
|
| 1294 |
+
min_value=30, max_value=200, value=72,
|
| 1295 |
+
help="Heart beats per minute")
|
| 1296 |
+
cholesterol = st.slider("Cholesterol Level (mg/dL)",
|
| 1297 |
+
min_value=100, max_value=400, value=180)
|
| 1298 |
+
glucose = st.slider("Blood Glucose (mg/dL)",
|
| 1299 |
+
min_value=50, max_value=500, value=95)
|
| 1300 |
+
bmi = st.slider("BMI", min_value=15.0, max_value=40.0, value=23.5, step=0.1)
|
| 1301 |
+
else:
|
| 1302 |
+
st.subheader("کلینیکل پیرامیٹرز")
|
| 1303 |
+
bp_systolic = st.slider("بلڈ پریشر (سسٹولک)",
|
| 1304 |
+
min_value=70, max_value=250, value=120,
|
| 1305 |
+
help="سسٹولک بلڈ پریشر mmHg میں")
|
| 1306 |
+
bp_diastolic = st.slider("بلڈ پریشر (ڈائیسٹولک)",
|
| 1307 |
+
min_value=40, max_value=150, value=80,
|
| 1308 |
+
help="ڈائیسٹولک بلڈ پریشر mmHg میں")
|
| 1309 |
+
heart_rate = st.slider("دل کی دھڑکن (bpm)",
|
| 1310 |
+
min_value=30, max_value=200, value=72,
|
| 1311 |
+
help="دل کی دھڑکن فی منٹ")
|
| 1312 |
+
cholesterol = st.slider("کولیسٹرول کی سطح (mg/dL)",
|
| 1313 |
+
min_value=100, max_value=400, value=180)
|
| 1314 |
+
glucose = st.slider("خون میں گلوکوز (mg/dL)",
|
| 1315 |
+
min_value=50, max_value=500, value=95)
|
| 1316 |
+
bmi = st.slider("باڈی ماس انڈیکس", min_value=15.0, max_value=40.0, value=23.5, step=0.1)
|
| 1317 |
+
|
| 1318 |
+
# Symptoms Section
|
| 1319 |
+
if language == "English":
|
| 1320 |
+
st.subheader("Reported Symptoms")
|
| 1321 |
+
col3, col4 = st.columns(2)
|
| 1322 |
+
with col3:
|
| 1323 |
+
chest_pain = st.checkbox("Chest Pain or Discomfort")
|
| 1324 |
+
shortness_breath = st.checkbox("Shortness of Breath")
|
| 1325 |
+
palpitations = st.checkbox("Heart Palpitations")
|
| 1326 |
+
with col4:
|
| 1327 |
+
fatigue = st.checkbox("Persistent Fatigue")
|
| 1328 |
+
dizziness = st.checkbox("Dizziness or Lightheadedness")
|
| 1329 |
+
blurred_vision = st.checkbox("Blurred Vision")
|
| 1330 |
+
else:
|
| 1331 |
+
st.subheader("رپورٹ کردہ علامات")
|
| 1332 |
+
col3, col4 = st.columns(2)
|
| 1333 |
+
with col3:
|
| 1334 |
+
chest_pain = st.checkbox("سینے میں درد یا بے چینی")
|
| 1335 |
+
shortness_breath = st.checkbox("سانس لینے میں دشواری")
|
| 1336 |
+
palpitations = st.checkbox("دل کی دھڑکن میں اضافہ")
|
| 1337 |
+
with col4:
|
| 1338 |
+
fatigue = st.checkbox("مسلسل تھکاوٹ")
|
| 1339 |
+
dizziness = st.checkbox("چکر آنا یا سر ہلکا محسوس ہونا")
|
| 1340 |
+
blurred_vision = st.checkbox("دھندلا نظر آنا")
|
| 1341 |
+
|
| 1342 |
+
# Assessment Button
|
| 1343 |
+
if language == "English":
|
| 1344 |
+
assess_button = st.form_submit_button("🚀 Calculate Risk Score & Priority",
|
| 1345 |
+
use_container_width=True)
|
| 1346 |
+
else:
|
| 1347 |
+
assess_button = st.form_submit_button("🚀 خطرے کا اسکور اور ترجیح معلوم کریں",
|
| 1348 |
+
use_container_width=True)
|
| 1349 |
+
|
| 1350 |
+
if assess_button:
|
| 1351 |
+
# Validate inputs
|
| 1352 |
+
validation_errors = validate_patient_data(age, bp_systolic, bp_diastolic, heart_rate)
|
| 1353 |
+
|
| 1354 |
+
if validation_errors:
|
| 1355 |
+
for error in validation_errors:
|
| 1356 |
+
st.error(f"❌ {error}")
|
| 1357 |
+
else:
|
| 1358 |
+
try:
|
| 1359 |
+
with st.spinner("🔍 Analyzing patient data and calculating risks..."):
|
| 1360 |
+
# Prepare symptoms dictionary
|
| 1361 |
+
symptoms_dict = {
|
| 1362 |
+
'chest_pain': chest_pain,
|
| 1363 |
+
'shortness_breath': shortness_breath,
|
| 1364 |
+
'palpitations': palpitations,
|
| 1365 |
+
'fatigue': fatigue,
|
| 1366 |
+
'dizziness': dizziness,
|
| 1367 |
+
'blurred_vision': blurred_vision
|
| 1368 |
+
}
|
| 1369 |
+
|
| 1370 |
+
# Store patient data
|
| 1371 |
+
st.session_state.patient_data = {
|
| 1372 |
+
'name': name,
|
| 1373 |
+
'age': age,
|
| 1374 |
+
'gender': gender,
|
| 1375 |
+
'contact': contact,
|
| 1376 |
+
'bp_systolic': bp_systolic,
|
| 1377 |
+
'bp_diastolic': bp_diastolic,
|
| 1378 |
+
'heart_rate': heart_rate,
|
| 1379 |
+
'cholesterol': cholesterol,
|
| 1380 |
+
'glucose': glucose,
|
| 1381 |
+
'bmi': bmi,
|
| 1382 |
+
'symptoms': symptoms_dict
|
| 1383 |
+
}
|
| 1384 |
+
|
| 1385 |
+
# Predict risks using ML models
|
| 1386 |
+
heart_risk, diabetes_risk, hypertension_risk = predict_with_models(
|
| 1387 |
+
age, bp_systolic, bp_diastolic, heart_rate,
|
| 1388 |
+
cholesterol, glucose, bmi, symptoms_dict, models
|
| 1389 |
+
)
|
| 1390 |
+
|
| 1391 |
+
# Calculate integrated priority score
|
| 1392 |
+
priority_score = calculate_priority_score(
|
| 1393 |
+
heart_risk, diabetes_risk, hypertension_risk
|
| 1394 |
+
)
|
| 1395 |
+
|
| 1396 |
+
priority_level, recommendation, risk_class = get_priority_recommendation(
|
| 1397 |
+
priority_score, language
|
| 1398 |
+
)
|
| 1399 |
+
|
| 1400 |
+
# Store results
|
| 1401 |
+
st.session_state.risk_scores = {
|
| 1402 |
+
'heart': heart_risk,
|
| 1403 |
+
'diabetes': diabetes_risk,
|
| 1404 |
+
'hypertension': hypertension_risk,
|
| 1405 |
+
'priority': priority_score,
|
| 1406 |
+
'recommendation': recommendation,
|
| 1407 |
+
'level': priority_level
|
| 1408 |
+
}
|
| 1409 |
+
|
| 1410 |
+
# Add to assessment history
|
| 1411 |
+
st.session_state.assessment_history.append({
|
| 1412 |
+
'timestamp': datetime.now(),
|
| 1413 |
+
'patient_data': st.session_state.patient_data.copy(),
|
| 1414 |
+
'risk_scores': st.session_state.risk_scores.copy()
|
| 1415 |
+
})
|
| 1416 |
+
|
| 1417 |
+
# Display results
|
| 1418 |
+
st.markdown("---")
|
| 1419 |
+
st.success("✅ Risk assessment completed successfully!")
|
| 1420 |
+
|
| 1421 |
+
# Risk Scores Visualization
|
| 1422 |
+
if language == "English":
|
| 1423 |
+
st.subheader("📊 Disease Risk Assessment Dashboard")
|
| 1424 |
+
else:
|
| 1425 |
+
st.subheader("📊 بیماری کے خطرے کی تشخیص ڈیش بورڈ")
|
| 1426 |
+
|
| 1427 |
+
col5, col6, col7, col8 = st.columns(4)
|
| 1428 |
+
|
| 1429 |
+
risk_metrics = [
|
| 1430 |
+
(heart_risk, "Heart Disease", "❤️", "#FF6B6B"),
|
| 1431 |
+
(diabetes_risk, "Diabetes", "🩺", "#4ECDC4"),
|
| 1432 |
+
(hypertension_risk, "Hypertension", "💓", "#45B7D1"),
|
| 1433 |
+
(priority_score, "Priority Score", "🎯", "#96CEB4")
|
| 1434 |
+
]
|
| 1435 |
+
|
| 1436 |
+
for (value, title, emoji, color), col in zip(risk_metrics, [col5, col6, col7, col8]):
|
| 1437 |
+
with col:
|
| 1438 |
+
fig = go.Figure(go.Indicator(
|
| 1439 |
+
mode = "gauge+number+delta",
|
| 1440 |
+
value = value,
|
| 1441 |
+
domain = {'x': [0, 1], 'y': [0, 1]},
|
| 1442 |
+
title = {'text': f"{emoji} {title}", 'font': {'size': 14}},
|
| 1443 |
+
gauge = {
|
| 1444 |
+
'axis': {'range': [0, 1], 'tickwidth': 1},
|
| 1445 |
+
'bar': {'color': color},
|
| 1446 |
+
'steps': [
|
| 1447 |
+
{'range': [0, 0.3], 'color': "lightgreen"},
|
| 1448 |
+
{'range': [0.3, 0.7], 'color': "yellow"},
|
| 1449 |
+
{'range': [0.7, 1], 'color': "red"}
|
| 1450 |
+
],
|
| 1451 |
+
'threshold': {
|
| 1452 |
+
'line': {'color': "black", 'width': 4},
|
| 1453 |
+
'thickness': 0.75,
|
| 1454 |
+
'value': 0.7
|
| 1455 |
+
}
|
| 1456 |
+
}
|
| 1457 |
+
))
|
| 1458 |
+
fig.update_layout(height=250, margin=dict(l=10, r=10, t=50, b=10))
|
| 1459 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 1460 |
+
|
| 1461 |
+
# Priority Recommendation
|
| 1462 |
+
st.markdown(f'<div class="priority-box {risk_class}">', unsafe_allow_html=True)
|
| 1463 |
+
if language == "English":
|
| 1464 |
+
st.markdown(f"## 🎯 Clinical Priority Recommendation")
|
| 1465 |
+
st.markdown(f"### {recommendation}")
|
| 1466 |
+
st.markdown(f"**Overall Risk Score:** `{priority_score:.3f}`")
|
| 1467 |
+
st.markdown(f"**Recommended Action:** `{priority_level.replace('_', ' ').title()}`")
|
| 1468 |
+
|
| 1469 |
+
# Additional clinical guidance
|
| 1470 |
+
if priority_level == "EMERGENCY_CARE":
|
| 1471 |
+
st.warning("🚨 **Immediate Action Required:** Patient should be directed to emergency department without delay.")
|
| 1472 |
+
elif priority_level == "SAME_DAY_CONSULT":
|
| 1473 |
+
st.info("ℹ️ **Urgent Consultation:** Schedule appointment within 24 hours.")
|
| 1474 |
+
else:
|
| 1475 |
+
st.success("✅ **Routine Care:** Schedule within regular appointment system.")
|
| 1476 |
+
|
| 1477 |
+
else:
|
| 1478 |
+
st.markdown(f"## 🎯 کلینیکل ترجیحی سفارش")
|
| 1479 |
+
st.markdown(f"### {recommendation}")
|
| 1480 |
+
st.markdown(f"**کل خطرے کا اسکور:** `{priority_score:.3f}`")
|
| 1481 |
+
st.markdown(f"**سفارش کردہ عمل:** `{priority_level.replace('_', ' ').title()}`")
|
| 1482 |
+
|
| 1483 |
+
if priority_level == "EMERGENCY_CARE":
|
| 1484 |
+
st.warning("🚨 **فوری کارروائی ضروری:** مریض کو بغیر کسی تاخیر کے ایمرجنسی ڈیپارٹمنٹ بھیجا جائے۔")
|
| 1485 |
+
elif priority_level == "SAME_DAY_CONSULT":
|
| 1486 |
+
st.info("ℹ️ **فوری مشاورت:** 24 گھنٹے کے اندر اپائنٹمنٹ شیڈول کریں۔")
|
| 1487 |
+
else:
|
| 1488 |
+
st.success("✅ **روٹین کیئر:** معمول کی اپائنٹمنٹ سسٹم کے اندر شیڈول کریں۔")
|
| 1489 |
+
|
| 1490 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 1491 |
+
|
| 1492 |
+
except Exception as e:
|
| 1493 |
+
st.error(f"❌ Error in risk assessment: {str(e)}")
|
| 1494 |
+
|
| 1495 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 1496 |
+
|
| 1497 |
+
with tab2:
|
| 1498 |
+
# Healthcare Chatbot
|
| 1499 |
+
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1500 |
+
|
| 1501 |
+
if language == "English":
|
| 1502 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">💬 SehatAI Health Assistant</h2>', unsafe_allow_html=True)
|
| 1503 |
+
st.write("Ask health-related questions and get instant, reliable medical information")
|
| 1504 |
+
else:
|
| 1505 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">💬 سیحت اے آئی ہیلتھ اسسٹنٹ</h2>', unsafe_allow_html=True)
|
| 1506 |
+
st.write("صحت سے متعلق سوالات پوچھیں اور فوری، قابل اعتماد طبی معلومات حاصل کریں")
|
| 1507 |
+
|
| 1508 |
+
# Groq API Configuration - Hidden from interface as requested
|
| 1509 |
+
# Check if API key is available in environment or secrets
|
| 1510 |
+
groq_api_key = st.secrets.get("GROQ_API_KEY", "") if hasattr(st, 'secrets') else ""
|
| 1511 |
+
|
| 1512 |
+
if groq_api_key:
|
| 1513 |
+
st.session_state.groq_api_key = groq_api_key
|
| 1514 |
+
try:
|
| 1515 |
+
groq_client = GroqClient(groq_api_key)
|
| 1516 |
+
chatbot = HealthcareChatbot(groq_client)
|
| 1517 |
+
except Exception as e:
|
| 1518 |
+
chatbot = HealthcareChatbot()
|
| 1519 |
+
else:
|
| 1520 |
+
chatbot = HealthcareChatbot()
|
| 1521 |
+
|
| 1522 |
+
# Display chat history
|
| 1523 |
+
for message in st.session_state.chat_history:
|
| 1524 |
+
if message["role"] == "user":
|
| 1525 |
+
st.markdown(f'<div class="chat-message user-message"><strong>You:</strong> {message["content"]}</div>', unsafe_allow_html=True)
|
| 1526 |
+
else:
|
| 1527 |
+
st.markdown(f'<div class="chat-message bot-message"><strong>🤖 Health Assistant:</strong> {message["content"]}</div>', unsafe_allow_html=True)
|
| 1528 |
+
|
| 1529 |
+
# Chat input
|
| 1530 |
+
if prompt := st.chat_input(
|
| 1531 |
+
"Type your health question here..." if language == "English"
|
| 1532 |
+
else "اپنا صحت کا سوال یہاں ٹائپ کریں..."
|
| 1533 |
+
):
|
| 1534 |
+
# Add user message to chat history
|
| 1535 |
+
st.session_state.chat_history.append({"role": "user", "content": prompt})
|
| 1536 |
+
|
| 1537 |
+
# Generate bot response
|
| 1538 |
+
with st.spinner("💭 Analyzing your question..." if language == "English" else "💭 آپ کا سوال تجزیہ ہو رہا ہے..."):
|
| 1539 |
+
response = chatbot.get_response(prompt, language)
|
| 1540 |
+
st.session_state.chat_history.append({"role": "assistant", "content": response})
|
| 1541 |
+
|
| 1542 |
+
# Limit chat history to last 10 messages
|
| 1543 |
+
if len(st.session_state.chat_history) > 10:
|
| 1544 |
+
st.session_state.chat_history = st.session_state.chat_history[-10:]
|
| 1545 |
+
|
| 1546 |
+
st.rerun()
|
| 1547 |
+
|
| 1548 |
+
# Quick action buttons
|
| 1549 |
+
if language == "English":
|
| 1550 |
+
st.subheader("Quick Health Topics")
|
| 1551 |
+
else:
|
| 1552 |
+
st.subheader("فوری صحت کے موضوعات")
|
| 1553 |
+
|
| 1554 |
+
col_qa1, col_qa2, col_qa3, col_qa4 = st.columns(4)
|
| 1555 |
+
|
| 1556 |
+
with col_qa1:
|
| 1557 |
+
if st.button("❤️ Heart Health", use_container_width=True):
|
| 1558 |
+
if language == "English":
|
| 1559 |
+
query = "Tell me about heart disease symptoms and prevention"
|
| 1560 |
+
else:
|
| 1561 |
+
query = "دل کی بیماری کی علامات اور بچاؤ کے بارے میں بتائیں"
|
| 1562 |
+
st.session_state.chat_history.append({"role": "user", "content": query})
|
| 1563 |
+
st.rerun()
|
| 1564 |
+
|
| 1565 |
+
with col_qa2:
|
| 1566 |
+
if st.button("🩺 Diabetes", use_container_width=True):
|
| 1567 |
+
if language == "English":
|
| 1568 |
+
query = "What are diabetes symptoms and management strategies?"
|
| 1569 |
+
else:
|
| 1570 |
+
query = "ذیابیطس کی علامات اور انتظام کی حکمت عملی کیا ہیں؟"
|
| 1571 |
+
st.session_state.chat_history.append({"role": "user", "content": query})
|
| 1572 |
+
st.rerun()
|
| 1573 |
+
|
| 1574 |
+
with col_qa3:
|
| 1575 |
+
if st.button("💓 Blood Pressure", use_container_width=True):
|
| 1576 |
+
if language == "English":
|
| 1577 |
+
query = "How to control high blood pressure naturally?"
|
| 1578 |
+
else:
|
| 1579 |
+
query = "قدرتی طور پر ہائی ��لڈ پریشر کو کیسے کنٹرول کریں؟"
|
| 1580 |
+
st.session_state.chat_history.append({"role": "user", "content": query})
|
| 1581 |
+
st.rerun()
|
| 1582 |
+
|
| 1583 |
+
with col_qa4:
|
| 1584 |
+
if st.button("🍎 Nutrition", use_container_width=True):
|
| 1585 |
+
if language == "English":
|
| 1586 |
+
query = "What is a healthy diet for heart health?"
|
| 1587 |
+
else:
|
| 1588 |
+
query = "دل کی صحت کے لیے صحت مند غذا کیا ہے؟"
|
| 1589 |
+
st.session_state.chat_history.append({"role": "user", "content": query})
|
| 1590 |
+
st.rerun()
|
| 1591 |
+
|
| 1592 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 1593 |
+
|
| 1594 |
+
with tab3:
|
| 1595 |
+
# Medical Reports
|
| 1596 |
+
st.markdown('<div class="section-container">', unsafe_allow_html=True)
|
| 1597 |
+
|
| 1598 |
+
if language == "English":
|
| 1599 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">📋 Medical Reports & Analytics</h2>', unsafe_allow_html=True)
|
| 1600 |
+
st.write("Download comprehensive medical reports and view assessment analytics")
|
| 1601 |
+
else:
|
| 1602 |
+
st.markdown('<h2 style="color: #00401A; border-bottom: 3px solid #00401A; padding-bottom: 10px;">📋 طبی رپورٹس اور تجزیات</h2>', unsafe_allow_html=True)
|
| 1603 |
+
st.write("جامع طبی رپورٹس ڈاؤن لوڈ کریں اور تشخیص کے تجزیات دیکھیں")
|
| 1604 |
+
|
| 1605 |
+
if st.session_state.assessment_history:
|
| 1606 |
+
# Latest assessment
|
| 1607 |
+
latest_assessment = st.session_state.assessment_history[-1]
|
| 1608 |
+
|
| 1609 |
+
# Download PDF report
|
| 1610 |
+
if language == "English":
|
| 1611 |
+
st.subheader("Download Patient Report")
|
| 1612 |
+
else:
|
| 1613 |
+
st.subheader("مریض رپورٹ ڈاؤن لوڈ کریں")
|
| 1614 |
+
|
| 1615 |
+
pdf_generator = PDFReportGenerator()
|
| 1616 |
+
pdf_bytes = pdf_generator.generate_report(
|
| 1617 |
+
latest_assessment['patient_data'],
|
| 1618 |
+
latest_assessment['risk_scores'],
|
| 1619 |
+
language
|
| 1620 |
+
)
|
| 1621 |
+
|
| 1622 |
+
if language == "English":
|
| 1623 |
+
st.markdown(create_download_link(pdf_bytes, "sehatai_medical_report.pdf", "📥 Download Medical Report (PDF)"), unsafe_allow_html=True)
|
| 1624 |
+
else:
|
| 1625 |
+
st.markdown(create_download_link(pdf_bytes, "sehatai_medical_report.pdf", "📥 طبی رپورٹ ڈاؤن لوڈ کریں (PDF)"), unsafe_allow_html=True)
|
| 1626 |
+
|
| 1627 |
+
# Analytics Section
|
| 1628 |
+
if language == "English":
|
| 1629 |
+
st.subheader("Assessment Analytics")
|
| 1630 |
+
else:
|
| 1631 |
+
st.subheader("تشخیص کے تجزیات")
|
| 1632 |
+
|
| 1633 |
+
col_anal1, col_anal2, col_anal3 = st.columns(3)
|
| 1634 |
+
|
| 1635 |
+
with col_anal1:
|
| 1636 |
+
st.metric(
|
| 1637 |
+
"Total Assessments" if language == "English" else "کل تشخیص",
|
| 1638 |
+
len(st.session_state.assessment_history)
|
| 1639 |
+
)
|
| 1640 |
+
|
| 1641 |
+
with col_anal2:
|
| 1642 |
+
latest_priority = latest_assessment['risk_scores']['priority']
|
| 1643 |
+
st.metric(
|
| 1644 |
+
"Current Priority Score" if language == "English" else "موجودہ ترجیحی اسکور",
|
| 1645 |
+
f"{latest_priority:.1%}"
|
| 1646 |
+
)
|
| 1647 |
+
|
| 1648 |
+
with col_anal3:
|
| 1649 |
+
high_risk_count = sum(1 for assess in st.session_state.assessment_history
|
| 1650 |
+
if assess['risk_scores']['priority'] > 0.7)
|
| 1651 |
+
st.metric(
|
| 1652 |
+
"High Risk Cases" if language == "English" else "اعلی خطرہ والے معاملات",
|
| 1653 |
+
high_risk_count
|
| 1654 |
+
)
|
| 1655 |
+
|
| 1656 |
+
# Risk distribution chart
|
| 1657 |
+
if len(st.session_state.assessment_history) > 1:
|
| 1658 |
+
risk_data = pd.DataFrame([
|
| 1659 |
+
{
|
| 1660 |
+
'Heart Risk': assess['risk_scores']['heart'],
|
| 1661 |
+
'Diabetes Risk': assess['risk_scores']['diabetes'],
|
| 1662 |
+
'Hypertension Risk': assess['risk_scores']['hypertension'],
|
| 1663 |
+
'Assessment': i+1
|
| 1664 |
+
} for i, assess in enumerate(st.session_state.assessment_history[-5:])
|
| 1665 |
+
])
|
| 1666 |
+
|
| 1667 |
+
fig = px.line(risk_data, x='Assessment', y=['Heart Risk', 'Diabetes Risk', 'Hypertension Risk'],
|
| 1668 |
+
title="Risk Trend Analysis" if language == "English" else "خطرے کے رجحان کا تجزیہ",
|
| 1669 |
+
color_discrete_map={
|
| 1670 |
+
'Heart Risk': '#FF6B6B',
|
| 1671 |
+
'Diabetes Risk': '#4ECDC4',
|
| 1672 |
+
'Hypertension Risk': '#45B7D1'
|
| 1673 |
+
})
|
| 1674 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 1675 |
+
|
| 1676 |
+
else:
|
| 1677 |
+
if language == "English":
|
| 1678 |
+
st.info("👆 Complete a patient assessment to generate reports and view analytics")
|
| 1679 |
+
else:
|
| 1680 |
+
st.info("👆 رپورٹس تیار کرنے اور تجزیات دیکھنے کے لیے مریض کی تشخیص مکمل کریں")
|
| 1681 |
+
|
| 1682 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 1683 |
+
|
| 1684 |
+
if __name__ == "__main__":
|
| 1685 |
+
main()
|