File size: 4,137 Bytes
67a1743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a890d57
67a1743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
"""
Test script to verify Entry Classifier is working correctly
"""

import json
from core_classes import GeminiAPI, EntryClassifier, ClinicalBackground

# Mock API for testing
class MockGeminiAPI:
    def __init__(self):
        self.call_counter = 0
    
    def generate_response(self, system_prompt, user_prompt, temperature=0.7, call_type=""):
        self.call_counter += 1
        
        # Simulate real Gemini responses based on user message
        user_message = user_prompt.split('PATIENT MESSAGE: "')[1].split('"')[0] if 'PATIENT MESSAGE: "' in user_prompt else ""
        
        print(f"🔍 Testing message: '{user_message}'")
        
        # Improved classification logic
        if any(word in user_message.lower() for word in ["вправ", "спорт", "тренув", "реабілітац", "фізичн", "exercise", "workout", "fitness"]):
            if any(word in user_message.lower() for word in ["болить", "біль", "pain", "симптом"]):
                return '{"K": "Lifestyle Mode", "V": "hybrid", "T": "2024-09-05T12:00:00Z"}'
            else:
                return '{"K": "Lifestyle Mode", "V": "on", "T": "2024-09-05T12:00:00Z"}'
        elif any(word in user_message.lower() for word in ["болить", "біль", "нудота", "симптом", "pain", "nausea"]):
            return '{"K": "Lifestyle Mode", "V": "off", "T": "2024-09-05T12:00:00Z"}'
        else:
            return '{"K": "Lifestyle Mode", "V": "off", "T": "2024-09-05T12:00:00Z"}'

def test_entry_classifier():
    """Test Entry Classifier with various messages"""
    
    print("🧪 Testing Entry Classifier with improved prompts...")
    
    # Create mock API and classifier
    api = MockGeminiAPI()
    classifier = EntryClassifier(api)
    
    # Create mock clinical background
    clinical_bg = ClinicalBackground(
        patient_id="test",
        patient_name="Serhii",
        patient_age="52",
        active_problems=["Type 2 diabetes", "Hypertension"],
        past_medical_history=[],
        current_medications=["Amlodipine"],
        allergies="None",
        vital_signs_and_measurements=[],
        laboratory_results=[],
        assessment_and_plan="",
        critical_alerts=[],
        social_history={},
        recent_clinical_events=[]
    )
    
    # Test cases
    test_cases = [
        ("усе добре давай займемося вправами", "on", "Clear exercise request"),
        ("хочу почати тренуватися", "on", "Fitness motivation"),
        ("поговоримо про реабілітацію", "on", "Rehabilitation discussion"),
        ("давай займемося спортом", "on", "Sports activity request"),
        ("які вправи мені підходять", "on", "Exercise inquiry"),
        ("у мене болить голова", "off", "Medical symptom"),
        ("привіт", "off", "Greeting"),
        ("хочу займатися спортом але болить спина", "hybrid", "Mixed lifestyle + medical"),
    ]
    
    results = []
    for message, expected, description in test_cases:
        try:
            classification = classifier.classify(message, clinical_bg)
            actual = classification.get("V", "unknown")
            status = "✅" if actual == expected else "❌"
            results.append((status, message, actual, expected, description))
            print(f"  {status} '{message}' → V={actual} (expected: {expected}) - {description}")
        except Exception as e:
            print(f"  ❌ Error testing '{message}': {e}")
            results.append(("❌", message, "error", expected, description))
    
    # Summary
    passed = sum(1 for r in results if r[0] == "✅")
    total = len(results)
    print(f"\n📊 Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("🎉 All Entry Classifier tests passed!")
    else:
        print("⚠️ Some tests failed - Entry Classifier needs adjustment")
    
    return passed == total

if __name__ == "__main__":
    test_entry_classifier()