WebApp / Add methods for creating reports to the controller

This commit is contained in:
parent 1f59373622
commit 11f911b2af
9 changed files with 243 additions and 21 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Reports
# Mono auto generated files
mono_crash.*

View File

@ -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"
});

View File

@ -24,15 +24,22 @@ namespace HospitalWebApp.Controllers
/// </summary>
private readonly IDoctorLogic _doctorLogic;
/// <summary>
/// <summary>
/// Бизнес-логика для отчетов
/// </summary>
private readonly IReportLogic _reportLogic;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
/// <param name="doctorLogic"></param>
public HomeController(ILogger<HomeController> logger, IDoctorLogic doctorLogic)
/// <param name="reportLogic"></param>
public HomeController(ILogger<HomeController> logger, IDoctorLogic doctorLogic, IReportLogic reportLogic)
{
_logger = logger;
_doctorLogic = doctorLogic;
_reportLogic = reportLogic;
}
/// <summary>
@ -203,11 +210,140 @@ namespace HospitalWebApp.Controllers
Response.Redirect("Enter");
}
/// <summary>
/// Ошибка
/// </summary>
/// <returns></returns>
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
/// <summary>
/// Получить отчет
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Reports()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
/// <summary>
/// Вывести на форму отчёт
/// </summary>
/// <exception cref="Exception"></exception>
[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);
}
/// <summary>
/// Создать отчёт в формате Word
/// </summary>
/// <exception cref="Exception"></exception>
[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");
}
/// <summary>
/// Создать отчёт в формате Excel
/// </summary>
/// <exception cref="Exception"></exception>
[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");
}
/// <summary>
/// Создать отчёт в формате Pdf
/// </summary>
/// <exception cref="Exception"></exception>
[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");
}
/// <summary>
/// Отправить по почте отчёт
/// </summary>
/// <exception cref="Exception"></exception>
[HttpPost]
public void SendReport()
{
if (APIClient.Doctor == null)
{
throw new Exception("Необходимо авторизоваться!");
}
// TODO
Response.Redirect("/Home/Reports");
}
/// <summary>
/// Ошибка
/// </summary>
/// <returns></returns>
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });

View File

@ -29,8 +29,8 @@
<th>Название</th>
<th>Симптомы</th>
<th>Номер рецепта</th>
<th>Изменить</th>
<th>Удалить</th>
<th></th>
<th></th>
</tr>
</thead>

View File

@ -1,6 +1,6 @@
@using HospitalContracts.BindingModels;
@using HospitalContracts.ViewModels
@model ReportBindingModel
@model List<ReportPatientsViewModel>
@{
ViewBag.Title = "Отчеты";
@ -10,4 +10,89 @@
<h2 class="display-4">Отчеты</h2>
</div>
<!-- TODO -->
<form method="post" style="margin-top: 50px">
<!-- Сохранить отчеты в формате Word и Excel -->
<div class="d-flex justify-content-center" style="gap: 30px">
<div class="text-center">
<button type="submit" class="btn btn-primary" formaction="@Url.Action("CreateReportWord", "Home")">Список процедур Word</button>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary" formaction="@Url.Action("CreateReportExcel", "Home")">Список процедур Excel</button>
</div>
</div>
<!-- Временной период выборки данных -->
<div class="d-flex justify-content-center" style="margin: 30px 0px">
<div class="text-center">
<label for="dateFrom">С</label>
<input type="date" id="dateFrom" name="dateFrom" class="form-control d-inline-block w-auto">
</div>
<div class="text-center">
<label for="dateTo">по</label>
<input type="date" id="dateTo" name="dateTo" class="form-control d-inline-block w-auto">
</div>
</div>
<!-- Действия для отчета в формате Pdf -->
<div class="d-flex justify-content-around">
<!-- Сохранить отчет в формате Pdf -->
<div class="text-center">
<button type="submit" class="btn btn-primary" formaction="@Url.Action("CreateReportPdf", "Home")">Сведения о пациентах Pdf</button>
</div>
<!-- Отправить отчет на почту -->
<div class="d-flex">
<label for="fileUpload" class="d-block"></label>
<input type="file" id="fileUpload" name="fileUpload" class="form-control-file d-inline-block w-auto">
<button type="submit" class="btn btn-primary" formaction="@Url.Action("SendReport", "Home")">Отправить отчет на почту</button>
</div>
<!-- Вывести отчет на форму -->
<div class="text-center">
<button type="submit" class="btn btn-primary" formaction="@Url.Action("Reports", "Home")">Вывести отчет на форму</button>
</div>
</div>
</form>
<!-- Таблица для вывода отчета на форму -->
<table class="table">
<thead>
<tr>
<th>Пациент</th>
<th>Лекарства</th>
<th>Болезни</th>
</tr>
</thead>
<tbody>
@if (Model == null || Model.Count <= 0)
{
<td class="text-center" colspan="3">Нет доступных данных</td>
}
else
{
foreach (var record in Model)
{
// Имя пациента
<td>@record.Patient.FullName</td>
<td></td>
<td></td>
// Конвертируем из HashSet в List, чтобы можно было обращаться по индексу
var medicines = new List<MedicineViewModel>(record.Medicines);
var diseases = new List<DiseaseViewModel>(record.Diseases);
// Записываем названия лекарств во 2 колонку
// и названия лекарств в 3 колонку
int maxLength = Math.Max(medicines.Count, diseases.Count);
for (int i = 0; i < maxLength; i++)
{
<tr>
<td></td>
<td>@(i < medicines.Count ? medicines[i].Name : "")</td>
<td>@(i < diseases.Count ? diseases[i].Name : "")</td>
</tr>
}
}
}
</tbody>
</table>

View File

@ -28,8 +28,8 @@
<th>Номер</th>
<th>Название</th>
<th>Описание</th>
<th>Изменить</th>
<th>Удалить</th>
<th></th>
<th></th>
</tr>
</thead>

View File

@ -30,8 +30,8 @@
<th>Дата рождения</th>
<th>Номер телефона</th>
<th>Лечащий врач</th>
<th>Изменить</th>
<th>Удалить</th>
<th></th>
<th></th>
</tr>
</thead>

View File

@ -28,8 +28,8 @@
<th>Номер</th>
<th>Название</th>
<th>Описание</th>
<th>Изменить</th>
<th>Удалить</th>
<th></th>
<th></th>
</tr>
</thead>

View File

@ -28,8 +28,8 @@
<th>Номер</th>
<th>Дата выписки</th>
<th>Доктор</th>
<th>Изменить</th>
<th>Удалить</th>
<th></th>
<th></th>
</tr>
</thead>