File size: 929 Bytes
dda3dc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from chatbot.intents import detect_intent
from models.bart_explainer import generate_explanation

def chatbot_response(question, note, risk_score):
    intent = detect_intent(question)

    if intent == "appointment":
        if "follow" in note.lower():
            return "Your discharge summary mentions a follow-up. Please consult your provider for scheduling."
        return "No specific follow-up appointment is mentioned in the discharge summary."

    if intent == "severity":
        if risk_score > 0.6:
            level = "high"
        elif risk_score > 0.3:
            level = "moderate"
        else:
            level = "low"

        return f"Your readmission risk is considered {level}."

    if intent == "explanation":
        return generate_explanation(note, risk_score)

    return "I can help explain risk, follow-up, or discharge information. I cannot provide medical advice."