diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs new file mode 100644 index 0000000..9995140 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs @@ -0,0 +1,107 @@ +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; +using PolyclinicContracts.StoragesContracts; +using PolyclinicContracts.ViewModels; + +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 List GetDiagnoses() + { + var diagnoses = _diagnoseStorage.GetFullList(); + var courses = _courseStorage.GetFullList(); + var symptomes = _symptomStorage.GetFullList(); + + var result = new List(); + + 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) + { + var dianoseReportModel = new ReportDiagnoseWithCoursesAndSymptomesViewModel { + DiagnoseId = diagnose.Id, + DiagnoseName = diagnose.Name, + DiagnoseComment = diagnose.Comment, + DiagnoseDateStart = diagnose.DateStartDiagnose, + DiagnoseDateStop = diagnose.DateStopDiagnose, + Courses = diagnoseCourses.Select(x => (x.DaysCount, x.PillsPerDay)).ToList(), + Symptomes = diagnoseSymptomes.Select(x => x.Name).ToList() + }; + result.Add(dianoseReportModel); + } + } + return result; + } + + public List GetMedicamentsByDiagnoses(ReportBindingModel model) + { + var diagnoses = _diagnoseStorage + .GetFilteredList(new DiagnoseSearchModel + { + From = model.DateFrom, + To = model.DateTo + }); + + var symptomes = _symptomStorage + .GetFullList(); + + var medicaments = _medicamentStorage.GetFullList(); + + List result = new(); + + foreach (var diagnose in diagnoses) + { + 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)); + } + var diagnoseReportModel = new ReportMedicamentsByDiagnoseViewModel { + DiagnoseId = diagnose.Id, + DiagnoseName = diagnose.Name, + DiagnoseComment = diagnose.Comment, + DiagnoseDateStart = diagnose.DateStartDiagnose, + DiagnoseDateStop = diagnose.DateStopDiagnose, + Medicaments = diagnoseMedicaments.Distinct().Select(x => x.Name).ToList() + }; + result.Add(diagnoseReportModel); + } + return result; + } + + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveSecureComponentToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveSecuresToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs new file mode 100644 index 0000000..c046a8a --- /dev/null +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs @@ -0,0 +1,14 @@ +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.ViewModels; + +namespace PolyclinicContracts.BusinessLogicsContracts +{ + public interface IImplementerReportLogic + { + List GetDiagnoses(); + List GetMedicamentsByDiagnoses(ReportBindingModel model); + void SaveSecuresToWordFile(ReportBindingModel model); + void SaveSecureComponentToExcelFile(ReportBindingModel model); + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/Polyclinic/PolyclinicContracts/SearchModels/DiagnoseSearchModel.cs b/Polyclinic/PolyclinicContracts/SearchModels/DiagnoseSearchModel.cs index 1ccfb4c..7921c20 100644 --- a/Polyclinic/PolyclinicContracts/SearchModels/DiagnoseSearchModel.cs +++ b/Polyclinic/PolyclinicContracts/SearchModels/DiagnoseSearchModel.cs @@ -5,7 +5,7 @@ public int? Id { get; set; } public string? Name { get; set; } public int? UserId { get; set; } - public DateTime? From { get; } - public DateTime? To { get; } + public DateTime? From { get; set; } + public DateTime? To { get; set; } } } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnoseWithCoursesAndSymptomesViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnoseWithCoursesAndSymptomesViewModel.cs new file mode 100644 index 0000000..df52d06 --- /dev/null +++ b/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnoseWithCoursesAndSymptomesViewModel.cs @@ -0,0 +1,13 @@ +namespace PolyclinicContracts.ViewModels +{ + public class ReportDiagnoseWithCoursesAndSymptomesViewModel + { + public int DiagnoseId { get; set; } + public string DiagnoseName { get; set; } = string.Empty; + public string DiagnoseComment { get; set; } = string.Empty; + public DateTime DiagnoseDateStart { get; set; } + public DateTime? DiagnoseDateStop { get; set; } = null; + public List Symptomes { get; set; } = new(); + public List<(int DaysCount, int PillsPerDay)> Courses = new(); + } +} diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportMedicamentsByDiagnoseViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportMedicamentsByDiagnoseViewModel.cs new file mode 100644 index 0000000..e9b3bf6 --- /dev/null +++ b/Polyclinic/PolyclinicContracts/ViewModels/ReportMedicamentsByDiagnoseViewModel.cs @@ -0,0 +1,12 @@ +namespace PolyclinicContracts.ViewModels +{ + public class ReportMedicamentsByDiagnoseViewModel + { + public int DiagnoseId { get; set; } + public string DiagnoseName { get; set; } = string.Empty; + public string DiagnoseComment { get; set; } = string.Empty; + public DateTime DiagnoseDateStart { get; set; } + public DateTime? DiagnoseDateStop { get; set; } = null; + public List Medicaments = new(); + } +}