Update endpoints.py
Browse files- endpoints.py +9 -3
endpoints.py
CHANGED
@@ -183,6 +183,7 @@ def create_router(agent, logger, patients_collection, analysis_collection, users
|
|
183 |
try:
|
184 |
# Fetch notifications for the current user
|
185 |
notifications = await notifications_collection.find({"user_id": current_user["email"]}).sort("timestamp", -1).to_list(length=10)
|
|
|
186 |
return [
|
187 |
{
|
188 |
"id": str(notification["_id"]),
|
@@ -382,19 +383,24 @@ def create_router(agent, logger, patients_collection, analysis_collection, users
|
|
382 |
file_type=content_type,
|
383 |
file_content=file_content
|
384 |
)
|
|
|
385 |
|
386 |
# Create a notification if suicide risk is detected
|
387 |
-
|
|
|
|
|
388 |
notification = {
|
389 |
"user_id": current_user["email"],
|
390 |
-
"message": f"Suicide risk alert for patient {patient_id}: {
|
391 |
"patient_id": patient_id,
|
392 |
"timestamp": datetime.utcnow(),
|
393 |
-
"severity": "high" if
|
394 |
"read": False
|
395 |
}
|
396 |
await notifications_collection.insert_one(notification)
|
397 |
logger.info(f"✅ Created notification for suicide risk alert: {notification}")
|
|
|
|
|
398 |
|
399 |
if "_id" in analysis and isinstance(analysis["_id"], ObjectId):
|
400 |
analysis["_id"] = str(analysis["_id"])
|
|
|
183 |
try:
|
184 |
# Fetch notifications for the current user
|
185 |
notifications = await notifications_collection.find({"user_id": current_user["email"]}).sort("timestamp", -1).to_list(length=10)
|
186 |
+
logger.info(f"Retrieved {len(notifications)} notifications for {current_user['email']}")
|
187 |
return [
|
188 |
{
|
189 |
"id": str(notification["_id"]),
|
|
|
383 |
file_type=content_type,
|
384 |
file_content=file_content
|
385 |
)
|
386 |
+
logger.info(f"Analysis result for patient {patient_id}: {analysis}")
|
387 |
|
388 |
# Create a notification if suicide risk is detected
|
389 |
+
suicide_risk = analysis.get("suicide_risk", {})
|
390 |
+
logger.info(f"Suicide risk detected: {suicide_risk}")
|
391 |
+
if suicide_risk.get("level") != "none":
|
392 |
notification = {
|
393 |
"user_id": current_user["email"],
|
394 |
+
"message": f"Suicide risk alert for patient {patient_id}: {suicide_risk['level'].upper()} (Score: {suicide_risk['score']})",
|
395 |
"patient_id": patient_id,
|
396 |
"timestamp": datetime.utcnow(),
|
397 |
+
"severity": "high" if suicide_risk["level"] in ["moderate", "severe"] else "medium",
|
398 |
"read": False
|
399 |
}
|
400 |
await notifications_collection.insert_one(notification)
|
401 |
logger.info(f"✅ Created notification for suicide risk alert: {notification}")
|
402 |
+
else:
|
403 |
+
logger.warning(f"No suicide risk detected for patient {patient_id}, no notification created")
|
404 |
|
405 |
if "_id" in analysis and isinstance(analysis["_id"], ObjectId):
|
406 |
analysis["_id"] = str(analysis["_id"])
|