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

108 lines
4.4 KiB
C#

using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels;
namespace PolyclinicBusinessLogic.BusinessLogics
{
public class ImplementerReportLogic : IImplementerReportLogic
{
private readonly IDiagnoseStorage _diagnoseStorage;
private readonly IMedicamentStorage _medicamentStorage;
private readonly ICourseStorage _courseStorage;
private readonly ISymptomStorage _symptomStorage;
public ImplementerReportLogic(IDiagnoseStorage diagnoseStorage, IMedicamentStorage medicamentStorage, ICourseStorage courseStorage, ISymptomStorage symptomStorage)
{
_diagnoseStorage = diagnoseStorage;
_medicamentStorage = medicamentStorage;
_courseStorage = courseStorage;
_symptomStorage = symptomStorage;
}
public List<ReportDiagnoseWithCoursesAndSymptomesViewModel> GetDiagnoses()
{
var diagnoses = _diagnoseStorage.GetFullList();
var courses = _courseStorage.GetFullList();
var symptomes = _symptomStorage.GetFullList();
var result = new List<ReportDiagnoseWithCoursesAndSymptomesViewModel>();
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)
{
var dianoseReportModel = new ReportDiagnoseWithCoursesAndSymptomesViewModel {
DiagnoseId = diagnose.Id,
DiagnoseName = diagnose.Name,
DiagnoseComment = diagnose.Comment,
DiagnoseDateStart = diagnose.DateStartDiagnose,
DiagnoseDateStop = diagnose.DateStopDiagnose,
Courses = diagnoseCourses.Select(x => (x.DaysCount, x.PillsPerDay)).ToList(),
Symptomes = diagnoseSymptomes.Select(x => x.Name).ToList()
};
result.Add(dianoseReportModel);
}
}
return result;
}
public List<ReportMedicamentsByDiagnoseViewModel> GetMedicamentsByDiagnoses(ReportBindingModel model)
{
var diagnoses = _diagnoseStorage
.GetFilteredList(new DiagnoseSearchModel
{
From = model.DateFrom,
To = model.DateTo
});
var symptomes = _symptomStorage
.GetFullList();
var medicaments = _medicamentStorage.GetFullList();
List<ReportMedicamentsByDiagnoseViewModel> result = new();
foreach (var diagnose in diagnoses)
{
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));
}
var diagnoseReportModel = new ReportMedicamentsByDiagnoseViewModel {
DiagnoseId = diagnose.Id,
DiagnoseName = diagnose.Name,
DiagnoseComment = diagnose.Comment,
DiagnoseDateStart = diagnose.DateStartDiagnose,
DiagnoseDateStop = diagnose.DateStopDiagnose,
Medicaments = diagnoseMedicaments.Distinct().Select(x => x.Name).ToList()
};
result.Add(diagnoseReportModel);
}
return result;
}
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveSecureComponentToExcelFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveSecuresToWordFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
}