File size: 1,204 Bytes
136d8e3
5f3adb3
136d8e3
5f3adb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm
from reportlab.lib.utils import simpleSplit
def generate_pdf(path, title, soap_dict, ai_summary):
    c = canvas.Canvas(path, pagesize=A4)
    W, H = A4
    x, y = 20*mm, H - 25*mm
    def head(t, s=18):
        nonlocal y; c.setFont("Helvetica-Bold", s); c.drawString(x, y, t); y -= 8*mm
    def para(label, text, s=10):
        nonlocal y; c.setFont("Helvetica-Bold", s); c.drawString(x, y, f"{label}:"); y -= 5*mm
        c.setFont("Helvetica", s)
        for line in simpleSplit(text, "Helvetica", s, W - 40*mm):
            c.drawString(x, y, line); y -= 5*mm
        y -= 2*mm
    head(title, 18)
    para("Subjective", soap_dict.get("subjective",""))
    para("Objective", soap_dict.get("objective",""))
    para("Assessment", "\n".join(soap_dict.get("assessment",[])))
    para("Plan", "\n".join(soap_dict.get("plan",[])))
    para("Red Flags", "\n".join(soap_dict.get("red_flags",[])))
    para("Follow-up", soap_dict.get("follow_up",""))
    para("Citations", "\n".join(soap_dict.get("citations",[])))
    para("AI Summary", ai_summary or "(not provided)")
    c.showPage(); c.save()