2024-05-14 23:49:46 +04:00
|
|
|
|
using MedicalDatabaseContracts;
|
|
|
|
|
using MedicalDatabaseContracts.Models;
|
|
|
|
|
using MedicalDatabaseContracts.SearchModels;
|
|
|
|
|
using MedicalDatabaseContracts.ViewModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace MedicalBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
2024-05-15 01:35:29 +04:00
|
|
|
|
public class DiagnoseLogic : AbstractLogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel>
|
2024-05-14 23:49:46 +04:00
|
|
|
|
{
|
2024-05-15 01:35:29 +04:00
|
|
|
|
public DiagnoseLogic(
|
|
|
|
|
ILogger<AbstractLogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel>> logger,
|
|
|
|
|
IStorage<Diagnose> storage) : base(logger, storage) { }
|
2024-05-14 23:49:46 +04:00
|
|
|
|
|
2024-05-15 01:35:29 +04:00
|
|
|
|
protected override bool CheckModelBySearchModel(Diagnose model, DiagnoseSearchModel searchModel)
|
2024-05-14 23:49:46 +04:00
|
|
|
|
{
|
2024-05-15 01:35:29 +04:00
|
|
|
|
if (searchModel.Id != null && searchModel.Id != model.Id)
|
|
|
|
|
return false;
|
|
|
|
|
if (!string.IsNullOrEmpty(searchModel.Name) && searchModel.Name != model.Name)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2024-05-14 23:49:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 01:35:29 +04:00
|
|
|
|
protected override void CheckModelIsValid(Diagnose model)
|
2024-05-14 23:49:46 +04:00
|
|
|
|
{
|
2024-05-15 01:35:29 +04:00
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
else if (string.IsNullOrEmpty(model.Name))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model.Name));
|
|
|
|
|
}
|
|
|
|
|
else if (ReadList(new DiagnoseSearchModel { Name = model.Name }).Count != 0)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException($"Диагноз с таким названием уже есть: \"{model.Name}\"");
|
|
|
|
|
}
|
2024-05-14 23:49:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 01:35:29 +04:00
|
|
|
|
protected override DiagnoseViewModel GetViewModel(Diagnose model)
|
2024-05-14 23:49:46 +04:00
|
|
|
|
{
|
2024-05-15 01:35:29 +04:00
|
|
|
|
return new DiagnoseViewModel {
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name
|
|
|
|
|
};
|
2024-05-14 23:49:46 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|