2024-04-27 21:32:29 +04:00
|
|
|
|
using HospitalBusinessLogics.OfficePackage.HelperEnums;
|
|
|
|
|
using HospitalBusinessLogics.OfficePackage.HelperModels;
|
2024-04-30 18:43:06 +04:00
|
|
|
|
using HospitalContracts.ViewModels;
|
2024-04-27 21:32:29 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace HospitalBusinessLogics.OfficePackage
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Абстрактный класс для создания отчета Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class AbstractSaveToPdf
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать отчет Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
public void CreateReport(PdfInfo info)
|
|
|
|
|
{
|
|
|
|
|
// Создаем файл
|
|
|
|
|
CreatePdf(info);
|
|
|
|
|
|
|
|
|
|
// Создаем заголовок
|
|
|
|
|
// "Сведения по пациентам."
|
|
|
|
|
CreateParagraph(new PdfParagraph
|
|
|
|
|
{
|
|
|
|
|
Text = info.Title,
|
|
|
|
|
Style = "NormalTitle"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Период выборки данных
|
|
|
|
|
// "с XX.XX.XXXX по XX.XX.XXXX"
|
|
|
|
|
CreateParagraph(new PdfParagraph
|
|
|
|
|
{
|
2024-05-26 23:04:41 +04:00
|
|
|
|
Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
2024-04-27 21:32:29 +04:00
|
|
|
|
Style = "Normal"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Создаем таблицу с тремя колонками
|
|
|
|
|
CreateTable(new List<string> { "7cm", "4cm", "4cm" });
|
|
|
|
|
|
|
|
|
|
// Создаем заголовок таблицы
|
|
|
|
|
// "Пациент" | "Лекарства" | "Болезни"
|
|
|
|
|
CreateRow(new PdfRowParameters
|
|
|
|
|
{
|
|
|
|
|
Texts = new List<string> { "Пациент", "Лекарства", "Болезни" },
|
|
|
|
|
Style = "NormalTitle",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Записываем основную информацию
|
|
|
|
|
foreach (var view in info.PatientsInfo)
|
|
|
|
|
{
|
|
|
|
|
// Записываем имя пациента в первую колонку
|
|
|
|
|
CreateRow(new PdfRowParameters
|
|
|
|
|
{
|
2024-04-30 18:43:06 +04:00
|
|
|
|
Texts = new List<string> { view.Patient.FullName, "", "" },
|
2024-04-27 21:32:29 +04:00
|
|
|
|
Style = "Normal",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-30 18:43:06 +04:00
|
|
|
|
// Конвертируем из HashSet в List, чтобы можно было обращаться по индексу
|
|
|
|
|
List<MedicineViewModel> medicines = new List<MedicineViewModel>(view.Medicines);
|
|
|
|
|
List<DiseaseViewModel> diseases = new List<DiseaseViewModel>(view.Diseases);
|
|
|
|
|
|
2024-04-27 21:32:29 +04:00
|
|
|
|
// Записываем названия лекарств во 2 колонку
|
|
|
|
|
// и названия лекарств в 3 колонку
|
2024-04-30 18:43:06 +04:00
|
|
|
|
int maxLength = Math.Max(medicines.Count, diseases.Count);
|
2024-04-27 21:32:29 +04:00
|
|
|
|
for (int i = 0; i < maxLength; i++)
|
|
|
|
|
{
|
2024-04-30 18:43:06 +04:00
|
|
|
|
string medicine = (i < medicines.Count) ? medicines[i].Name : "";
|
|
|
|
|
string disease = (i < diseases.Count) ? diseases[i].Name : "";
|
2024-04-27 21:32:29 +04:00
|
|
|
|
CreateRow(new PdfRowParameters
|
|
|
|
|
{
|
|
|
|
|
Texts = new List<string> { "", medicine, disease },
|
|
|
|
|
Style = "Normal",
|
|
|
|
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Сохраняем файл
|
|
|
|
|
SavePdf(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать файл Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
protected abstract void CreatePdf(PdfInfo info);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать абзац с текстом
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paragraph"></param>
|
|
|
|
|
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать таблицу
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="columns"></param>
|
|
|
|
|
protected abstract void CreateTable(List<string> columns);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать и заполнить строку
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rowParameters"></param>
|
|
|
|
|
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранить файл Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
|
|
|
|
protected abstract void SavePdf(PdfInfo info);
|
|
|
|
|
}
|
|
|
|
|
}
|