From f15d160157fb354dc9af3e6a2599270716ca10c7 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Thu, 30 May 2024 02:36:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=BE=D0=B2=20=D0=B2=20?= =?UTF-8?q?=D0=B2=D0=BE=D1=80=D0=B4=20=D0=B8=20=D1=8D=D0=BA=D1=81=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ImplementerReportLogic.cs | 4 +-- .../IImplementerReportLogic.cs | 2 +- .../Controllers/ReportsController.cs | 31 ++++++++++++++++- .../Models/MedicamentsByDiagnosesFormModel.cs | 9 ++++- .../Reports/MedicamentsByDiagnoses.cshtml | 33 +++++++++++-------- 5 files changed, 61 insertions(+), 18 deletions(-) diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs index af98fb3..5535cff 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs @@ -63,9 +63,9 @@ namespace PolyclinicBusinessLogic.BusinessLogics return report; } - public List GetReportMedicamentsByDiagnoses(List diagnoses) + public List GetReportMedicamentsByDiagnoses(int[] diagnosesIds) { - List diagnoseViewModels = diagnoses.Select(x => _diagnoseStorage.GetElement(new DiagnoseSearchModel { Id = x.Id })).ToList(); + List diagnoseViewModels = diagnosesIds.Select(x => _diagnoseStorage.GetElement(new DiagnoseSearchModel { Id = x })).ToList(); var symptomes = _symptomStorage.GetFullList(); var medicaments = _medicamentStorage.GetFullList(); diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs index 330b0ae..0134200 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs @@ -7,7 +7,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts public interface IImplementerReportLogic { ReportDiagnosesByPeriodViewModel GetReportDiagnosesByPeriod(DateTime? dateStart, DateTime? dateEnd); - List GetReportMedicamentsByDiagnoses(List diagnoses); + List GetReportMedicamentsByDiagnoses(int[] diagnosesIds); void SaveReportMedicamentsByDiagnosesToWordFile(ReportBindingModel reportInfo, List reportModel); void SaveReportMedicamentsByDiagnosesToExcelFile(ReportBindingModel reportInfo, List reportModel); void SaveReportDiagnosesByPeriodToPdfFile(ReportBindingModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel); diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs index 318d3df..b43b8de 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs @@ -2,6 +2,7 @@ using PolyclinicBusinessLogic.OfficePackage.HelperEnums; using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; using PolyclinicContracts.ViewModels; using PolyclinicWebAppImplementer.Models; @@ -68,13 +69,41 @@ namespace PolyclinicWebAppImplementer.Controllers { return RedirectToAction("Login", "User"); } + var diagnoses = _diagnoseLogic.ReadList(new DiagnoseSearchModel { UserId = currentUser.Id }); + if (model.SelectedDiagnoses != null) + { + model.Diagnoses = diagnoses.Select(x => (x, model.SelectedDiagnoses.Contains(x.Id))).ToList(); + } + else + { + model.Diagnoses = diagnoses.Select(x => (x, false)).ToList(); + } if (HttpContext.Request.Method == "GET") { return View(model); } else { - return View(model); + var reportInfo = new ReportBindingModel(); + + var reportModel = _reportLogic.GetReportMedicamentsByDiagnoses(model.SelectedDiagnoses); + + if (model.ReportType == ReportType.Word) + { + reportInfo.FileName = model.FileName + ".docx"; + _reportLogic.SaveReportMedicamentsByDiagnosesToWordFile(reportInfo, reportModel); + } + else + { + reportInfo.FileName = model.FileName + ".xlsx"; + _reportLogic.SaveReportMedicamentsByDiagnosesToExcelFile(reportInfo, reportModel); + } + + var filePath = Path.Combine(Directory.GetCurrentDirectory(), reportInfo.FileName); + byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); + string mimeType = model.ReportType == ReportType.Word ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + + return File(fileBytes, mimeType, reportInfo.FileName); } } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/MedicamentsByDiagnosesFormModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/MedicamentsByDiagnosesFormModel.cs index 2b2135c..fe0a13f 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Models/MedicamentsByDiagnosesFormModel.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/MedicamentsByDiagnosesFormModel.cs @@ -1,6 +1,13 @@ -namespace PolyclinicWebAppImplementer.Models +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicContracts.ViewModels; + +namespace PolyclinicWebAppImplementer.Models { public class MedicamentsByDiagnosesFormModel { + public string FileName { get; set; } + public ReportType ReportType { get; set; } + public List<(DiagnoseViewModel Diagnose, bool IsChecked)> Diagnoses { get; set; } = new(); + public int[]? SelectedDiagnoses { get; set; } } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/MedicamentsByDiagnoses.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/MedicamentsByDiagnoses.cshtml index 5c5b465..b98b9cb 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/MedicamentsByDiagnoses.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/MedicamentsByDiagnoses.cshtml @@ -1,19 +1,26 @@ -@{ +@using PolyclinicBusinessLogic.OfficePackage.HelperEnums +@model MedicamentsByDiagnosesFormModel +@{ ViewBag.SelectedSiteMenuItem = SiteMenuItems.MedicamentsByDiagnoses; }

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

-
+
Выберите болезни
    - @{ - for(int i = 0; i < 10; i++) - { -
  • - - -
  • - } + @foreach (var item in Model.Diagnoses) + { +
  • + @if (item.IsChecked) + { + + } + else + { + + } + +
  • }
@@ -21,18 +28,18 @@
Укажите формат файла
- +
- +
Укажите название файла
- +