2024-05-27 01:52:34 +04:00
|
|
|
|
using HospitalBusinessLogics.MailWorker;
|
|
|
|
|
using HospitalContracts.BindingModels;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
using HospitalContracts.BusinessLogicsContracts;
|
|
|
|
|
using HospitalContracts.SearchModels;
|
2024-05-23 01:38:16 +04:00
|
|
|
|
using HospitalContracts.ViewModels;
|
|
|
|
|
using HospitalDataModels.Enums;
|
|
|
|
|
using HospitalWebApp.Models;
|
2024-04-29 00:38:02 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace HospitalWebApp.Controllers
|
|
|
|
|
{
|
2024-05-23 01:38:16 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Главный контроллер
|
|
|
|
|
/// </summary>
|
2024-04-29 00:38:02 +04:00
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
2024-05-23 01:38:16 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логгер
|
|
|
|
|
/// </summary>
|
2024-04-29 00:38:02 +04:00
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для сущности "Доктор"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IDoctorLogic _doctorLogic;
|
|
|
|
|
|
2024-05-26 23:04:41 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для отчетов
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
|
2024-05-27 01:52:34 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для отправки писем
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly AbstractMailWorker _mailLogic;
|
|
|
|
|
|
2024-05-26 23:04:41 +04:00
|
|
|
|
/// <summary>
|
2024-05-23 01:38:16 +04:00
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger"></param>
|
2024-05-25 23:29:08 +04:00
|
|
|
|
/// <param name="doctorLogic"></param>
|
2024-05-26 23:04:41 +04:00
|
|
|
|
/// <param name="reportLogic"></param>
|
2024-05-27 01:52:34 +04:00
|
|
|
|
/// <param name="mailLogic"></param>
|
|
|
|
|
public HomeController(ILogger<HomeController> logger, IDoctorLogic doctorLogic, IReportLogic reportLogic, AbstractMailWorker mailLogic)
|
2024-04-29 00:38:02 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_doctorLogic = doctorLogic;
|
2024-05-26 23:04:41 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
2024-05-27 01:52:34 +04:00
|
|
|
|
_mailLogic = mailLogic;
|
2024-04-29 00:38:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 01:38:16 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Домашняя страница
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2024-05-25 23:29:08 +04:00
|
|
|
|
public IActionResult Index()
|
2024-04-29 00:38:02 +04:00
|
|
|
|
{
|
2024-05-23 01:38:16 +04:00
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APIClient.Doctor);
|
2024-04-29 00:38:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 01:38:16 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Личные данные доктора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2024-04-29 00:38:02 +04:00
|
|
|
|
public IActionResult Privacy()
|
2024-05-23 01:38:16 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(APIClient.Doctor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Личные данные доктора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fullname"></param>
|
|
|
|
|
/// <param name="post"></param>
|
|
|
|
|
/// <param name="email"></param>
|
|
|
|
|
/// <param name="password"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string fullname, DoctorPost post, string email, string password)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_doctorLogic.Update(new DoctorBindingModel
|
2024-05-23 01:38:16 +04:00
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Doctor.Id,
|
|
|
|
|
FullName = fullname,
|
|
|
|
|
Post = post,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APIClient.Doctor.FullName = fullname;
|
|
|
|
|
APIClient.Doctor.Post = post;
|
|
|
|
|
APIClient.Doctor.Email = email;
|
|
|
|
|
APIClient.Doctor.Password = password;
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Privacy");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Аутентификация
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
2024-04-29 00:38:02 +04:00
|
|
|
|
{
|
2024-05-25 23:29:08 +04:00
|
|
|
|
if (APIClient.Doctor != null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы уже авторизовались!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 00:38:02 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 01:38:16 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Аутентификация
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="email"></param>
|
|
|
|
|
/// <param name="password"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string email, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
APIClient.Doctor = _doctorLogic.ReadElement(new DoctorSearchModel
|
|
|
|
|
{
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
2024-05-23 01:38:16 +04:00
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("Index");
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Регистрация
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
2024-05-25 23:29:08 +04:00
|
|
|
|
if (APIClient.Doctor != null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы уже зарегистрировались!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 01:38:16 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Регистрация
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fullname"></param>
|
|
|
|
|
/// <param name="post"></param>
|
|
|
|
|
/// <param name="email"></param>
|
|
|
|
|
/// <param name="password"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string fullname, DoctorPost post, string email, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_doctorLogic.Create(new DoctorBindingModel
|
2024-05-23 01:38:16 +04:00
|
|
|
|
{
|
|
|
|
|
FullName = fullname,
|
|
|
|
|
Post = post,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выйти из аккаунта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public void Logout()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.Doctor = null;
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 23:04:41 +04:00
|
|
|
|
/// <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>
|
2024-05-27 01:52:34 +04:00
|
|
|
|
/// <param name="fileUpload"></param>
|
2024-05-26 23:04:41 +04:00
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
2024-05-27 01:52:34 +04:00
|
|
|
|
public void SendReport(IFormFile fileUpload)
|
2024-05-26 23:04:41 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 01:52:34 +04:00
|
|
|
|
if (fileUpload == null || fileUpload.Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Файл не выбран или пуст!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Путь до файла
|
|
|
|
|
var uploadPath = @"D:\ULSTU\Семестр 4\РПП Coursework\Reports\";
|
|
|
|
|
var fileName = Path.GetFileName(fileUpload.FileName);
|
|
|
|
|
var fullPath = Path.Combine(uploadPath, fileName);
|
|
|
|
|
|
|
|
|
|
_mailLogic.MailSendAsync(new MailSendInfoBindingModel
|
|
|
|
|
{
|
|
|
|
|
MailAddress = APIClient.Doctor.Email,
|
|
|
|
|
Subject = $"{fileName.Split('.')[0]}",
|
|
|
|
|
Text = $"Отчёт отправлен {DateTime.Now}",
|
|
|
|
|
Path = fullPath
|
|
|
|
|
});
|
2024-05-26 23:04:41 +04:00
|
|
|
|
|
|
|
|
|
Response.Redirect("/Home/Reports");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ошибка
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
2024-04-29 00:38:02 +04:00
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|