Initial commit - Diabetic Dost
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from .doctor_service import DoctorDeliveryService, GLOBAL_DOCTOR_DELIVERY
|
||||
|
||||
__all__ = ["DoctorDeliveryService", "GLOBAL_DOCTOR_DELIVERY"]
|
||||
@@ -0,0 +1,46 @@
|
||||
import logging
|
||||
from typing import Dict, Any, List, Optional
|
||||
from datetime import datetime, timezone
|
||||
|
||||
logger = logging.getLogger("sehat_doctor_delivery")
|
||||
|
||||
class DoctorDeliveryService:
|
||||
"""Delivers completed pre-screening summaries and real-time emergency alerts to clinical queue."""
|
||||
def __init__(self):
|
||||
self.emergency_feed: List[Dict[str, Any]] = []
|
||||
self.completed_queue: List[Dict[str, Any]] = []
|
||||
|
||||
def push_emergency_alert(self, emergency_event: Dict[str, Any]):
|
||||
self.emergency_feed.insert(0, emergency_event)
|
||||
logger.warning(f"🚨 CLINICAL EMERGENCY PUSHED TO DOCTOR FEED: {emergency_event.get('session_id')}")
|
||||
|
||||
def push_completed_summary(self, summary: Dict[str, Any]):
|
||||
self.completed_queue.insert(0, summary)
|
||||
session_id = summary.get("session_id")
|
||||
logger.info(f"✅ CLINICAL SUMMARY PUSHED TO DOCTOR QUEUE: {session_id}")
|
||||
|
||||
# Automatic dispatch to doctor via WhatsApp if DOCTOR_WHATSAPP_NUMBER is configured in .env
|
||||
import os
|
||||
doc_phone = os.getenv("DOCTOR_WHATSAPP_NUMBER", "").strip()
|
||||
if doc_phone:
|
||||
try:
|
||||
from report.whatsapp_service import GLOBAL_WHATSAPP_SERVICE
|
||||
logger.info(f"Auto-dispatching patient summary to doctor at {doc_phone} via WhatsApp...")
|
||||
GLOBAL_WHATSAPP_SERVICE.send_doctor_summary_whatsapp(doc_phone, summary)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to auto-dispatch WhatsApp summary to doctor: {e}")
|
||||
|
||||
def send_summary_to_doctor(self, doctor_phone: str, summary: Dict[str, Any], pdf_bytes: Optional[bytes] = None) -> Dict[str, Any]:
|
||||
"""Manually trigger sending a completed summary to a specified doctor's WhatsApp number."""
|
||||
from report.whatsapp_service import GLOBAL_WHATSAPP_SERVICE
|
||||
return GLOBAL_WHATSAPP_SERVICE.send_doctor_summary_whatsapp(doctor_phone, summary, pdf_bytes)
|
||||
|
||||
def get_emergency_feed(self) -> List[Dict[str, Any]]:
|
||||
return self.emergency_feed
|
||||
|
||||
def get_doctor_queue(self) -> List[Dict[str, Any]]:
|
||||
return self.completed_queue
|
||||
|
||||
|
||||
# Global instance
|
||||
GLOBAL_DOCTOR_DELIVERY = DoctorDeliveryService()
|
||||
Reference in New Issue
Block a user