Реализация логики получения данных для отчетов.

This commit is contained in:
Anastasia 2023-04-07 14:50:12 +04:00
parent 2a52d1264d
commit 215304007f
21 changed files with 708 additions and 0 deletions

View File

@ -0,0 +1,176 @@
using HospitalBusinessLogic.OfficePackage;
using HospitalBusinessLogic.OfficePackage.HelperModels;
using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicsContracts;
using HospitalContracts.SearchModels;
using HospitalContracts.StoragesContracts;
using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IPatientStorage _patientStorage;
private readonly IRecipeStorage _recipeStorage;
private readonly IMedicineStorage _medicineStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IPatientStorage patientStorage, IRecipeStorage recipeStorage, IMedicineStorage medicineStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_patientStorage = patientStorage;
_recipeStorage = recipeStorage;
_medicineStorage = medicineStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportPatientMedicineViewModel> GetPatientMedicine()
{
throw new NotImplementedException();
}
/// <summary>
/// Получение списка лекарств с указанием пациентов
/// </summary>
/// <returns></returns>
public List<ReportPatientMedicineViewModel> GetPatientMedicineModule()
{
var medicines = _medicineStorage.GetFullList();
var recipes = _recipeStorage.GetFullList();
var patients = _patientStorage.GetFullList();
var list = new List<ReportPatientMedicineViewModel>();
foreach (var patient in patients)
{
var record = new ReportPatientMedicineViewModel
{
PatientSurname = patient.Surname,
PatientName = patient.Name,
PatientPatronymic = patient.Patronymic,
Medicines = new Dictionary<int, string>(),
};
foreach (var recipe in recipes)
{
if (patient.PatientRecipes.ContainsValue(recipe))
{
foreach (var medicine in medicines)
{
if (recipe.RecipeMedicines.ContainsKey(medicine.Id))
{
record.Medicines.Add(medicine.Id, medicine.Name);
}
}
}
}
list.Add(record);
}
return list;
}
/// <summary>
/// Получение списка пациентов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportPatientsViewModel> GetPatients(ReportBindingModel model)
{
var patients = _patientStorage.GetFilteredList(new PatientSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
var medicines = _medicineStorage.GetFullList();
var recipes = _recipeStorage.GetFullList();
var list = new List<ReportPatientsViewModel>();
foreach (var patient in patients)
{
var record = new ReportPatientsViewModel
{
Id = patient.Id,
PatientSurname = patient.Surname,
PatientName = patient.Name,
PatientPatronymic = patient.Patronymic,
Medicines = new Dictionary<int, string>()
};
foreach (var recipe in recipes)
{
if (patient.PatientRecipes.ContainsValue(recipe))
{
foreach (var medicine in medicines)
{
if (recipe.RecipeMedicines.ContainsKey(medicine.Id))
{
record.Medicines.Add(medicine.Id, medicine.Name);
}
}
}
}
list.Add(record);
}
return list;
}
public void SavePatientMedicineToExcelFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SavePatientMedicineToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SavePatientsToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
///// <summary>
///// Сохранение компонент в файл-Word
///// </summary>
///// <param name="model"></param>
//public void SaveFurnitureModuleToWordFile(ReportBindingModel model)
//{
// _saveToWord.CreateDoc(new WordInfo
// {
// FileName = model.FileName,
// Title = "Список компонент",
// Sets = _setStorage.GetFullList()
// });
//}
///// <summary>
///// Сохранение компонент с указаеним продуктов в файл-Excel
///// </summary>
///// <param name="model"></param>
//public void SaveSetFurnitureModuleToExcelFile(ReportBindingModel model)
//{
// _saveToExcel.CreateReport(new ExcelInfo
// {
// FileName = model.FileName,
// Title = "Список компонент",
// SetFurnitureModules = GetSetFurnitureModule()
// });
//}
///// <summary>
///// Сохранение заказов в файл-Pdf
///// </summary>
///// <param name="model"></param>
//public void SaveOrdersToPdfFile(ReportBindingModel model)
//{
// _saveToPdf.CreateDoc(new PdfInfo
// {
// FileName = model.FileName,
// Title = "Список заказов",
// DateFrom = model.DateFrom!.Value,
// DateTo = model.DateTo!.Value,
// Orders = GetOrders(model)
// });
//}
}
}

View File

@ -0,0 +1,83 @@
using HospitalBusinessLogic.OfficePackage.HelperEnums;
using HospitalBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcel
{
/// <summary>
/// Создание отчета
/// </summary>
/// <param name="info"></param>
public void CreateReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var pm in info.PatientMedicines)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pm.MedicineName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
//Text = pm.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateExcel(ExcelInfo info);
/// <summary>
/// Добавляем новую ячейку в лист
/// </summary>
/// <param name="cellParameters"></param>
protected abstract void InsertCellInWorksheet(ExcelCellParameters
excelParams);
/// <summary>
/// Объединение ячеек
/// </summary>
/// <param name="mergeParameters"></param>
protected abstract void MergeCells(ExcelMergeParameters excelParams);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveExcel(ExcelInfo info);
}
}

View File

@ -0,0 +1,75 @@
using HospitalBusinessLogic.OfficePackage.HelperEnums;
using HospitalBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style =
"NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата", "Пациент","Лекарства" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var patient in info.Patients)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { patient.Id.ToString(), patient.PatientSurname, patient.PatientName, patient.PatientPatronymic, patient.MedicineName},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
SavePdf(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreatePdf(PdfInfo info);
/// <summary>
/// Создание параграфа с текстом
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateParagraph(PdfParagraph paragraph);
/// <summary>
/// Создание таблицы
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateTable(List<string> columns);
/// <summary>
/// Создание и заполнение строки
/// </summary>
/// <param name="rowParameters"></param>
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -0,0 +1,56 @@
using HospitalBusinessLogic.OfficePackage.HelperEnums;
using HospitalBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
public void CreateDoc(WordInfo info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
foreach (var medicine in info.Medicines)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {(medicine.Name, new WordTextProperties { Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordInfo info);
/// <summary>
/// Создание абзаца с текстом
/// </summary>
/// <param name="paragraph"></param>
/// <returns></returns>
protected abstract void CreateParagraph(WordParagraph paragraph);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfo info);
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperEnums
{
public enum ExcelStyleInfoType
{
Title,
Text,
TextWithBroder
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Rigth
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperEnums
{
public enum WordJustificationType
{
Center,
Both
}
}

View File

@ -0,0 +1,19 @@
using HospitalBusinessLogic.OfficePackage.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class ExcelCellParameters
{
public string ColumnName { get; set; } = string.Empty;
public uint RowIndex { get; set; }
public string Text { get; set; } = string.Empty;
public string CellReference => $"{ColumnName}{RowIndex}";
public ExcelStyleInfoType StyleInfo { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class ExcelInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportPatientMedicineViewModel> PatientMedicines
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class ExcelMergeParameters
{
public string CellFromName { get; set; } = string.Empty;
public string CellToName { get; set; } = string.Empty;
public string Merge => $"{CellFromName}:{CellToName}";
}
}

View File

@ -0,0 +1,19 @@
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class PdfInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportPatientsViewModel> Patients { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using HospitalBusinessLogic.OfficePackage.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using HospitalBusinessLogic.OfficePackage.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class PdfRowParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class WordInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<MedicineViewModel> Medicines { get; set; } = new();
public IEnumerable<object> Components { get; internal set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class WordParagraph
{
public List<(string, WordTextProperties)> Texts { get; set; } = new();
public WordTextProperties? TextProperties { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using HospitalBusinessLogic.OfficePackage.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.OfficePackage.HelperModels
{
public class WordTextProperties
{
public string Size { get; set; } = string.Empty;
public bool Bold { get; set; }
public WordJustificationType JustificationType { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BindingModels
{
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,40 @@
using HospitalContracts.BindingModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BusinessLogicsContracts
{
public interface IReportLogic
{
/// <summary>
/// получение списка по «Medicine» на основе выбранных записях «Patient»
/// </summary>
/// <returns></returns>
List<ReportPatientMedicineViewModel> GetPatientMedicine();
/// <summary>
/// Получение списка пациентов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
List<ReportPatientsViewModel> GetPatients(ReportBindingModel model);
/// <summary>
/// Сохранение лекарств в файл-Word
/// </summary>
/// <param name="model"></param>
void SavePatientMedicineToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение лекарств в файл-Excel
/// </summary>
/// <param name="model"></param>
void SavePatientMedicineToExcelFile(ReportBindingModel model);
/// <summary>
/// Сохранение пациентов в файл-Pdf
/// </summary>
/// <param name="model"></param>
void SavePatientsToPdfFile(ReportBindingModel model);
}
}

View File

@ -17,5 +17,7 @@ namespace HospitalContracts.SearchModels
public string? Patronymic { get; set; }
public int? DoctorId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,29 @@
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.ViewModels
{
public class ReportPatientMedicineViewModel
{
public int Id { get; set; }
public string PatientSurname { get; set; } = string.Empty;
public string PatientName { get; set; } = string.Empty;
public string PatientPatronymic { get; set; } = string.Empty;
public int RecipeId { get; set; }
public int DoctorId { get; set; }
public Dictionary<int, string> Medicines { get; set; } = new();
public string MedicineName { get; set; }
}
}

View File

@ -0,0 +1,29 @@
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.ViewModels
{
public class ReportPatientsViewModel
{
public int Id { get; set; }
public string PatientSurname { get; set; } = string.Empty;
public string PatientName { get; set; } = string.Empty;
public string PatientPatronymic { get; set; } = string.Empty;
public int RecipeId { get; set; }
public string MedicineName { get; set; } = string.Empty;
public List<int> Recipes { get; set; } = new();
public Dictionary<int, string> Medicines { get; set; } = new();
}
}