Update Diabetic Dost backend

This commit is contained in:
Sanika Gurav
2026-10-16 09:35:34 +05:30
parent e7a92cafd4
commit 18f55dba58
+11 -6
View File
@@ -55,7 +55,7 @@ def load_config(config_path: str = "config.yaml") -> Dict[str, Any]:
for candidate in [config_path, "backend/config.yaml", "../config.yaml", str(BASE_DIR / "config.yaml")]:
if os.path.exists(candidate):
try:
import yaml
import yaml # type: ignore[import-untyped]
with open(candidate, "r", encoding="utf-8") as f:
return yaml.safe_load(f) or {}
except Exception:
@@ -470,7 +470,9 @@ async def websocket_session_endpoint(websocket: WebSocket):
elif event_type in ["AUDIO_CHUNK", "ASR_FINAL", "PATIENT_TURN"]:
transcript = msg.get("transcript", "")
sid = msg.get("session_id") or session_id
sid = str(msg.get("session_id") or session_id or "")
if not sid:
continue
await websocket.send_json({"event": "AI_THINKING", "session_id": sid})
@@ -674,7 +676,7 @@ async def send_whatsapp_report(
admin: Dict[str, Any] = Depends(require_admin_auth)
):
"""Send clinical summary PDF via WhatsApp to a given phone number."""
if not REPORTS_ENABLED:
if not REPORTS_ENABLED or not GLOBAL_WHATSAPP_SERVICE:
raise HTTPException(status_code=503, detail="Report module not available.")
summary = GLOBAL_ORCHESTRATOR.get_session_summary(session_id)
@@ -703,7 +705,7 @@ async def patient_send_report(
req: WhatsAppSendRequest
):
"""Patient-facing: send their own report via WhatsApp after consultation."""
if not REPORTS_ENABLED:
if not REPORTS_ENABLED or not GLOBAL_WHATSAPP_SERVICE:
return {"status": "unavailable", "message": "WhatsApp delivery not configured."}
summary = GLOBAL_ORCHESTRATOR.get_session_summary(session_id)
@@ -736,7 +738,7 @@ class DoctorSummarySendRequest(BaseModel):
async def get_doctor_summary_preview_endpoint(
session_id: str,
doctor_phone: Optional[str] = None,
request: Request = None
request: Optional[Request] = None
):
"""
Returns the complete structured summary text, patient metadata, and pre-calculated
@@ -752,6 +754,9 @@ async def get_doctor_summary_preview_endpoint(
if not summary:
raise HTTPException(status_code=404, detail=f"Session '{session_id}' summary not found.")
if not GLOBAL_WHATSAPP_SERVICE:
raise HTTPException(status_code=503, detail="WhatsApp service is not available.")
doc_phone = doctor_phone or os.getenv("DOCTOR_WHATSAPP_NUMBER", "").strip() or "+918830578295"
host_url = str(request.base_url) if request else ""
preview = GLOBAL_WHATSAPP_SERVICE.get_doctor_summary_preview(doc_phone, summary, host_url=host_url)
@@ -767,7 +772,7 @@ async def get_doctor_summary_preview_endpoint(
async def send_summary_to_doctor_endpoint(
req: DoctorSummarySendRequest,
session_id: Optional[str] = None,
request: Request = None
request: Optional[Request] = None
):
"""
Sends the complete clinical pre-screening summary directly to the doctor.