private double ConditionedSymptomsProbability(Disease disease, string symptoms) { string[] uniqueSymptoms = symptoms.Split(";"); double symptomsProbability = 1d; foreach (string symptom in uniqueSymptoms) { if (symptom.Equals("")) { continue; } int symptomID = _context.Symptoms.Where(sym => sym.SymptomName.Equals(symptom)).First().Id; SymptomDisease symptomDisease = _context.SymptomDiseases.Where(symDis => symDis.DiseaseID.Equals(disease.Id) && symDis.SymptomID.Equals(symptomID)).FirstOrDefault(); if (symptomDisease != null) { symptomsProbability *= symptomDisease.OccurenceProbability; } else { symptomsProbability *= 0.02; } } return(symptomsProbability); }
public async Task <IActionResult> PostDisease(DiseaseData disease) { if (!ModelState.IsValid) { return(BadRequest()); } var check = await _context.Diseases .Where(d => d.Name == disease.Disease.Name) .FirstOrDefaultAsync(); var type = await _context.Specialties.FindAsync(disease.Type); if (check != null || type == null) { return(BadRequest()); } disease.Disease.Specialty = type; await _context.Diseases.AddAsync(disease.Disease); foreach (var id in disease.Symptoms) { var symptomDiseases = new SymptomDisease { DiseaseID = disease.Disease.ID, SymptomID = id }; await _context.SymptomDiseases.AddAsync(symptomDiseases); } await _context.SaveChangesAsync(); return(Ok(disease)); }
private double ConditionedSymptomsRefusal(Disease disease, string symptoms) { string[] uniqueSymptoms = symptoms.Split(";"); double symptomsProbability = 1d; foreach (string symptom in uniqueSymptoms) { if (symptom.Equals("")) { continue; } Symptom symptomX = _context.Symptoms.Where(sym => sym.SymptomName.Equals(symptom)).First(); SymptomDisease symptomDisease = _context.SymptomDiseases.Where(symDis => symDis.DiseaseID.Equals(disease.Id) && symDis.SymptomID.Equals(symptomX.Id)).FirstOrDefault(); if (symptomDisease != null) { symptomsProbability *= (symptomX.OccurenceProbability - symptomDisease.OccurenceProbability * disease.GeneralProbability) / (1d - DiseaseGeneralProbability(disease)); } else { symptomsProbability *= 0.98d; } } return(symptomsProbability); }
public async Task <IActionResult> PutDisease(int id, DiseaseData item) { if (!ModelState.IsValid || id != item.Disease.ID) { return(BadRequest()); } var disease = await _context.Diseases.FindAsync(id); var type = await _context.Specialties.FindAsync(item.Type); var check = await _context.Diseases .Where(d => d.Name == item.Disease.Name) .FirstOrDefaultAsync(); if (disease == null || type == null || (check != null && check.ID != item.Disease.ID)) { return(BadRequest()); } disease.Name = item.Disease.Name; disease.Details = item.Disease.Details; disease.Specialty = type; var symptomDiseases = await _context.SymptomDiseases .Where(d => d.DiseaseID == disease.ID) .Include(s => s.Symptom) .ToListAsync(); _context.SymptomDiseases.RemoveRange(symptomDiseases); foreach (var ids in item.Symptoms) { var symptomDisease = new SymptomDisease { DiseaseID = disease.ID, SymptomID = ids }; await _context.SymptomDiseases.AddAsync(symptomDisease); } _context.Diseases.Update(disease); await _context.SaveChangesAsync(); return(Ok(disease)); }