сделаны однонаправленные связи + добавлены контракты работника

This commit is contained in:
ValAnn 2024-04-27 21:51:26 +04:00
parent 6654a1b627
commit 575e573a38
27 changed files with 521 additions and 35 deletions

View File

@ -0,0 +1,115 @@
using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicContracts;
using HospitalContracts.SearchModels;
using HospitalContracts.StoragesContracts;
using HospitalContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.BusinessLogics
{
public class DiseaseLogic : IDiseaseLogic
{
private readonly ILogger _logger;
private readonly IDiseaseStorage _diseaseStorage;
public DiseaseLogic(ILogger<DiseaseLogic> logger, IDiseaseStorage diseaseStorage)
{
_logger = logger;
_diseaseStorage = diseaseStorage;
}
public bool Create(DiseaseBindingModel model)
{
CheckModel(model);
if (_diseaseStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(DiseaseBindingModel model)
{
CheckModel(model);
if (_diseaseStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(DiseaseBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_diseaseStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public DiseaseViewModel? ReadElement(DiseaseSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Name:{Name}. Id:{ Id}", model.Name, model.Id);
var element = _diseaseStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<DiseaseViewModel>? ReadList(DiseaseSearchModel? model)
{
_logger.LogInformation("ReadList. DiseaseId:{Id}", model?.Id);
var list = model == null ? _diseaseStorage.GetFullList() : _diseaseStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(DiseaseBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия болезни", nameof(model.Name));
}
_logger.LogInformation("Disease. Name:{Name}. Description:{Description}. DoctorId:{DoctorId}. Id:{ Id}", model.Name, model.Description, model.DoctorId, model.Id);
var element = _diseaseStorage.GetElement(new DiseaseSearchModel
{
Name = model.Name,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Болезнь с такими данными уже есть");
}
}
}
}

View File

@ -1,7 +0,0 @@
namespace HospitalBusinessLogic
{
public class Class1
{
}
}

View File

@ -0,0 +1,17 @@
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BindingModels
{
public class DiseaseBindingModel : IDiseaseModel
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public int DoctorId { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HospitalDataModels.Models;
namespace HospitalContracts.BindingModels
{
public class DoctorBindingModel : IDoctorModel
{
public int Id { get; set; }
public string FIO { get; set; } = string.Empty;
public string Login { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string MailAddress { get; set; } = string.Empty;
public string PhoneNumber { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,26 @@
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BindingModels
{
public class PatientBindingModel : IPatientModel
{
public int Id { get; set; }
public string FIO { get; set; } = string.Empty;
public string Adress { get; set; } = string.Empty;
public DateOnly BirthDate { get; set; }
public int DoctorId { get; set; }
public Dictionary<int, IProcedureModel> PatientProcedures { get; set; } = new();
public Dictionary<int, IRecipeModel> PatientRecipes { get; set; } = new();
}
}

View File

@ -0,0 +1,23 @@
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BindingModels
{
public class RecipeBindingModel : IRecipeModel
{
public int Id { get; set; }
public string Description { get; set; } = string.Empty;
public DateTime IssueDate { get; set; } = DateTime.Now;
public int DiseaseId { get; set; }
public int DoctorId { get; set; }
public Dictionary<int, IMedicineModel> RecipeMedicines { get; set; } = new();
}
}

View File

@ -0,0 +1,24 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BusinessLogicContracts
{
public interface IDiseaseLogic
{
List<DiseaseViewModel>? ReadList(DiseaseSearchModel? model);
DiseaseViewModel? ReadElement(DiseaseSearchModel model);
bool Create(DiseaseBindingModel model);
bool Update(DiseaseBindingModel model);
bool Delete(DiseaseBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BusinessLogicContracts
{
public interface IDoctorLogic
{
List<DoctorViewModel>? ReadList(DoctorSearchModel? model);
DoctorViewModel? ReadElement(DoctorSearchModel model);
bool Create(DoctorBindingModel model);
bool Update(DoctorBindingModel model);
bool Delete(DoctorBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BusinessLogicContracts
{
public interface IPatientLogic
{
List<PatientViewModel>? ReadList(PatientSearchModel? model);
PatientViewModel? ReadElement(PatientSearchModel model);
bool Create(PatientBindingModel model);
bool Update(PatientBindingModel model);
bool Delete(PatientBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.BusinessLogicContracts
{
public interface IRecipeLogic
{
List<RecipeViewModel>? ReadList(RecipeSearchModel? model);
RecipeViewModel? ReadElement(RecipeSearchModel model);
bool Create(RecipeBindingModel model);
bool Update(RecipeBindingModel model);
bool Delete(RecipeBindingModel model);
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.SearchModels
{
public class DiseaseSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public int? DoctorId { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.SearchModels
{
public class DoctorSearchModel
{
public int? Id { get; set; }
public string? FIO { get; set; }
public string? Login { get; set; }
public string? Password { get; set; }
public string? MailAddress { get; set; }
public string? PhoneNumber { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.SearchModels
{
public class PatientSearchModel
{
public int? Id { get; set; }
public string? FIO { get; set; }
public string? Adress { get; set; }
public DateOnly? BirthDate { get; set; }
public int? DoctorId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.SearchModels
{
public class RecipeSearchModel
{
public int? Id { get; set; }
public int? DoctorId { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.StoragesContracts
{
public interface IDiseaseStorage
{
List<DiseaseViewModel> GetFullList();
List<DiseaseViewModel> GetFilteredList(DiseaseSearchModel model);
DiseaseViewModel? GetElement(DiseaseSearchModel model);
DiseaseViewModel? Insert(DiseaseBindingModel model);
DiseaseViewModel? Update(DiseaseBindingModel model);
DiseaseViewModel? Delete(DiseaseBindingModel model);
}
}

View File

@ -0,0 +1,26 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.StoragesContracts
{
public interface IDoctorStorage
{
List<DoctorViewModel> GetFullList();
List<DoctorViewModel> GetFilteredList(DoctorSearchModel model);
DoctorViewModel? GetElement(DoctorSearchModel model);
DoctorViewModel? Insert(DoctorBindingModel model);
DoctorViewModel? Update(DoctorBindingModel model);
DoctorViewModel? Delete(DoctorBindingModel model);
}
}

View File

@ -0,0 +1,26 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.StoragesContracts
{
public interface IPatientStorage
{
List<PatientViewModel> GetFullList();
List<PatientViewModel> GetFilteredList(PatientSearchModel model);
PatientViewModel? GetElement(PatientSearchModel model);
PatientViewModel? Insert(PatientBindingModel model);
PatientViewModel? Update(PatientBindingModel model);
PatientViewModel? Delete(PatientBindingModel model);
}
}

View File

@ -0,0 +1,27 @@
using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.StoragesContracts
{
public interface IRecipeStorage
{
List<RecipeViewModel> GetFullList();
List<RecipeViewModel> GetFilteredList(RecipeSearchModel model);
RecipeViewModel? GetElement(RecipeSearchModel model);
RecipeViewModel? Insert(RecipeBindingModel model);
RecipeViewModel? Update(RecipeBindingModel model);
RecipeViewModel? Delete(RecipeBindingModel model);
}
}

View File

@ -1,12 +1,22 @@
using System;
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalContracts.ViewModels
{
internal class DiseaseViewModel
public class DiseaseViewModel : IDiseaseModel
{
public int Id { get; set; }
[DisplayName("Название болезни")]
public string Name { get; set; } = string.Empty;
[DisplayName("Описание болезни")]
public string Description { get; set; } = string.Empty;
public int DoctorId { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System;
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
@ -7,23 +8,23 @@ using System.Threading.Tasks;
namespace HospitalContracts.ViewModels
{
public class DoctorViewModel
public class DoctorViewModel : IDoctorModel
{
public int Id { get; set; }
[DisplayName("ФИО")]
string FIO { get; }
public string FIO { get; set; } = string.Empty;
[DisplayName("Логин")]
string Login { get; }
public string Login { get; set; } = string.Empty;
[DisplayName("Пароль")]
string Password { get; }
public string Password { get; set; } = string.Empty;
[DisplayName("Электронная почта")]
string MailAddress { get; }
public string MailAddress { get; set; } = string.Empty;
[DisplayName("Номер телефона")]
string PhoneNumber { get; }
public string PhoneNumber { get; set; } = string.Empty;
}
}

View File

@ -8,18 +8,18 @@ using HospitalDataModels.Models;
namespace HospitalContracts.ViewModels
{
public class PatientViewModel
public class PatientViewModel : IPatientModel
{
public int Id { get; set; }
[DisplayName("ФИО")]
string FIO { get; }
public string FIO { get; }
[DisplayName("Дата рождения")]
DateOnly BirthDate { get; }
public DateOnly BirthDate { get; }
[DisplayName("Адрес")]
string Adress { get; }
public string Adress { get; }
public int DoctorId { get; set; }

View File

@ -1,4 +1,5 @@
using System;
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,7 +7,18 @@ using System.Threading.Tasks;
namespace HospitalContracts.ViewModels
{
internal class RecipeViewModel
public class RecipeViewModel : IRecipeModel
{
public string Description { get; set; } = string.Empty;
public DateTime IssueDate { get; set; } = DateTime.Now;
public int DiseaseId { get; set; }
public int DoctorId { get; set; }
public Dictionary<int, IMedicineModel> RecipeMedicines { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -7,7 +7,9 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="Enums\" />
<Compile Remove="Enums\**" />
<EmbeddedResource Remove="Enums\**" />
<None Remove="Enums\**" />
</ItemGroup>
</Project>

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace HospitalDataModels.Models
{
internal interface IDoctorModel : IId
public interface IDoctorModel : IId
{
string FIO { get; }
string Login { get; }

View File

@ -12,7 +12,7 @@ namespace HospitalDataModels.Models
string CountryOrigin { get; }
double Price { get; }
int PharmacistId { get; }
Dictionary<int, IProcedureModel> MedicineProcedures { get; }
Dictionary<int, IRecipeModel> MedicineRecipes { get; } //во всех сущностях проверить связи
/*Dictionary<int, IProcedureModel> MedicineProcedures { get; }*/
Dictionary<int, IRecipeModel> MedicineRecipes { get; } //во всех сущностях проверить связи*/
}
}

View File

@ -12,9 +12,9 @@ namespace HospitalDataModels.Models
DateTime Date { get; }
int DescriptionOfTheProcedureId { get; }
int PharmacistId { get; }
Dictionary<int, IMedicineModel> MedicineProcedures { get; }
Dictionary<int, IMedicineModel> ProcedureMedicines { get; }
Dictionary<int, IPatientModel> PatientProcedures { get; }//проверка коммита
//Dictionary<int, IPatientModel> PatientProcedures { get; }//проверка коммита
}
}

View File

@ -1,7 +0,0 @@
namespace HospitalDatabaseImplement
{
public class Class1
{
}
}