File size: 1,270 Bytes
eba3517
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# utils/rule_engine.py

import json
import os

class RuleEngine:
    def __init__(self, dataset_path):
        self.dataset_path = dataset_path

    def evaluate_diagnosis(self, patient_id, doctor_diagnosis):
        """
        Compares doctor's diagnosis with ground truth from metadata.
        """
        json_path = os.path.join(self.dataset_path, "json", f"{patient_id}.json")
        if not os.path.exists(json_path):
            return {"status": "error", "message": f"No data found for {patient_id}"}

        with open(json_path, "r") as f:
            patient_data = json.load(f)

        true_diagnosis = patient_data["metadata"]["disease"].lower()
        doctor_diagnosis = doctor_diagnosis.lower()

        # Simple rule-based scoring
        if doctor_diagnosis in true_diagnosis:
            score = 100
            feedback = "Excellent! Your diagnosis matches the ground truth."
        else:
            score = 60
            feedback = f"Partial match. True diagnosis: {true_diagnosis}. You may have missed key indicators."

        return {
            "patient_id": patient_id,
            "doctor_diagnosis": doctor_diagnosis,
            "true_diagnosis": true_diagnosis,
            "score": score,
            "feedback": feedback
        }