File size: 2,277 Bytes
542c765
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test the new schema-to-text-to-chat conversion pipeline
"""
import sys
from pathlib import Path

# Add backend to path
sys.path.insert(0, str(Path(__file__).parent))

from app.routers.doctor_upload import convert_analysis_to_text

# Sample schema from PDF analysis
sample_analysis = {
    "findings": [
        {
            "parameter": "Haemoglobin",
            "value": 9.2,
            "unit": "g/dL",
            "status": "LOW",
            "reference": "13.0 - 17.0"
        },
        {
            "parameter": "Iron",
            "value": 45,
            "unit": "µg/dL",
            "status": "LOW",
            "reference": "60 - 170"
        },
        {
            "parameter": "Vitamin B12",
            "value": 180,
            "unit": "pg/mL",
            "status": "LOW",
            "reference": "200 - 900"
        },
        {
            "parameter": "RBC",
            "value": 3.8,
            "unit": "10^6/µL",
            "status": "LOW",
            "reference": "4.5 - 5.5"
        },
        {
            "parameter": "WBC",
            "value": 7.2,
            "unit": "10^3/µL",
            "status": "NORMAL",
            "reference": "4.5 - 11.0"
        }
    ],
    "severity_level": "NORMAL",
    "affected_organs": ["Blood", "Bone Marrow"],
    "dietary_flags": ["Low Iron Intake", "Insufficient B12"],
    "exercise_flags": ["Fatigue Limiting Activity"]
}

print("=" * 80)
print("SCHEMA-TO-TEXT CONVERSION TEST")
print("=" * 80)

print("\n📊 Input Schema:")
print("-" * 80)
for finding in sample_analysis["findings"]:
    print(f"  {finding['parameter']}: {finding['value']} {finding['unit']} ({finding['status']})")

print("\n" + "=" * 80)
print("⚙️  Converting schema to natural language text...")
print("=" * 80)

text_output = convert_analysis_to_text(sample_analysis)

print("\n📝 Output Text (what will be sent to chat system):")
print("-" * 80)
print(text_output)
print("-" * 80)

print("\n✅ Conversion successful!")
print("\nThis text will now be:")
print("1. Sent to the chat system as user input")
print("2. Processed by get_enhanced_mock_response()")
print("3. Returned as human-friendly doctor response")
print("\n🎯 Result: Schema → Text → Chat Response (all in one flow)")