public async Task <RedirectToRouteResult> RedistributionOfWeights() { using (var transaction = db.Database.BeginTransaction()) { try { db.SymptomsWeights.RemoveRange(db.SymptomsWeights.Where(sw => true)); //удаление всех записей таблицы //Проход по всем диагнозам в БД foreach (var diagnosis in db.Diagnoses.OrderBy(d => d.Id)) { uint countSymptoms = 0; Dictionary <int, int> countSymptomsInDiagnosis = new Dictionary <int, int>(); //Подсчет кол-ва встречающихся симптомов в диагнозе foreach (var report in db.DoctorReports.Where(r => r.DiagnosisId == diagnosis.Id)) { List <int> idSymptoms = Symptom.GetSymptomsInt(report.IdSymptoms); foreach (var idSymptom in idSymptoms) { if (!countSymptomsInDiagnosis.ContainsKey(idSymptom)) { countSymptomsInDiagnosis[idSymptom] = 0; } countSymptomsInDiagnosis[idSymptom]++; countSymptoms++; } } if (countSymptoms <= 0) { continue; } double koef = 100.0 / countSymptoms; //коэффициент важности встречи симптома Dictionary <int, double> weightsSymptoms = new Dictionary <int, double>(); foreach (var key in countSymptomsInDiagnosis.Keys) { weightsSymptoms[key] = countSymptomsInDiagnosis[key] * koef; } db.SymptomsWeights.AddRange(GetSymptomWeightsByDiagnosis(diagnosis.Id, weightsSymptoms)); } await db.SaveChangesAsync(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } return(RedirectToAction("Index", "Cabinet")); }
public async Task <ActionResult> DoctorReport(int id) { User user = (User)Session["currentUser"]; DoctorReport report = await db.DoctorReports.FindAsync(id); List <int> symptomsId = Symptom.GetSymptomsInt(report.IdSymptoms); List <string> symptoms = new List <string>(); foreach (var symptomId in symptomsId) { Symptom s = db.Symptoms.Find(symptomId); symptoms.Add(s.Name); } ViewBag.symptoms = symptoms; return(View(report)); }
public async Task <ActionResult> ShowPatientInfo(int?id, int?idAppointment) { User patient = await db.Patients.FindAsync(id), doctor = (User)Session["currentUser"]; //Appointment appointment = await db.Appointments.Where(ap => ap.IdPatient == patient.Id && ap.IdDoctor == doctor.Id).OrderByDescending(ap=>ap.Day).FirstAsync(); Appointment appointment = db.Appointments.Find(idAppointment); List <int> symptomsId = Symptom.GetSymptomsInt(appointment.IdSymptoms); List <Symptom> symptoms = new List <Symptom>(); foreach (var symptomId in symptomsId) { Symptom symptom = db.Symptoms.Find(symptomId); symptoms.Add(symptom); } ViewBag.appointment = appointment; ViewBag.symptoms = symptoms; return(View(patient)); }