File size: 3,173 Bytes
c024705
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Check professional ID and fix the API query
"""

import sqlite3

def check_professional_data():
    """Check professional data and fix the query"""
    
    DB_FILE = "aimhsa.db"
    
    try:
        conn = sqlite3.connect(DB_FILE)
        
        print("="*60)
        print("CHECKING PROFESSIONAL DATA")
        print("="*60)
        
        # Check professionals
        professionals = conn.execute("""
            SELECT id, username, first_name, last_name, email
            FROM professionals 
            ORDER BY id
        """).fetchall()
        
        print(f"Found {len(professionals)} professionals:")
        for p in professionals:
            print(f"   ID: {p[0]} | Username: {p[1]} | Name: {p[2]} {p[3]} | Email: {p[4]}")
        
        # Check the specific booking
        booking = conn.execute("""
            SELECT booking_id, user_account, professional_id, risk_level, risk_score
            FROM automated_bookings 
            WHERE booking_id = 'd63a7794-a89c-452c-80a6-24691e3cb848'
        """).fetchone()
        
        if booking:
            print(f"\nBooking found:")
            print(f"   Booking ID: {booking[0]}")
            print(f"   User Account: {booking[1]}")
            print(f"   Professional ID: {booking[2]}")
            print(f"   Risk Level: {booking[3]}")
            print(f"   Risk Score: {booking[4]}")
        else:
            print("\n❌ Booking not found")
        
        # Test the exact query from the API with the correct professional ID
        if booking:
            professional_id = booking[2]
            print(f"\nTesting API query with professional ID: {professional_id}")
            
            test_query = conn.execute("""
                SELECT ab.booking_id, ab.conv_id, ab.user_account, ab.user_ip, ab.risk_level, ab.risk_score,
                       ab.detected_indicators, ab.conversation_summary, ab.booking_status, 
                       ab.scheduled_datetime, ab.session_type, ab.created_ts, ab.updated_ts,
                       u.fullname, u.email, u.telephone, u.province, u.district, u.created_at
                FROM automated_bookings ab
                LEFT JOIN users u ON ab.user_account = u.username
                WHERE ab.booking_id = ? AND ab.professional_id = ?
            """, ('d63a7794-a89c-452c-80a6-24691e3cb848', professional_id)).fetchone()
            
            if test_query:
                print("✅ API query successful!")
                print(f"   Booking ID: {test_query[0]}")
                print(f"   User Account: {test_query[2]}")
                print(f"   Full Name: {test_query[13]}")
                print(f"   Email: {test_query[14]}")
                print(f"   Phone: {test_query[15]}")
                print(f"   Province: {test_query[16]}")
                print(f"   District: {test_query[17]}")
                print(f"   Created At: {test_query[18]}")
            else:
                print("❌ API query failed - no results")
        
        conn.close()
        
    except Exception as e:
        print(f"❌ Database Error: {e}")

if __name__ == "__main__":
    check_professional_data()