134 lines
4.7 KiB
C#
134 lines
4.7 KiB
C#
using HospitalBusinessLogic.OfficePackage;
|
|
using HospitalBusinessLogic.OfficePackage.HelperModels;
|
|
using HospitalContracts.BindingModels;
|
|
using HospitalContracts.BusinessLogicsContracts;
|
|
using HospitalContracts.SearchModels;
|
|
using HospitalContracts.StoragesContracts;
|
|
using HospitalContracts.ViewModels;
|
|
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 IKurseStorage _kurseStorage;
|
|
private readonly IMedicinesStorage _medicineStorage;
|
|
private readonly IRecipesStorage _recipeStorage;
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
public ReportLogic(IKurseStorage kurseStorage, IMedicinesStorage medicineStorage, IRecipesStorage recipeStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
|
{
|
|
_saveToExcel = saveToExcel;
|
|
_saveToWord = saveToWord;
|
|
_saveToPdf = saveToPdf;
|
|
_kurseStorage = kurseStorage;
|
|
_medicineStorage = medicineStorage;
|
|
_recipeStorage = recipeStorage;
|
|
}
|
|
public List<ReportKurseMedicinesViewModel> GetKurseMedicines(List<int> Ids)
|
|
{
|
|
if (Ids == null)
|
|
{
|
|
return new List<ReportKurseMedicinesViewModel>();
|
|
}
|
|
var kurses = _kurseStorage.GetFullList();
|
|
List<MedicinesViewModel> medicines = new List<MedicinesViewModel>();
|
|
foreach (var mId in Ids)
|
|
{
|
|
var res = _medicineStorage.GetElement(new MedicinesSearchModel { Id = mId });
|
|
if (res != null)
|
|
{
|
|
medicines.Add(res);
|
|
}
|
|
}
|
|
var list = new List<ReportKurseMedicinesViewModel>();
|
|
foreach (var medicine in medicines)
|
|
{
|
|
var record = new ReportKurseMedicinesViewModel
|
|
{
|
|
MedicinesName = medicine.MedicinesName,
|
|
Kurses = new List<Tuple<int, string>>()
|
|
};
|
|
foreach (var kurse in kurses)
|
|
{
|
|
if (kurse.KurseMedicines.ContainsKey(medicine.Id))
|
|
{
|
|
record.Kurses.Add(new Tuple<int, string>(kurse.Id, kurse.Duration));
|
|
}
|
|
}
|
|
list.Add(record);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public List<ReportRecipesViewModel> GetRecipes(ReportBindingModel model)
|
|
{
|
|
var listAll = new List<ReportRecipesViewModel>();
|
|
|
|
var listRecipes = _recipeStorage.GetFilteredList(new RecipesSearchModel
|
|
{
|
|
ClientId = model.ClientId,
|
|
DateFrom = model.DateFrom,
|
|
DateTo = model.DateTo
|
|
});
|
|
|
|
foreach (var recipe in listRecipes)
|
|
{
|
|
listAll.Add(new ReportRecipesViewModel
|
|
{
|
|
Date = recipe.Date,
|
|
Dose = recipe.Dose,
|
|
ModeofApplication = recipe.ModeOfApplication
|
|
});
|
|
}
|
|
return listAll;
|
|
}
|
|
|
|
public void SaveMedicinesToExcelFile(ReportBindingModel model)
|
|
{
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Список курсов",
|
|
KurseMedicines = GetKurseMedicines(model.Ids)
|
|
});
|
|
}
|
|
|
|
public void SaveMedicinesToWordFile(ReportBindingModel model)
|
|
{
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Список курсов",
|
|
KurseMedicines = GetKurseMedicines(model.Ids)
|
|
});
|
|
}
|
|
|
|
public void SaveRecipesToPdfFile(ReportBindingModel model)
|
|
{
|
|
if (model.DateFrom == null)
|
|
{
|
|
throw new ArgumentException("Дата начала не задана");
|
|
}
|
|
|
|
if (model.DateTo == null)
|
|
{
|
|
throw new ArgumentException("Дата окончания не задана");
|
|
}
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Список рецептов",
|
|
DateFrom = model.DateFrom!.Value,
|
|
DateTo = model.DateTo!.Value,
|
|
Recipes = GetRecipes(model)
|
|
});
|
|
}
|
|
}
|
|
}
|