From b65e364788e968e5eb019479fa7c274eb1a6adac Mon Sep 17 00:00:00 2001 From: ValAnn Date: Mon, 29 Apr 2024 11:20:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BD=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hospital/Hospital/HospitalView.csproj | 7 + .../BusinessLogics/DoctorLogic.cs | 124 ++++++++++++++++++ .../BusinessLogics/PatientLogic.cs | 120 +++++++++++++++++ .../BusinessLogics/ProcedureLogic.cs | 2 +- .../BusinessLogics/RecipeLogic.cs | 115 ++++++++++++++++ 5 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/DoctorLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/PatientLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/BusinessLogics/RecipeLogic.cs diff --git a/Hospital/Hospital/HospitalView.csproj b/Hospital/Hospital/HospitalView.csproj index b57c89e..f97c885 100644 --- a/Hospital/Hospital/HospitalView.csproj +++ b/Hospital/Hospital/HospitalView.csproj @@ -8,4 +8,11 @@ enable + + + + + + + \ No newline at end of file diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/DoctorLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/DoctorLogic.cs new file mode 100644 index 0000000..e568222 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/DoctorLogic.cs @@ -0,0 +1,124 @@ +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 DoctorLogic : IDoctorLogic + { + private readonly ILogger _logger; + private readonly IDoctorStorage _doctorStorage; + + public DoctorLogic(ILogger logger, IDoctorStorage doctorStorage) + { + _logger = logger; + _doctorStorage = doctorStorage; + } + + public bool Create(DoctorBindingModel model) + { + CheckModel(model); + if (_doctorStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(DoctorBindingModel model) + { + CheckModel(model); + if (_doctorStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(DoctorBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_doctorStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public DoctorViewModel? ReadElement(DoctorSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Login:{Login}. PhoneNumber:{PhoneNumber}. Id:{ Id}", model.Login, model.PhoneNumber, model.Id); + var element = _doctorStorage.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? ReadList(DoctorSearchModel? model) + { + _logger.LogInformation("ReadList. DoctorId:{Id}", model?.Id); + var list = model == null ? _doctorStorage.GetFullList() : _doctorStorage.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(DoctorBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина врача", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.PhoneNumber)) + { + throw new ArgumentNullException("Нет номера телефона врача", nameof(model.PhoneNumber)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля врача", nameof(model.Password)); + } + _logger.LogInformation("Doctor. Login:{Login}. PhoneNumber:{PhoneNumber}. Password:{Password}. Id:{ Id}", model.Login, model.PhoneNumber, model.Password, model.Id); + var element = _doctorStorage.GetElement(new DoctorSearchModel + { + Login = model.Login, + PhoneNumber = model.PhoneNumber, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Врач с таким именем уже есть"); + } + } + } +} diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/PatientLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/PatientLogic.cs new file mode 100644 index 0000000..dbab8f7 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/PatientLogic.cs @@ -0,0 +1,120 @@ +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 PatientLogic : IPatientLogic + { + private readonly ILogger _logger; + private readonly IPatientStorage _patientStorage; + + public PatientLogic(ILogger logger, IPatientStorage patientStorage) + { + _logger = logger; + _patientStorage = patientStorage; + } + + public bool Create(PatientBindingModel model) + { + CheckModel(model); + if (_patientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(PatientBindingModel model) + { + CheckModel(model); + if (_patientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(PatientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_patientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public PatientViewModel? ReadElement(PatientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FIO:{FIO}. Id:{ Id}", model.FIO, model.Id); + var element = _patientStorage.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? ReadList(PatientSearchModel? model) + { + _logger.LogInformation("ReadList. PatientId:{Id}", model?.Id); + var list = model == null ? _patientStorage.GetFullList() : _patientStorage.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(PatientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FIO)) + { + throw new ArgumentNullException("Нет FIO пациента", nameof(model.FIO)); + } + + /*if (model.BirthDate < DateTime.Now.) + { + throw new ArgumentNullException("Возраст пациента должен быть больше 0", nameof(model.FIO)); + }*/ //TODO + _logger.LogInformation("Patient. Login:{Login}. PhoneNumber:{PhoneNumber}. Password:{Password}. BirthDate:{BirthDate}. DoctorId:{DoctorId}. Id:{ Id}", model.FIO, model.BirthDate, model.DoctorId, model.Id); + var element = _patientStorage.GetElement(new PatientSearchModel + { + FIO = model.FIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пациент с такими данными уже есть"); + } + } + } +} diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/ProcedureLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/ProcedureLogic.cs index f2d0b73..beba3c6 100644 --- a/Hospital/HospitalBusinessLogic/BusinessLogics/ProcedureLogic.cs +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/ProcedureLogic.cs @@ -106,7 +106,7 @@ true) { // throw new ArgumentNullException("Цена мороженного услуги быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Service. ServiceName:{ServiceName}. Price:{ Price }. Id: { Id}", model.Name, model.Price, model.Id); + _logger.LogInformation("Service. ServiceName:{ServiceName}. Price:{ Price }. Id: { Id}", model.Name, model.Id); var element = _serviceStorage.GetElement(new ProcedureSearchModel { Name = model.Name diff --git a/Hospital/HospitalBusinessLogic/BusinessLogics/RecipeLogic.cs b/Hospital/HospitalBusinessLogic/BusinessLogics/RecipeLogic.cs new file mode 100644 index 0000000..5fa5cf4 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/BusinessLogics/RecipeLogic.cs @@ -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 RecipeLogic : IRecipeLogic + { + private readonly ILogger _logger; + private readonly IRecipeStorage _recipeStorage; + + public RecipeLogic(ILogger logger, IRecipeStorage recipeStorage) + { + _logger = logger; + _recipeStorage = recipeStorage; + } + + public bool Create(RecipeBindingModel model) + { + CheckModel(model); + if (_recipeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(RecipeBindingModel model) + { + CheckModel(model); + if (_recipeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(RecipeBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_recipeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public RecipeViewModel? ReadElement(RecipeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _recipeStorage.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? ReadList(RecipeSearchModel? model) + { + _logger.LogInformation("ReadList. RecipeId:{Id}", model?.Id); + var list = model == null ? _recipeStorage.GetFullList() : _recipeStorage.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(RecipeBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.RecipeMedicines == null || model.RecipeMedicines.Count == 0) + { + throw new ArgumentNullException("Нет лекарств в рецепте", nameof(model.RecipeMedicines)); + } + _logger.LogInformation("Recipe. Id:{ Id}. DiseaseId:{DiseaseId}. DoctorId:{DoctorId}", model.Id, model.DiseaseId, model.DoctorId); + var element = _recipeStorage.GetElement(new RecipeSearchModel + { + Id = model.Id, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пациент с такими данными уже есть"); + } + } + } +}