вроде работает отображение отчета в пдф на форме

This commit is contained in:
2024-05-29 21:16:38 +04:00
parent 1c68c684c6
commit 97c8230045
9 changed files with 121 additions and 99 deletions

View File

@@ -1,5 +1,6 @@
using PolyclinicBusinessLogic.OfficePackage; using PolyclinicBusinessLogic.OfficePackage;
using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel; using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel;
using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF;
using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word;
using PolyclinicContracts.BindingModels; using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.BusinessLogicsContracts;
@@ -21,9 +22,11 @@ namespace PolyclinicBusinessLogic.BusinessLogics
private readonly AbstractSaveToWordCoursesByProcedures saveToWord; private readonly AbstractSaveToWordCoursesByProcedures saveToWord;
private readonly AbstractSaveToExcelCoursesByProcedure saveToExcel; private readonly AbstractSaveToExcelCoursesByProcedure saveToExcel;
private readonly AbstractSaveToPdfProcedures saveToPdf;
public SuretorReportLogic(IProcedureStorage procedureStorage, IMedicamentStorage medicamentStorage, public SuretorReportLogic(IProcedureStorage procedureStorage, IMedicamentStorage medicamentStorage,
ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage, ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage,
AbstractSaveToWordCoursesByProcedures saveToWord, AbstractSaveToExcelCoursesByProcedure saveToExcel) AbstractSaveToWordCoursesByProcedures saveToWord, AbstractSaveToExcelCoursesByProcedure saveToExcel,
AbstractSaveToPdfProcedures saveToPdf)
{ {
this.procedureStorage = procedureStorage; this.procedureStorage = procedureStorage;
this.medicamentStorage = medicamentStorage; this.medicamentStorage = medicamentStorage;
@@ -32,6 +35,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics
this.recipeStorage = recipeStorage; this.recipeStorage = recipeStorage;
this.saveToWord = saveToWord; this.saveToWord = saveToWord;
this.saveToExcel = saveToExcel; this.saveToExcel = saveToExcel;
this.saveToPdf = saveToPdf;
} }
public List<CourseViewModel> GetProcedureCourses(ProcedureSearchModel model) public List<CourseViewModel> GetProcedureCourses(ProcedureSearchModel model)
@@ -65,7 +69,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics
return list; return list;
} }
public List<ReportProceduresViewModel> GetProceduresByMedicametsAndSymptoms(ReportBindingModel model) public List<ReportProceduresViewModel> GetProceduresByMedicametsAndSymptoms()
{ {
var procedures = procedureStorage.GetFullList(); var procedures = procedureStorage.GetFullList();
var medicaments = medicamentStorage.GetFullList(); var medicaments = medicamentStorage.GetFullList();
@@ -76,9 +80,10 @@ namespace PolyclinicBusinessLogic.BusinessLogics
{ {
var record = new ReportProceduresViewModel var record = new ReportProceduresViewModel
{ {
Id = procedure.Id,
ProcedureName = procedure.Name, ProcedureName = procedure.Name,
DateStartProcedure = procedure.DateStartProcedure, DateStartProcedure = procedure.DateStartProcedure,
DateStopProcedure = procedure.DateStopProcedure, DateStopProcedure = procedure.DateStopProcedure ?? DateTime.MaxValue,
MedicamentSymptom = new List<(string medicamentName, string symptomName)>() MedicamentSymptom = new List<(string medicamentName, string symptomName)>()
}; };
foreach (var medicament in medicaments) foreach (var medicament in medicaments)
@@ -121,7 +126,14 @@ namespace PolyclinicBusinessLogic.BusinessLogics
public void SaveProceduresToPdfFile(ReportBindingModel model) public void SaveProceduresToPdfFile(ReportBindingModel model)
{ {
throw new NotImplementedException(); saveToPdf.CreateDoc(new PdfProceduresByMedicamentsAndSymptomsInfo
{
FileName= model.FileName,
Title = "Отчет по процедурам с расшифровкой по симптомам и лекарствам",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo.Value,
Procedures = GetProceduresByMedicametsAndSymptoms()
});
} }
} }
} }

View File

@@ -3,7 +3,7 @@ using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF;
namespace PolyclinicBusinessLogic.OfficePackage namespace PolyclinicBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToPdfCoursesByProcedure public abstract class AbstractSaveToPdfProcedures
{ {
public void CreateDoc(PdfProceduresByMedicamentsAndSymptomsInfo info) public void CreateDoc(PdfProceduresByMedicamentsAndSymptomsInfo info)
{ {
@@ -23,25 +23,25 @@ namespace PolyclinicBusinessLogic.OfficePackage
CreateTable(new List<string> { "1cm", "3cm", "3cm", "4cm", "4cm", "4cm" }); CreateTable(new List<string> { "1cm", "3cm", "3cm", "4cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters CreateRow(new PdfRowParameters
{ {
Texts = new List<string> { "Номер", "Дата начала процедуры", "Дата окончания процедуры", "Процедура", "Лекарство", "Симптом" }, Texts = new List<string> { "Номер", "Период 'с'", "Период 'до'", "Процедура", "Лекарство", "Симптом" },
Style = "NormalTitle", Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center ParagraphAlignment = PdfParagraphAlignmentType.Center
}); });
foreach (var order in info.Orders) foreach (var procedure in info.Procedures)
{ {
CreateRow(new PdfRowParameters foreach (var ms in procedure.MedicamentSymptom)
{ {
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.Status.ToString(), order.SushiName, order.Sum.ToString() }, CreateRow(new PdfRowParameters
Style = "Normal", {
ParagraphAlignment = PdfParagraphAlignmentType.Left, Texts = new List<string> { procedure.Id.ToString(), procedure.DateStartProcedure.ToShortTimeString(),
}); procedure.DateStopProcedure?.ToShortTimeString() ?? "нет даты окончания процедуры",
procedure.ProcedureName, ms.medicamentName, ms.symptomName},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left,
});
}
} }
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
});
SavePdf(info); SavePdf(info);
} }
/// <summary> /// <summary>

View File

@@ -8,8 +8,14 @@ namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public DateTime DateFrom { get; set; } public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; } public DateTime DateTo { get; set; }
public List<ReportProceduresViewModel> Procedures{ get; set; } = new(); public List<ReportProceduresViewModel> Procedures { get; set; } = new();
public List<MedicamentViewModel> Medicaments { get; set; } = new();
public List<SymptomViewModel> Symptoms { get; set; } = new(); //public List<ReportProceduresViewModel> Procedures{ get; set; } = new();
//public List<ReportProceduresViewModel> MedicamentSymptom { get; set; } = new();
/*public List<(string medicamentName, string symptomName)> MedicamentSymptom { get; set; } = new();*/
/* public List<MedicamentViewModel> Medicaments { get; set; } = new();
public List<SymptomViewModel> Symptoms { get; set; } = new();*/
} }
} }

View File

@@ -6,7 +6,7 @@ using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF;
namespace PolyclinicBusinessLogic.OfficePackage.Implements namespace PolyclinicBusinessLogic.OfficePackage.Implements
{ {
public class SaveToPdfCoursesByProcedure : AbstractSaveToPdfCoursesByProcedure public class SaveToPdfProcedures : AbstractSaveToPdfProcedures
{ {
private Document? _document; private Document? _document;
private Section? _section; private Section? _section;

View File

@@ -22,7 +22,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
List<ReportProceduresViewModel> GetProceduresByMedicametsAndSymptoms(ReportBindingModel model); List<ReportProceduresViewModel> GetProceduresByMedicametsAndSymptoms();
/// <summary> /// <summary>
/// Сохранение курсов по процедурам в файл-Word /// Сохранение курсов по процедурам в файл-Word

View File

@@ -2,6 +2,7 @@
{ {
public class ReportProceduresViewModel public class ReportProceduresViewModel
{ {
public int Id { get; set; }
public string ProcedureName { get; set; } = string.Empty; public string ProcedureName { get; set; } = string.Empty;
public DateTime DateStartProcedure { get; set; } public DateTime DateStartProcedure { get; set; }
public DateTime? DateStopProcedure { get; set;} public DateTime? DateStopProcedure { get; set;}

View File

@@ -372,7 +372,7 @@ namespace PolyclinicWebAppSuretor.Controllers
{ {
_suretorReportLogic.SaveCoursesByProcedureToWordFile(report, procedureSearch); _suretorReportLogic.SaveCoursesByProcedureToWordFile(report, procedureSearch);
} }
else if(fileFormat == "xlsx") else if (fileFormat == "xlsx")
{ {
_suretorReportLogic.SaveCoursesByProcedureToExcelFile(report, procedureSearch); _suretorReportLogic.SaveCoursesByProcedureToExcelFile(report, procedureSearch);
} }
@@ -383,21 +383,61 @@ namespace PolyclinicWebAppSuretor.Controllers
return File(fileBytes, mimeType, fileName); return File(fileBytes, mimeType, fileName);
} }
/// <summary>
// PROCEDURESREPORT
/// </summary>
/// <returns></returns>
[HttpGet] [HttpGet]
[HttpPost] /*public IActionResult ProceduresReport()
public IActionResult ProceduresReport()
{ {
if (HttpContext.Request.Method == "POST") return View(new List<ReportProceduresViewModel>());
}*/
[HttpPost]
public IActionResult ProceduresReport(DateTime? dateFrom, DateTime? dateTo, string reportType)
{
if (reportType == "form")
{ {
ViewData["ShowReport"] = true; var proceduresReport = _suretorReportLogic.GetProceduresByMedicametsAndSymptoms();
return View();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>)
if (dateFrom.HasValue)
{
proceduresReport = proceduresReport.Where(p => p.DateStartProcedure >= dateFrom.Value).ToList();
}
if (dateTo.HasValue)
{
proceduresReport = proceduresReport.Where(p => p.DateStopProcedure <= dateTo.Value).ToList();
}
return View(proceduresReport);
}
else if (reportType == "email")
{
var reportBindingModel = new ReportBindingModel
{
FileName = "ProceduresReport.pdf",
DateFrom = dateFrom,
DateTo = dateTo
};
_suretorReportLogic.SaveProceduresToPdfFile(reportBindingModel);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
var fileBytes = System.IO.File.ReadAllBytes(reportBindingModel.FileName);
var fileName = "ProceduresReport.pdf";
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return File(fileBytes, "application/pdf", fileName);
} }
else else
{ {
return View(); return View(new List<ReportProceduresViewModel>());
} }
} }
[HttpGet] [HttpGet]
[HttpPost] [HttpPost]
public IActionResult Login() public IActionResult Login()

View File

@@ -23,6 +23,7 @@ builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<AbstractSaveToWordCoursesByProcedures, SaveToWordCoursesByProcedure>(); builder.Services.AddTransient<AbstractSaveToWordCoursesByProcedures, SaveToWordCoursesByProcedure>();
builder.Services.AddTransient<AbstractSaveToExcelCoursesByProcedure, SaveToExcelCoursesByProcedure>(); builder.Services.AddTransient<AbstractSaveToExcelCoursesByProcedure, SaveToExcelCoursesByProcedure>();
builder.Services.AddTransient<AbstractSaveToPdfProcedures, SaveToPdfProcedures>();
builder.Services.AddTransient<ISuretorReportLogic, SuretorReportLogic>(); builder.Services.AddTransient<ISuretorReportLogic, SuretorReportLogic>();
builder.Services.AddTransient<IDiagnoseLogic, DiagnoseLogic>(); builder.Services.AddTransient<IDiagnoseLogic, DiagnoseLogic>();

View File

@@ -1,19 +1,17 @@
@using PolyclinicContracts.ViewModels @using PolyclinicContracts.ViewModels
@model List<ReportProceduresViewModel>
@{ @{
ViewData["Title"] = "ProceduresReport"; ViewData["Title"] = "ProceduresReport";
} }
<div class="d-flex flex-column"> <div class="d-flex flex-column">
<form method="post" class="form-procedures-report d-flex mb-4"> <form method="post" class="form-procedures-report d-flex mb-4">
<div class="me-5"> <div class="me-5">
<label for="dateFrom"> <label for="dateFrom">Дата начала</label>
Дата начала
</label>
<input type="date" id="dateFrom" name="dateFrom" /> <input type="date" id="dateFrom" name="dateFrom" />
</div> </div>
<div class="me-5"> <div class="me-5">
<label for="dateTo"> <label for="dateTo">Дата завершения</label>
Дата завершения
</label>
<input type="date" id="dateTo" name="dateTo" /> <input type="date" id="dateTo" name="dateTo" />
</div> </div>
<div class="me-5"> <div class="me-5">
@@ -28,77 +26,41 @@
</div> </div>
</fieldset> </fieldset>
</div> </div>
<button class="btn btn-primary btn-sm" type="submit"> <button class="btn btn-primary btn-sm" type="submit">Сформировать</button>
Сформировать
</button>
</form> </form>
@if (ViewData.ContainsKey("ShowReport"))
@if (Model != null && Model.Any())
{ {
<table class="table mt-3 caption-top table-hover"> <table class="table mt-3 caption-top table-hover">
<caption>Отчет по лекарствам с 01.01.2023 по 31.12.2023</caption> <caption>Отчет по процедурам</caption>
<thead> <thead>
<tr> <tr>
<th scope="col"> <th scope="col">Номер</th>
# <th scope="col">Процедура</th>
</th> <th scope="col">Дата начала</th>
<th scope="col"> <th scope="col">Дата завершения</th>
Процедура <th scope="col">Лекарство</th>
</th> <th scope="col">Симптом</th>
<th scope="col">
Дата начала
</th>
<th scope="col">
Дата завершения
</th>
<th scope="col">
Лекарства
</th>
<th scope="col">
Симптомы
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@{ @foreach (var item in Model)
for (int i = 0; i < 5; i++) {
{ <tr>
<tr> <td>@item.Id</td>
<th scope="row"> <td>@item.ProcedureName</td>
@(i + 1) <td>@item.DateStartProcedure.ToShortDateString()</td>
</th> <td>@item.DateStopProcedure?.ToShortDateString()</td>
<td> @foreach (var ms in item.MedicamentSymptom)
Процедура мытья спины {
</td> <td>@ms.medicamentName</td>
<td> <td>@ms.symptomName</td>
16.03.2023 }
</td>
<td> @* <td>@string.Join("<br/>", item.MedicamentSymptom.Select(ms => ms.medicamentName))</td>
20.10.2023 <td>@string.Join("<br/>", item.MedicamentSymptom.Select(ms => ms.symptomName))</td> *@
</td> </tr>
<td>
Амоксициллин<sup>&reg;</sup>
</td>
<td>
Лихорадка
</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Активированный уголь<sup>&reg;</sup></td>
<td>Покрасения</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Аскорбиновая кислота<sup>&reg;</sup></td>
<td>Головокружение</td>
</tr>
}
} }
</tbody> </tbody>
</table> </table>