From c65f745450eca6aa5438f1fa219c40f734658929 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Wed, 15 May 2024 01:54:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=86=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/PatientLogic.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Medical/MedicalBusinessLogic/BusinessLogics/PatientLogic.cs 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 + }; + } + } +}