Spaces:
Runtime error
Runtime error
| """ | |
| Test Industry Modules (Healthcare and Education) | |
| Run with: python test_industry_modules.py | |
| """ | |
| import sys | |
| import os | |
| # Add parent directory to path | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from app.services.healthcare_module import ( | |
| HealthcareModule, | |
| get_healthcare_module | |
| ) | |
| from app.services.education_module import ( | |
| EducationModule, | |
| AcademicTopic, | |
| get_education_module | |
| ) | |
| def test_healthcare_symptom_checker(): | |
| """Test healthcare symptom checker""" | |
| print("=" * 60) | |
| print("TESTING HEALTHCARE SYMPTOM CHECKER") | |
| print("=" * 60) | |
| healthcare = HealthcareModule() | |
| # Test cases | |
| test_cases = [ | |
| { | |
| "symptoms": ["fever", "headache"], | |
| "description": "Mild symptoms" | |
| }, | |
| { | |
| "symptoms": ["chest pain", "shortness of breath"], | |
| "description": "Emergency symptoms" | |
| }, | |
| { | |
| "symptoms": ["cough", "fever", "nausea"], | |
| "description": "Multiple symptoms" | |
| }, | |
| ] | |
| for test_case in test_cases: | |
| print(f"\n๐ Test: {test_case['description']}") | |
| print(f"Symptoms: {', '.join(test_case['symptoms'])}") | |
| result = healthcare.check_symptoms(test_case['symptoms']) | |
| print(f"\n Severity: {result['severity']}") | |
| print(f" Urgency: {result['urgency']}") | |
| print(f" Possible Conditions: {', '.join(result['possible_conditions'][:3])}") | |
| print(f"\n Advice:\n {result['advice'].replace(chr(10), chr(10) + ' ')}") | |
| print(f"\n Disclaimer: {result['disclaimer']}") | |
| if result.get('red_flags'): | |
| print(f"\n โ ๏ธ Red Flags:") | |
| for flag in result['red_flags'][:3]: | |
| print(f" - {flag}") | |
| def test_healthcare_glossary(): | |
| """Test medical glossary""" | |
| print("\n" + "=" * 60) | |
| print("TESTING MEDICAL GLOSSARY") | |
| print("=" * 60) | |
| healthcare = HealthcareModule() | |
| medical_terms = ["hypertension", "diabetes", "asthma", "unknown_term"] | |
| for term in medical_terms: | |
| print(f"\n๐ Looking up: '{term}'") | |
| definition = healthcare.get_medical_term_definition(term) | |
| if definition: | |
| print(f" Definition: {definition['definition']}") | |
| print(f" Urdu: {definition.get('urdu', 'N/A')}") | |
| else: | |
| print(f" โ Term not found in glossary") | |
| def test_hipaa_compliance(): | |
| """Test HIPAA compliance features""" | |
| print("\n" + "=" * 60) | |
| print("TESTING HIPAA COMPLIANCE") | |
| print("=" * 60) | |
| healthcare = HealthcareModule() | |
| # Test PII masking | |
| print("\n๐ Testing PII Masking:") | |
| pii_texts = [ | |
| "My SSN is 123-45-6789 and phone is 5551234567", | |
| "Contact me at john.doe@example.com", | |
| "No PII in this text", | |
| ] | |
| for text in pii_texts: | |
| masked = healthcare.mask_pii(text) | |
| print(f"\n Original: {text}") | |
| print(f" Masked: {masked}") | |
| # Test audit logging | |
| print("\n๐ Testing Audit Logging:") | |
| healthcare.check_symptoms(["fever"]) | |
| healthcare.get_medical_term_definition("diabetes") | |
| print(f" Audit log entries: {len(healthcare.audit_log)}") | |
| if healthcare.audit_log: | |
| print(f" Latest entry:") | |
| latest = healthcare.audit_log[-1] | |
| for key, value in latest.items(): | |
| print(f" {key}: {value}") | |
| def test_education_topic_classification(): | |
| """Test education topic classification""" | |
| print("\n" + "=" * 60) | |
| print("TESTING EDUCATION TOPIC CLASSIFICATION") | |
| print("=" * 60) | |
| education = EducationModule() | |
| # Test queries | |
| test_queries = [ | |
| ("What are admission requirements?", AcademicTopic.ADMISSIONS), | |
| ("How to check my result?", AcademicTopic.RESULTS), | |
| ("What courses can I take?", AcademicTopic.COURSES), | |
| ("How much is the tuition fee?", AcademicTopic.FEES), | |
| ("Tell me about scholarships", AcademicTopic.SCHOLARSHIPS), | |
| ] | |
| print("\nClassification Results:") | |
| correct = 0 | |
| for query, expected_topic in test_queries: | |
| detected_topic = education.classify_academic_topic(query) | |
| status = "โ" if detected_topic == expected_topic else "โ" | |
| if detected_topic == expected_topic: | |
| correct += 1 | |
| print(f"\n{status} Query: '{query}'") | |
| print(f" Expected: {expected_topic.value}") | |
| print(f" Detected: {detected_topic.value}") | |
| print(f"\n๐ Accuracy: {correct}/{len(test_queries)} ({100*correct/len(test_queries):.1f}%)") | |
| def test_student_support(): | |
| """Test student support responses""" | |
| print("\n" + "=" * 60) | |
| print("TESTING STUDENT SUPPORT RESPONSES") | |
| print("=" * 60) | |
| education = EducationModule() | |
| # Test different topics | |
| topics = [ | |
| AcademicTopic.ADMISSIONS, | |
| AcademicTopic.COURSES, | |
| AcademicTopic.RESULTS, | |
| ] | |
| for topic in topics: | |
| print(f"\n๐ Topic: {topic.value.upper()}") | |
| response = education.get_student_support_response( | |
| query=f"Tell me about {topic.value}", | |
| topic=topic | |
| ) | |
| print(f" Related Topics: {', '.join(response['related_topics'][:3])}") | |
| print(f"\n Guidance:\n {response['guidance'].replace(chr(10), chr(10) + ' ')}") | |
| if response['common_questions']: | |
| print(f"\n Common Questions:") | |
| for q in response['common_questions'][:2]: | |
| print(f" - {q}") | |
| def test_academic_glossary(): | |
| """Test academic glossary""" | |
| print("\n" + "=" * 60) | |
| print("TESTING ACADEMIC GLOSSARY") | |
| print("=" * 60) | |
| education = EducationModule() | |
| academic_terms = ["gpa", "semester", "transcript", "unknown_term"] | |
| for term in academic_terms: | |
| print(f"\n๐ Looking up: '{term}'") | |
| definition = education.get_academic_term_definition(term) | |
| if definition: | |
| print(f" Definition: {definition['definition']}") | |
| if 'urdu' in definition: | |
| print(f" Urdu: {definition['urdu']}") | |
| if 'range' in definition: | |
| print(f" Range: {definition['range']}") | |
| else: | |
| print(f" โ Term not found in glossary") | |
| def test_admission_checklist(): | |
| """Test admission checklist""" | |
| print("\n" + "=" * 60) | |
| print("TESTING ADMISSION CHECKLIST") | |
| print("=" * 60) | |
| education = EducationModule() | |
| checklist = education.get_admission_checklist() | |
| print("\nโ Admission Checklist:") | |
| for item in checklist: | |
| print(f"\n Step {item['step']}: {item['title']}") | |
| print(f" {item['description']}") | |
| print(f" ุงุฑุฏู: {item['urdu']}") | |
| if __name__ == "__main__": | |
| print("\n๐ Starting Industry Module Tests\n") | |
| try: | |
| # Healthcare tests | |
| test_healthcare_symptom_checker() | |
| test_healthcare_glossary() | |
| test_hipaa_compliance() | |
| # Education tests | |
| test_education_topic_classification() | |
| test_student_support() | |
| test_academic_glossary() | |
| test_admission_checklist() | |
| print("\n" + "=" * 60) | |
| print("โ ALL TESTS COMPLETED") | |
| print("=" * 60 + "\n") | |
| except Exception as e: | |
| print(f"\nโ TEST FAILED: {e}") | |
| import traceback | |
| traceback.print_exc() | |