Работа с бд
This commit is contained in:
parent
5dc8138d3d
commit
167747ecae
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<int, (ISymptomsModel, int)> SymptomsRecipe
|
||||
public Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
public Dictionary<int, (IProceduresModel, int)> ProceduresRecipe
|
||||
public Dictionary<int, (IProceduresModel, int)> RecipeProcedures
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ namespace HospitalContracts.ViewModels
|
||||
[DisplayName("Лекарство")]
|
||||
public int MedicinesId { get; set; }
|
||||
[DisplayName("Симптом")]
|
||||
public Dictionary<int, (ISymptomsModel, int)> SymptomsRecipe
|
||||
public Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
[DisplayName("Процедура")]
|
||||
public Dictionary<int, (IProceduresModel, int)> ProceduresRecipe
|
||||
public Dictionary<int, (IProceduresModel, int)> RecipeProcedures
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace HospitalDataBaseImplements
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -6,4 +6,20 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MigraDoc.DocumentObjectModel.Core" Version="1.0.0" />
|
||||
<PackageReference Include="MigraDoc.Rendering.Core" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
|
||||
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
31
HospitalDataBaseImplements/HospitalDatabase.cs
Normal file
31
HospitalDataBaseImplements/HospitalDatabase.cs
Normal file
@ -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<Kurses> Kurse { set; get; }
|
||||
public virtual DbSet<Illness> Illnesses { set; get; }
|
||||
public virtual DbSet<IllnessKurse> IllnessKurse { set; get; }
|
||||
public virtual DbSet<IllnessSymptoms> IllnessSymptomses { set; get; }
|
||||
public virtual DbSet<RecipesSymptoms> RecipesSymptoms { set; get; }
|
||||
public virtual DbSet<RecipesProcedures> RecipesProcedures { set; get; }
|
||||
public virtual DbSet<Symptoms> Symptomses { set; get; }
|
||||
public virtual DbSet<Recipes> Recipes { set; get; }
|
||||
public virtual DbSet<Medicines> Medicines { set; get; }
|
||||
}
|
||||
}
|
116
HospitalDataBaseImplements/Implements/IllnessStorage.cs
Normal file
116
HospitalDataBaseImplements/Implements/IllnessStorage.cs
Normal file
@ -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<IllnessViewModel> 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<IllnessViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
12
HospitalDataBaseImplements/Implements/KurseStorage.cs
Normal file
12
HospitalDataBaseImplements/Implements/KurseStorage.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
12
HospitalDataBaseImplements/Implements/MedicinesStorage.cs
Normal file
12
HospitalDataBaseImplements/Implements/MedicinesStorage.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
12
HospitalDataBaseImplements/Implements/ProceduresStorage.cs
Normal file
12
HospitalDataBaseImplements/Implements/ProceduresStorage.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
12
HospitalDataBaseImplements/Implements/RecipesStorage.cs
Normal file
12
HospitalDataBaseImplements/Implements/RecipesStorage.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
12
HospitalDataBaseImplements/Implements/SymptomsStorage.cs
Normal file
12
HospitalDataBaseImplements/Implements/SymptomsStorage.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
147
HospitalDataBaseImplements/Models/Illness.cs
Normal file
147
HospitalDataBaseImplements/Models/Illness.cs
Normal file
@ -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<int, (IKurseModel, int)>? _illnessKurses = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IKurseModel, int)> 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<IllnessKurse> Kurses { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (ISymptomsModel, int)>? _illnessSymptomses = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (ISymptomsModel, int)> 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<IllnessSymptoms> 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;
|
||||
}
|
||||
}
|
||||
}
|
22
HospitalDataBaseImplements/Models/IllnessKurse.cs
Normal file
22
HospitalDataBaseImplements/Models/IllnessKurse.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
22
HospitalDataBaseImplements/Models/IllnessSymptoms.cs
Normal file
22
HospitalDataBaseImplements/Models/IllnessSymptoms.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
70
HospitalDataBaseImplements/Models/Kurses.cs
Normal file
70
HospitalDataBaseImplements/Models/Kurses.cs
Normal file
@ -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<IllnessKurse> 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
|
||||
};
|
||||
}
|
||||
}
|
58
HospitalDataBaseImplements/Models/Medicines.cs
Normal file
58
HospitalDataBaseImplements/Models/Medicines.cs
Normal file
@ -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
|
||||
};
|
||||
}
|
||||
}
|
58
HospitalDataBaseImplements/Models/Procedures.cs
Normal file
58
HospitalDataBaseImplements/Models/Procedures.cs
Normal file
@ -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
|
||||
};
|
||||
}
|
||||
}
|
100
HospitalDataBaseImplements/Models/Recipes.cs
Normal file
100
HospitalDataBaseImplements/Models/Recipes.cs
Normal file
@ -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<int, (IProceduresModel, int)>? _recipeProcedures = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProceduresModel, int)> 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<RecipesProcedures> Procedures { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (ISymptomsModel, int)>? _recipeSymptoms = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (ISymptomsModel, int)> 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<RecipesSymptoms> 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
|
||||
};
|
||||
}
|
||||
}
|
12
HospitalDataBaseImplements/Models/RecipesProcedures.cs
Normal file
12
HospitalDataBaseImplements/Models/RecipesProcedures.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
12
HospitalDataBaseImplements/Models/RecipesSymptoms.cs
Normal file
12
HospitalDataBaseImplements/Models/RecipesSymptoms.cs
Normal file
@ -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
|
||||
{
|
||||
}
|
||||
}
|
62
HospitalDataBaseImplements/Models/Symptoms.cs
Normal file
62
HospitalDataBaseImplements/Models/Symptoms.cs
Normal file
@ -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<IllnessSymptoms> IllnessSymptomses { get; set; } = new();
|
||||
[ForeignKey("SymptomsId")]
|
||||
public virtual List<Recipes> 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
|
||||
};
|
||||
}
|
||||
}
|
@ -11,5 +11,6 @@ namespace HospitalDataModels.Models
|
||||
string Duration { get; }
|
||||
int CountInDay { get; }
|
||||
int MedicinesId { get; }
|
||||
string MedicinesName { get; }
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace HospitalDataModels.Models
|
||||
DateTime Date { get; }
|
||||
string ModeOfApplication { get; }
|
||||
int MedicinesId { get; }
|
||||
Dictionary<int, (IProceduresModel, int)> ProceduresRecipe { get; }
|
||||
Dictionary<int, (ISymptomsModel, int)> SymptomsRecipe { get; }
|
||||
Dictionary<int, (IProceduresModel, int)> RecipeProcedures { get; }
|
||||
Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user