2023-04-05 00:33:37 +04:00
|
|
|
|
using HospitalContracts.BindingModels;
|
|
|
|
|
using HospitalContracts.BusinessLogicsContracts;
|
|
|
|
|
using HospitalContracts.SearchModels;
|
|
|
|
|
using HospitalContracts.StoragesContracts;
|
|
|
|
|
using HospitalContracts.ViewModels;
|
2023-06-03 15:50:25 +04:00
|
|
|
|
using HospitalDataModels.Models;
|
2023-04-05 00:33:37 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace HospitalBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ProceduresLogic : IProceduresLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IProceduresStorage _proceduresStorage;
|
|
|
|
|
public ProceduresLogic(ILogger<ProceduresLogic> logger, IProceduresStorage proceduresStorage)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_proceduresStorage = proceduresStorage;
|
|
|
|
|
}
|
2023-06-03 15:50:25 +04:00
|
|
|
|
|
2023-06-19 13:29:55 +04:00
|
|
|
|
public bool AddMedicineToProcedure(ProceduresSearchModel model, IMedicinesModel medicine)
|
2023-06-03 15:50:25 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("AddMedicine.Id:{ Id}", model.Id);
|
|
|
|
|
var element = _proceduresStorage.GetElement(model);
|
|
|
|
|
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("AddMedicine element not found");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("AddMedicine find. Id:{Id}", element.Id);
|
|
|
|
|
|
|
|
|
|
element.ProcedureMedicine[medicine.Id] = medicine;
|
|
|
|
|
|
|
|
|
|
_proceduresStorage.Update(new()
|
|
|
|
|
{
|
|
|
|
|
Id = element.Id,
|
|
|
|
|
ProceduresName = element.ProceduresName,
|
|
|
|
|
Type = element.Type,
|
|
|
|
|
ClientId = element.ClientId,
|
|
|
|
|
ProcedureMedicine = element.ProcedureMedicine
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-04-05 00:33:37 +04:00
|
|
|
|
public bool Create(ProceduresBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_proceduresStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Delete(ProceduresBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
|
|
|
|
if (_proceduresStorage.Delete(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Delete operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProceduresViewModel? ReadElement(ProceduresSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadElement. ProceduresName:{ProceduresName}. Id:{ Id}", model.ProceduresName, model.Id);
|
|
|
|
|
var element = _proceduresStorage.GetElement(model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadElement element not found");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ProceduresViewModel>? ReadList(ProceduresSearchModel? model)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("ReadList. ProceduresName:{ProceduresName}. Id:{ Id}", model?.ProceduresName, model?.Id);
|
|
|
|
|
var list = model == null ? _proceduresStorage.GetFullList() : _proceduresStorage.GetFilteredList(model);
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadList return null list");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(ProceduresBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_proceduresStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Update operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckModel(ProceduresBindingModel model, bool withParams = true)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
if (!withParams)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(model.ProceduresName))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет названия процедуры", nameof(model.ProceduresName));
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(model.Type))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет типа процедуры", nameof(model.Type));
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Procedures. ProceduresName:{ProceduresName}. Type:{ Type}. Id: { Id} ", model.ProceduresName, model.Type, model.Id);
|
|
|
|
|
var element = _proceduresStorage.GetElement(new ProceduresSearchModel
|
|
|
|
|
{
|
|
|
|
|
ProceduresName = model.ProceduresName
|
|
|
|
|
});
|
|
|
|
|
if (element != null && element.Id != model.Id)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Процедура с таким названием уже есть");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|