using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.ViewModels; using PolyclinicDataModels.Models; namespace PolyclinicBusinessLogic.BusinessLogics { public class ImplementerReportLogic : IImplementerReportLogic { private readonly IDiagnoseStorage _diagnoseStorage; private readonly IMedicamentStorage _medicamentStorage; private readonly ICourseStorage _courseStorage; private readonly ISymptomStorage _symptomStorage; public ImplementerReportLogic(IDiagnoseStorage diagnoseStorage, IMedicamentStorage medicamentStorage, ICourseStorage courseStorage, ISymptomStorage symptomStorage) { _diagnoseStorage = diagnoseStorage; _medicamentStorage = medicamentStorage; _courseStorage = courseStorage; _symptomStorage = symptomStorage; } public ReportDiagnosesByPeriodViewModel GetReportDiagnosesByPeriod(DateTime? dateStart, DateTime? dateEnd) { var diagnoses = _diagnoseStorage.GetFilteredList(new DiagnoseSearchModel { From = dateStart, To = dateEnd }); var courses = _courseStorage.GetFullList(); var symptomes = _symptomStorage.GetFullList(); var report = new ReportDiagnosesByPeriodViewModel(); foreach (var diagnose in diagnoses) { var diagnoseCourses = courses.Where(x => x.CourseDiagnoses.ContainsKey(diagnose.Id)).ToList(); var diagnoseSymptomes = symptomes.Where(x => x.SymptomDiagnoses.ContainsKey(diagnose.Id)).ToList(); if (diagnoseCourses.Count > 0 && diagnoseSymptomes.Count > 0) { report.DiagnosesData.Add((diagnose, diagnoseSymptomes, diagnoseCourses)); } } report.DateStart = dateStart; report.DateEnd = dateEnd; return report; } public List GetReportMedicamentsByDiagnoses(List diagnoses) { List diagnoseViewModels = diagnoses.Select(x => _diagnoseStorage.GetElement(new DiagnoseSearchModel { Id = x.Id })).ToList(); var symptomes = _symptomStorage.GetFullList(); var medicaments = _medicamentStorage.GetFullList(); List report = new(); foreach (var diagnose in diagnoseViewModels) { var diagnoseSymptomes = symptomes .Where(x => x.SymptomDiagnoses.ContainsKey(diagnose.Id)) .ToList(); var diagnoseMedicaments = new List(); foreach (var symptom in diagnoseSymptomes) { diagnoseMedicaments.AddRange(medicaments.Where(x => x.SymptomId == symptom.Id)); } report.Add(new ReportMedicamentsByDiagnoseViewModel { Diagnose = diagnose, Medicaments = diagnoseMedicaments.DistinctBy(x => x.Name).ToList() }); } return report; } public void SaveReportDiagnosesWithSymptomesAndCoursesByPeriodToPdfFile(ReportInfoModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel) { throw new NotImplementedException(); } public void SaveReportMedicamentsByDiagnosesToExcelFile(ReportInfoModel reportInfo, List reportModel) { throw new NotImplementedException(); } public void SaveReportMedicamentsByDiagnosesToWordFile(ReportInfoModel reportInfo, List reportModel) { throw new NotImplementedException(); } } }