61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
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, bool modelUpdate = false)
|
|
{
|
|
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
|
|
{
|
|
Id = model.Id,
|
|
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
|
|
};
|
|
}
|
|
}
|
|
}
|