-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreports.py
More file actions
48 lines (41 loc) · 1.46 KB
/
reports.py
File metadata and controls
48 lines (41 loc) · 1.46 KB
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
# reports.py
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib import colors
from io import BytesIO
def generate_patient_pdf(records, ai_summary):
buffer = BytesIO()
p = canvas.Canvas(buffer, pagesize=letter)
width, height = letter
# Header
p.setFont("Helvetica-Bold", 16)
p.drawString(100, height - 50, "Patient Health Vital Report (2026)")
p.setFont("Helvetica", 10)
p.drawString(100, height - 70, f"Generated on: 2026-01-16")
p.line(100, height - 75, 500, height - 75)
# Table Header
p.setFont("Helvetica-Bold", 10)
y = height - 100
p.drawString(100, y, "Time")
p.drawString(200, y, "BPM")
p.drawString(250, y, "SpO2")
p.drawString(300, y, "Status")
p.drawString(400, y, "Risk Score")
# Table Content
p.setFont("Helvetica", 9)
for r in records:
y -= 20
p.drawString(100, y, str(r['timestamp']))
p.drawString(200, y, str(r['bpm']))
p.drawString(250, y, f"{r['spo2']}%")
p.drawString(300, y, r['status'])
# Display the AI Risk score we calculated earlier
p.drawString(400, y, f"{r.get('risk_score', 'N/A')}%")
# Footer/AI Recommendation
p.line(100, y - 20, 500, y - 20)
p.setFont("Helvetica-Oblique", 10)
p.drawString(100, y - 40, f"AI Summary: {ai_summary}")
p.showPage()
p.save()
buffer.seek(0)
return buffer