forked from Do-yoon/medgemma-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintent_engine.py
More file actions
58 lines (50 loc) · 1.95 KB
/
Copy pathintent_engine.py
File metadata and controls
58 lines (50 loc) · 1.95 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from domain_model import ClinicalBlackboard
from datetime import datetime
class ClinicalIntentEngine:
def evaluate_intent(self, bb: ClinicalBlackboard):
cs = bb.clinical_state
vitals = (cs.vitals_summary or "").lower()
procedure = (cs.procedure_display or "").lower()
# Clinical-context driven intent inference (no hardcoded scenario IDs)
if "acute mental change" in vitals or "stat" in procedure:
cs.intent = "emergent"
cs.priority_score = 0.95
elif "fever" in vitals or "pain" in vitals:
cs.intent = "same_day_addon"
cs.priority_score = 0.75
else:
cs.intent = "scheduled"
cs.priority_score = 0.4
cs.last_recomputed = datetime.utcnow()
bb.reasoning_trace.append({
"agent": "intent_engine",
"decision": f"Intent classified as {cs.intent} based on clinical context.",
"priority_score": cs.priority_score
})
return bb
def apply_emergency_override(bb: ClinicalBlackboard):
cs = bb.clinical_state
if cs.intent != "emergent":
return bb
if cs.pa_status.value == "required_missing":
cs.override_reason = "Emergency Exception — PA Bypassed"
bb.reasoning_trace.append({
"agent": "intent_engine",
"decision": "Emergency Override Applied: PA condition dropped."
})
return bb
def recompute_priority(bb: ClinicalBlackboard):
cs = bb.clinical_state
vitals = (cs.vitals_summary or "").lower()
# Dynamically recompute priority from clinical indicators
score = cs.priority_score
if "acute mental change" in vitals:
score = 1.0 # highest priority
elif "fever" in vitals:
score = 0.8 # infection concern
elif "pain" in vitals:
score = 0.7 # pain-related urgency
else:
score = 0.4 # routine
cs.priority_score = max(0.0, min(score, 1.0))
return bb