krishnasimha commited on
Commit
4f0bba7
·
verified ·
1 Parent(s): 54a2a71

Update pages/4_View_Patient_Records.py

Browse files
Files changed (1) hide show
  1. pages/4_View_Patient_Records.py +23 -8
pages/4_View_Patient_Records.py CHANGED
@@ -7,25 +7,40 @@ st.title("📁 Stored Patient Reports")
7
  conn = sqlite3.connect("patients.db")
8
  c = conn.cursor()
9
 
10
- # Create table if missing
11
  c.execute("""
12
  CREATE TABLE IF NOT EXISTS reports (
13
  id INTEGER PRIMARY KEY AUTOINCREMENT,
14
- patient_name TEXT,
15
- uploaded_on TEXT,
16
- summary TEXT
17
  )
18
  """)
19
  conn.commit()
20
 
21
- # Now the table definitely exists
22
- c.execute("SELECT patient_name, uploaded_on, summary FROM reports")
 
 
 
 
 
 
 
 
 
23
  data = c.fetchall()
24
 
25
  if len(data) == 0:
26
  st.info("No reports found.")
27
  else:
28
  for name, date, summary in data:
29
- st.write(f"### {name} {date}")
30
- st.write(summary)
 
 
 
 
31
  st.write("---")
 
 
 
 
 
7
  conn = sqlite3.connect("patients.db")
8
  c = conn.cursor()
9
 
10
+ # --- Ensure base table exists and required columns exist (simple migration) ---
11
  c.execute("""
12
  CREATE TABLE IF NOT EXISTS reports (
13
  id INTEGER PRIMARY KEY AUTOINCREMENT,
14
+ patient_name TEXT
 
 
15
  )
16
  """)
17
  conn.commit()
18
 
19
+ for col in ("uploaded_on", "summary", "raw_text"):
20
+ try:
21
+ c.execute(f"ALTER TABLE reports ADD COLUMN {col} TEXT")
22
+ except sqlite3.OperationalError:
23
+ # Column already exists
24
+ pass
25
+ conn.commit()
26
+ # --------------------------------------------------------------------------
27
+
28
+ # Now the table definitely exists and has required columns
29
+ c.execute("SELECT patient_name, COALESCE(uploaded_on, ''), COALESCE(summary, '') FROM reports")
30
  data = c.fetchall()
31
 
32
  if len(data) == 0:
33
  st.info("No reports found.")
34
  else:
35
  for name, date, summary in data:
36
+ display_date = date if date else "No date"
37
+ st.write(f"### {name} — {display_date}")
38
+ if summary:
39
+ st.write(summary)
40
+ else:
41
+ st.info("No summary available for this report.")
42
  st.write("---")
43
+
44
+ # Close DB connection
45
+ conn.close()
46
+