У меня нет слов
This commit is contained in:
parent
004c0381f5
commit
0dc935797e
@ -15,74 +15,74 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportLogicPharmacist : IReportLogicPharmacist
|
||||
{
|
||||
private readonly IProcedureStorage _serviceStorage;
|
||||
private readonly IProcedureStorage _procedureStorage;
|
||||
private readonly IMedicineStorage _medicineStorage;
|
||||
private readonly IRecipeStorage _animalStorage;
|
||||
private readonly AbstractSaveToExcelPharmacist _saveToExcel;
|
||||
private readonly AbstractSaveToWordPharmacist _saveToWord;
|
||||
public ReportLogicPharmacist(IProcedureStorage serviceStorage, IMedicineStorage medicineStorage, IRecipeStorage animalStorage,
|
||||
public ReportLogicPharmacist(IProcedureStorage procedureStorage, IMedicineStorage medicineStorage,
|
||||
AbstractSaveToExcelPharmacist saveToExcel, AbstractSaveToWordPharmacist saveToWord)
|
||||
{
|
||||
_serviceStorage = serviceStorage;
|
||||
_procedureStorage = procedureStorage;
|
||||
_medicineStorage = medicineStorage;
|
||||
_animalStorage = animalStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
}
|
||||
|
||||
public List<ListRecipesViewModel> GetServiceAnimals(List<int> services)
|
||||
public List<ListRecipesViewModel> GetProcedureRecipes(List<int> procedures)
|
||||
{
|
||||
|
||||
List<ListRecipesViewModel> ans = new();
|
||||
foreach (var service in services)
|
||||
List<Tuple<ProcedureViewModel, List<Tuple<MedicineViewModel, List<RecipeViewModel>>>>> response =
|
||||
_procedureStorage.GetReportInfo(new ListRecipesSearchModel { proceduresIds = procedures });
|
||||
|
||||
foreach (var procedure in response)
|
||||
{
|
||||
var medicines = _medicineStorage.GetFilteredList(new MedicineSearchModel { ProcedureId = service });
|
||||
Dictionary<int, int> counter = new();
|
||||
foreach (var medicine in medicines)
|
||||
Dictionary<int, (RecipeViewModel, int)> counter = new();
|
||||
foreach (var medicine in procedure.Item2)
|
||||
{
|
||||
var animals = _animalStorage.GetFilteredList(new RecipeSearchModel { MedicineId = medicine.Id });
|
||||
foreach (var animal in animals)
|
||||
foreach (var recipe in medicine.Item2)
|
||||
{
|
||||
if (!counter.ContainsKey(animal.Id))
|
||||
counter.Add(animal.Id, 1);
|
||||
if (!counter.ContainsKey(recipe.Id))
|
||||
counter.Add(recipe.Id, (recipe, 1));
|
||||
else
|
||||
{
|
||||
counter[animal.Id]++;
|
||||
counter[recipe.Id] = (counter[recipe.Id].Item1, counter[recipe.Id].Item2 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<RecipeViewModel> res = new();
|
||||
foreach (var cnt in counter)
|
||||
{
|
||||
if (cnt.Value != medicines.Count)
|
||||
if (cnt.Value.Item2 != procedure.Item2.Count)
|
||||
continue;
|
||||
res.Add(_animalStorage.GetElement(new RecipeSearchModel { Id = cnt.Key }));
|
||||
res.Add(cnt.Value.Item1);
|
||||
}
|
||||
ans.Add(new ListRecipesViewModel
|
||||
{
|
||||
ProcedureName = _serviceStorage.GetElement(new ProcedureSearchModel { Id = service }).Name,
|
||||
ProcedureName = procedure.Item1.Name,
|
||||
Recipes = res
|
||||
});
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
public void SaveAnimalsToExcelFile(ListRecipesBindingModel model)
|
||||
public void SaveRecipesToExcelFile(ListRecipesBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateReport(new ExcelInfoPharmacist
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список рецептов для процедур",
|
||||
ProceduresRecipes = GetServiceAnimals(model.Procedures)
|
||||
ProceduresRecipes = GetProcedureRecipes(model.Procedures)
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveAnimalsToWordFile(ListRecipesBindingModel model)
|
||||
public void SaveRecipesToWordFile(ListRecipesBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateDoc(new WordInfoPharmacist
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список рецептов для процедур",
|
||||
ProceduresRecipes = GetServiceAnimals(model.Procedures)
|
||||
ProceduresRecipes = GetProcedureRecipes(model.Procedures)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ namespace HospitalContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IReportLogicPharmacist //В процессе
|
||||
{
|
||||
List<ListRecipesViewModel> GetServiceAnimals(List<int> services);
|
||||
void SaveAnimalsToWordFile(ListRecipesBindingModel model);
|
||||
void SaveAnimalsToExcelFile(ListRecipesBindingModel model);
|
||||
List<ListRecipesViewModel> GetProcedureRecipes(List<int> services);
|
||||
void SaveRecipesToWordFile(ListRecipesBindingModel model);
|
||||
void SaveRecipesToExcelFile(ListRecipesBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalContracts.SearchModels
|
||||
{
|
||||
public class ListRecipesSearchModel
|
||||
{
|
||||
public List<int>? proceduresIds { get; set; }
|
||||
}
|
||||
}
|
@ -13,6 +13,5 @@ namespace HospitalContracts.SearchModels
|
||||
public string? CountryOrigin { get; set; }
|
||||
public double? Price { get; set; }
|
||||
public int? PharmacistId { get; set; }
|
||||
public int? ProcedureId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalContracts.SearchModels
|
||||
{
|
||||
public class PatientDescriptionProceduresSearchModel
|
||||
{
|
||||
public List<int>? medicinesIds { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ namespace HospitalContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? DoctorId { get; set; }
|
||||
DateTime IssueDate { get; }
|
||||
public int? MedicineId { get; set; }
|
||||
DateTime IssueDate { get; }
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace HospitalContracts.StoragesContracts
|
||||
{
|
||||
List<ProcedureViewModel> GetFullList();
|
||||
List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model);
|
||||
List<Tuple<ProcedureViewModel, List<Tuple<MedicineViewModel, List<RecipeViewModel>>>>> GetReportInfo(ListRecipesSearchModel model);
|
||||
ProcedureViewModel? GetElement(ProcedureSearchModel model);
|
||||
ProcedureViewModel? Insert(ProcedureBindingModel model);
|
||||
ProcedureViewModel? Update(ProcedureBindingModel model);
|
||||
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HospitalContracts.ViewModels;
|
||||
|
||||
namespace HospitalDataBaseImplement.Implements
|
||||
{
|
||||
public class PatientsDescriptionProceduresViewModel
|
||||
{
|
||||
public string PatientName { get; set; } = string.Empty;
|
||||
public List<PatientViewModel> Patients { get; set; } = new();
|
||||
public List<DescriptionProcedureViewModel> DescriptionProcedures { get; set; } = new();
|
||||
}
|
||||
}
|
@ -31,8 +31,7 @@ namespace HospitalDatabaseImplement.Implements
|
||||
return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Recipes)
|
||||
.ThenInclude(x => x.Recipe).Include(x => x.Procedures).ThenInclude(x => x.Procedure)
|
||||
.Where(x => (string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
|
||||
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)
|
||||
&& (!model.ProcedureId.HasValue || x.Procedures.Select(x => x.ProcedureId).ToList().Contains(model.ProcedureId.Value)))
|
||||
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -26,17 +26,14 @@ namespace HospitalDatabaseImplement.Implements
|
||||
public List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model)
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return context.Procedures
|
||||
.Include(x => x.Medicines)
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return context.Procedures.Include(x => x.Pharmacist)
|
||||
.Include(x => x.Medicines)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
.Where(x => (string.IsNullOrEmpty(model.Name) || x.Name.Contains(model.Name))
|
||||
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProcedureViewModel? GetElement(ProcedureSearchModel model)
|
||||
@ -46,10 +43,14 @@ namespace HospitalDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
using var context = new HospitalDatabase();
|
||||
return context.Procedures
|
||||
.Include(x => x.Medicines)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
return context.Procedures.Include(x => x.Pharmacist)
|
||||
.Include(x => x.Medicines)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) &&
|
||||
x.Name == model.Name) ||
|
||||
(model.Id.HasValue && x.Id ==
|
||||
model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Insert(ProcedureBindingModel model)
|
||||
@ -64,6 +65,23 @@ namespace HospitalDatabaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
return newProcedure.GetViewModel;
|
||||
}
|
||||
public List<Tuple<ProcedureViewModel, List<Tuple<MedicineViewModel, List<RecipeViewModel>>>>> GetReportInfo(ListRecipesSearchModel model)
|
||||
{
|
||||
if (model.proceduresIds == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HospitalDatabase();
|
||||
return context.Procedures
|
||||
.Where(procedure => model.proceduresIds.Contains(procedure.Id))
|
||||
.Select(procedure => new Tuple<ProcedureViewModel, List<Tuple<MedicineViewModel, List<RecipeViewModel>>>>(procedure.GetViewModel,
|
||||
context.ProcedureMedicines.Include(medicine => medicine.Medicine)
|
||||
.Include(medicine => medicine.Procedure).Where(medicine => procedure.Id == medicine.ProcedureId).
|
||||
Select(medicine => new Tuple<MedicineViewModel, List<RecipeViewModel>>(medicine.Medicine.GetViewModel,
|
||||
context.RecipeMedicines.Include(x => x.Recipe).Where(x => x.MedicineId == medicine.Medicine.Id).
|
||||
Select(x => x.Recipe.GetViewModel).ToList())).ToList())).ToList();
|
||||
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Update(ProcedureBindingModel model)
|
||||
{
|
||||
@ -71,17 +89,18 @@ namespace HospitalDatabaseImplement.Implements
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var procedure = context.Procedures
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (procedure == null)
|
||||
var iceCream = context.Procedures.Include(x => x.Pharmacist)
|
||||
.Include(x => x.Medicines).ThenInclude(x => x.Medicine).FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (iceCream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
procedure.Update(model);
|
||||
iceCream.Update(model);
|
||||
context.SaveChanges();
|
||||
procedure.UpdateMedicines(context, model);
|
||||
iceCream.UpdateMedicines(context, model);
|
||||
transaction.Commit();
|
||||
return procedure.GetViewModel;
|
||||
return iceCream.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -93,9 +112,10 @@ namespace HospitalDatabaseImplement.Implements
|
||||
public ProcedureViewModel? Delete(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
var element = context.Procedures
|
||||
.Include(x => x.Medicines)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
var element = context.Procedures.Include(x => x.Pharmacist)
|
||||
.Include(x => x.Medicines)
|
||||
.ThenInclude(x => x.Medicine)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Procedures.Remove(element);
|
||||
|
Loading…
Reference in New Issue
Block a user