From 2fb5871f9d264effa70f73c2e7a6ff02600111ec Mon Sep 17 00:00:00 2001 From: ValAnn Date: Mon, 27 May 2024 00:51:16 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8D=D1=82=D1=81=20=D0=BE=D0=BB=20?= =?UTF-8?q?=D0=B0=D0=B9=20=D0=B3=D0=B5=D1=81=20=D1=8D=D0=BD=D0=B4=20=D0=B1?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicDoctor.cs | 186 +++++++++- .../HospitalBusinessLogic.csproj | 2 + .../MailWorker/AbstractMailWorker.cs | 3 +- .../AbstractSaveToExcelDoctor.cs | 73 ++++ .../OfficePackage/AbstractSaveToPdfDoctor.cs | 74 ++++ .../OfficePackage/AbstractSaveToWordDoctor.cs | 61 ++++ .../HelperEnums/PdfParagraphAlignmentType.cs | 15 + .../HelperModels/ExcelInfoDoctor.cs | 20 ++ .../OfficePackage/HelperModels/PdfInfo.cs | 18 + .../HelperModels/PdfParagraph.cs | 17 + .../HelperModels/PdfRowParameters.cs | 17 + .../HelperModels/WordInfoDoctor.cs | 16 + .../Implements/SaveToExcelDoctor.cs | 333 ++++++++++++++++++ .../Implements/SaveToPdfDoctor.cs | 109 ++++++ .../Implements/SaveToWordDoctor.cs | 117 ++++++ .../BindingModels/PatientBindingModel.cs | 3 +- .../IDoctorReportLogic.cs | 12 +- .../IReportLogicDoctorcs.cs | 17 - ...hModel.cs => ListProceduresSearchModel.cs} | 2 +- .../MedicineDiseasesSearchModel.cs | 16 + .../StoragesContracts/IPatientStorage.cs | 3 + .../StoragesContracts/IRecipeStorage.cs | 2 + ...iewModel.cs => ListProceduresViewModel.cs} | 3 +- .../ViewModels/ListRecipeViewModel.cs | 1 + .../ViewModels/MedicinesDiseasesViewModel.cs | 1 + .../Implementss/PatientStorage.cs | 25 ++ .../Implementss/RecipeStorage.cs | 23 +- .../Models/Patient.cs | 1 + .../Models/Procedure.cs | 9 +- .../Models/Recipe.cs | 9 +- .../Controllers/HomeController.cs | 113 +++++- .../HospitalDoctorApp.csproj | 1 + .../HospitalDoctorApp/Views/Home/Index.cshtml | 2 +- .../Views/Home/IndexRecipes.cshtml | 2 +- .../Views/Home/LinkMedicineAndRecipe.cshtml | 28 -- .../Views/Home/PatientRecipes.cshtml | 72 ++++ .../Views/Home/ProcedureListReport.cshtml | 19 +- .../Views/Home/Report.cshtml | 2 +- .../Views/Home/Statistics.cshtml | 91 +++++ .../Views/Shared/_Layout.cshtml | 3 + .../Controllers/DiseaseController.cs | 2 +- .../Controllers/PatientController.cs | 4 +- .../Controllers/RecipeController.cs | 22 +- .../Controllers/ReportController.cs | 10 +- Hospital/HospitalRestApi/Program.cs | 29 ++ Hospital/HospitalRestApi/appsettings.json | 8 +- 46 files changed, 1491 insertions(+), 105 deletions(-) create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToExcelDoctor.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToPdfDoctor.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToWordDoctor.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/ExcelInfoDoctor.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/WordInfoDoctor.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToExcelDoctor.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToPdfDoctor.cs create mode 100644 Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs delete mode 100644 Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicDoctorcs.cs rename Hospital/HospitalContracts/SearchModels/{ListProcedureSearchModel.cs => ListProceduresSearchModel.cs} (84%) create mode 100644 Hospital/HospitalContracts/SearchModels/MedicineDiseasesSearchModel.cs rename Hospital/HospitalContracts/ViewModels/{ListProcedureViewModel.cs => ListProceduresViewModel.cs} (75%) delete mode 100644 Hospital/HospitalDoctorApp/Views/Home/LinkMedicineAndRecipe.cshtml create mode 100644 Hospital/HospitalDoctorApp/Views/Home/PatientRecipes.cshtml create mode 100644 Hospital/HospitalDoctorApp/Views/Home/Statistics.cshtml diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicDoctor.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicDoctor.cs index 1a360d1..cf60d83 100644 --- a/Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicDoctor.cs +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/ReportLogicDoctor.cs @@ -12,6 +12,8 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using HospitalBusinessLogic.OfficePackage; +using HospitalBusinessLogic.OfficePackage.HelperModels; namespace HospitalBusinessLogic.BusinessLogics { @@ -23,8 +25,12 @@ namespace HospitalBusinessLogic.BusinessLogics private readonly IProcedureStorage _procedureStorage; private readonly IRecipeStorage _recipeStorage; private readonly IDiseaseStorage _diseaseStorage; + private readonly AbstractSaveToExcelDoctor _saveToExcel; + private readonly AbstractSaveToWordDoctor _saveToWord; + private readonly AbstractSaveToPdfDoctor _saveToPdf; - public ReportLogicDoctor(IPatientStorage patientStorage, IMedicineStorage medicineStorage, IProcedureStorage procedureStorage, IRecipeStorage recipeStorage, IDiseaseStorage diseaseStorage) + public ReportLogicDoctor(IPatientStorage patientStorage, IMedicineStorage medicineStorage, IProcedureStorage procedureStorage, IRecipeStorage recipeStorage, IDiseaseStorage diseaseStorage, + AbstractSaveToExcelDoctor saveToExcel, AbstractSaveToWordDoctor saveToWord, AbstractSaveToPdfDoctor saveToPdf) { _patientStorage = patientStorage; @@ -32,10 +38,14 @@ namespace HospitalBusinessLogic.BusinessLogics _procedureStorage = procedureStorage; _recipeStorage = recipeStorage; _diseaseStorage = diseaseStorage; - } + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + + } //отчет по лекарствам и болезням у пациента за период - public List GetMedicineDiseases(ReportBindingModel model, PatientBindingModel patientModel) + /*public List GetPatientDiseases(ReportBindingModel model, PatientBindingModel patientModel) { var list = new List(); var patients = _patientStorage.GetFilteredList(new PatientSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo, Id = patientModel.Id }); @@ -44,15 +54,15 @@ namespace HospitalBusinessLogic.BusinessLogics { var purchase = _patientStorage.GetElement(new() { Id = patient.Id })!; List diseaseList = new List(); - List medicineList = new List(); + List patientList = new List(); foreach (var recipe in _recipeStorage.GetFilteredList(new RecipeSearchModel {PatientId = patient.Id})) { - foreach (var medicine in _medicineStorage.GetFilteredList(new MedicineSearchModel { RecipeId = recipe.Id })) + foreach (var patient in _patientStorage.GetFilteredList(new PatientSearchModel { RecipeId = recipe.Id })) { - medicineList.Add(new(medicine.Name)); + patientList.Add(new(patient.Name)); - foreach (var disease in medicine.MedicineRecipes) + foreach (var disease in patient.PatientRecipes) { diseaseList.Add(disease.Value.Description); } @@ -64,7 +74,7 @@ namespace HospitalBusinessLogic.BusinessLogics FIO = patient.FIO, Diseases = diseaseList, - Medicines = medicineList + Patients = patientList }; list.Add(record); } @@ -102,19 +112,161 @@ namespace HospitalBusinessLogic.BusinessLogics - public void SavePatientsToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - - public void SaveProcedureRecipesToExcelFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } public void SaveProcedureRecipesToWordFile(ReportBindingModel model) { throw new NotImplementedException(); } + + public List GetRecipeProcedures(List recipes) + { + + List ans = new(); + List>>>> response = + _recipeStorage.GetReportInfo(new ListProceduresSearchModel { recipesIds = recipes }); + + foreach (var recipe in response) + { + Dictionary counter = new(); + foreach (var patient in recipe.Item2) + { + foreach (var procedure in patient.Item2) + { + if (!counter.ContainsKey(procedure.Id)) + counter.Add(procedure.Id, (procedure, 1)); + else + { + counter[procedure.Id] = (counter[procedure.Id].Item1, counter[procedure.Id].Item2 + 1); + } + } + } + List res = new(); + foreach (var cnt in counter) + { + if (cnt.Value.Item2 != recipe.Item2.Count) + continue; + res.Add(cnt.Value.Item1); + } + ans.Add(new ListProceduresViewModel + { + RecipeName = recipe.Item1.Description, + Procedures = res + }); + } + return ans; + } + }*/ + public List GetRecipeProcedures(List recipes) + { + + List ans = new(); + List>>>> response = + _recipeStorage.GetReportInfo(new ListProceduresSearchModel { recipesIds = recipes }); + + foreach (var recipe in response) + { + Dictionary counter = new(); + foreach (var patient in recipe.Item2) + { + foreach (var procedure in patient.Item2) + { + if (!counter.ContainsKey(procedure.Id)) + counter.Add(procedure.Id, (procedure, 1)); + else + { + counter[procedure.Id] = (counter[procedure.Id].Item1, counter[procedure.Id].Item2 + 1); + } + } + } + List res = new(); + foreach (var cnt in counter) + { + if (cnt.Value.Item2 != recipe.Item2.Count) + continue; + res.Add(cnt.Value.Item1); + } + ans.Add(new ListProceduresViewModel + { + RecipeName = recipe.Item1.Description, + Procedures = res + }); + } + return ans; + } + + public void SaveProceduresToExcelFile(ListProceduresBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfoDoctor + { + FileName = model.FileName, + Title = "Список процедур для рецептов", + RecipesProcedures = GetRecipeProcedures(model.Recipes) + }); + } + + public void SaveProceduresToWordFile(ListProceduresBindingModel model) + { + _saveToWord.CreateDoc(new WordInfoDoctor + { + FileName = model.FileName, + Title = "Список процедур для рецептов", + RecipesProcedures = GetRecipeProcedures(model.Recipes) + }); + } + + public List GetPatientMedicinesAndDiseases(MedicinesDiseasesBindingModel model) + { + List ans = new(); + List>>>> responseDisease = + _patientStorage.GetDiseasesInfo(new MedicineDiseasesSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo!, DoctorId = model.DoctorId! }); + List>>>> responseMedicines = + _patientStorage.GetMedicinesInfo(new MedicineDiseasesSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo!, DoctorId = model.DoctorId! }); + Dictionary dict = new(); + + foreach (var patient in responseDisease) + { + dict.Add(patient.Item1.Id, new()); + dict[patient.Item1.Id].PatientFIO = patient.Item1.FIO; + dict[patient.Item1.Id].Date = patient.Item1.BirthDate; + foreach (var recipe in patient.Item2) + { + foreach (var guidance in recipe.Item2) + { + dict[patient.Item1.Id].Diseases.Add(guidance); + } + } + } + + foreach (var patient in responseMedicines) + { + HashSet used = new(); + foreach (var recipe in patient.Item2) + { + foreach (var medicine in recipe.Item2) + { + if (used.Contains(medicine.Id)) + continue; + dict[patient.Item1.Id].Medicines.Add(medicine); + } + } + ans.Add(dict[patient.Item1.Id]); + } + return ans; + } + + public void SavePatientsToPdfFile(MedicinesDiseasesBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список пациентов", + DateFrom = model.DateFrom!, + DateTo = model.DateTo!, + Patients = GetPatientMedicinesAndDiseases(model) + }); + + } } + } + diff --git a/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj index 3387e4a..05faa0e 100644 --- a/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj +++ b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj @@ -9,6 +9,8 @@ + + diff --git a/Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs b/Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs index 284f9c0..146d0ce 100644 --- a/Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -1,4 +1,5 @@ -using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToExcelDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToExcelDoctor.cs new file mode 100644 index 0000000..c8d4a60 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToExcelDoctor.cs @@ -0,0 +1,73 @@ +using HospitalBusinessLogic.OfficePackage.HelperEnums; +using HospitalBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelDoctor + { + public void CreateReport(ExcelInfoDoctor info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + + foreach (var rec in info.RecipesProcedures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = rec.ProcedureName, + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + + foreach (var animal in rec.Procedures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = animal.Name, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + rowIndex++; + } + + rowIndex++; + } + + SaveExcel(info); + } + + protected abstract void CreateExcel(ExcelInfoDoctor info); + + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + protected abstract void SaveExcel(ExcelInfoDoctor info); + } +} + diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToPdfDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToPdfDoctor.cs new file mode 100644 index 0000000..473ab9b --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToPdfDoctor.cs @@ -0,0 +1,74 @@ +using HospitalBusinessLogic.OfficePackage.HelperEnums; +using HospitalBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfDoctor + { + public void CreateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = + "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style + = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "4cm", "4cm", "4cm", "4cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "ФИО пациента", "Болезнь", +"Лекарство" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var patient in info.Patients) + { + CreateRow(new PdfRowParameters + { + Texts = new List { patient.Date.ToString(), patient.PatientFIO, "", "" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var disease in patient.Diseases) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", "", disease.Name.ToString(), "" }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + foreach (var medicine in patient.Medicines) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", "", "", medicine.Name.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + + } + SavePdf(info); + } + protected abstract void CreatePdf(PdfInfo info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfInfo info); + } +} \ No newline at end of file diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToWordDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToWordDoctor.cs new file mode 100644 index 0000000..5b1e1dc --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/AbstractSaveToWordDoctor.cs @@ -0,0 +1,61 @@ +using HospitalBusinessLogic.OfficePackage.HelperEnums; +using HospitalBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordDoctor + { + public void CreateDoc(WordInfoDoctor info) + { + CreateWord(info); + + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + foreach (var rec in info.RecipesProcedures) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { (rec.ProcedureName, new WordTextProperties { Size = "24", Bold=true})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + + foreach (var procedure in rec.Procedures) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { (procedure.Name, new WordTextProperties { Size = "20", Bold=false})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + } + SaveWord(info); + } + + protected abstract void CreateWord(WordInfoDoctor info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(WordInfoDoctor info); + } +} \ No newline at end of file diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/Hospital/HospitalBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..6aa2f54 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Rigth + } +} diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/ExcelInfoDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/ExcelInfoDoctor.cs new file mode 100644 index 0000000..5c1babb --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/ExcelInfoDoctor.cs @@ -0,0 +1,20 @@ +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfoDoctor + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List RecipesProcedures + { + get; + set; + } = new(); + } +} diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..2e06e72 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,18 @@ +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Patients { get; set; } = new(); + } +} diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..46328e1 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,17 @@ +using HospitalBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + + } +} diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..b0dbab8 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,17 @@ +using HospitalBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + + } +} diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/WordInfoDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/WordInfoDoctor.cs new file mode 100644 index 0000000..c74e5b6 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/HelperModels/WordInfoDoctor.cs @@ -0,0 +1,16 @@ +using HospitalContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoDoctor + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List RecipesProcedures { get; set; } = new(); + } +} diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToExcelDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToExcelDoctor.cs new file mode 100644 index 0000000..f936d67 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToExcelDoctor.cs @@ -0,0 +1,333 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; +using HospitalBusinessLogic.OfficePackage.HelperEnums; +using HospitalBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.Implements +{ + public class SaveToExcelDoctor : AbstractSaveToExcelDoctor + { + private SpreadsheetDocument? _spreadsheetDocument; + private SharedStringTablePart? _shareStringPart; + private Worksheet? _worksheet; + + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + fonts.Append(fontUsual); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 2U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + fills.Append(fill1); + fills.Append(fill2); + + var borders = new Borders() { Count = 2U }; + + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + + var borderThin = new Border(); + + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + + borders.Append(borderNoBorder); + borders.Append(borderThin); + + var cellStyleFormats = new CellStyleFormats() + { + Count = 1U + }; + var cellFormatStyle = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 0U + }; + + cellStyleFormats.Append(cellFormatStyle); + + var cellFormats = new CellFormats() + { + Count = 3U + }; + var cellFormatFont = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + ApplyFont = true + }; + var cellFormatFontAndBorder = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 1U, + FormatId = 0U, + ApplyFont = true, + ApplyBorder = true + }; + var cellFormatTitle = new CellFormat() + { + NumberFormatId = 0U, + FontId = 1U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + WrapText = true, + Horizontal = HorizontalAlignmentValues.Center + }, + ApplyFont = true + }; + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + var cellStyles = new CellStyles() { Count = 1U }; + cellStyles.Append(new CellStyle() + { + Name = "Normal", + FormatId = 0U, + BuiltinId = 0U + }); + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() + { + Count = 0U + }; + + var tableStyles = new TableStyles() + { + Count = 0U, + DefaultTableStyle = "TableStyleMedium2", + DefaultPivotStyle = "PivotStyleLight16" + }; + var stylesheetExtensionList = new StylesheetExtensionList(); + var stylesheetExtension1 = new StylesheetExtension() + { + Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" + }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() + { + DefaultSlicerStyle = "SlicerStyleLight1" + }); + var stylesheetExtension2 = new StylesheetExtension() + { + Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" + }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() + { + DefaultTimelineStyle = "TimeSlicerStyleLight1" + }); + + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfoDoctor info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + CreateStyles(workbookpart); + _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() ? _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() : _spreadsheetDocument.WorkbookPart.AddNewPart(); + + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + _worksheet = worksheetPart.Worksheet; + } + + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + + var sheetData = _worksheet.GetFirstChild(); + + if (sheetData == null) + { + return; + } + + Row row; + + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + + Cell cell; + + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + var newCell = new Cell() + { + CellReference = excelParams.CellReference + }; + row.InsertBefore(newCell, refCell); + cell = newCell; + } + + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + } + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + + protected override void SaveExcel(ExcelInfoDoctor info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + } + } +} diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToPdfDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToPdfDoctor.cs new file mode 100644 index 0000000..ccdb873 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToPdfDoctor.cs @@ -0,0 +1,109 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using HospitalBusinessLogic.OfficePackage.HelperModels; +using HospitalBusinessLogic.OfficePackage.HelperEnums; + +namespace HospitalBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdfDoctor : AbstractSaveToPdfDoctor + { + private Document? _document; + private Section? _section; + private Table? _table; + private static ParagraphAlignment + GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + /// + /// Создание стилей для документа + /// + /// + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected override void CreatePdf(PdfInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = + GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = + GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + protected override void SavePdf(PdfInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } + +} \ No newline at end of file diff --git a/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs b/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs new file mode 100644 index 0000000..4a45675 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs @@ -0,0 +1,117 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using HospitalBusinessLogic.OfficePackage.HelperEnums; +using HospitalBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.OfficePackage.Implements +{ + public class SaveToWordDoctor : AbstractSaveToWordDoctor + { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + private static JustificationValues + GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + properties.AppendChild(pageSize); + return properties; + } + + private static ParagraphProperties? + CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() + { + Val = + GetJustificationValues(paragraphProperties.JustificationType) + }); + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = + paragraphProperties.Size + }); + } + properties.AppendChild(paragraphMarkRunProperties); + return properties; + } + protected override void CreateWord(WordInfoDoctor info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, + WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + docRun.AppendChild(new Text + { + Text = run.Item1, + Space = + SpaceProcessingModeValues.Preserve + }); + docParagraph.AppendChild(docRun); + } + _docBody.AppendChild(docParagraph); + } + protected override void SaveWord(WordInfoDoctor info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalContracts/BindingModels/PatientBindingModel.cs b/Hospital/HospitalContracts/BindingModels/PatientBindingModel.cs index d0abf50..f535ab2 100644 --- a/Hospital/HospitalContracts/BindingModels/PatientBindingModel.cs +++ b/Hospital/HospitalContracts/BindingModels/PatientBindingModel.cs @@ -20,6 +20,7 @@ namespace HospitalContracts.BindingModels public int DoctorId { get; set; } public Dictionary PatientProcedures { get; set; } = new(); + public Dictionary PatientRecipes { get; set; } = new(); - } + } } diff --git a/Hospital/HospitalContracts/BusinessLogicContracts/IDoctorReportLogic.cs b/Hospital/HospitalContracts/BusinessLogicContracts/IDoctorReportLogic.cs index 0e2c1b0..0442004 100644 --- a/Hospital/HospitalContracts/BusinessLogicContracts/IDoctorReportLogic.cs +++ b/Hospital/HospitalContracts/BusinessLogicContracts/IDoctorReportLogic.cs @@ -10,10 +10,12 @@ namespace HospitalContracts.BusinessLogicContracts { public interface IDoctorReportLogic { - List GetPatients(); - List GetMedicineDiseases(ReportBindingModel model, PatientBindingModel patientModel); - void SaveProcedureRecipesToWordFile(ReportBindingModel model); - void SaveProcedureRecipesToExcelFile(ReportBindingModel model); - void SavePatientsToPdfFile(ReportBindingModel model); + // List GetPatients(); + List GetRecipeProcedures(List services); + //List GetMedicineDiseases(ReportBindingModel model, PatientBindingModel patientModel); + List GetPatientMedicinesAndDiseases(MedicinesDiseasesBindingModel services); + void SaveProceduresToWordFile(ListProceduresBindingModel model); + void SaveProceduresToExcelFile(ListProceduresBindingModel model); + void SavePatientsToPdfFile(MedicinesDiseasesBindingModel model); } } diff --git a/Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicDoctorcs.cs b/Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicDoctorcs.cs deleted file mode 100644 index 674ba2f..0000000 --- a/Hospital/HospitalContracts/BusinessLogicContracts/IReportLogicDoctorcs.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HospitalContracts.BindingModels; -using HospitalContracts.ViewModels; - -namespace HospitalContracts.BusinessLogicContracts -{ - public interface IReportLogicDoctorcs - { - List GetProcedureRecipes(List animals); - void SaveServicesToWordFile(ListProceduresBindingModel model); - void SaveServicesToExcelFile(ListProceduresBindingModel model); - } -} diff --git a/Hospital/HospitalContracts/SearchModels/ListProcedureSearchModel.cs b/Hospital/HospitalContracts/SearchModels/ListProceduresSearchModel.cs similarity index 84% rename from Hospital/HospitalContracts/SearchModels/ListProcedureSearchModel.cs rename to Hospital/HospitalContracts/SearchModels/ListProceduresSearchModel.cs index bde786e..23739b6 100644 --- a/Hospital/HospitalContracts/SearchModels/ListProcedureSearchModel.cs +++ b/Hospital/HospitalContracts/SearchModels/ListProceduresSearchModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace HospitalContracts.SearchModels { - public class ListProcedureSearchModel + public class ListProceduresSearchModel { public List? recipesIds { get; set; } } diff --git a/Hospital/HospitalContracts/SearchModels/MedicineDiseasesSearchModel.cs b/Hospital/HospitalContracts/SearchModels/MedicineDiseasesSearchModel.cs new file mode 100644 index 0000000..0ad3e9b --- /dev/null +++ b/Hospital/HospitalContracts/SearchModels/MedicineDiseasesSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.SearchModels +{ + public class MedicineDiseasesSearchModel + { + public List? patientsIds { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + public int? DoctorId { get; set; } + } +} diff --git a/Hospital/HospitalContracts/StoragesContracts/IPatientStorage.cs b/Hospital/HospitalContracts/StoragesContracts/IPatientStorage.cs index a003172..1c5494a 100644 --- a/Hospital/HospitalContracts/StoragesContracts/IPatientStorage.cs +++ b/Hospital/HospitalContracts/StoragesContracts/IPatientStorage.cs @@ -22,5 +22,8 @@ namespace HospitalContracts.StoragesContracts PatientViewModel? Update(PatientBindingModel model); PatientViewModel? Delete(PatientBindingModel model); + List>>>> GetDiseasesInfo(MedicineDiseasesSearchModel model); + List>>>> GetMedicinesInfo(MedicineDiseasesSearchModel model); + } } diff --git a/Hospital/HospitalContracts/StoragesContracts/IRecipeStorage.cs b/Hospital/HospitalContracts/StoragesContracts/IRecipeStorage.cs index d6f0c18..0534c25 100644 --- a/Hospital/HospitalContracts/StoragesContracts/IRecipeStorage.cs +++ b/Hospital/HospitalContracts/StoragesContracts/IRecipeStorage.cs @@ -22,6 +22,8 @@ namespace HospitalContracts.StoragesContracts RecipeViewModel? Update(RecipeBindingModel model); RecipeViewModel? Delete(RecipeBindingModel model); + List>>>> GetReportInfo(ListProceduresSearchModel model); + } } diff --git a/Hospital/HospitalContracts/ViewModels/ListProcedureViewModel.cs b/Hospital/HospitalContracts/ViewModels/ListProceduresViewModel.cs similarity index 75% rename from Hospital/HospitalContracts/ViewModels/ListProcedureViewModel.cs rename to Hospital/HospitalContracts/ViewModels/ListProceduresViewModel.cs index 4e1d14f..90b3bfb 100644 --- a/Hospital/HospitalContracts/ViewModels/ListProcedureViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/ListProceduresViewModel.cs @@ -6,9 +6,10 @@ using System.Threading.Tasks; namespace HospitalContracts.ViewModels { - public class ListProcedureViewModel + public class ListProceduresViewModel { public string ProcedureName { get; set; } = string.Empty; + public string RecipeName { get; set; } = string.Empty; public List Procedures { get; set; } = new(); } } diff --git a/Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs b/Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs index 935f6f9..7bd69bb 100644 --- a/Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/ListRecipeViewModel.cs @@ -10,5 +10,6 @@ namespace HospitalContracts.ViewModels { public string ProcedureName { get; set; } = string.Empty; public List Recipes { get; set; } = new(); + public List Procedures { get; set; } = new(); } } diff --git a/Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs b/Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs index e9fa2b7..fb13ae2 100644 --- a/Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs @@ -9,6 +9,7 @@ namespace HospitalContracts.ViewModels public class MedicinesDiseasesViewModel { public string PatientFIO { get; set; } = string.Empty; + public DateTime Date { get; set; } = new DateTime(); public List Medicines { get; set; } = new(); public List Diseases { get; set; } = new(); } diff --git a/Hospital/HospitalDatabaseImplement/Implementss/PatientStorage.cs b/Hospital/HospitalDatabaseImplement/Implementss/PatientStorage.cs index ccc0db6..ec22760 100644 --- a/Hospital/HospitalDatabaseImplement/Implementss/PatientStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implementss/PatientStorage.cs @@ -118,5 +118,30 @@ namespace HospitalDatabaseImplement.Implementss } return null; } + + public List>>>> GetDiseasesInfo(MedicineDiseasesSearchModel model) + { + using var context = new HospitalDatabase(); + return context.Patients.Where(patient => patient.DoctorId == model.DoctorId && patient.BirthDate >= model.DateFrom && patient.BirthDate <= model.DateTo) + .Select(patient => new Tuple>>>(patient.GetViewModel, + context.PatientRecipes.Include(recipe => recipe.Recipe) + .Include(recipe => recipe.Patient).Where(recipe => patient.Id == recipe.PatientId). + Select(recipe => new Tuple>(recipe.Recipe.GetViewModel, + context.Diseases.Include(x => x.Recipes).Where(x => x.Id == recipe.RecipeId). + Select(x => x.GetViewModel).ToList())).ToList())).ToList(); + + } + public List>>>> GetMedicinesInfo(MedicineDiseasesSearchModel model) + { + using var context = new HospitalDatabase(); + return context.Patients.Where(patient => patient.DoctorId == model.DoctorId && patient.BirthDate >= model.DateFrom && patient.BirthDate <= model.DateTo) + .Select(patient => new Tuple>>>(patient.GetViewModel, + context.PatientRecipes.Include(recipe => recipe.Recipe) + .Include(recipe => recipe.Patient).Where(recipe => patient.Id == recipe.PatientId). + Select(recipe => new Tuple>(recipe.Recipe.GetViewModel, + context.RecipeMedicines.Include(x => x.Medicine).Where(x => x.RecipeId == recipe.RecipeId ). + Select(x => x.Medicine.GetViewModel).ToList())).ToList())).ToList(); + + } } } diff --git a/Hospital/HospitalDatabaseImplement/Implementss/RecipeStorage.cs b/Hospital/HospitalDatabaseImplement/Implementss/RecipeStorage.cs index 080a502..90a8cb0 100644 --- a/Hospital/HospitalDatabaseImplement/Implementss/RecipeStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implementss/RecipeStorage.cs @@ -58,8 +58,10 @@ namespace HospitalDatabaseImplement.Implementss } using var context = new HospitalDatabase(); return context.Recipes - .Include(x => x.Doctor) - .Include(x => x.Patients) + .Include(x => x.Disease) + .Include(x => x.Doctor) + + .Include(x => x.Patients) .ThenInclude(x => x.Patient) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; @@ -119,5 +121,22 @@ namespace HospitalDatabaseImplement.Implementss } return null; } + public List>>>> GetReportInfo(ListProceduresSearchModel model) + { + if (model.recipesIds == null) + { + return new(); + } + using var context = new HospitalDatabase(); + return context.Recipes + .Where(recipe => model.recipesIds.Contains(recipe.Id)) + .Select(recipe => new Tuple>>>(recipe.GetViewModel, + context.PatientRecipes.Include(patient => patient.Patient) + .Include(patient => patient.Recipe).Where(patient => recipe.Id == patient.RecipeId). + Select(patient => new Tuple>(patient.Patient.GetViewModel, + context.PatientProcedures.Include(x => x.Procedure).Where(x => x.PatientId == patient.Patient.Id). + Select(x => x.Procedure.GetViewModel).ToList())).ToList())).ToList(); + + } } } diff --git a/Hospital/HospitalDatabaseImplement/Models/Patient.cs b/Hospital/HospitalDatabaseImplement/Models/Patient.cs index 739259d..68c5014 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Patient.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Patient.cs @@ -97,6 +97,7 @@ namespace HospitalDatabaseImplement.Models public PatientViewModel GetViewModel => new() { + Id = Id, FIO = FIO, Address = Address, BirthDate = BirthDate, diff --git a/Hospital/HospitalDatabaseImplement/Models/Procedure.cs b/Hospital/HospitalDatabaseImplement/Models/Procedure.cs index 2538d50..367dd51 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Procedure.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Procedure.cs @@ -70,9 +70,12 @@ namespace HospitalDatabaseImplement.Models public ProcedureViewModel GetViewModel => new() { Id = Id, - Name = Name, - ProcedureMedicines = ProcedureMedicines - }; + PharmacistId = PharmacistId, + Name = Name, + ProcedureMedicines = ProcedureMedicines, + Date = Date, + DescriptionProcedureId = DescriptionProcedureId + }; [Required] public DateTime Date { get; set; } diff --git a/Hospital/HospitalDatabaseImplement/Models/Recipe.cs b/Hospital/HospitalDatabaseImplement/Models/Recipe.cs index eadc189..c3567d9 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Recipe.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Recipe.cs @@ -69,14 +69,19 @@ namespace HospitalDatabaseImplement.Modelss { IssueDate = model.IssueDate; Description = model.Description; - } + DiseaseId = model.DiseaseId; + + + } public RecipeViewModel GetViewModel => new() { Id = Id, IssueDate = IssueDate, Description = Description, - RecipePatients = RecipePatients + RecipePatients = RecipePatients, + DoctorId= DoctorId, + DiseaseId = DiseaseId }; public void UpdatePatients(HospitalDatabase context, RecipeBindingModel model) diff --git a/Hospital/HospitalDoctorApp/Controllers/HomeController.cs b/Hospital/HospitalDoctorApp/Controllers/HomeController.cs index f319f84..43353a2 100644 --- a/Hospital/HospitalDoctorApp/Controllers/HomeController.cs +++ b/Hospital/HospitalDoctorApp/Controllers/HomeController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using System.Globalization; using System.IO.Pipelines; +using System.Text; namespace HospitalDoctorApp.Controllers { @@ -420,7 +421,7 @@ namespace HospitalDoctorApp.Controllers #endregion #region Промежуточные таблицы - public IActionResult PatientRecipes() + /*public IActionResult PatientRecipes() { if (APIClient.Doctor == null) { @@ -457,7 +458,7 @@ namespace HospitalDoctorApp.Controllers RecipePatients = v }); Response.Redirect("IndexRecipes"); - } + }*/ public IActionResult ProcedurePatients() { if (APIClient.Doctor == null) @@ -553,7 +554,7 @@ namespace HospitalDoctorApp.Controllers [HttpGet] public IActionResult ProcedureListReport() { - ViewBag.Services = APIClient.GetRequest>($"api/recipe/getrecipes?doctorid={APIClient.Doctor.Id}"); + ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipes?doctorid={APIClient.Doctor.Id}"); return View(); } @@ -597,6 +598,7 @@ namespace HospitalDoctorApp.Controllers } } + [HttpGet] public IActionResult GetWordFile() { @@ -615,7 +617,7 @@ namespace HospitalDoctorApp.Controllers } [HttpGet] - public string GetPacientsReport(DateTime dateFrom, DateTime dateTo) + public string GetPatientsReport(DateTime dateFrom, DateTime dateTo) { if (APIClient.Doctor == null) { @@ -651,7 +653,7 @@ namespace HospitalDoctorApp.Controllers { table += ""; table += ""; - table += $""; + table += $"{patient.Date}"; table += $"{patient.PatientFIO}"; table += $""; table += $""; @@ -659,7 +661,7 @@ namespace HospitalDoctorApp.Controllers foreach (var disease in patient.Diseases) { table += ""; - table += $"{disease.Description}"; + table += $""; table += $""; table += $"{disease.Name}"; table += $""; @@ -668,10 +670,10 @@ namespace HospitalDoctorApp.Controllers foreach (var medicine in patient.Medicines) { table += ""; + table += $""; + table += $""; + table += $""; table += $"{medicine.Name}"; - table += $""; - table += $""; - table += $"{medicine.CountryOrigin}"; table += ""; } table += ""; @@ -700,8 +702,99 @@ namespace HospitalDoctorApp.Controllers Response.Redirect("Report"); } - #endregion + #endregion + + public IActionResult PatientRecipes() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + /*ViewBag.Medicines = APIPharmacist.GetRequest>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}"); + ViewBag.Animals = APIPharmacist.GetRequest>($"api/animal/getanimallist");*/ + + ViewBag.Patients = APIClient.GetRequest>("api/patient/getpatients"); + ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipelist?doctorid={APIClient.Doctor.Id}"); + return View(); + } + + + [HttpPost] + public void PatientRecipes(int recipe, string description, int diseaseId, + List patients) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + + if (string.IsNullOrEmpty(description)) + { + throw new Exception("Ошибка в введенных данных"); + } + Dictionary a = new Dictionary(); + foreach (int patient in patients) + { + a.Add(patient, new PatientSearchModel { Id = patient } as IPatientModel); + } + APIClient.PostRequest("api/recipe/updaterecipe?isconnection=true", new RecipeBindingModel + { + Id = recipe, + Description = description, + DoctorId = APIClient.Doctor.Id, + DiseaseId = diseaseId, + RecipePatients = a + }); + Response.Redirect("Index"); + } + + public IActionResult Statistics() + { + //ViewBag.Patients = APIClient.GetRequest>("api/patient/getpatients"); + var patients = APIClient.GetRequest>("api/patient/getpatients"); + List groups = new List { 0, 0, 0, 0, 0 }; + foreach ( var patient in patients) + { + groups[Convert.ToInt32(((DateTime.Now - patient.BirthDate).TotalDays / 365)) / 20] += 1; + } + ViewBag.PatientsGroups = groups; + + + + var recipes = APIClient.GetRequest>($"api/recipe/getrecipes?doctorid={APIClient.Doctor.Id}"); + var diseases = APIClient.GetRequest>($"api/disease/getdiseases?doctorid={APIClient.Doctor.Id}"); + var diseaseLinkCounts = new Dictionary(); // Словарь для подсчета количества рецептов + foreach (var recipe in recipes) + { + if ( diseaseLinkCounts.ContainsKey(recipe.DiseaseId)) + { + diseaseLinkCounts[recipe.DiseaseId]++; // Увеличиваем счетчик для данной болезни + } + else + { + diseaseLinkCounts[recipe.DiseaseId] = 1; // Инициализируем счетчик для новой болезни + } + } + var diseaseIds = diseaseLinkCounts.Keys.Select(diseaseId => diseaseId); + List diseaseNames = diseases + .Where(model => diseaseIds.Contains(model.Id)) + .Select(model => model.Name) + .ToList(); + + var linkCounts = diseaseLinkCounts.Values; + + ViewBag.DiseaseNames = diseaseNames; + ViewBag.LinkCounts = linkCounts; + + ViewBag.ABC = new List { 'A', 'B', 'C' }; + + return View(); + + + } } + + } diff --git a/Hospital/HospitalDoctorApp/HospitalDoctorApp.csproj b/Hospital/HospitalDoctorApp/HospitalDoctorApp.csproj index 5179b68..6facce0 100644 --- a/Hospital/HospitalDoctorApp/HospitalDoctorApp.csproj +++ b/Hospital/HospitalDoctorApp/HospitalDoctorApp.csproj @@ -7,6 +7,7 @@ + diff --git a/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml b/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml index 5ae7a6e..468fab3 100644 --- a/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml @@ -20,7 +20,7 @@

Редактировать пациента Удалить пациента - Связать пациента и процедуру +

Создать пациента diff --git a/Hospital/HospitalDoctorApp/Views/Home/IndexRecipes.cshtml b/Hospital/HospitalDoctorApp/Views/Home/IndexRecipes.cshtml index 7fe5cf2..037e8de 100644 --- a/Hospital/HospitalDoctorApp/Views/Home/IndexRecipes.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Home/IndexRecipes.cshtml @@ -20,7 +20,7 @@

Редактировать рецепт Удалить рецепт - Связать рецепт(процедуру?) и пациента + Связать рецепт и пациента

Создать рецепт diff --git a/Hospital/HospitalDoctorApp/Views/Home/LinkMedicineAndRecipe.cshtml b/Hospital/HospitalDoctorApp/Views/Home/LinkMedicineAndRecipe.cshtml deleted file mode 100644 index 384b77e..0000000 --- a/Hospital/HospitalDoctorApp/Views/Home/LinkMedicineAndRecipe.cshtml +++ /dev/null @@ -1,28 +0,0 @@ -@{ - ViewData["Title"] = "CreateDisease"; -} - - - - - -

-
- - -
- -
-
-
-
-
diff --git a/Hospital/HospitalDoctorApp/Views/Home/PatientRecipes.cshtml b/Hospital/HospitalDoctorApp/Views/Home/PatientRecipes.cshtml new file mode 100644 index 0000000..d2e7101 --- /dev/null +++ b/Hospital/HospitalDoctorApp/Views/Home/PatientRecipes.cshtml @@ -0,0 +1,72 @@ +@using HospitalContracts.ViewModels; + +@{ + ViewData["Title"] = "PatientRecipes"; +} + +
+

Связывание пациента и рецептов

+
+
+
+
Рецепт:
+
+ +
+
+ + + +
+
Пациент:
+
+ +
+
+
+
+
+
+
+ +@section Scripts +{ + +} \ No newline at end of file diff --git a/Hospital/HospitalDoctorApp/Views/Home/ProcedureListReport.cshtml b/Hospital/HospitalDoctorApp/Views/Home/ProcedureListReport.cshtml index 76eb66b..3170792 100644 --- a/Hospital/HospitalDoctorApp/Views/Home/ProcedureListReport.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Home/ProcedureListReport.cshtml @@ -17,14 +17,23 @@ -
-
-
-
+
+ +
+ + +
+
+ + +
+
+
+
diff --git a/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml b/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml index 1eadaec..75a132a 100644 --- a/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml @@ -49,7 +49,7 @@ if (dateFrom && dateTo) { $.ajax({ method: "GET", - url: "/Home/GetAnimalsReport", + url: "/Home/GetPatientsReport", data: { dateFrom: dateFrom, dateTo: dateTo }, success: function (result) { if (result != null) { diff --git a/Hospital/HospitalDoctorApp/Views/Home/Statistics.cshtml b/Hospital/HospitalDoctorApp/Views/Home/Statistics.cshtml new file mode 100644 index 0000000..38afc42 --- /dev/null +++ b/Hospital/HospitalDoctorApp/Views/Home/Statistics.cshtml @@ -0,0 +1,91 @@ + + + + + +
+
+
+ +
+ +
+ +
+
+ +@*
+ +
*@ +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml b/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml index 8d2f281..b8c916e 100644 --- a/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml @@ -44,6 +44,9 @@ +
diff --git a/Hospital/HospitalRestApi/Controllers/DiseaseController.cs b/Hospital/HospitalRestApi/Controllers/DiseaseController.cs index 92b107e..213b1d3 100644 --- a/Hospital/HospitalRestApi/Controllers/DiseaseController.cs +++ b/Hospital/HospitalRestApi/Controllers/DiseaseController.cs @@ -6,7 +6,7 @@ using HospitalContracts.SearchModels; using HospitalContracts.ViewModels; using HospitalDatabaseImplement.Models; -namespace VetClinicRestApi.Controllers +namespace HospitalRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] diff --git a/Hospital/HospitalRestApi/Controllers/PatientController.cs b/Hospital/HospitalRestApi/Controllers/PatientController.cs index a34df06..2216ce8 100644 --- a/Hospital/HospitalRestApi/Controllers/PatientController.cs +++ b/Hospital/HospitalRestApi/Controllers/PatientController.cs @@ -6,7 +6,7 @@ using HospitalContracts.SearchModels; using HospitalContracts.ViewModels; using HospitalDatabaseImplement.Models; -namespace VetClinicRestApi.Controllers +namespace HospitalRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] @@ -54,7 +54,7 @@ namespace VetClinicRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка визитов"); + _logger.LogError(ex, "Ошибка получения списка пациентов"); throw; } } diff --git a/Hospital/HospitalRestApi/Controllers/RecipeController.cs b/Hospital/HospitalRestApi/Controllers/RecipeController.cs index f9a172c..da05a8d 100644 --- a/Hospital/HospitalRestApi/Controllers/RecipeController.cs +++ b/Hospital/HospitalRestApi/Controllers/RecipeController.cs @@ -6,7 +6,7 @@ using HospitalContracts.SearchModels; using HospitalContracts.ViewModels; using HospitalDatabaseImplement.Models; -namespace VetClinicRestApi.Controllers +namespace HospitalRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] @@ -38,6 +38,26 @@ namespace VetClinicRestApi.Controllers throw; } } + [HttpGet] + public List GetRecipes(int? doctorId = null) + { + try + { + List res; + if (!doctorId.HasValue) + res = _recipe.ReadList(null); + else + res = _recipe.ReadList(new RecipeSearchModel { DoctorId = doctorId }); + foreach (var recipe in res) + recipe.RecipePatients = null; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка услуг"); + throw; + } + } [HttpGet] public List? GetRecipeList(int? doctorId = null) diff --git a/Hospital/HospitalRestApi/Controllers/ReportController.cs b/Hospital/HospitalRestApi/Controllers/ReportController.cs index 5b5c14c..3a46d29 100644 --- a/Hospital/HospitalRestApi/Controllers/ReportController.cs +++ b/Hospital/HospitalRestApi/Controllers/ReportController.cs @@ -1,5 +1,7 @@ using HospitalBusinessLogic.BusinessLogics; +using HospitalBusinessLogic.MailWorker; using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; using HospitalContracts.BusinessLogicsContracts; using HospitalContracts.ViewModels; using Microsoft.AspNetCore.Http; @@ -11,9 +13,9 @@ namespace HospitalRestApi.Controllers [ApiController] public class ReportController : Controller { - private readonly IReportLogicDoctor _reportDoctor; + private readonly IDoctorReportLogic _reportDoctor; private readonly AbstractMailWorker _mailWorker; - public ReportController(ILogger logger, IReportLogicPharmacist reportPharmacist, AbstractMailWorker mailWorker) + public ReportController(ILogger logger, IDoctorReportLogic reportPharmacist, AbstractMailWorker mailWorker) { _reportDoctor = reportPharmacist; _mailWorker = mailWorker; @@ -36,7 +38,7 @@ namespace HospitalRestApi.Controllers } } [HttpPost] - public void CreateProceddureListExcelFile(ListProceduresBindingModel model) + public void CreateProcedureListExcelFile(ListProceduresBindingModel model) { try { @@ -58,7 +60,7 @@ namespace HospitalRestApi.Controllers model.DateFrom = DateFrom; model.DateTo = DateTo; model.DoctorId = doctorId; - return _reportDoctor.GetMedicinesDiseases(model); + return _reportDoctor.GetPatientMedicinesAndDiseases(model); } catch (Exception ex) { diff --git a/Hospital/HospitalRestApi/Program.cs b/Hospital/HospitalRestApi/Program.cs index 28a2ff0..cad973d 100644 --- a/Hospital/HospitalRestApi/Program.cs +++ b/Hospital/HospitalRestApi/Program.cs @@ -1,9 +1,14 @@ using HospitalBusinessLogic.BusinessLogics; +using HospitalBusinessLogic.MailWorker; +using HospitalBusinessLogic.OfficePackage; using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.BusinessLogicsContracts; using HospitalContracts.StoragesContracts; using HospitalDatabaseImplement.Implements; using HospitalDatabaseImplement.Implementss; using Microsoft.OpenApi.Models; +using HospitalBusinessLogic.OfficePackage.Implements; +using HospitalContracts.BindingModels; var builder = WebApplication.CreateBuilder(args); @@ -31,6 +36,12 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddSingleton(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -44,6 +55,24 @@ builder.Services.AddSwaggerGen(c => }); }); var app = builder.Build(); +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() +?? string.Empty, + MailPassword = +builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? +string.Empty, + SmtpClientHost = +builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? +string.Empty, + SmtpClientPort = +Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? +string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/Hospital/HospitalRestApi/appsettings.json b/Hospital/HospitalRestApi/appsettings.json index 10f68b8..6629177 100644 --- a/Hospital/HospitalRestApi/appsettings.json +++ b/Hospital/HospitalRestApi/appsettings.json @@ -5,5 +5,11 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "valanuni04@gmail.com", + "MailPassword": "bpkm pnxf rbvi sroc" }