Skip to content

Commit 8c37d3e

Browse files
committed
fix: Robustify PDF generation and parsing
1 parent 9ff4fc5 commit 8c37d3e

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

backend/pdf_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ def generate_medical_report(user_name: str, report_type: str, prediction: str, d
7878
pdf.set_text_color(100)
7979
pdf.multi_cell(0, 5, "DISCLAIMER: This report is generated by an automated analysis system for informational purposes only. It is NOT a substitute for a diagnosis by a Registered Medical Practitioner (RMP). Please consult a doctor for official medical advice.")
8080

81-
return pdf.output(dest='S').encode('latin1') # Return bytes
81+
return bytes(pdf.output())

backend/report.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def download_health_report(
7474
# 1. Fetch latest health record (Simulating a general summary for now)
7575
# In a real app, we'd aggregate multiple records.
7676
# For now, let's grab the most recent prediction if any.
77-
latest_record = db.query(models.Prediction).filter(
78-
models.Prediction.user_id == current_user.id
79-
).order_by(models.Prediction.created_at.desc()).first()
77+
latest_record = db.query(models.HealthRecord).filter(
78+
models.HealthRecord.user_id == current_user.id
79+
).order_by(models.HealthRecord.timestamp.desc()).first()
8080

8181
report_data = {
8282
"age": 30, # Default/Placeholder if profile empty
@@ -92,11 +92,15 @@ def download_health_report(
9292
advice_list = ["maintain a balanced diet", "regular exercise"]
9393

9494
if latest_record:
95-
prediction_val = f"{latest_record.record_type.capitalize()} Analysis: {latest_record.prediction_result}"
96-
# Extract clinical data from the record if stored in a structured way
97-
# (Assuming models.Prediction has a 'input_data' JSON column or similar,
98-
# skipping complex parsing for this hotfix)
99-
pass
95+
prediction_val = f"{latest_record.record_type.capitalize()} Analysis: {latest_record.prediction}"
96+
# Extract clinical data
97+
import json
98+
try:
99+
if latest_record.data:
100+
parsed_data = json.loads(latest_record.data)
101+
report_data.update(parsed_data)
102+
except Exception as e:
103+
logger.warning(f"Failed to parse record data: {e}")
100104

101105
# 2. Generate PDF using the existing service
102106
pdf_bytes = pdf_service.generate_medical_report(

requirements.txt

36 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)