From 993cd30fde47770054dc20c757e4ec8f38508c3c Mon Sep 17 00:00:00 2001 From: Alenka Date: Fri, 3 May 2024 00:41:11 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D1=82=20=D1=81=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=20(=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E=D1=81=D1=8C=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tientsDescriptionProceduresBindingModel.cs | 15 ++++++++ .../DescriptionProcedureSearchModel.cs | 3 +- .../StoragesContracts/IMedicineStorage.cs | 2 ++ .../Implementss/MedicineStorage.cs | 34 +++++++++++++++++++ .../Implementss/ProcedureStorage.cs | 10 +++--- 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 Hospital/HospitalContracts/BindingModels/PatientsDescriptionProceduresBindingModel.cs diff --git a/Hospital/HospitalContracts/BindingModels/PatientsDescriptionProceduresBindingModel.cs b/Hospital/HospitalContracts/BindingModels/PatientsDescriptionProceduresBindingModel.cs new file mode 100644 index 0000000..fc0424d --- /dev/null +++ b/Hospital/HospitalContracts/BindingModels/PatientsDescriptionProceduresBindingModel.cs @@ -0,0 +1,15 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalContracts.BindingModels +{ + public class PatientsDescriptionProceduresBindingModel + { + public string FileName { get; set; } = string.Empty; + public List Medicines { get; set; } = new(); + } +} diff --git a/Hospital/HospitalContracts/SearchModels/DescriptionProcedureSearchModel.cs b/Hospital/HospitalContracts/SearchModels/DescriptionProcedureSearchModel.cs index 7e68e7a..90672c7 100644 --- a/Hospital/HospitalContracts/SearchModels/DescriptionProcedureSearchModel.cs +++ b/Hospital/HospitalContracts/SearchModels/DescriptionProcedureSearchModel.cs @@ -11,6 +11,7 @@ namespace HospitalContracts.SearchModels public int? Id { get; set; } public string? Description { get; set; } = string.Empty; public int? PharmacistId { get; set; } - + public int? ProcedureId { get; set; } + } } diff --git a/Hospital/HospitalContracts/StoragesContracts/IMedicineStorage.cs b/Hospital/HospitalContracts/StoragesContracts/IMedicineStorage.cs index c85c314..791f072 100644 --- a/Hospital/HospitalContracts/StoragesContracts/IMedicineStorage.cs +++ b/Hospital/HospitalContracts/StoragesContracts/IMedicineStorage.cs @@ -13,6 +13,8 @@ namespace HospitalContracts.StoragesContracts { List GetFullList(); List GetFilteredList(MedicineSearchModel model); + List>>>> GetDescriptionProceduresInfo(PatientDescriptionProceduresSearchModel model); + List>>>> GetPatientsInfo(PatientDescriptionProceduresSearchModel model); MedicineViewModel? GetElement(MedicineSearchModel model); MedicineViewModel? Insert(MedicineBindingModel model); MedicineViewModel? Update(MedicineBindingModel model); diff --git a/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs b/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs index 04c36f8..0c309da 100644 --- a/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs +++ b/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs @@ -35,6 +35,40 @@ namespace HospitalDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + public List>>>> GetDescriptionProceduresInfo(PatientDescriptionProceduresSearchModel model) + { + if (model.medicinesIds == null) + { + return new(); + } + using var context = new HospitalDatabase(); + return context.Medicines + .Where(medicine => model.medicinesIds.Contains(medicine.Id)) + .Select(medicine => new Tuple>>>(medicine.GetViewModel, + context.ProcedureMedicines.Include(service => service.Procedure) + .Include(service => service.Medicine).Where(service => medicine.Id == service.MedicineId). + Select(service => new Tuple>(service.Procedure.GetViewModel, + context.DescriptionProcedures.Include(x => x.Procedures). + Select(x => x.GetViewModel).ToList())).ToList())).ToList(); + + } + public List>>>> GetPatientsInfo(PatientDescriptionProceduresSearchModel model) + { + if (model.medicinesIds == null) + { + return new(); + } + using var context = new HospitalDatabase(); + return context.Medicines + .Where(medicine => model.medicinesIds.Contains(medicine.Id)) + .Select(medicine => new Tuple>>>(medicine.GetViewModel, + context.ProcedureMedicines.Include(service => service.Procedure) + .Include(service => service.Medicine).Where(service => medicine.Id == service.MedicineId). + Select(service => new Tuple>(service.Procedure.GetViewModel, + context.PatientProcedures.Include(x => x.Patient).Where(x => x.ProcedureId == service.ProcedureId ). + Select(x => x.Patient.GetViewModel).ToList())).ToList())).ToList(); + + } public MedicineViewModel? GetElement(MedicineSearchModel model) { diff --git a/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs b/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs index 46c2b8e..f3e23e5 100644 --- a/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs @@ -89,18 +89,18 @@ namespace HospitalDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var iceCream = context.Procedures.Include(x => x.Pharmacist) + var Procedure = context.Procedures.Include(x => x.Pharmacist) .Include(x => x.Medicines).ThenInclude(x => x.Medicine).FirstOrDefault(rec => rec.Id == model.Id); - if (iceCream == null) + if (Procedure == null) { return null; } - iceCream.Update(model); + Procedure.Update(model); context.SaveChanges(); - iceCream.UpdateMedicines(context, model); + Procedure.UpdateMedicines(context, model); transaction.Commit(); - return iceCream.GetViewModel; + return Procedure.GetViewModel; } catch {