استخدام AI لتحليل النصوص الطبية.
# تحليل النصوص الطبية بالذكاء الاصطناعي
import iris
import re
from collections import Counter
class MedicalTextAnalyzer:
def __init__(self):
self.conn = iris.connect('localhost', 1972, 'USER')
def extract_entities(self, text):
# استخراج الأعراض
symptoms = ['صداع', 'حمى', 'سعال', 'ألم', 'التهاب', 'غثيان', 'دوار']
found = [s for s in symptoms if s in text]
# استخراج الأدوية
drugs = ['باراسيتامول', 'أموكسيسيلين', 'ميتفورمين', 'أوميبرازول']
found_drugs = [d for d in drugs if d in text]
return {
'symptoms': found,
'drugs': found_drugs,
'word_count': len(text.split())
}
def classify_note(self, text):
# تصنيف الملاحظة السريرية
if any(w in text for w in ['طوارئ', 'حرج', 'عاجل']):
return 'urgent'
elif any(w in text for w in ['روتين', 'متابعة', 'فحص']):
return 'routine'
else:
return 'general'
def generate_summary(self, patient_id):
# تلخيص بيانات المريض
cursor = self.conn.cursor()
cursor.execute("""
SELECT Description FROM Hospital.Models.Diagnosis
WHERE PatientId = ? ORDER BY DiagnosedDate DESC LIMIT 5
""", [patient_id])
diagnoses = [row[0] for row in cursor]
summary = f"ملخص المريض {patient_id}: "
summary += f"عدد التشخيصات: {len(diagnoses)}. "
if diagnoses:
summary += f"آخر تشخيص: {diagnoses[0]}"
return summary