PIbd-21_CourseWork_Polyclin.../Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs

129 lines
5.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports;
using PolyclinicBusinessLogic.OfficePackage.HelperModels;
using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel;
using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF;
using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels;
using PolyclinicDataModels.Models;
namespace PolyclinicBusinessLogic.BusinessLogics
{
public class ImplementerReportLogic : IImplementerReportLogic
{
private readonly IDiagnoseStorage _diagnoseStorage;
private readonly IMedicamentStorage _medicamentStorage;
private readonly ICourseStorage _courseStorage;
private readonly ISymptomStorage _symptomStorage;
private readonly AbstractReportMedicamentsByDiagnosesSaveToExcel _saveToExcel;
private readonly AbstractReportMedicamentsByDiagnosesSaveToWord _saveToWord;
private readonly AbstractReportDiagnosesByPeriodSaveToPdf _saveToPdf;
public ImplementerReportLogic(
IDiagnoseStorage diagnoseStorage,
IMedicamentStorage medicamentStorage,
ICourseStorage courseStorage,
ISymptomStorage symptomStorage,
AbstractReportMedicamentsByDiagnosesSaveToWord saveToWord,
AbstractReportDiagnosesByPeriodSaveToPdf saveToPdf,
AbstractReportMedicamentsByDiagnosesSaveToExcel saveToExcel)
{
_diagnoseStorage = diagnoseStorage;
_medicamentStorage = medicamentStorage;
_courseStorage = courseStorage;
_symptomStorage = symptomStorage;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
_saveToExcel = saveToExcel;
}
public ReportDiagnosesByPeriodViewModel GetReportDiagnosesByPeriod(DateTime? dateStart, DateTime? dateEnd)
{
var diagnoses = _diagnoseStorage.GetFilteredList(new DiagnoseSearchModel { From = dateStart, To = dateEnd });
var courses = _courseStorage.GetFullList();
var symptomes = _symptomStorage.GetFullList();
var report = new ReportDiagnosesByPeriodViewModel();
foreach (var diagnose in diagnoses)
{
var diagnoseCourses = courses.Where(x => x.CourseDiagnoses.ContainsKey(diagnose.Id)).ToList();
var diagnoseSymptomes = symptomes.Where(x => x.SymptomDiagnoses.ContainsKey(diagnose.Id)).ToList();
if (diagnoseCourses.Count > 0 && diagnoseSymptomes.Count > 0)
{
report.DiagnosesData.Add((diagnose, diagnoseSymptomes, diagnoseCourses));
}
}
report.DateStart = dateStart;
report.DateEnd = dateEnd;
return report;
}
public List<ReportMedicamentsByDiagnoseViewModel> GetReportMedicamentsByDiagnoses(int[] diagnosesIds)
{
List<DiagnoseViewModel> diagnoseViewModels = diagnosesIds.Select(x => _diagnoseStorage.GetElement(new DiagnoseSearchModel { Id = x })).ToList();
var symptomes = _symptomStorage.GetFullList();
var medicaments = _medicamentStorage.GetFullList();
List<ReportMedicamentsByDiagnoseViewModel> report = new();
foreach (var diagnose in diagnoseViewModels)
{
var diagnoseSymptomes = symptomes
.Where(x => x.SymptomDiagnoses.ContainsKey(diagnose.Id))
.ToList();
var diagnoseMedicaments = new List<MedicamentViewModel>();
foreach (var symptom in diagnoseSymptomes)
{
diagnoseMedicaments.AddRange(medicaments.Where(x => x.SymptomId == symptom.Id));
}
report.Add(new ReportMedicamentsByDiagnoseViewModel
{
Diagnose = diagnose,
Medicaments = diagnoseMedicaments.DistinctBy(x => x.Name).ToList()
});
}
return report;
}
public void SaveReportDiagnosesByPeriodToPdfFile(ReportBindingModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel)
{
_saveToPdf.CreateDoc(new PdfDiagnosesByPeriodInfo
{
Title = "Отчет по болезням за период с расшифровкой по симптомам и курсам",
DateFrom = reportModel.DateStart,
DateTo = reportModel.DateEnd,
FileName = reportInfo.FileName,
PeriodString = reportInfo.GetPeriodString(),
Report = reportModel
});
}
public void SaveReportMedicamentsByDiagnosesToExcelFile(ReportBindingModel reportInfo, List<ReportMedicamentsByDiagnoseViewModel> reportModel)
{
_saveToExcel.CreateReport(new ReportMedicamentsByDiagnosesInfo
{
FileName = reportInfo.FileName,
Title = "Лекарства по болезням",
ReportModel = reportModel
});
}
public void SaveReportMedicamentsByDiagnosesToWordFile(ReportBindingModel reportInfo, List<ReportMedicamentsByDiagnoseViewModel> reportModel)
{
_saveToWord.CreateDoc(new ReportMedicamentsByDiagnosesInfo
{
FileName = reportInfo.FileName,
Title = "Лекарства по болезням",
ReportModel = reportModel
});
}
}
}