Ali2206 commited on
Commit
af6102d
·
verified ·
1 Parent(s): 8ac50b9

Update analysis.py

Browse files
Files changed (1) hide show
  1. analysis.py +16 -2
analysis.py CHANGED
@@ -15,11 +15,25 @@ async def create_alert(patient_id: str, risk_data: dict):
15
  "score": risk_data["score"],
16
  "factors": risk_data["factors"],
17
  "timestamp": datetime.utcnow(),
18
- "acknowledged": False
 
 
 
 
 
 
 
 
 
 
19
  }
20
  await alerts_collection.insert_one(alert_doc)
 
 
 
 
21
  logger.warning(f"⚠️ Created suicide risk alert for patient {patient_id}")
22
-
23
  async def analyze_patient_report(patient_id: Optional[str], report_content: str, file_type: str, file_content: bytes):
24
  identifier = patient_id if patient_id else compute_file_content_hash(file_content)
25
  report_data = {"identifier": identifier, "content": report_content, "file_type": file_type}
 
15
  "score": risk_data["score"],
16
  "factors": risk_data["factors"],
17
  "timestamp": datetime.utcnow(),
18
+ "acknowledged": False,
19
+ # Facebook-like notification fields
20
+ "notification": {
21
+ "type": NotificationType.RISK_ALERT,
22
+ "status": NotificationStatus.UNREAD,
23
+ "title": f"Suicide Risk: {risk_data['level'].capitalize()}",
24
+ "message": f"Patient {patient_id} shows {risk_data['level']} risk factors",
25
+ "icon": "⚠️",
26
+ "action_url": f"/patient/{patient_id}/risk-assessment",
27
+ "priority": "high" if risk_data["level"] in ["high", "severe"] else "medium"
28
+ }
29
  }
30
  await alerts_collection.insert_one(alert_doc)
31
+
32
+ # Trigger real-time notification
33
+ await broadcast_notification(alert_doc["notification"])
34
+
35
  logger.warning(f"⚠️ Created suicide risk alert for patient {patient_id}")
36
+ return alert_doc
37
  async def analyze_patient_report(patient_id: Optional[str], report_content: str, file_type: str, file_content: bytes):
38
  identifier = patient_id if patient_id else compute_file_content_hash(file_content)
39
  report_data = {"identifier": identifier, "content": report_content, "file_type": file_type}