feat: Refactor report generation to use async methods and improve error handling; enhance spirometry table extraction with better CSV formatting

This commit is contained in:
bolade
2025-10-04 10:35:02 +01:00
parent 358898b7db
commit 0a735d88c8
5 changed files with 123 additions and 38 deletions
+7 -3
View File
@@ -12,7 +12,6 @@ from pathlib import Path
from fastapi import FastAPI, File, Form, HTTPException, UploadFile
from fastapi.responses import FileResponse
from pydantic import BaseModel
from services.report_generator import ReportGeneratorService
app = FastAPI(
@@ -138,7 +137,7 @@ async def generate_report(
}
# Generate report using the service
result = report_service.generate_report(
result = await report_service.generate_report(
spirometry_pdf_path=str(spirometry_path),
pnoe_csv_path=str(pnoe_path),
seca_excel_path=str(seca_path),
@@ -153,9 +152,14 @@ async def generate_report(
)
except Exception as e:
import traceback
error_details = traceback.format_exc()
print(f"ERROR: {error_details}") # This will show in terminal
raise HTTPException(
status_code=500,
detail=f"Error generating report: {str(e)}",
detail=f"Error generating report: {str(e)}\n{error_details}",
)
finally:
# Close file handles