Spaces:
Runtime error
Runtime error
Update utils/rule_engine.py
Browse files- utils/rule_engine.py +38 -0
utils/rule_engine.py
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# utils/rule_engine.py
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
class RuleEngine:
|
| 7 |
+
def __init__(self, dataset_path):
|
| 8 |
+
self.dataset_path = dataset_path
|
| 9 |
+
|
| 10 |
+
def evaluate_diagnosis(self, patient_id, doctor_diagnosis):
|
| 11 |
+
"""
|
| 12 |
+
Compares doctor's diagnosis with ground truth from metadata.
|
| 13 |
+
"""
|
| 14 |
+
json_path = os.path.join(self.dataset_path, "json", f"{patient_id}.json")
|
| 15 |
+
if not os.path.exists(json_path):
|
| 16 |
+
return {"status": "error", "message": f"No data found for {patient_id}"}
|
| 17 |
+
|
| 18 |
+
with open(json_path, "r") as f:
|
| 19 |
+
patient_data = json.load(f)
|
| 20 |
+
|
| 21 |
+
true_diagnosis = patient_data["metadata"]["disease"].lower()
|
| 22 |
+
doctor_diagnosis = doctor_diagnosis.lower()
|
| 23 |
+
|
| 24 |
+
# Simple rule-based scoring
|
| 25 |
+
if doctor_diagnosis in true_diagnosis:
|
| 26 |
+
score = 100
|
| 27 |
+
feedback = "Excellent! Your diagnosis matches the ground truth."
|
| 28 |
+
else:
|
| 29 |
+
score = 60
|
| 30 |
+
feedback = f"Partial match. True diagnosis: {true_diagnosis}. You may have missed key indicators."
|
| 31 |
+
|
| 32 |
+
return {
|
| 33 |
+
"patient_id": patient_id,
|
| 34 |
+
"doctor_diagnosis": doctor_diagnosis,
|
| 35 |
+
"true_diagnosis": true_diagnosis,
|
| 36 |
+
"score": score,
|
| 37 |
+
"feedback": feedback
|
| 38 |
+
}
|