Реализовал логику диагнозов

This commit is contained in:
Никита Потапов 2024-05-15 01:35:29 +04:00
parent 27a285e573
commit 4f354276e9
7 changed files with 36 additions and 215 deletions

View File

@ -20,7 +20,7 @@ namespace MedicalBusinessLogic.BusinessLogics
_storage = storage;
}
protected abstract bool CheckModelIsValid(M model);
protected abstract void CheckModelIsValid(M model);
protected abstract bool CheckModelBySearchModel(M model, S searchModel);
@ -79,12 +79,9 @@ namespace MedicalBusinessLogic.BusinessLogics
public virtual bool Create(M model, out long elapsedMilliseconds)
{
elapsedMilliseconds = 0;
if (!CheckModelIsValid(model))
{
return false;
}
try
{
CheckModelIsValid(model);
_storage.Insert(model, out elapsedMilliseconds);
_logger.LogInformation($"Insert operation success");
return true;
@ -99,12 +96,9 @@ namespace MedicalBusinessLogic.BusinessLogics
public virtual bool Update(M model, out long elapsedMilliseconds)
{
elapsedMilliseconds = 0;
if (!CheckModelIsValid(model))
{
return false;
}
try
{
CheckModelIsValid(model);
_storage.Update(model, out elapsedMilliseconds);
_logger.LogInformation($"Update record id:{model.Id} operation success");
return true;

View File

@ -3,43 +3,47 @@ using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System.Globalization;
namespace MedicalBusinessLogic.BusinessLogics
{
public class DiagnoseLogic : ILogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel>
public class DiagnoseLogic : AbstractLogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel>
{
private readonly IStorage<Diagnose> _diagnoseStorage;
private readonly ILogger<DiagnoseLogic> _logger;
public DiagnoseLogic(
ILogger<AbstractLogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel>> logger,
IStorage<Diagnose> storage) : base(logger, storage) { }
public DiagnoseLogic(IStorage<Diagnose> diagnoseStorage, ILogger<DiagnoseLogic> logger)
protected override bool CheckModelBySearchModel(Diagnose model, DiagnoseSearchModel searchModel)
{
_diagnoseStorage = diagnoseStorage;
_logger = logger;
if (searchModel.Id != null && searchModel.Id != model.Id)
return false;
if (!string.IsNullOrEmpty(searchModel.Name) && searchModel.Name != model.Name)
return false;
return true;
}
public bool Create(Diagnose model)
protected override void CheckModelIsValid(Diagnose model)
{
throw new NotImplementedException();
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}\"");
}
}
public bool Delete(int id)
protected override DiagnoseViewModel GetViewModel(Diagnose model)
{
throw new NotImplementedException();
}
public DiagnoseViewModel? ReadElement(int id)
{
throw new NotImplementedException();
}
public List<DiagnoseViewModel>? ReadList(DiagnoseSearchModel? searchModel)
{
throw new NotImplementedException();
}
public bool Update(Diagnose model)
{
throw new NotImplementedException();
return new DiagnoseViewModel {
Id = model.Id,
Name = model.Name
};
}
}
}

View File

@ -1,45 +0,0 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace MedicalBusinessLogic.BusinessLogics
{
public class DoctorLogic : ILogic<Doctor, DoctorViewModel, DoctorSearchModel>
{
private readonly IStorage<Doctor> _doctorStorage;
private readonly ILogger<DoctorLogic> _logger;
public DoctorLogic(IStorage<Doctor> doctorStorage, ILogger<DoctorLogic> logger)
{
_doctorStorage = doctorStorage;
_logger = logger;
}
public bool Create(Doctor model)
{
throw new NotImplementedException();
}
public bool Delete(int id)
{
throw new NotImplementedException();
}
public DoctorViewModel? ReadElement(int id)
{
throw new NotImplementedException();
}
public List<DoctorViewModel>? ReadList(DoctorSearchModel? searchModel)
{
throw new NotImplementedException();
}
public bool Update(Doctor model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,45 +0,0 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace MedicalBusinessLogic.BusinessLogics
{
public class PatientLogic : ILogic<Patient, PatientViewModel, PatientSearchModel>
{
private readonly IStorage<Patient> _patientStorage;
private readonly ILogger<PatientLogic> _logger;
public PatientLogic(IStorage<Patient> patientStorage, ILogger<PatientLogic> logger)
{
_patientStorage = patientStorage;
_logger = logger;
}
public bool Create(Patient model)
{
throw new NotImplementedException();
}
public bool Delete(int id)
{
throw new NotImplementedException();
}
public PatientViewModel? ReadElement(int id)
{
throw new NotImplementedException();
}
public List<PatientViewModel>? ReadList(PatientSearchModel? searchModel)
{
throw new NotImplementedException();
}
public bool Update(Patient model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,45 +0,0 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace MedicalBusinessLogic.BusinessLogics
{
public class SpecializationLogic : ILogic<Specialization, SpecializationViewModel, SpecializationSearchModel>
{
private readonly IStorage<Specialization> _specializationStorage;
private readonly ILogger<SpecializationLogic> _logger;
public SpecializationLogic(IStorage<Specialization> specializationStorage, ILogger<SpecializationLogic> logger)
{
_specializationStorage = specializationStorage;
_logger = logger;
}
public bool Create(Specialization model)
{
throw new NotImplementedException();
}
public bool Delete(int id)
{
throw new NotImplementedException();
}
public SpecializationViewModel? ReadElement(int id)
{
throw new NotImplementedException();
}
public List<SpecializationViewModel>? ReadList(SpecializationSearchModel? searchModel)
{
throw new NotImplementedException();
}
public bool Update(Specialization model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,45 +0,0 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace MedicalBusinessLogic.BusinessLogics
{
public class VisitLogic : ILogic<Visit, VisitViewModel, VisitSearchModel>
{
private readonly IStorage<Visit> _visitStorage;
private readonly ILogger<VisitLogic> _logger;
public VisitLogic(IStorage<Visit> visitStorage, ILogger<VisitLogic> logger)
{
_visitStorage = visitStorage;
_logger = logger;
}
public bool Create(Visit model)
{
throw new NotImplementedException();
}
public bool Delete(int id)
{
throw new NotImplementedException();
}
public VisitViewModel? ReadElement(int id)
{
throw new NotImplementedException();
}
public List<VisitViewModel>? ReadList(VisitSearchModel? searchModel)
{
throw new NotImplementedException();
}
public bool Update(Visit model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,4 +1,7 @@
namespace MedicalDatabaseContracts.SearchModels
{
public class DiagnoseSearchModel : AbstractSearchModel { }
public class DiagnoseSearchModel : AbstractSearchModel
{
public string? Name { get; set; }
}
}