Update src/report_generator.py
Browse files- src/report_generator.py +157 -159
src/report_generator.py
CHANGED
@@ -150,6 +150,7 @@ Do NOT invent any data. Return ONLY the JSON object.
|
|
150 |
def build_medical_report(data: dict) -> bytes:
|
151 |
"""
|
152 |
Generates a PDF from the extracted JSON and returns PDF bytes.
|
|
|
153 |
"""
|
154 |
# Create a temporary file for the PDF
|
155 |
fd, temp_path = tempfile.mkstemp(suffix='.pdf')
|
@@ -165,29 +166,36 @@ def build_medical_report(data: dict) -> bytes:
|
|
165 |
bottomMargin=2*cm
|
166 |
)
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
# Set up styles with more professional fonts
|
169 |
styles = getSampleStyleSheet()
|
170 |
|
171 |
-
# Title style
|
172 |
styles.add(ParagraphStyle(
|
173 |
name='ReportTitle',
|
174 |
fontName='Helvetica-Bold',
|
175 |
-
fontSize=
|
176 |
-
leading=
|
177 |
alignment=TA_CENTER,
|
178 |
-
spaceAfter=0.
|
179 |
-
textColor=
|
180 |
))
|
181 |
|
182 |
# Section heading style
|
183 |
styles.add(ParagraphStyle(
|
184 |
name='SectionHeading',
|
185 |
fontName='Helvetica-Bold',
|
186 |
-
fontSize=
|
187 |
-
leading=
|
188 |
spaceAfter=0.1*inch,
|
189 |
alignment=TA_LEFT,
|
190 |
-
textColor=
|
191 |
))
|
192 |
|
193 |
# Normal text style
|
@@ -197,7 +205,8 @@ def build_medical_report(data: dict) -> bytes:
|
|
197 |
fontSize=10,
|
198 |
leading=12,
|
199 |
spaceAfter=0.1*inch,
|
200 |
-
alignment=TA_LEFT
|
|
|
201 |
))
|
202 |
|
203 |
# Company info style
|
@@ -207,248 +216,237 @@ def build_medical_report(data: dict) -> bytes:
|
|
207 |
fontSize=9,
|
208 |
leading=11,
|
209 |
alignment=TA_RIGHT,
|
210 |
-
textColor=
|
211 |
))
|
212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
# Initialize elements list
|
214 |
elems = []
|
215 |
|
216 |
-
# Add logo and company header
|
217 |
-
logo_path = "src/assets/Logo_no_background.png"
|
218 |
|
219 |
-
# Get logo image
|
220 |
logo_img = get_reportlab_image(logo_path)
|
221 |
|
222 |
-
#
|
223 |
company_info = Paragraph(
|
224 |
"""
|
225 |
-
<b>Daease</b><br/>
|
226 |
-
Website: http://daease.com
|
227 |
-
Email: [email protected]
|
228 |
""",
|
229 |
styles['CompanyInfo']
|
230 |
)
|
231 |
|
|
|
232 |
if logo_img:
|
233 |
-
# Use the logo in the header table
|
234 |
header_table = Table([[logo_img, company_info]], colWidths=[doc.width/2.0]*2)
|
235 |
header_table.setStyle(TableStyle([
|
236 |
('VALIGN', (0, 0), (-1, -1), 'TOP'),
|
237 |
('ALIGN', (0, 0), (0, 0), 'LEFT'),
|
238 |
('ALIGN', (1, 0), (1, 0), 'RIGHT'),
|
239 |
('BOTTOMPADDING', (0, 0), (-1, -1), 10),
|
|
|
240 |
]))
|
|
|
241 |
else:
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
('TEXTCOLOR', (0, 0), (0, 0), colors.navy),
|
252 |
-
]))
|
253 |
|
254 |
-
elems.append(header_table)
|
255 |
elems.append(Spacer(1, 0.3*inch))
|
256 |
|
257 |
-
# Add title
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
spaceAfter=0.3*inch,
|
265 |
-
textColor=colors.navy
|
266 |
)
|
267 |
-
elems.append(
|
268 |
elems.append(Spacer(1, 0.2*inch))
|
269 |
|
270 |
-
# Add a horizontal line
|
271 |
-
|
272 |
-
|
273 |
-
('LINEABOVE', (0, 0), (-1, -1), 1,
|
|
|
274 |
]))
|
275 |
-
elems.append(
|
276 |
-
elems.append(Spacer(1, 0.
|
277 |
|
278 |
-
#
|
279 |
patient = data.get('patient', {})
|
280 |
|
281 |
-
#
|
282 |
patient_data = [
|
283 |
-
['Patient Information', '', ''],
|
284 |
-
['Name
|
285 |
-
['Age
|
286 |
-
['Gender
|
287 |
-
['Visit Date
|
288 |
]
|
289 |
|
290 |
-
# Create a more structured patient table with better column distribution
|
291 |
patient_table = Table(
|
292 |
patient_data,
|
293 |
-
colWidths=[doc.width * 0.
|
294 |
-
rowHeights=[0.4*inch, 0.
|
295 |
)
|
|
|
296 |
patient_table.setStyle(TableStyle([
|
297 |
-
# Header
|
298 |
-
('
|
299 |
-
('
|
300 |
-
('FONTNAME', (0, 0), (2, 0), 'Helvetica-Bold'),
|
301 |
-
('SPAN', (0, 0), (2, 0)), # Span all columns in header
|
302 |
-
('ALIGN', (0, 0), (2, 0), 'CENTER'),
|
303 |
|
304 |
-
# Label column styling
|
305 |
-
('FONTNAME', (0, 1), (0, -1), 'Helvetica-Bold'),
|
306 |
('ALIGN', (0, 1), (0, -1), 'RIGHT'),
|
307 |
-
('RIGHTPADDING', (0, 1), (0, -1), 10),
|
308 |
-
|
309 |
-
# Value column styling (second column)
|
310 |
-
('ALIGN', (1, 1), (1, -1), 'LEFT'),
|
311 |
-
|
312 |
-
# Table borders and grid
|
313 |
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
|
314 |
-
('
|
315 |
-
('BOX', (0, 0), (1, -1), 1, colors.darkblue),
|
316 |
|
317 |
-
#
|
318 |
-
('BACKGROUND', (0,
|
319 |
-
('
|
|
|
|
|
|
|
|
|
320 |
]))
|
321 |
|
322 |
elems.append(patient_table)
|
323 |
-
elems.append(Spacer(1, 0.
|
324 |
-
|
325 |
-
#
|
326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
if isinstance(content, list):
|
328 |
content = '\n'.join(map(str, content))
|
329 |
elif content is not None and not isinstance(content, str):
|
330 |
content = str(content)
|
331 |
-
|
332 |
-
|
333 |
-
content = '–'
|
334 |
-
|
335 |
-
# Create a gradient-like effect with nested tables
|
336 |
section_data = [
|
337 |
-
#
|
338 |
-
|
339 |
-
ParagraphStyle(
|
340 |
-
name='TableHeader',
|
341 |
-
fontName='Helvetica-Bold',
|
342 |
-
fontSize=11,
|
343 |
-
textColor=colors.white,
|
344 |
-
alignment=TA_LEFT
|
345 |
-
))],
|
346 |
-
# Content row
|
347 |
-
[Paragraph(content, styles['NormalText'])]
|
348 |
]
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
#
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
('
|
|
|
|
|
|
|
|
|
359 |
|
360 |
-
#
|
361 |
-
('
|
362 |
-
('RIGHTPADDING', (0, 1), (0, 1), 10),
|
363 |
-
('TOPPADDING', (0, 1), (0, 1), 8),
|
364 |
-
('BOTTOMPADDING', (0, 1), (0, 1), 8),
|
365 |
-
('BACKGROUND', (0, 1), (0, 1), colors.white),
|
366 |
|
367 |
-
#
|
368 |
-
('
|
369 |
]))
|
370 |
|
371 |
-
elems.append(
|
372 |
-
|
373 |
-
# Add all medical information sections as tables
|
374 |
-
add_section_table("Chief Complaint", data.get('chief_complaint'))
|
375 |
-
add_section_table("History of Present Illness", data.get('history_of_present_illness'))
|
376 |
-
add_section_table("Past Medical History", data.get('past_medical_history'))
|
377 |
-
add_section_table("Medications", data.get('medications'))
|
378 |
-
add_section_table("Allergies", data.get('allergies'))
|
379 |
-
add_section_table("Examination Findings", data.get('examination'))
|
380 |
-
add_section_table("Diagnosis", data.get('diagnosis'))
|
381 |
-
add_section_table("Recommendations", data.get('recommendations'))
|
382 |
-
add_section_table("Reasoning", data.get('reasoning'))
|
383 |
-
add_section_table("Sources", data.get('sources'))
|
384 |
|
385 |
# Add AI signature section
|
386 |
elems.append(Spacer(1, 0.4*inch))
|
387 |
|
388 |
# Add a horizontal line before signature
|
389 |
-
|
390 |
-
|
391 |
-
('LINEABOVE', (0, 0), (-1, -1), 0.5,
|
|
|
392 |
]))
|
393 |
-
elems.append(
|
394 |
elems.append(Spacer(1, 0.2*inch))
|
395 |
|
396 |
-
#
|
397 |
-
signature_text = Paragraph("
|
398 |
-
ai_name = Paragraph("
|
399 |
|
400 |
-
# Use the
|
401 |
-
signature_img = get_reportlab_image("src/assets/
|
402 |
|
403 |
if signature_img:
|
404 |
-
# Create a 3-column table for better alignment
|
405 |
sig_table = Table(
|
406 |
-
[[signature_text, ''
|
407 |
-
[signature_img, ''
|
408 |
-
[ai_name, ''
|
409 |
-
colWidths=[doc.width * 0.3, doc.width * 0.
|
|
|
410 |
)
|
411 |
|
412 |
sig_table.setStyle(TableStyle([
|
413 |
('ALIGN', (0, 0), (0, -1), 'CENTER'),
|
414 |
('VALIGN', (0, 0), (0, -1), 'MIDDLE'),
|
|
|
415 |
]))
|
416 |
elems.append(sig_table)
|
417 |
else:
|
418 |
-
# Text-only fallback for signature
|
419 |
sig_text = Paragraph(
|
420 |
-
"
|
421 |
-
|
422 |
-
|
423 |
-
fontName='Helvetica-Bold',
|
424 |
-
fontSize=10,
|
425 |
-
alignment=TA_LEFT,
|
426 |
-
spaceAfter=0.1*inch
|
427 |
-
)
|
428 |
)
|
429 |
elems.append(sig_text)
|
430 |
|
431 |
-
# Add disclaimer with
|
432 |
elems.append(Spacer(1, 0.3*inch))
|
433 |
disclaimer = Paragraph(
|
434 |
-
"
|
435 |
-
|
436 |
-
|
437 |
ParagraphStyle(
|
438 |
name='Disclaimer',
|
439 |
fontName='Helvetica-Oblique',
|
440 |
fontSize=8,
|
441 |
-
|
442 |
-
borderWidth=1,
|
443 |
-
borderColor=colors.lightgrey,
|
444 |
-
borderPadding=5,
|
445 |
-
borderRadius=2
|
446 |
)
|
447 |
)
|
448 |
elems.append(disclaimer)
|
449 |
|
450 |
-
# Build the PDF document
|
451 |
-
doc.build(elems)
|
452 |
|
453 |
# Read PDF bytes
|
454 |
with open(temp_path, 'rb') as file:
|
|
|
150 |
def build_medical_report(data: dict) -> bytes:
|
151 |
"""
|
152 |
Generates a PDF from the extracted JSON and returns PDF bytes.
|
153 |
+
Modern dark theme version with minimal design.
|
154 |
"""
|
155 |
# Create a temporary file for the PDF
|
156 |
fd, temp_path = tempfile.mkstemp(suffix='.pdf')
|
|
|
166 |
bottomMargin=2*cm
|
167 |
)
|
168 |
|
169 |
+
# Custom colors for dark theme
|
170 |
+
background_color = colors.black
|
171 |
+
text_color = colors.white
|
172 |
+
accent_color = colors.purple
|
173 |
+
secondary_color = colors.lavender
|
174 |
+
highlight_color = colors.mediumorchid
|
175 |
+
|
176 |
# Set up styles with more professional fonts
|
177 |
styles = getSampleStyleSheet()
|
178 |
|
179 |
+
# Title style with gradient effect
|
180 |
styles.add(ParagraphStyle(
|
181 |
name='ReportTitle',
|
182 |
fontName='Helvetica-Bold',
|
183 |
+
fontSize=20,
|
184 |
+
leading=24,
|
185 |
alignment=TA_CENTER,
|
186 |
+
spaceAfter=0.3*inch,
|
187 |
+
textColor=highlight_color
|
188 |
))
|
189 |
|
190 |
# Section heading style
|
191 |
styles.add(ParagraphStyle(
|
192 |
name='SectionHeading',
|
193 |
fontName='Helvetica-Bold',
|
194 |
+
fontSize=14,
|
195 |
+
leading=16,
|
196 |
spaceAfter=0.1*inch,
|
197 |
alignment=TA_LEFT,
|
198 |
+
textColor=accent_color
|
199 |
))
|
200 |
|
201 |
# Normal text style
|
|
|
205 |
fontSize=10,
|
206 |
leading=12,
|
207 |
spaceAfter=0.1*inch,
|
208 |
+
alignment=TA_LEFT,
|
209 |
+
textColor=text_color
|
210 |
))
|
211 |
|
212 |
# Company info style
|
|
|
216 |
fontSize=9,
|
217 |
leading=11,
|
218 |
alignment=TA_RIGHT,
|
219 |
+
textColor=secondary_color
|
220 |
))
|
221 |
|
222 |
+
# Setup canvas callback to draw background
|
223 |
+
def add_page_background(canvas, doc):
|
224 |
+
canvas.saveState()
|
225 |
+
canvas.setFillColor(background_color)
|
226 |
+
canvas.rect(0, 0, doc.pagesize[0], doc.pagesize[1], fill=1)
|
227 |
+
canvas.restoreState()
|
228 |
+
|
229 |
# Initialize elements list
|
230 |
elems = []
|
231 |
|
232 |
+
# Add logo and company header
|
233 |
+
logo_path = "src/assets/Logo_no_background.png"
|
234 |
|
235 |
+
# Get logo image
|
236 |
logo_img = get_reportlab_image(logo_path)
|
237 |
|
238 |
+
# Company info
|
239 |
company_info = Paragraph(
|
240 |
"""
|
241 |
+
<b><font color="#E0B0FF">Daease</font></b><br/>
|
242 |
+
Website: <font color="#E0B0FF">http://daease.com/</font><br/>
|
243 |
+
Email: <font color="#E0B0FF">[email protected]</font>
|
244 |
""",
|
245 |
styles['CompanyInfo']
|
246 |
)
|
247 |
|
248 |
+
# Add header with logo or text-only fallback
|
249 |
if logo_img:
|
|
|
250 |
header_table = Table([[logo_img, company_info]], colWidths=[doc.width/2.0]*2)
|
251 |
header_table.setStyle(TableStyle([
|
252 |
('VALIGN', (0, 0), (-1, -1), 'TOP'),
|
253 |
('ALIGN', (0, 0), (0, 0), 'LEFT'),
|
254 |
('ALIGN', (1, 0), (1, 0), 'RIGHT'),
|
255 |
('BOTTOMPADDING', (0, 0), (-1, -1), 10),
|
256 |
+
('BACKGROUND', (0, 0), (-1, -1), background_color),
|
257 |
]))
|
258 |
+
elems.append(header_table)
|
259 |
else:
|
260 |
+
company_header = Paragraph(
|
261 |
+
"""
|
262 |
+
<b><font color="#E0B0FF" size="14">Daease</font></b><br/>
|
263 |
+
Website: <font color="#E0B0FF">http://daease.com/</font><br/>
|
264 |
+
Email: <font color="#E0B0FF">[email protected]</font>
|
265 |
+
""",
|
266 |
+
styles['CompanyInfo']
|
267 |
+
)
|
268 |
+
elems.append(company_header)
|
|
|
|
|
269 |
|
|
|
270 |
elems.append(Spacer(1, 0.3*inch))
|
271 |
|
272 |
+
# Add title with subtle gradient-like effect
|
273 |
+
title = Paragraph(
|
274 |
+
'<font color="#E0B0FF">Daease</font> '
|
275 |
+
'<font color="#D8BFD8">Medical</font> '
|
276 |
+
'<font color="#DA70D6">Consultation</font> '
|
277 |
+
'<font color="#BA55D3">Report</font>',
|
278 |
+
styles['ReportTitle']
|
|
|
|
|
279 |
)
|
280 |
+
elems.append(title)
|
281 |
elems.append(Spacer(1, 0.2*inch))
|
282 |
|
283 |
+
# Add a horizontal separator line
|
284 |
+
separator = Table([['']], colWidths=[doc.width], rowHeights=[1])
|
285 |
+
separator.setStyle(TableStyle([
|
286 |
+
('LINEABOVE', (0, 0), (-1, -1), 1, accent_color),
|
287 |
+
('BACKGROUND', (0, 0), (-1, -1), background_color),
|
288 |
]))
|
289 |
+
elems.append(separator)
|
290 |
+
elems.append(Spacer(1, 0.3*inch))
|
291 |
|
292 |
+
# --- TABLE 1: Patient Information ---
|
293 |
patient = data.get('patient', {})
|
294 |
|
295 |
+
# Create a cleaner patient info table
|
296 |
patient_data = [
|
297 |
+
[Paragraph('<font color="#BA55D3"><b>Patient Information</b></font>', styles['SectionHeading']), ''],
|
298 |
+
['<font color="#D8BFD8">Name:</font>', patient.get('name', '–')],
|
299 |
+
['<font color="#D8BFD8">Age:</font>', patient.get('age', '–')],
|
300 |
+
['<font color="#D8BFD8">Gender:</font>', patient.get('gender', '–')],
|
301 |
+
['<font color="#D8BFD8">Visit Date:</font>', data.get('visit_date', datetime.now().strftime("%Y-%m-%d"))]
|
302 |
]
|
303 |
|
|
|
304 |
patient_table = Table(
|
305 |
patient_data,
|
306 |
+
colWidths=[doc.width * 0.3, doc.width * 0.7],
|
307 |
+
rowHeights=[0.4*inch, 0.25*inch, 0.25*inch, 0.25*inch, 0.25*inch]
|
308 |
)
|
309 |
+
|
310 |
patient_table.setStyle(TableStyle([
|
311 |
+
# Header styling
|
312 |
+
('SPAN', (0, 0), (1, 0)), # Span the header cell
|
313 |
+
('ALIGN', (0, 0), (0, 0), 'CENTER'),
|
|
|
|
|
|
|
314 |
|
315 |
+
# Label column styling
|
|
|
316 |
('ALIGN', (0, 1), (0, -1), 'RIGHT'),
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
|
318 |
+
('RIGHTPADDING', (0, 1), (0, -1), 12),
|
|
|
319 |
|
320 |
+
# Cell styling
|
321 |
+
('BACKGROUND', (0, 0), (-1, -1), background_color),
|
322 |
+
('TEXTCOLOR', (1, 1), (1, -1), text_color),
|
323 |
+
|
324 |
+
# Borders
|
325 |
+
('GRID', (0, 1), (1, -1), 0.5, secondary_color),
|
326 |
+
('BOX', (0, 1), (1, -1), 1, accent_color),
|
327 |
]))
|
328 |
|
329 |
elems.append(patient_table)
|
330 |
+
elems.append(Spacer(1, 0.4*inch))
|
331 |
+
|
332 |
+
# --- TABLE 2: Medical Information (All in one table) ---
|
333 |
+
# Collect all medical data
|
334 |
+
medical_sections = [
|
335 |
+
("Chief Complaint", data.get('chief_complaint')),
|
336 |
+
("History of Present Illness", data.get('history_of_present_illness')),
|
337 |
+
("Past Medical History", data.get('past_medical_history')),
|
338 |
+
("Medications", data.get('medications')),
|
339 |
+
("Allergies", data.get('allergies')),
|
340 |
+
("Examination Findings", data.get('examination')),
|
341 |
+
("Diagnosis", data.get('diagnosis')),
|
342 |
+
("Recommendations", data.get('recommendations')),
|
343 |
+
("Reasoning", data.get('reasoning')),
|
344 |
+
("Sources", data.get('sources'))
|
345 |
+
]
|
346 |
+
|
347 |
+
# Create table data
|
348 |
+
elems.append(Paragraph('<font color="#BA55D3"><b>Medical Information</b></font>', styles['SectionHeading']))
|
349 |
+
elems.append(Spacer(1, 0.1*inch))
|
350 |
+
|
351 |
+
# Create medical info rows
|
352 |
+
for title, content in medical_sections:
|
353 |
+
if not content or str(content).strip() == '':
|
354 |
+
content = '–'
|
355 |
+
|
356 |
+
# Format content as paragraphs
|
357 |
if isinstance(content, list):
|
358 |
content = '\n'.join(map(str, content))
|
359 |
elif content is not None and not isinstance(content, str):
|
360 |
content = str(content)
|
361 |
+
|
362 |
+
# Add section
|
|
|
|
|
|
|
363 |
section_data = [
|
364 |
+
[f'<font color="#D8BFD8"><b>{title}</b></font>',
|
365 |
+
Paragraph(content, styles['NormalText'])]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
]
|
367 |
|
368 |
+
section_table = Table(
|
369 |
+
section_data,
|
370 |
+
colWidths=[doc.width * 0.25, doc.width * 0.75],
|
371 |
+
rowHeights=None # Auto height
|
372 |
+
)
|
373 |
+
|
374 |
+
section_table.setStyle(TableStyle([
|
375 |
+
# Cell styling
|
376 |
+
('VALIGN', (0, 0), (0, 0), 'TOP'),
|
377 |
+
('ALIGN', (0, 0), (0, 0), 'RIGHT'),
|
378 |
+
('RIGHTPADDING', (0, 0), (0, 0), 12),
|
379 |
+
('TOPPADDING', (0, 0), (1, 0), 8),
|
380 |
+
('BOTTOMPADDING', (0, 0), (1, 0), 8),
|
381 |
|
382 |
+
# Background
|
383 |
+
('BACKGROUND', (0, 0), (-1, -1), background_color),
|
|
|
|
|
|
|
|
|
384 |
|
385 |
+
# Bottom border only
|
386 |
+
('LINEBELOW', (0, 0), (1, 0), 0.5, secondary_color),
|
387 |
]))
|
388 |
|
389 |
+
elems.append(section_table)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
|
391 |
# Add AI signature section
|
392 |
elems.append(Spacer(1, 0.4*inch))
|
393 |
|
394 |
# Add a horizontal line before signature
|
395 |
+
sig_separator = Table([['']], colWidths=[doc.width], rowHeights=[1])
|
396 |
+
sig_separator.setStyle(TableStyle([
|
397 |
+
('LINEABOVE', (0, 0), (-1, -1), 0.5, accent_color),
|
398 |
+
('BACKGROUND', (0, 0), (-1, -1), background_color),
|
399 |
]))
|
400 |
+
elems.append(sig_separator)
|
401 |
elems.append(Spacer(1, 0.2*inch))
|
402 |
|
403 |
+
# Signature text
|
404 |
+
signature_text = Paragraph('<font color="#D8BFD8"><i>Generated by</i></font>', styles['NormalText'])
|
405 |
+
ai_name = Paragraph('<font color="#BA55D3"><b>Daease AI Medical Assistant</b></font>', styles['NormalText'])
|
406 |
|
407 |
+
# Use the logo as signature if available
|
408 |
+
signature_img = get_reportlab_image("src/assets/Logo_no_background.png", width=1.2*inch, height=0.8*inch)
|
409 |
|
410 |
if signature_img:
|
|
|
411 |
sig_table = Table(
|
412 |
+
[[signature_text, ''],
|
413 |
+
[signature_img, ''],
|
414 |
+
[ai_name, '']],
|
415 |
+
colWidths=[doc.width * 0.3, doc.width * 0.7],
|
416 |
+
rowHeights=[None, None, None]
|
417 |
)
|
418 |
|
419 |
sig_table.setStyle(TableStyle([
|
420 |
('ALIGN', (0, 0), (0, -1), 'CENTER'),
|
421 |
('VALIGN', (0, 0), (0, -1), 'MIDDLE'),
|
422 |
+
('BACKGROUND', (0, 0), (-1, -1), background_color),
|
423 |
]))
|
424 |
elems.append(sig_table)
|
425 |
else:
|
|
|
426 |
sig_text = Paragraph(
|
427 |
+
'<font color="#D8BFD8"><i>Generated by</i></font><br/>'
|
428 |
+
'<font color="#BA55D3"><b>Daease AI Medical Assistant</b></font>',
|
429 |
+
styles['NormalText']
|
|
|
|
|
|
|
|
|
|
|
430 |
)
|
431 |
elems.append(sig_text)
|
432 |
|
433 |
+
# Add disclaimer with subtle styling
|
434 |
elems.append(Spacer(1, 0.3*inch))
|
435 |
disclaimer = Paragraph(
|
436 |
+
'<font color="#A9A9A9"><i>Disclaimer: This report is generated by AI for informational purposes only. '
|
437 |
+
'It should not replace professional medical advice, diagnosis, or treatment. '
|
438 |
+
'Always consult with a qualified healthcare provider for medical concerns.</i></font>',
|
439 |
ParagraphStyle(
|
440 |
name='Disclaimer',
|
441 |
fontName='Helvetica-Oblique',
|
442 |
fontSize=8,
|
443 |
+
alignment=TA_CENTER
|
|
|
|
|
|
|
|
|
444 |
)
|
445 |
)
|
446 |
elems.append(disclaimer)
|
447 |
|
448 |
+
# Build the PDF document with background
|
449 |
+
doc.build(elems, onFirstPage=add_page_background, onLaterPages=add_page_background)
|
450 |
|
451 |
# Read PDF bytes
|
452 |
with open(temp_path, 'rb') as file:
|