Spaces:
Sleeping
Sleeping
Update app/routes/analytics.py
Browse files- app/routes/analytics.py +18 -4
app/routes/analytics.py
CHANGED
|
@@ -88,19 +88,33 @@ async def get_all_reports(
|
|
| 88 |
current_user: Dict[str, Any] = Depends(require_role("doctor", "lab_tech", "admin")),
|
| 89 |
):
|
| 90 |
"""Returns all extracted clinical pathology reports in the EMR vault."""
|
|
|
|
| 91 |
reports = db.query(PathologyReport).order_by(PathologyReport.created_at.desc()).all()
|
| 92 |
out = []
|
| 93 |
for r in reports:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
out.append({
|
| 95 |
"id": str(r.id),
|
|
|
|
| 96 |
"file_id": str(r.document_id) if r.document_id else "",
|
| 97 |
"patient_name": r.patient_name or "Unknown Patient",
|
| 98 |
"patient_id": r.patient_id or "N/A",
|
| 99 |
"test_type": r.test_type or "General Pathology",
|
| 100 |
-
"test_date": str(r.test_date) if r.test_date else "",
|
| 101 |
-
"diagnosis": r.diagnosis or "",
|
| 102 |
-
"findings":
|
| 103 |
-
"
|
|
|
|
|
|
|
| 104 |
"created_at": str(r.created_at) if r.created_at else "",
|
| 105 |
})
|
| 106 |
return {"status": "success", "reports": out, "total": len(out)}
|
|
|
|
| 88 |
current_user: Dict[str, Any] = Depends(require_role("doctor", "lab_tech", "admin")),
|
| 89 |
):
|
| 90 |
"""Returns all extracted clinical pathology reports in the EMR vault."""
|
| 91 |
+
import json
|
| 92 |
reports = db.query(PathologyReport).order_by(PathologyReport.created_at.desc()).all()
|
| 93 |
out = []
|
| 94 |
for r in reports:
|
| 95 |
+
# Safely parse findings JSON
|
| 96 |
+
parsed_findings = []
|
| 97 |
+
if isinstance(r.findings, list):
|
| 98 |
+
parsed_findings = r.findings
|
| 99 |
+
elif isinstance(r.findings, str) and r.findings.strip():
|
| 100 |
+
try:
|
| 101 |
+
parsed_findings = json.loads(r.findings)
|
| 102 |
+
except Exception:
|
| 103 |
+
parsed_findings = []
|
| 104 |
+
|
| 105 |
out.append({
|
| 106 |
"id": str(r.id),
|
| 107 |
+
"document_id": str(r.document_id) if r.document_id else "",
|
| 108 |
"file_id": str(r.document_id) if r.document_id else "",
|
| 109 |
"patient_name": r.patient_name or "Unknown Patient",
|
| 110 |
"patient_id": r.patient_id or "N/A",
|
| 111 |
"test_type": r.test_type or "General Pathology",
|
| 112 |
+
"test_date": str(r.test_date) if r.test_date else "Recent",
|
| 113 |
+
"diagnosis": r.diagnosis or "Normal",
|
| 114 |
+
"findings": parsed_findings,
|
| 115 |
+
"findings_count": len(parsed_findings),
|
| 116 |
+
"summary": r.summary or "",
|
| 117 |
+
"clinical_summary": r.summary or "",
|
| 118 |
"created_at": str(r.created_at) if r.created_at else "",
|
| 119 |
})
|
| 120 |
return {"status": "success", "reports": out, "total": len(out)}
|