From 4881a7c7ca696703d296a16b97247bdeee83781b Mon Sep 17 00:00:00 2001 From: ValAnn Date: Sat, 25 May 2024 22:42:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=BE=D0=B2,=20=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B4=D0=BE=D0=BA=D1=82=D0=BE=D1=80=D0=B0,=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B8=D0=B9=20=D1=81=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D1=8F=D0=BC=D0=B8=20=D0=B4=D0=BE=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B0,=20=D0=B1=D0=B0=D0=B9=D0=BD=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3=20=D0=B8=20=D0=B2=D1=8C=D1=8E=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D1=87?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HospitalBusinessLogic.csproj | 2 +- .../MailWorker/AbstractMailWorker.cs | 63 +++++++ .../MailWorker/MailWorker.cs | 50 ++++++ .../ListProceduresBindingModel.cs | 1 + .../BindingModels/MailConfigBindingModel.cs | 18 ++ .../BindingModels/MailSendInfoBindingModel.cs | 15 ++ .../MedicinesDiseasesBindingModel.cs | 17 ++ .../ViewModels/MedicinesDiseasesViewModel.cs | 15 ++ .../Controllers/HomeController.cs | 168 ++++++++++++++++-- .../Views/Home/Report.cshtml | 112 ++++++------ .../Views/Shared/_Layout.cshtml | 7 + .../Controllers/ReportController.cs | 88 +++++++++ 12 files changed, 493 insertions(+), 63 deletions(-) create mode 100644 Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 Hospital/HospitalBusinessLogic/MailWorker/MailWorker.cs create mode 100644 Hospital/HospitalContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 Hospital/HospitalContracts/BindingModels/MailSendInfoBindingModel.cs create mode 100644 Hospital/HospitalContracts/BindingModels/MedicinesDiseasesBindingModel.cs create mode 100644 Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs create mode 100644 Hospital/HospitalRestApi/Controllers/ReportController.cs diff --git a/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj index 11fde8d..3387e4a 100644 --- a/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj +++ b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs b/Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..284f9c0 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,63 @@ +using HospitalContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + protected string _mailPassword = string.Empty; + protected string _smtpClientHost = string.Empty; + protected int _smtpClientPort; + protected string _popHost = string.Empty; + protected int _popPort; + private readonly IPharmacistLogic _pharmacistLogic; + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger logger, IPharmacistLogic pharmacistLogic) + { + _logger = logger; + _pharmacistLogic = pharmacistLogic; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + + await SendMailAsync(info); + } + + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + } +} diff --git a/Hospital/HospitalBusinessLogic/MailWorker/MailWorker.cs b/Hospital/HospitalBusinessLogic/MailWorker/MailWorker.cs new file mode 100644 index 0000000..5265178 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/MailWorker/MailWorker.cs @@ -0,0 +1,50 @@ +using HospitalContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Net.Mime; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using HospitalContracts.BindingModels; + +namespace HospitalBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IPharmacistLogic pharmacistLogic) : base(logger, pharmacistLogic) { } + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + Attachment attachment = new Attachment("C:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); + objMailMessage.Attachments.Add(attachment); + + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + + + } +} diff --git a/Hospital/HospitalContracts/BindingModels/ListProceduresBindingModel.cs b/Hospital/HospitalContracts/BindingModels/ListProceduresBindingModel.cs index 5d73e6a..2bba585 100644 --- a/Hospital/HospitalContracts/BindingModels/ListProceduresBindingModel.cs +++ b/Hospital/HospitalContracts/BindingModels/ListProceduresBindingModel.cs @@ -10,5 +10,6 @@ namespace HospitalContracts.BindingModels { public string FileName { get; set; } = string.Empty; public List Recipes { get; set; } = new(); + } } diff --git a/Hospital/HospitalContracts/BindingModels/MailConfigBindingModel.cs b/Hospital/HospitalContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..0f7df55 --- /dev/null +++ b/Hospital/HospitalContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + public string MailPassword { get; set; } = string.Empty; + public string SmtpClientHost { get; set; } = string.Empty; + public int SmtpClientPort { get; set; } + public string PopHost { get; set; } = string.Empty; + public int PopPort { get; set; } + } +} diff --git a/Hospital/HospitalContracts/BindingModels/MailSendInfoBindingModel.cs b/Hospital/HospitalContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..333f25f --- /dev/null +++ b/Hospital/HospitalContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Text { get; set; } = string.Empty; + } +} diff --git a/Hospital/HospitalContracts/BindingModels/MedicinesDiseasesBindingModel.cs b/Hospital/HospitalContracts/BindingModels/MedicinesDiseasesBindingModel.cs new file mode 100644 index 0000000..2feb3fe --- /dev/null +++ b/Hospital/HospitalContracts/BindingModels/MedicinesDiseasesBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BindingModels +{ + public class MedicinesDiseasesBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } = DateTime.Now; + public DateTime DateTo { get; set; } = DateTime.Now; + public int? DoctorId { get; set; } + public string? Email { get; set; } + } +} diff --git a/Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs b/Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs new file mode 100644 index 0000000..e9fa2b7 --- /dev/null +++ b/Hospital/HospitalContracts/ViewModels/MedicinesDiseasesViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.ViewModels +{ + public class MedicinesDiseasesViewModel + { + public string PatientFIO { get; set; } = string.Empty; + public List Medicines { get; set; } = new(); + public List Diseases { get; set; } = new(); + } +} diff --git a/Hospital/HospitalDoctorApp/Controllers/HomeController.cs b/Hospital/HospitalDoctorApp/Controllers/HomeController.cs index 4d95edf..f319f84 100644 --- a/Hospital/HospitalDoctorApp/Controllers/HomeController.cs +++ b/Hospital/HospitalDoctorApp/Controllers/HomeController.cs @@ -5,6 +5,7 @@ using HospitalDataModels.Models; using HospitalDoctorApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using System.Globalization; using System.IO.Pipelines; namespace HospitalDoctorApp.Controllers @@ -515,17 +516,7 @@ namespace HospitalDoctorApp.Controllers return result; } - [HttpGet] - public IActionResult ServiceListReport() - { - ViewBag.Animals = APIClient.GetRequest>($"api/animal/getanimallist?adminid={APIClient.Doctor.Id}"); - return View(); - } - [HttpGet] - public IActionResult Report() - { - return View(); - } + [HttpGet] public Tuple>? GetRecipe(int recipeId) { @@ -556,6 +547,161 @@ namespace HospitalDoctorApp.Controllers return result; } + + + #region Reports + [HttpGet] + public IActionResult ProcedureListReport() + { + ViewBag.Services = APIClient.GetRequest>($"api/recipe/getrecipes?doctorid={APIClient.Doctor.Id}"); + return View(); + } + + [HttpPost] + public void ProcedureListReport(List recipes, string type) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (recipes.Count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + + + if (type == "docx") + { + APIClient.PostRequest("api/report/createprocedurelistwordfile", new ListProceduresBindingModel + { + Recipes = recipes, + FileName = "C:\\ReportsCourseWork\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIClient.PostRequest("api/report/createprocedurelistexcelfile", new ListProceduresBindingModel + { + Recipes = recipes, + FileName = "C:\\ReportsCourseWork\\excelfile.xlsx" + }); + Response.Redirect("GetExcelFile"); + } + } + + [HttpGet] + public IActionResult GetWordFile() + { + return new PhysicalFileResult("C:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + + public IActionResult GetExcelFile() + { + return new PhysicalFileResult("C:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } + [HttpGet] + public IActionResult Report() + { + ViewBag.Report = new List(); + return View(); + } + + [HttpGet] + public string GetPacientsReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture); + string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture); + result = APIClient.GetRequest> + ($"api/report/getmedicinesdiseasesreport?datefrom={dateFromS}&dateto={dateToS}&doctorid={APIClient.Doctor.Id}")!; + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + table += "

Предварительный отчет

"; + table += "
"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach (var patient in result) + { + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + foreach (var disease in patient.Diseases) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + foreach (var medicine in patient.Medicines) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + table += ""; + } + table += "
ДатаФИО пациентаБолезньЛекарство
{patient.PatientFIO}
{disease.Description}{disease.Name}
{medicine.Name}{medicine.CountryOrigin}
"; + table += "
"; + return table; + } + + [HttpPost] + public void Report(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/report/sendmedicinesdiseasesreporttoemail", new MedicinesDiseasesBindingModel + { + FileName = "C:\\ReportsCourseWork\\pdffile.pdf", + DoctorId = APIClient.Doctor.Id, + DateFrom = dateFrom, + DateTo = dateTo, + Email = APIClient.Doctor.MailAddress + + }); + Response.Redirect("Report"); + + } + #endregion } + } diff --git a/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml b/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml index b916fce..1eadaec 100644 --- a/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Home/Report.cshtml @@ -1,55 +1,65 @@ @{ ViewData["Title"] = "Report"; } -
-

Список пациентов с расшифровкой по лекарствам и болезням

+ +
+
+

Список пациентов с расшифровкой по лекарствам и болезням за период

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
-
- @{ - -
-
Начальная дата:
-
- -
-
-
-
Конечная дата:
-
- -
-
- - - - - - - - - - - - будет заполняться вьюшками отчета - -
- Номер - - Дата - - Пациент - - Лекарство - - Болезнь -
-
-
-
-
-
-
-
-
- } -
\ No newline at end of file + +@section Scripts { + +} \ No newline at end of file diff --git a/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml b/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml index bb5bd21..8d2f281 100644 --- a/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Shared/_Layout.cshtml @@ -37,6 +37,13 @@ + + +
diff --git a/Hospital/HospitalRestApi/Controllers/ReportController.cs b/Hospital/HospitalRestApi/Controllers/ReportController.cs new file mode 100644 index 0000000..5b5c14c --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/ReportController.cs @@ -0,0 +1,88 @@ +using HospitalBusinessLogic.BusinessLogics; +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportController : Controller + { + private readonly IReportLogicDoctor _reportDoctor; + private readonly AbstractMailWorker _mailWorker; + public ReportController(ILogger logger, IReportLogicPharmacist reportPharmacist, AbstractMailWorker mailWorker) + { + _reportDoctor = reportPharmacist; + _mailWorker = mailWorker; + } + [Microsoft.AspNetCore.Mvc.HttpGet] + public IActionResult Index(ReportLogicPharmacist reportPharmacist) + { + return View(); + } + [HttpPost] + public void CreateProcedureListWordFile(ListProceduresBindingModel model) + { + try + { + _reportDoctor.SaveProceduresToWordFile(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpPost] + public void CreateProceddureListExcelFile(ListProceduresBindingModel model) + { + try + { + _reportDoctor.SaveProceduresToExcelFile(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpGet] + public List GetMedicinesDiseasesReport(string dateFrom, string dateTo, int doctorId) + { + try + { + DateTime DateFrom = DateTime.Parse(dateFrom); + DateTime DateTo = DateTime.Parse(dateTo); + MedicinesDiseasesBindingModel model = new(); + model.DateFrom = DateFrom; + model.DateTo = DateTo; + model.DoctorId = doctorId; + return _reportDoctor.GetMedicinesDiseases(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void SendMedicinesDiseasesReportToEmail(MedicinesDiseasesBindingModel model) + { + try + { + _reportDoctor.SavePatientsToPdfFile(model); + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = model.Email!, + Subject = "Отчет по patients", + Text = "TextPatients" + }); + } + catch (Exception ex) + { + throw; + } + } + } +}