File size: 910 Bytes
f814c93
cb51934
 
 
f814c93
cb51934
f814c93
cb51934
f814c93
 
 
 
cb5b0e4
2231cf4
 
f814c93
 
 
 
 
2231cf4
 
 
 
 
f814c93
2231cf4
f814c93
 
 
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
# db.py
import os
import psycopg2
import psycopg2.extras
import urllib.parse as urlparse

DATABASE_URL = os.getenv("DATABASE_URL")  # full connection string

def fetch_client_info(identifier: str):
    """Return a dict row from insurance_clients by client_id or policy_number."""
    if not identifier:
        return None
    try:
        conn = psycopg2.connect(DATABASE_URL, cursor_factory=psycopg2.extras.RealDictCursor)
        cur = conn.cursor()
        cur.execute("""
            SELECT * FROM insurance_clients
            WHERE client_id = %s OR policy_number = %s
            LIMIT 1;
        """, (identifier, identifier))
        row = cur.fetchone()
        cur.close()
        conn.close()
        if row:
            return dict(row)
        return None
    except Exception as e:
        # keep simple logging - the Space logs will show this
        print("DB error:", e)
        return None