2023-05-20 06:49:33 +04:00
|
|
|
|
using HospitalContracts.BindingModels;
|
|
|
|
|
using HospitalContracts.BusinessLogicsContracts;
|
|
|
|
|
using HospitalContracts.SearchModels;
|
|
|
|
|
using HospitalContracts.ViewModels;
|
|
|
|
|
using HospitalDataModels.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Net;
|
2023-04-07 01:21:27 +04:00
|
|
|
|
|
|
|
|
|
namespace HospitalRestApi.Controllers
|
|
|
|
|
{
|
2023-05-20 06:49:33 +04:00
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class MainController : Controller
|
2023-04-07 01:21:27 +04:00
|
|
|
|
{
|
2023-05-20 06:49:33 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IClientLogic _client;
|
|
|
|
|
private readonly IProceduresLogic _procedure;
|
|
|
|
|
private readonly IMedicinesLogic _medicine;
|
|
|
|
|
private readonly IKurseLogic _kurse;
|
|
|
|
|
private readonly ISymptomsLogic _symptom;
|
|
|
|
|
private readonly IRecipesLogic _recipe;
|
|
|
|
|
private readonly IIllnessLogic _illness;
|
|
|
|
|
|
|
|
|
|
public MainController(ILogger<MainController> logger, IClientLogic client, IProceduresLogic procedure, IMedicinesLogic medicine, IKurseLogic kurse, ISymptomsLogic symptom, IRecipesLogic recipe, IIllnessLogic illness)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_client = client;
|
|
|
|
|
_procedure = procedure;
|
|
|
|
|
_medicine = medicine;
|
|
|
|
|
_kurse = kurse;
|
|
|
|
|
_symptom = symptom;
|
|
|
|
|
_recipe = recipe;
|
|
|
|
|
_illness = illness;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ПРОЦЕДУРЫ
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ProceduresViewModel>? GetProcedureList(int? clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (clientId == null)
|
|
|
|
|
{
|
|
|
|
|
return _procedure.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
return _procedure.ReadList(new ProceduresSearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка процедур");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ProceduresViewModel>? GetProcedures()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _procedure.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка процедур");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-19 13:29:55 +04:00
|
|
|
|
//[HttpGet]
|
|
|
|
|
//public ProceduresViewModel? GetProcedure(int procedureId)
|
|
|
|
|
//{
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// return _procedure.ReadElement(new ProceduresSearchModel
|
|
|
|
|
// {
|
|
|
|
|
// Id = procedureId
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// _logger.LogError(ex, "Ошибка получения процедуры по id={Id}", procedureId);
|
|
|
|
|
// throw;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2023-05-20 06:49:33 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateProcedure(ProceduresBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_procedure.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания процедуры");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateProcedure(ProceduresBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
model.ProcedureMedicine = null!;
|
|
|
|
|
_procedure.Update(model);
|
2023-05-20 06:49:33 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления процедуры");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-19 13:29:55 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public Tuple<ProceduresViewModel, List<Tuple<string>>>? GetProcedure(int procedureId)
|
2023-06-03 15:50:25 +04:00
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
try
|
2023-06-03 15:50:25 +04:00
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
var elem = _procedure.ReadElement(new ProceduresSearchModel { Id = procedureId });
|
|
|
|
|
if (elem == null)
|
|
|
|
|
return null;
|
|
|
|
|
return Tuple.Create(elem, elem.ProcedureMedicine.Select(x => Tuple.Create(x.Value.MedicinesName)).ToList());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения процедуры по id={Id}", procedureId);
|
|
|
|
|
throw;
|
2023-06-03 15:50:25 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-19 13:29:55 +04:00
|
|
|
|
//private ProceduresBindingModel GetModelWithMedicines(ProceduresBindingModel model)
|
|
|
|
|
//{
|
|
|
|
|
// var medicines = _medicine.ReadList(new MedicinesSearchModel { Ids = model.ProcedureMedicine.Keys.ToArray() });
|
|
|
|
|
// if (medicines != null)
|
|
|
|
|
// {
|
|
|
|
|
// model.ProcedureMedicine = medicines.Where(m => model.ProcedureMedicine.Keys.Contains(m.Id))
|
|
|
|
|
// .ToDictionary(m => m.Id, m => m as IMedicinesModel);
|
|
|
|
|
// }
|
|
|
|
|
// return model;
|
|
|
|
|
//}
|
|
|
|
|
|
2023-05-20 06:49:33 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteProcedure(ProceduresBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_procedure.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления процедуры");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ЛЕКАРСТВА
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<MedicinesViewModel>? GetMedicinesList(int? clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (clientId == null)
|
|
|
|
|
{
|
|
|
|
|
return _medicine.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
return _medicine.ReadList(new MedicinesSearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка лекарств");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<MedicinesViewModel>? GetMedicines()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _medicine.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка лекарств");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public MedicinesViewModel? GetMedicine(int medicineId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _medicine.ReadElement(new MedicinesSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = medicineId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения лекарства по id={Id}", medicineId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateMedicine(MedicinesBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_medicine.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания лекарства");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateMedicine(MedicinesBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_medicine.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления лекарства");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteMedicine(MedicinesBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_medicine.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления лекарства");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// РЕЦЕПТЫ
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<RecipesViewModel>? GetRecipesList(int clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _recipe.ReadList(new RecipesSearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка рецептов");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateRecipe(RecipesBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-06-03 15:50:25 +04:00
|
|
|
|
_recipe.Create(model);
|
2023-05-20 06:49:33 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания рецепта");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<RecipesViewModel>? GetRecipes()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _recipe.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка рецептов");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-19 13:29:55 +04:00
|
|
|
|
//[HttpGet]
|
|
|
|
|
//public RecipesViewModel? GetRecipe(int recipeId)
|
|
|
|
|
//{
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// return _recipe.ReadElement(new RecipesSearchModel
|
|
|
|
|
// {
|
|
|
|
|
// Id = recipeId
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// _logger.LogError(ex, "Ошибка получения рецепта по id={Id}", recipeId);
|
|
|
|
|
// throw;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateRecipe(RecipesBindingModel model)
|
2023-05-20 06:49:33 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
model.RecipeProcedures = null!;
|
|
|
|
|
_recipe.Update(model);
|
2023-05-20 06:49:33 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
2023-05-20 06:49:33 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-19 13:29:55 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public Tuple<RecipesViewModel, List<Tuple<string>>>? GetRecipe(int recipeId)
|
2023-05-20 06:49:33 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
var elem = _recipe.ReadElement(new RecipesSearchModel { Id = recipeId });
|
|
|
|
|
if (elem == null)
|
|
|
|
|
return null;
|
|
|
|
|
return Tuple.Create(elem, elem.RecipeProcedures.Select(x => Tuple.Create(x.Value.ProceduresName)).ToList());
|
2023-05-20 06:49:33 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения процедуры по id={Id}", recipeId);
|
2023-05-20 06:49:33 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-19 13:29:55 +04:00
|
|
|
|
|
2023-05-20 06:49:33 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void AddProcedures(Tuple<RecipesSearchModel, ProceduresViewModel> model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_recipe.AddProcedures(model.Item1, model.Item2);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-06-03 15:50:25 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка добавления процедуры в рецепт.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-06-19 13:29:55 +04:00
|
|
|
|
public void AddMedicineToProcedure(Tuple<ProceduresSearchModel, MedicinesViewModel> model)
|
2023-06-03 15:50:25 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-06-19 13:29:55 +04:00
|
|
|
|
_procedure.AddMedicineToProcedure(model.Item1, model.Item2);
|
2023-06-03 15:50:25 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка добавления лекарства в процедуру.");
|
2023-05-20 06:49:33 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private RecipesBindingModel GetModelWithProcedures( RecipesBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var medicines = _procedure.ReadList(new ProceduresSearchModel { Ids = model.RecipeProcedures.Keys.ToArray() });
|
|
|
|
|
if (medicines != null)
|
|
|
|
|
{
|
|
|
|
|
model.RecipeProcedures = medicines.Where(m => model.RecipeProcedures.Keys.Contains(m.Id))
|
|
|
|
|
.ToDictionary(m => m.Id, m => m as IProceduresModel);
|
|
|
|
|
}
|
|
|
|
|
return model;
|
2023-04-07 01:21:27 +04:00
|
|
|
|
}
|
2023-06-03 15:50:25 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteRecipe(RecipesBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_recipe.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления рецепта");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<SymptomsViewModel>? GetSymptoms()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _symptom.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-07 01:21:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-20 06:49:33 +04:00
|
|
|
|
|