from db import get_connection | |
def save_history(user_id, symptoms, diagnosis): | |
with get_connection() as conn, conn.cursor() as cur: | |
cur.execute("INSERT INTO mb_history (user_id, symptoms, diagnosis) VALUES (%s, %s, %s)", | |
(user_id, symptoms, diagnosis)) | |
conn.commit() | |
def get_history(user_id): | |
with get_connection() as conn, conn.cursor() as cur: | |
cur.execute(""" | |
SELECT timestamp, symptoms, diagnosis | |
FROM mb_history | |
WHERE user_id = %s | |
ORDER BY timestamp DESC | |
""", (user_id,)) | |
return cur.fetchall() | |