# 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 }