Реализовал логику пациентов

This commit is contained in:
Никита Потапов 2024-05-15 01:54:07 +04:00
parent b6922e4815
commit c65f745450

View File

@ -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<Patient, PatientViewModel, PatientSearchModel>
{
public PatientLogic(
ILogger<AbstractLogic<Patient, PatientViewModel, PatientSearchModel>> logger,
IStorage<Patient> 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
};
}
}
}