from fpdf import FPDF def generate_pdf(patient_name, notes, filename): pdf = FPDF() pdf.add_page() pdf.set_font("Arial", size=12) pdf.cell(0, 8, txt=f"Patient: {patient_name}", ln=True) pdf.ln(4) for note in notes: created = note.get('created_at', '') content = note.get('content', '') ai_analysis = note.get('ai_analysis', '') ai_suggestion = note.get('ai_suggestion', '') ai_diff = note.get('ai_differential', '') pdf.multi_cell(0, 7, txt=f"{created}\n{content}\nAI Analysis: {ai_analysis}\nAI Suggestion: {ai_suggestion}\nDifferential: {ai_diff}\n") pdf.ln(4) pdf.output(filename) return filename