From 167747ecae5c6b95a9bde3214a1fb365ff799530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BA=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=A0=D0=BE=D0=B3=D0=B0=D1=88=D0=BE=D0=B2=D0=B0?= Date: Wed, 5 Apr 2023 23:24:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/KurseLogic.cs | 2 +- .../BindingModels/KurseBindingModel.cs | 1 + .../BindingModels/RecipesBindingModel.cs | 4 +- .../ViewModels/KurseViewModel.cs | 5 +- .../ViewModels/RecipesViewModel.cs | 4 +- HospitalDataBaseImplements/Class1.cs | 7 - .../HospitalDataBaseImplements.csproj | 16 ++ .../HospitalDatabase.cs | 31 ++++ .../Implements/IllnessStorage.cs | 116 ++++++++++++++ .../Implements/KurseStorage.cs | 12 ++ .../Implements/MedicinesStorage.cs | 12 ++ .../Implements/ProceduresStorage.cs | 12 ++ .../Implements/RecipesStorage.cs | 12 ++ .../Implements/SymptomsStorage.cs | 12 ++ HospitalDataBaseImplements/Models/Illness.cs | 147 ++++++++++++++++++ .../Models/IllnessKurse.cs | 22 +++ .../Models/IllnessSymptoms.cs | 22 +++ HospitalDataBaseImplements/Models/Kurses.cs | 70 +++++++++ .../Models/Medicines.cs | 58 +++++++ .../Models/Procedures.cs | 58 +++++++ HospitalDataBaseImplements/Models/Recipes.cs | 100 ++++++++++++ .../Models/RecipesProcedures.cs | 12 ++ .../Models/RecipesSymptoms.cs | 12 ++ HospitalDataBaseImplements/Models/Symptoms.cs | 62 ++++++++ HospitalDataModels/Models/IKurseModel.cs | 1 + HospitalDataModels/Models/IRecipesModel.cs | 4 +- 26 files changed, 798 insertions(+), 16 deletions(-) delete mode 100644 HospitalDataBaseImplements/Class1.cs create mode 100644 HospitalDataBaseImplements/HospitalDatabase.cs create mode 100644 HospitalDataBaseImplements/Implements/IllnessStorage.cs create mode 100644 HospitalDataBaseImplements/Implements/KurseStorage.cs create mode 100644 HospitalDataBaseImplements/Implements/MedicinesStorage.cs create mode 100644 HospitalDataBaseImplements/Implements/ProceduresStorage.cs create mode 100644 HospitalDataBaseImplements/Implements/RecipesStorage.cs create mode 100644 HospitalDataBaseImplements/Implements/SymptomsStorage.cs create mode 100644 HospitalDataBaseImplements/Models/Illness.cs create mode 100644 HospitalDataBaseImplements/Models/IllnessKurse.cs create mode 100644 HospitalDataBaseImplements/Models/IllnessSymptoms.cs create mode 100644 HospitalDataBaseImplements/Models/Kurses.cs create mode 100644 HospitalDataBaseImplements/Models/Medicines.cs create mode 100644 HospitalDataBaseImplements/Models/Procedures.cs create mode 100644 HospitalDataBaseImplements/Models/Recipes.cs create mode 100644 HospitalDataBaseImplements/Models/RecipesProcedures.cs create mode 100644 HospitalDataBaseImplements/Models/RecipesSymptoms.cs create mode 100644 HospitalDataBaseImplements/Models/Symptoms.cs diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs index 76d8820..f70ca39 100644 --- a/Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/KurseLogic.cs @@ -105,7 +105,7 @@ namespace HospitalBusinessLogic.BusinessLogics { throw new ArgumentNullException("Количество приемов в день должно быть больше 0", nameof(model.CountInDay)); } - _logger.LogInformation("Kurse. KurseId:{Id}.CountInDay:{ CountInDay}. MedicinesId: { MedicinesId}", model.Id, model.CountInDay, model.MedicinesId); + _logger.LogInformation("Kurse. KurseId:{Id}.CountInDay:{ CountInDay}. MedicinesId: { MedicinesId}. MedicinesName: {MedicinesName}", model.Id, model.CountInDay, model.MedicinesId, model.MedicinesName); } } } diff --git a/HospitalContracts/BindingModels/KurseBindingModel.cs b/HospitalContracts/BindingModels/KurseBindingModel.cs index ab04866..269e64f 100644 --- a/HospitalContracts/BindingModels/KurseBindingModel.cs +++ b/HospitalContracts/BindingModels/KurseBindingModel.cs @@ -13,5 +13,6 @@ namespace HospitalContracts.BindingModels public string Duration { get; set; } = string.Empty; public int CountInDay { get; set; } public int MedicinesId { get; set; } + public string MedicinesName { get; set; } = string.Empty; } } diff --git a/HospitalContracts/BindingModels/RecipesBindingModel.cs b/HospitalContracts/BindingModels/RecipesBindingModel.cs index 4ee5fbd..e2753d5 100644 --- a/HospitalContracts/BindingModels/RecipesBindingModel.cs +++ b/HospitalContracts/BindingModels/RecipesBindingModel.cs @@ -14,13 +14,13 @@ namespace HospitalContracts.BindingModels public DateTime Date { get; set; } = DateTime.Now; public string ModeOfApplication { get; set; } = string.Empty; public int MedicinesId { get; set; } - public Dictionary SymptomsRecipe + public Dictionary RecipeSymptoms { get; set; } = new(); - public Dictionary ProceduresRecipe + public Dictionary RecipeProcedures { get; set; diff --git a/HospitalContracts/ViewModels/KurseViewModel.cs b/HospitalContracts/ViewModels/KurseViewModel.cs index 3c4ab2d..b2638e9 100644 --- a/HospitalContracts/ViewModels/KurseViewModel.cs +++ b/HospitalContracts/ViewModels/KurseViewModel.cs @@ -12,10 +12,11 @@ namespace HospitalContracts.ViewModels { public int Id { get; set; } [DisplayName("Продолжительность курса")] - public string Duration { get; set; } + public string Duration { get; set; } [DisplayName("Срок приема")] public int CountInDay { get; set; } + public int MedicinesId { get; set; } [DisplayName("Название лекарства")] - public int MedicinesId { get; } + public string MedicinesName { get; set; } } } diff --git a/HospitalContracts/ViewModels/RecipesViewModel.cs b/HospitalContracts/ViewModels/RecipesViewModel.cs index adc81df..28b2df8 100644 --- a/HospitalContracts/ViewModels/RecipesViewModel.cs +++ b/HospitalContracts/ViewModels/RecipesViewModel.cs @@ -20,13 +20,13 @@ namespace HospitalContracts.ViewModels [DisplayName("Лекарство")] public int MedicinesId { get; set; } [DisplayName("Симптом")] - public Dictionary SymptomsRecipe + public Dictionary RecipeSymptoms { get; set; } = new(); [DisplayName("Процедура")] - public Dictionary ProceduresRecipe + public Dictionary RecipeProcedures { get; set; diff --git a/HospitalDataBaseImplements/Class1.cs b/HospitalDataBaseImplements/Class1.cs deleted file mode 100644 index 5ac846c..0000000 --- a/HospitalDataBaseImplements/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace HospitalDataBaseImplements -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/HospitalDataBaseImplements/HospitalDataBaseImplements.csproj b/HospitalDataBaseImplements/HospitalDataBaseImplements.csproj index 132c02c..97b7af6 100644 --- a/HospitalDataBaseImplements/HospitalDataBaseImplements.csproj +++ b/HospitalDataBaseImplements/HospitalDataBaseImplements.csproj @@ -6,4 +6,20 @@ enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/HospitalDataBaseImplements/HospitalDatabase.cs b/HospitalDataBaseImplements/HospitalDatabase.cs new file mode 100644 index 0000000..f0f8955 --- /dev/null +++ b/HospitalDataBaseImplements/HospitalDatabase.cs @@ -0,0 +1,31 @@ +using HospitalDataBaseImplements.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements +{ + public class HospitalDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-0BJHUJC\SQLEXPRESS;Initial Catalog=GiftShopDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Kurse { set; get; } + public virtual DbSet Illnesses { set; get; } + public virtual DbSet IllnessKurse { set; get; } + public virtual DbSet IllnessSymptomses { set; get; } + public virtual DbSet RecipesSymptoms { set; get; } + public virtual DbSet RecipesProcedures { set; get; } + public virtual DbSet Symptomses { set; get; } + public virtual DbSet Recipes { set; get; } + public virtual DbSet Medicines { set; get; } + } +} diff --git a/HospitalDataBaseImplements/Implements/IllnessStorage.cs b/HospitalDataBaseImplements/Implements/IllnessStorage.cs new file mode 100644 index 0000000..ec383fa --- /dev/null +++ b/HospitalDataBaseImplements/Implements/IllnessStorage.cs @@ -0,0 +1,116 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using HospitalDataBaseImplements.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Implements +{ + public class IllnessStorage : IIllnessStorage + { + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.Illnesses + .Include(x => x.Kurses) + .ThenInclude(x => x.Kurse) + .Include(x => x.Symptomses) + .ThenInclude(x => x.Symptoms) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(IllnessSearchModel model) + { + if (string.IsNullOrEmpty(model.IllnessName)) + { + return new(); + } + using var context = new HospitalDatabase(); + return context.Illnesses + .Include(x => x.Kurses) + .ThenInclude(x => x.Kurse) + .Include(x => x.Symptomses) + .ThenInclude(x => x.Symptoms) + .Where(x => x.IllnessName.Contains(model.IllnessName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public IllnessViewModel? GetElement(IllnessSearchModel model) + { + if (string.IsNullOrEmpty(model.IllnessName) && !model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.Illnesses + .Include(x => x.Kurses) + .ThenInclude(x => x.Kurse) + .Include(x => x.Symptomses) + .ThenInclude(x => x.Symptoms) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.IllnessName) && + x.IllnessName == model.IllnessName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public IllnessViewModel? Insert(IllnessBindingModel model) + { + using var context = new HospitalDatabase(); + var newIllness = Illness.Create(context, model); + if (newIllness == null) + { + return null; + } + context.Illnesses.Add(newIllness); + context.SaveChanges(); + return newIllness.GetViewModel; + } + public IllnessViewModel? Update(IllnessBindingModel model) + { + using var context = new HospitalDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var illness = context.Illnesses.FirstOrDefault(rec => + rec.Id == model.Id); + if (illness == null) + { + return null; + } + illness.Update(model); + context.SaveChanges(); + illness.UpdateDrugCourses(context, model); + illness.UpdateSymptomses(context, model); + transaction.Commit(); + return illness.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public IllnessViewModel? Delete(IllnessBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.Illnesses + .Include(x => x.Kurses) + .Include(x => x.Symptomses) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Illnesses.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/HospitalDataBaseImplements/Implements/KurseStorage.cs b/HospitalDataBaseImplements/Implements/KurseStorage.cs new file mode 100644 index 0000000..904060a --- /dev/null +++ b/HospitalDataBaseImplements/Implements/KurseStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Implements +{ + public class KurseStorage + { + } +} diff --git a/HospitalDataBaseImplements/Implements/MedicinesStorage.cs b/HospitalDataBaseImplements/Implements/MedicinesStorage.cs new file mode 100644 index 0000000..3764e21 --- /dev/null +++ b/HospitalDataBaseImplements/Implements/MedicinesStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Implements +{ + public class MedicinesStorage + { + } +} diff --git a/HospitalDataBaseImplements/Implements/ProceduresStorage.cs b/HospitalDataBaseImplements/Implements/ProceduresStorage.cs new file mode 100644 index 0000000..d993bc7 --- /dev/null +++ b/HospitalDataBaseImplements/Implements/ProceduresStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Implements +{ + public class ProceduresStorage + { + } +} diff --git a/HospitalDataBaseImplements/Implements/RecipesStorage.cs b/HospitalDataBaseImplements/Implements/RecipesStorage.cs new file mode 100644 index 0000000..23018fe --- /dev/null +++ b/HospitalDataBaseImplements/Implements/RecipesStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Implements +{ + public class RecipesStorage + { + } +} diff --git a/HospitalDataBaseImplements/Implements/SymptomsStorage.cs b/HospitalDataBaseImplements/Implements/SymptomsStorage.cs new file mode 100644 index 0000000..9d3d249 --- /dev/null +++ b/HospitalDataBaseImplements/Implements/SymptomsStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Implements +{ + public class SymptomsStorage + { + } +} diff --git a/HospitalDataBaseImplements/Models/Illness.cs b/HospitalDataBaseImplements/Models/Illness.cs new file mode 100644 index 0000000..94b9c50 --- /dev/null +++ b/HospitalDataBaseImplements/Models/Illness.cs @@ -0,0 +1,147 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class Illness : IIllnessModel + { + public int Id { get; private set; } + [Required] + public string IllnessName { get; private set; } = string.Empty; + [Required] + public string Form { get; private set; } = string.Empty; + private Dictionary? _illnessKurses = null; + [NotMapped] + public Dictionary IllnessKurse + { + get + { + if (_illnessKurses == null) + { + _illnessKurses = Kurses.ToDictionary(recPC => recPC.KurseId, recPC => + (recPC.Kurse as IKurseModel, recPC.Count)); + } + return _illnessKurses; + } + } + [ForeignKey("IllnessId")] + public virtual List Kurses { get; set; } = new(); + + private Dictionary? _illnessSymptomses = null; + [NotMapped] + public Dictionary IllnessSymptoms + { + get + { + if (_illnessSymptomses == null) + { + _illnessSymptomses = Symptomses.ToDictionary(recPC => recPC.SymptomsId, recPC =>(recPC.Symptoms as ISymptomsModel, recPC.Count)); + } + return _illnessSymptomses; + } + } + [ForeignKey("IllnessId")] + public virtual List Symptomses { get; set; } = new(); + + public static Illness Create(HospitalDatabase context, IllnessBindingModel model) + { + return new Illness() + { + Id = model.Id, + IllnessName = model.IllnessName, + Form = model.Form, + Kurses = model.IllnessKurse.Select(x => new IllnessKurse + { + Kurse = context.Kurse.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + Symptomses = model.IllnessSymptoms.Select(x => new IllnessSymptoms + { + Symptoms = context.Symptomses.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + public void Update(IllnessBindingModel model) + { + IllnessName = model.IllnessName; + Form = model.Form; + } + public IllnessViewModel GetViewModel => new() + { + Id = Id, + IllnessName = IllnessName, + Form = Form, + IllnessKurse = IllnessKurse, + IllnessSymptoms = IllnessSymptoms + }; + public void UpdateDrugCourses(HospitalDatabase context, IllnessBindingModel model) + { + var illnessKurses = context.IllnessKurse.Where(rec => rec.IllnessId == model.Id).ToList(); + if (illnessKurses != null && illnessKurses.Count > 0) + { // удалили те, которых нет в модели + context.IllnessKurse.RemoveRange(illnessKurses.Where(rec + => !model.IllnessKurse.ContainsKey(rec.KurseId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateDrugCourse in illnessKurses) + { + updateDrugCourse.Count = + model.IllnessKurse[updateDrugCourse.KurseId].Item2; + model.IllnessKurse.Remove(updateDrugCourse.KurseId); + } + context.SaveChanges(); + } + var illness = context.Illnesses.First(x => x.Id == Id); + foreach (var pc in model.IllnessKurse) + { + context.IllnessKurse.Add(new IllnessKurse + { + Illness = illness, + Kurse = context.Kurse.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _illnessKurses = null; + } + public void UpdateSymptomses(HospitalDatabase context, IllnessBindingModel model) + { + var illnessSymptomses = context.IllnessSymptomses.Where(rec => rec.IllnessId == model.Id).ToList(); + if (illnessSymptomses != null && illnessSymptomses.Count > 0) + { // удалили те, которых нет в модели + context.IllnessSymptomses.RemoveRange(illnessSymptomses.Where(rec + => !model.IllnessSymptoms.ContainsKey(rec.SymptomsId))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateSymptoms in illnessSymptomses) + { + updateSymptoms.Count = + model.IllnessSymptoms[updateSymptoms.SymptomsId].Item2; + model.IllnessSymptoms.Remove(updateSymptoms.SymptomsId); + } + context.SaveChanges(); + } + var illness = context.Illnesses.First(x => x.Id == Id); + foreach (var pc in model.IllnessSymptoms) + { + context.IllnessSymptomses.Add(new IllnessSymptoms + { + Illness = illness, + Symptoms = context.Symptomses.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _illnessSymptomses = null; + } + } +} diff --git a/HospitalDataBaseImplements/Models/IllnessKurse.cs b/HospitalDataBaseImplements/Models/IllnessKurse.cs new file mode 100644 index 0000000..a558064 --- /dev/null +++ b/HospitalDataBaseImplements/Models/IllnessKurse.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class IllnessKurse + { + public int Id { get; set; } + [Required] + public int IllnessId { get; set; } + [Required] + public int KurseId { get; set; } + [Required] + public int Count { get; set; } + public virtual Illness Illness { get; set; } = new(); + public virtual Kurses Kurse { get; set; } = new(); + } +} diff --git a/HospitalDataBaseImplements/Models/IllnessSymptoms.cs b/HospitalDataBaseImplements/Models/IllnessSymptoms.cs new file mode 100644 index 0000000..d1d28b5 --- /dev/null +++ b/HospitalDataBaseImplements/Models/IllnessSymptoms.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class IllnessSymptoms + { + public int Id { get; set; } + [Required] + public int IllnessId { get; set; } + [Required] + public int SymptomsId { get; set; } + [Required] + public int Count { get; set; } + public virtual Illness Illness { get; set; } = new(); + public virtual Symptoms Symptoms { get; set; } = new(); + } +} diff --git a/HospitalDataBaseImplements/Models/Kurses.cs b/HospitalDataBaseImplements/Models/Kurses.cs new file mode 100644 index 0000000..48b5a1f --- /dev/null +++ b/HospitalDataBaseImplements/Models/Kurses.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HospitalDataModels.Models; +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; + +namespace HospitalDataBaseImplements.Models +{ + public class Kurses : IKurseModel + { + public int Id { get; private set; } + public int MedicinesId { get; private set; } + public string MedicinesName { get; private set; } = string.Empty; + [Required] + public string Duration { get; private set; } = string.Empty; + [Required] + public int CountInDay { get; private set; } + [ForeignKey("DrugCourseId")] + public virtual List IllnessKurses { get; set; } = new(); + public static Kurses? Create(KurseBindingModel model) + { + if (model == null) + { + return null; + } + return new Kurses() + { + Id = model.Id, + MedicinesId = model.MedicinesId, + MedicinesName = model.MedicinesName, + Duration = model.Duration, + CountInDay = model.CountInDay + }; + } + public static Kurses Create(KurseViewModel model) + { + return new Kurses + { + Id = model.Id, + MedicinesId = model.MedicinesId, + MedicinesName = model.MedicinesName, + Duration = model.Duration, + CountInDay = model.CountInDay + }; + } + public void Update(KurseBindingModel model) + { + if (model == null) + { + return; + } + MedicinesName = model.MedicinesName; + Duration = model.Duration; + CountInDay = model.CountInDay; + } + public KurseViewModel GetViewModel => new() + { + Id = Id, + MedicinesId = MedicinesId, + MedicinesName = MedicinesName, + Duration = Duration, + CountInDay = CountInDay + }; + } +} diff --git a/HospitalDataBaseImplements/Models/Medicines.cs b/HospitalDataBaseImplements/Models/Medicines.cs new file mode 100644 index 0000000..c7e65e5 --- /dev/null +++ b/HospitalDataBaseImplements/Models/Medicines.cs @@ -0,0 +1,58 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class Medicines : IMedicinesModel + { + public int Id { get; private set; } + [Required] + public string MedicinesName { get; private set; } = string.Empty; + [Required] + public string Group { get; private set; } = string.Empty; + public static Medicines? Create(MedicinesBindingModel model) + { + if (model == null) + { + return null; + } + return new Medicines() + { + Id = model.Id, + MedicinesName = model.MedicinesName, + Group = model.Group + }; + } + public static Medicines Create(MedicinesViewModel model) + { + return new Medicines + { + Id = model.Id, + MedicinesName = model.MedicinesName, + Group = model.Group + }; + } + public void Update(MedicinesBindingModel model) + { + if (model == null) + { + return; + } + MedicinesName = model.MedicinesName; + Group = model.Group; + } + public MedicinesViewModel GetViewModel => new() + { + Id = Id, + MedicinesName = MedicinesName, + Group = Group + }; + } +} diff --git a/HospitalDataBaseImplements/Models/Procedures.cs b/HospitalDataBaseImplements/Models/Procedures.cs new file mode 100644 index 0000000..4cda053 --- /dev/null +++ b/HospitalDataBaseImplements/Models/Procedures.cs @@ -0,0 +1,58 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class Procedures: IProceduresModel + { + public int Id { get; private set; } + [Required] + public string ProceduresName { get; private set; } = string.Empty; + [Required] + public string Type { get; private set; } = string.Empty; + public static Procedures? Create(ProceduresBindingModel model) + { + if (model == null) + { + return null; + } + return new Procedures() + { + Id = model.Id, + ProceduresName = model.ProceduresName, + Type = model.Type + }; + } + public static Procedures Create(ProceduresViewModel model) + { + return new Procedures + { + Id = model.Id, + ProceduresName = model.ProceduresName, + Type = model.Type + }; + } + public void Update(ProceduresBindingModel model) + { + if (model == null) + { + return; + } + ProceduresName = model.ProceduresName; + Type = model.Type; + } + public ProceduresViewModel GetViewModel => new() + { + Id = Id, + ProceduresName = ProceduresName, + Type = Type + }; + } +} diff --git a/HospitalDataBaseImplements/Models/Recipes.cs b/HospitalDataBaseImplements/Models/Recipes.cs new file mode 100644 index 0000000..1c61c0e --- /dev/null +++ b/HospitalDataBaseImplements/Models/Recipes.cs @@ -0,0 +1,100 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class Recipes : IRecipesModel + { + public int Id { get; private set; } + [Required] + public string Dose { get; private set; } = string.Empty; + [Required] + public DateTime Date { get; private set; } = DateTime.Now; + public int MedicinesId { get; private set; } + [Required] + public string ModeOfApplication { get; private set; } = string.Empty; + private Dictionary? _recipeProcedures = null; + [NotMapped] + public Dictionary RecipeProcedures + { + get + { + if (_recipeProcedures == null) + { + // _illnessProcedures = Procedures.ToDictionary(recPC => recPC.KurseId, recPC => + //(recPC.Kurse as IProceduresModel, recPC.Count)); + } + return _recipeProcedures; + } + } + [ForeignKey("ProceduresId")] ///////////////// + public virtual List Procedures { get; set; } = new(); + + private Dictionary? _recipeSymptoms = null; + [NotMapped] + public Dictionary RecipeSymptoms + { + get + { + if (_recipeSymptoms == null) + { + // _recipeSymptoms = Symptoms.ToDictionary(recPC => recPC.SymptomsId, recPC => (recPC.Symptoms as ISymptomsModel, recPC.Count)); + } + return _recipeSymptoms; + } + } + [ForeignKey("SymptomsId")] ///////////////// + public virtual List Symptoms { get; set; } = new(); + //[Required] + //public int SymptomsId { get; private set; } + //public string SymptomsName { get; private set; } = string.Empty; + //public virtual Symptoms Symptoms { get; set; } = new(); + public static Recipes? Create(RecipesBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Recipes() + { + Id = model.Id, + Dose = model.Dose, + Date = model.Date, + ModeOfApplication = model.ModeOfApplication, + //SymptomsId = model.SymptomsId, + //SymptomsName = model.SymptomsName + }; + } + + public void Update(RecipesBindingModel? model) + { + if (model == null) + { + return; + } + Dose = model.Dose; + Date = model.Date; + ModeOfApplication = model.ModeOfApplication; + //SymptomsName = model.SymptomsName; + } + + public RecipesViewModel GetViewModel => new() + { + Id = Id, + Dose = Dose, + Date = Date, + ModeOfApplication = ModeOfApplication, + //SymptomsId = SymptomsId, + //SymptomsName = SymptomsName + }; + } +} diff --git a/HospitalDataBaseImplements/Models/RecipesProcedures.cs b/HospitalDataBaseImplements/Models/RecipesProcedures.cs new file mode 100644 index 0000000..315c786 --- /dev/null +++ b/HospitalDataBaseImplements/Models/RecipesProcedures.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class RecipesProcedures + { + } +} diff --git a/HospitalDataBaseImplements/Models/RecipesSymptoms.cs b/HospitalDataBaseImplements/Models/RecipesSymptoms.cs new file mode 100644 index 0000000..9f5718d --- /dev/null +++ b/HospitalDataBaseImplements/Models/RecipesSymptoms.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class RecipesSymptoms + { + } +} diff --git a/HospitalDataBaseImplements/Models/Symptoms.cs b/HospitalDataBaseImplements/Models/Symptoms.cs new file mode 100644 index 0000000..d5c674c --- /dev/null +++ b/HospitalDataBaseImplements/Models/Symptoms.cs @@ -0,0 +1,62 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDataBaseImplements.Models +{ + public class Symptoms : ISymptomsModel + { + public int Id { get; private set; } + [Required] + public string SymptomName { get; set; } = string.Empty; + public string? Description { get; set; } = string.Empty; + [ForeignKey("SymptomsId")] + public virtual List IllnessSymptomses { get; set; } = new(); + [ForeignKey("SymptomsId")] + public virtual List Recipes { get; set; } = new(); + public static Symptoms? Create(SymptomsBindingModel model) + { + if (model == null) + { + return null; + } + return new Symptoms() + { + Id = model.Id, + SymptomName = model.SymptomName, + Description = model.Description + }; + } + public static Symptoms Create(SymptomsViewModel model) + { + return new Symptoms + { + Id = model.Id, + SymptomName = model.SymptomName, + Description = model.Description + }; + } + public void Update(SymptomsBindingModel model) + { + if (model == null) + { + return; + } + SymptomName = model.SymptomName; + Description = model.Description; + } + public SymptomsViewModel GetViewModel => new() + { + Id = Id, + SymptomName = SymptomName, + Description = Description + }; + } +} diff --git a/HospitalDataModels/Models/IKurseModel.cs b/HospitalDataModels/Models/IKurseModel.cs index 475f2a8..b5f6899 100644 --- a/HospitalDataModels/Models/IKurseModel.cs +++ b/HospitalDataModels/Models/IKurseModel.cs @@ -11,5 +11,6 @@ namespace HospitalDataModels.Models string Duration { get; } int CountInDay { get; } int MedicinesId { get; } + string MedicinesName { get; } } } diff --git a/HospitalDataModels/Models/IRecipesModel.cs b/HospitalDataModels/Models/IRecipesModel.cs index 14de723..7c35a30 100644 --- a/HospitalDataModels/Models/IRecipesModel.cs +++ b/HospitalDataModels/Models/IRecipesModel.cs @@ -12,7 +12,7 @@ namespace HospitalDataModels.Models DateTime Date { get; } string ModeOfApplication { get; } int MedicinesId { get; } - Dictionary ProceduresRecipe { get; } - Dictionary SymptomsRecipe { get; } + Dictionary RecipeProcedures { get; } + Dictionary RecipeSymptoms { get; } } }