From 11f911b2afe1e691b9bfcb0ff97870d34abcc126 Mon Sep 17 00:00:00 2001 From: Factorino73 Date: Sun, 26 May 2024 23:04:41 +0400 Subject: [PATCH] WebApp / Add methods for creating reports to the controller --- .gitignore | 1 + .../OfficePackage/AbstractSaveToPdf.cs | 2 +- .../Controllers/HomeController.cs | 150 +++++++++++++++++- .../Views/Disease/Diseases.cshtml | 4 +- .../HospitalWebApp/Views/Home/Reports.cshtml | 91 ++++++++++- .../Views/Medicine/Medicines.cshtml | 4 +- .../Views/Patient/Patients.cshtml | 4 +- .../Views/Procedure/Procedures.cshtml | 4 +- .../Views/Recipe/Recipes.cshtml | 4 +- 9 files changed, 243 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index ca1c7a3..3ceca38 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +Reports # Mono auto generated files mono_crash.* diff --git a/Hospital/HospitalBusinessLogics/OfficePackage/AbstractSaveToPdf.cs b/Hospital/HospitalBusinessLogics/OfficePackage/AbstractSaveToPdf.cs index 5b15209..648ab46 100644 --- a/Hospital/HospitalBusinessLogics/OfficePackage/AbstractSaveToPdf.cs +++ b/Hospital/HospitalBusinessLogics/OfficePackage/AbstractSaveToPdf.cs @@ -35,7 +35,7 @@ namespace HospitalBusinessLogics.OfficePackage // "с XX.XX.XXXX по XX.XX.XXXX" CreateParagraph(new PdfParagraph { - Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal" }); diff --git a/Hospital/HospitalWebApp/Controllers/HomeController.cs b/Hospital/HospitalWebApp/Controllers/HomeController.cs index 5bd1c30..5446063 100644 --- a/Hospital/HospitalWebApp/Controllers/HomeController.cs +++ b/Hospital/HospitalWebApp/Controllers/HomeController.cs @@ -24,15 +24,22 @@ namespace HospitalWebApp.Controllers /// private readonly IDoctorLogic _doctorLogic; - /// + /// + /// Бизнес-логика для отчетов + /// + private readonly IReportLogic _reportLogic; + + /// /// Конструктор /// /// /// - public HomeController(ILogger logger, IDoctorLogic doctorLogic) + /// + public HomeController(ILogger logger, IDoctorLogic doctorLogic, IReportLogic reportLogic) { _logger = logger; _doctorLogic = doctorLogic; + _reportLogic = reportLogic; } /// @@ -203,11 +210,140 @@ namespace HospitalWebApp.Controllers Response.Redirect("Enter"); } - /// - /// Ошибка - /// - /// - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + /// + /// Получить отчет + /// + /// + [HttpGet] + public IActionResult Reports() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(); + } + + /// + /// Вывести на форму отчёт + /// + /// + [HttpPost] + public IActionResult Reports(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue) + { + throw new Exception("Введены не все данные!"); + } + + var data = _reportLogic.GetPatientsInfo(new ReportBindingModel + { + DateFrom = dateFrom, + DateTo = dateTo, + DoctorId = APIClient.Doctor.Id + }); + + return View(data); + } + + /// + /// Создать отчёт в формате Word + /// + /// + [HttpPost] + public void CreateReportWord() + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + _reportLogic.SaveRecipeProceduresToWordFile(new ReportBindingModel + { + FileName = $@"D:\ULSTU\Семестр 4\РПП Coursework\Reports\Список процедур {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx", + DoctorId = APIClient.Doctor.Id + }); + + Response.Redirect("/Home/Reports"); + } + + /// + /// Создать отчёт в формате Excel + /// + /// + [HttpPost] + public void CreateReportExcel() + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + _reportLogic.SaveRecipeProceduresToExcelFile(new ReportBindingModel + { + FileName = $@"D:\ULSTU\Семестр 4\РПП Coursework\Reports\Список процедур {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx", + DoctorId = APIClient.Doctor.Id + }); + + Response.Redirect("/Home/Reports"); + } + + /// + /// Создать отчёт в формате Pdf + /// + /// + [HttpPost] + public void CreateReportPdf(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue) + { + throw new Exception("Введены не все данные!"); + } + + _reportLogic.SavePatientsInfoToPdfFile(new ReportBindingModel + { + FileName = $@"D:\ULSTU\Семестр 4\РПП Coursework\Reports\Сведения о пациентах {DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.pdf", + DoctorId = APIClient.Doctor.Id, + DateFrom = dateFrom, + DateTo = dateTo + }); + + Response.Redirect("/Home/Reports"); + } + + /// + /// Отправить по почте отчёт + /// + /// + [HttpPost] + public void SendReport() + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + // TODO + + Response.Redirect("/Home/Reports"); + } + + /// + /// Ошибка + /// + /// + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml b/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml index e5fee02..4912495 100644 --- a/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml +++ b/Hospital/HospitalWebApp/Views/Disease/Diseases.cshtml @@ -29,8 +29,8 @@ Название Симптомы Номер рецепта - Изменить - Удалить + + diff --git a/Hospital/HospitalWebApp/Views/Home/Reports.cshtml b/Hospital/HospitalWebApp/Views/Home/Reports.cshtml index 486efc1..642d7d4 100644 --- a/Hospital/HospitalWebApp/Views/Home/Reports.cshtml +++ b/Hospital/HospitalWebApp/Views/Home/Reports.cshtml @@ -1,6 +1,6 @@ -@using HospitalContracts.BindingModels; +@using HospitalContracts.ViewModels -@model ReportBindingModel +@model List @{ ViewBag.Title = "Отчеты"; @@ -10,4 +10,89 @@

Отчеты

- +
+ +
+
+ +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+ + +
+ + + +
+ + +
+ +
+
+
+ + + + + + + + + + + + @if (Model == null || Model.Count <= 0) + { + + } + else + { + foreach (var record in Model) + { + // Имя пациента + + + + + // Конвертируем из HashSet в List, чтобы можно было обращаться по индексу + var medicines = new List(record.Medicines); + var diseases = new List(record.Diseases); + + // Записываем названия лекарств во 2 колонку + // и названия лекарств в 3 колонку + int maxLength = Math.Max(medicines.Count, diseases.Count); + for (int i = 0; i < maxLength; i++) + { + + + + + + } + } + } + +
ПациентЛекарстваБолезни
Нет доступных данных@record.Patient.FullName
@(i < medicines.Count ? medicines[i].Name : "")@(i < diseases.Count ? diseases[i].Name : "")
\ No newline at end of file diff --git a/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml b/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml index 66c0195..d86a582 100644 --- a/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml +++ b/Hospital/HospitalWebApp/Views/Medicine/Medicines.cshtml @@ -28,8 +28,8 @@ Номер Название Описание - Изменить - Удалить + + diff --git a/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml b/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml index e93e145..e9c4e45 100644 --- a/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml +++ b/Hospital/HospitalWebApp/Views/Patient/Patients.cshtml @@ -30,8 +30,8 @@ Дата рождения Номер телефона Лечащий врач - Изменить - Удалить + + diff --git a/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml b/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml index 2926574..70963db 100644 --- a/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml +++ b/Hospital/HospitalWebApp/Views/Procedure/Procedures.cshtml @@ -28,8 +28,8 @@ Номер Название Описание - Изменить - Удалить + + diff --git a/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml b/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml index 1fd719e..7d41016 100644 --- a/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml +++ b/Hospital/HospitalWebApp/Views/Recipe/Recipes.cshtml @@ -28,8 +28,8 @@ Номер Дата выписки Доктор - Изменить - Удалить + +