diff --git a/Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs b/Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs new file mode 100644 index 0000000..0d39cac --- /dev/null +++ b/Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs @@ -0,0 +1,59 @@ +using MedicalDatabaseContracts; +using MedicalDatabaseContracts.Models; +using MedicalDatabaseContracts.SearchModels; +using MedicalDatabaseContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace MedicalBusinessLogic.BusinessLogics +{ + public class PatientLogic : AbstractLogic + { + public PatientLogic( + ILogger> logger, + IStorage storage) : base(logger, storage) { } + + protected override bool CheckModelBySearchModel(Patient model, PatientSearchModel searchModel) + { + if (searchModel.Id != null && searchModel.Id != model.Id) + return false; + if (!string.IsNullOrEmpty(searchModel.Name) && searchModel.Name != model.Name) + return false; + if (!string.IsNullOrEmpty(searchModel.Surname) && searchModel.Surname != model.Surname) + return false; + if (!string.IsNullOrEmpty(searchModel.Patronymic) && searchModel.Patronymic != model.Patronymic) + return false; + return true; + } + + protected override void CheckModelIsValid(Patient model) + { + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException(nameof(model.Name)); + } + else if (string.IsNullOrEmpty(model.Surname)) + { + throw new ArgumentNullException(nameof(model.Surname)); + } + else if (string.IsNullOrEmpty(model.PhoneNumber)) + { + throw new ArgumentNullException(nameof(model.PhoneNumber)); + } + } + + protected override PatientViewModel GetViewModel(Patient model) + { + return new PatientViewModel + { + Name = model.Name, + Surname = model.Surname, + Patronymic = model.Patronymic ?? string.Empty, + PhoneNumber = model.PhoneNumber, + Gender = model.Gender, + Birthday = model.Birthday, + Weight = model.Weight, + Height = model.Height + }; + } + } +}