File size: 968 Bytes
b1198f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re


def classify_role(user_message: str) -> str | None:
    """Return an inferred role from the user's message using regex cues."""
    text = (user_message or "").lower()

    if re.search(r"\b(caregiver|care giver|caring for|supporting|helping)\b", text):
        return "caregiver"

    if re.search(r"\b(pregnant|pregnancy|gestational|pregnant woman|gestational diabetes)\b", text):
        return "patient"

    if re.search(r"\b(diet|nutrition|meal plan|glycemic|carbohydrate|food facts|calorie|keto|vegetarian|vegan|grocery|menu)\b", text):
        return "dietary"

    if re.search(r"\b(study|research|paper|trial|meta-analysis|randomized|cohort|evidence|data|epidemiology)\b", text):
        return "researcher"

    if re.search(r"\b(doctor|dr\.|physician|provider|clinician|prescription|diagnosis|treatment|protocol|dose|medication|management|hba1c|a1c|insulin regimen|therapy|medical advice)\b", text):
        return "clinician"

    return None