осталось редактирование

This commit is contained in:
Екатерина Рогашова 2023-06-03 15:50:25 +04:00
parent dc5910e324
commit 22eecccf08
40 changed files with 704 additions and 525 deletions

View File

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace HospitalBusinessLogic.BusinessLogics namespace HospitalBusinessLogic.BusinessLogics
@ -107,6 +108,15 @@ namespace HospitalBusinessLogic.BusinessLogics
{ {
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
} }
if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase))
{
throw new ArgumentException("Неправильно введенный email", nameof(model.Email));
}
if (!Regex.IsMatch(model.Password, @"^^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$", RegexOptions.IgnoreCase))
{
throw new ArgumentException("Неправильно введенный пароль", nameof(model.Password));
}
_logger.LogInformation("Client. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}", model.ClientFIO, model.Email, model.Id); _logger.LogInformation("Client. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}", model.ClientFIO, model.Email, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel var element = _clientStorage.GetElement(new ClientSearchModel
{ {

View File

@ -3,6 +3,7 @@ using HospitalContracts.BusinessLogicsContracts;
using HospitalContracts.SearchModels; using HospitalContracts.SearchModels;
using HospitalContracts.StoragesContracts; using HospitalContracts.StoragesContracts;
using HospitalContracts.ViewModels; using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -21,6 +22,38 @@ namespace HospitalBusinessLogic.BusinessLogics
_logger = logger; _logger = logger;
_proceduresStorage = proceduresStorage; _proceduresStorage = proceduresStorage;
} }
public bool AddMedicines(ProceduresSearchModel model, IMedicinesModel medicine)
{
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;
}
public bool Create(ProceduresBindingModel model) public bool Create(ProceduresBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -130,6 +130,10 @@ namespace HospitalBusinessLogic.BusinessLogics
{ {
return; return;
} }
if (model.SymptomsId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор симптома", nameof(model.SymptomsId));
}
if (string.IsNullOrEmpty(model.Dose)) if (string.IsNullOrEmpty(model.Dose))
{ {
throw new ArgumentNullException("В рецепте нет дозировки", nameof(model.Dose)); throw new ArgumentNullException("В рецепте нет дозировки", nameof(model.Dose));
@ -138,7 +142,7 @@ namespace HospitalBusinessLogic.BusinessLogics
{ {
throw new ArgumentNullException("Нет способа приема", nameof(model.ModeOfApplication)); throw new ArgumentNullException("Нет способа приема", nameof(model.ModeOfApplication));
} }
_logger.LogInformation("Recipes.RecipesId:{Id}.Dose:{ Dose}.ModeOfApplication:{ ModeOfApplication}", model.Id, model.Dose, model.ModeOfApplication); _logger.LogInformation("Recipes.RecipesId:{Id}.Dose:{ Dose}.ModeOfApplication:{ ModeOfApplication}. MedicineId: { MedicineId}", model.Id, model.Dose, model.ModeOfApplication, model.SymptomsId);
} }
} }
} }

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.Metrics; using System.Diagnostics.Metrics;
using System.Reflection;
using System.Xml.Linq; using System.Xml.Linq;
namespace HospitalClientApp.Controllers namespace HospitalClientApp.Controllers
@ -123,23 +124,23 @@ namespace HospitalClientApp.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.Medicines = APIClient.GetRequest<List<MedicinesViewModel>>("api/main/getmedicineslist");
if (!id.HasValue) if (!id.HasValue)
{ {
return View(); return View(new ProceduresViewModel());
} }
var model = APIClient.GetRequest<ProceduresViewModel?>($"api/main/getprocedure?id={id}"); var model = APIClient.GetRequest<ProceduresViewModel?>($"api/main/getprocedure?id={id}");
return View(model); return View(model);
} }
[HttpPost] [HttpPost]
public void CreateProcedure(int? id, string procedurename, string proceduretype ) public void CreateProcedure(ProceduresBindingModel model, int? id, string procedurename, string proceduretype )
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
} }
if (id.HasValue) if (model.Id != 0)
{ {
APIClient.PostRequest("api/main/updateprocedure", new ProceduresBindingModel APIClient.PostRequest("api/main/updateprocedure", new ProceduresBindingModel
{ {
@ -199,6 +200,29 @@ namespace HospitalClientApp.Controllers
ViewBag.Procedures = APIClient.GetRequest<List<ProceduresViewModel>>($"api/main/getprocedurelist?clientId={APIClient.Client.Id}"); ViewBag.Procedures = APIClient.GetRequest<List<ProceduresViewModel>>($"api/main/getprocedurelist?clientId={APIClient.Client.Id}");
return View(); return View();
} }
//[HttpGet]
//public IActionResult AddDrugCourse()
//{
// if (APIClient.Client == null)
// {
// return Redirect("~/Home/Enter");
// }
// ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines");
// ViewBag.DrugCourses = APIClient.GetRequest<List<DrugCourseViewModel>>($"api/drugcourse/getdrugcourses");
// return View();
//}
//[HttpPost]
//public void AddMedicineDrugCourse(int medicine, int drugcourse)
//{
// if (APIClient.Client == null)
// {
// throw new Exception("Доступно только авторизованным пользователям");
// }
// APIClient.PostRequest($"api/medicine/addmedicinedrugcourse", (new DrugCourseBindingModel { Id = drugcourse }, new MedicineBindingModel { Id = medicine }));
// Response.Redirect("ListDrugCourses");
//}
/// <summary> /// <summary>
/// ЛЕКАРСТВА /// ЛЕКАРСТВА
/// </summary> /// </summary>
@ -310,19 +334,20 @@ namespace HospitalClientApp.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.Medicines = APIClient.GetRequest<List<MedicinesViewModel>>("api/main/getmedicineslist"); ViewBag.Symptomses = APIClient.GetRequest<List<SymptomsViewModel>>("api/main/getsymptoms");
ViewBag.Procedures = APIClient.GetRequest<List<ProceduresViewModel>>("api/main/getprocedurelist"); ViewBag.Procedures = APIClient.GetRequest<List<ProceduresViewModel>>("api/main/getprocedurelist");
if (!id.HasValue) if (!id.HasValue)
{ {
return View(new RecipesViewModel()); return View(new RecipesViewModel());
} }
var model = APIClient.GetRequest<RecipesViewModel?>($"api/main/getrecipe?id={id}");
var model = APIClient.GetRequest<ProceduresViewModel?>($"api/main/getprocedure?id={id}");
return View(model); return View(model);
} }
[HttpPost] [HttpPost]
public void CreateRecipe(RecipesBindingModel model) public void CreateRecipe(RecipesBindingModel model, int? id, int symptoms, string dose, string modeofapplication)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
@ -335,7 +360,13 @@ namespace HospitalClientApp.Controllers
} }
else else
{ {
APIClient.PostRequest("api/main/createrecipe", model); APIClient.PostRequest("api/main/createrecipe", new RecipesBindingModel
{
ClientId = APIClient.Client.Id,
Dose = dose,
SymptomsId = symptoms,
ModeOfApplication = modeofapplication
});
} }
Response.Redirect("ListRecipes"); Response.Redirect("ListRecipes");
} }
@ -364,6 +395,27 @@ namespace HospitalClientApp.Controllers
} }
return Tuple.Create(result.Item1, table); return Tuple.Create(result.Item1, table);
} }
[HttpPost]
public void DeleteRecipe(int recipe)
{
if (APIClient.Client == null)
{
throw new Exception("Доступно только авторизованным пользователям");
}
APIClient.PostRequest($"api/main/DeleteRecipe", new RecipesBindingModel { Id = recipe });
Response.Redirect("ListRecipes");
}
public IActionResult DeleteRecipe()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Recipes = APIClient.GetRequest<List<RecipesViewModel>>($"api/main/GetRecipesList?clientId={APIClient.Client.Id}");
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()

View File

@ -18,14 +18,80 @@ if (Model != null)
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Название процедуры:</div> <div class="col-4">Название процедуры:</div>
<div class="col-8"><input type="text" name="procedurename" id="procedurename" value="@Model?.MedicinesName" /></div> <div class="col-8"><input type="text" name="procedurename" id="procedurename"/></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Тип:</div> <div class="col-4">Тип:</div>
<div class="col-8"><input type="text" id="proceduretype" name="proceduretype" value="@Model?.Type" /></div> <div class="col-8"><input type="text" id="proceduretype" name="proceduretype" value="@Model?.Type" /></div>
</div> </div>
<div class="row">
<div class="col-4">Добавление лекарств</div>
<div class="col-8">
<div class="row">
<div class="col-6">
<select id="medicines" name="medicines" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines,"Id", "MedicinesName"))"></select>
</div>
<div class="col-6">
<button type="button" class="btn btn-success" onclick="addMedicine()">Добавить</button>
</div>
</div>
</div>
</div>
<div class="row">
<p class="text-center"><strong>Лекарства</strong></p>
<table id="medicinesTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Название</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var medicine in Model.ProcedureMedicine)
{
<tr>
<td>@medicine.Value.MedicinesName</td>
<td>
<button type="button" class="btn btn-danger" data-id="@medicine.Key" onclick="removeMedicine('@medicine.Key')">Удалить</button>
</td>
</tr>
}
</tbody>
</table>
</div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div> </div>
</form> </form>
@section scripts {
<script>
var procedureMedicine = @Json.Serialize(Model.ProcedureMedicine);
function addMedicine() {
var medicineId = $('#medicines').val();
var medicinesName = $('#medicines option:selected').text();
if (procedureMedicine.hasOwnProperty(medicineId)) {
alert('This medicine is already added.');
return;
}
procedureMedicine[medicineId] = { Id: medicineId, MedicinesName: medicinesName };
var row = $('<tr>').append($('<td>').text(medicinesName));
var removeButton = $('<button>').text('Удалить').attr('data-id', medicineId).attr('class', 'btn btn-danger').click((function (id) {
return function () {
removeMedicine(id);
};
})(medicineId));
row.append($('<td>').append(removeButton));
$('#medicinesTable tbody').append(row);
var input = $('<input>').attr('type', 'hidden').attr('name', 'ProcedureMedicine[' + medicineId + ']').val(medicineId);
$('#procedures-form').append(input);
}
function removeMedicine(medicineId) {
delete procedureMedicine[medicineId];
$('#medicinesTable button[data-id="' + medicineId + '"]').closest('tr').remove();
$('#procedures-form input[name="ProcedureMedicine[' + medicineId + ']"]').remove();
}
</script>
}

View File

@ -17,26 +17,28 @@
</div> </div>
<div class="row"> <div class="row">
<div class="row mb-3"> <div class="row mb-3">
<div class="col-4">Лекарство:</div> <div class="col-4">Привязка симптома:</div>
<div class="col-8"> <div class="col-8">
<select id="medicines" name="medicines" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines,"Id", "MedicinesName"))"></select> <select id="symptoms" name="symptoms" class="form-control" asp-items="@(new SelectList(@ViewBag.Symptomses,"Id", "SymptomName"))"></select>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="row">
<label>Добавление процедур:</label> <div class="col-4">Добавление процедур</div>
</div> <div class="col-8">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<select id="procedures" name="procedures" class="form-control" asp-items="@(new SelectList(@ViewBag.Procedures,"Id", "ProceduresName"))"></select> <select id="procedures" name="procedures" class="form-control" asp-items="@(new SelectList(@ViewBag.Procedures,"Id", "ProceduresName"))"></select>
</div> </div>
<div class="col-6"> <div class="col-6">
<button type="button" class="btn btn-success bg-dark" onclick="addProcedures()">Добавить</button> <button type="button" class="btn btn-success" onclick="addProcedures()">Добавить</button>
</div>
</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<p class="text-center"><strong>Процедуры</strong></p> <p class="text-center"><strong>Процедуры</strong></p>
<table id="prodedureTable" class="table table-bordered table-striped"> <table id="procedureTable" class="table table-bordered table-striped">
<thead> <thead>
<tr> <tr>
<th>Название</th> <th>Название</th>
@ -56,7 +58,6 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<br />
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
@ -65,16 +66,16 @@
@section scripts { @section scripts {
<script> <script>
var recipesProcedures = @Json.Serialize(Model.RecipeProcedures); var recipeProcedures = @Json.Serialize(Model.RecipeProcedures);
function addProcedures() { function addProcedures() {
var procedureId = $('#procedures').val(); var procedureId = $('#procedures').val();
var proceduresName = $('#procedures option:selected').text(); var procedureName = $('#procedures option:selected').text();
if (recipesProcedures.hasOwnProperty(procedureId)) { if (recipeProcedures.hasOwnProperty(procedureId)) {
alert('This procedure is already added.'); alert('This procedure is already added.');
return; return;
} }
recipesProcedures[procedureId] = { Id: procedureId, Name: proceduresName }; recipeProcedures[procedureId] = { Id: procedureId, ProceduresName: procedureName };
var row = $('<tr>').append($('<td>').text(proceduresName)); var row = $('<tr>').append($('<td>').text(procedureName));
var removeButton = $('<button>').text('Удалить').attr('data-id', procedureId).attr('class', 'btn btn-danger').click((function (id) { var removeButton = $('<button>').text('Удалить').attr('data-id', procedureId).attr('class', 'btn btn-danger').click((function (id) {
return function () { return function () {
removeProcedure(id); removeProcedure(id);
@ -83,13 +84,13 @@
row.append($('<td>').append(removeButton)); row.append($('<td>').append(removeButton));
$('#procedureTable tbody').append(row); $('#procedureTable tbody').append(row);
var input = $('<input>').attr('type', 'hidden').attr('name', 'RecipesProcedures[' + procedureId + ']').val(procedureId); var input = $('<input>').attr('type', 'hidden').attr('name', 'RecipeProcedures[' + procedureId + ']').val(procedureId);
$('#recipe-form').append(input); $('#recipe-form').append(input);
} }
function removeProcedure(procedureId) { function removeProcedure(procedureId) {
delete recipesProcedures[procedureId]; delete recipeProcedures[procedureId];
$('#procedureTable button[data-id="' + procedureId + '"]').closest('tr').remove(); $('#procedureTable button[data-id="' + procedureId + '"]').closest('tr').remove();
$('#recipe-form input[name="RecipesProcedures[' + procedureId + ']"]').remove(); $('#recipe-form input[name="RecipeProcedures[' + procedureId + ']"]').remove();
} }
</script> </script>
} }

View File

@ -0,0 +1,16 @@
@{
ViewData["Title"] = "DeleteRecipe";
}
<form method="post">
<div class="row">
<label class="lable">Рецепт: </label>
<div>
<select id="recipe" name="recipe" class="form-control" asp-items="@(new SelectList(@ViewBag.Recipes, "Id", "Id"))"></select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Удалить"/></div>
</div>
</form>

View File

@ -21,8 +21,6 @@
<p> <p>
<a class="btn btn-warning" asp-action="CreateRecipe">Создать рецепт</a> <a class="btn btn-warning" asp-action="CreateRecipe">Создать рецепт</a>
<a class="btn btn-warning" asp-action="DeleteRecipe">Удалить</a> <a class="btn btn-warning" asp-action="DeleteRecipe">Удалить</a>
<a class="btn btn-warning" asp-action="AddProcedures">Добавить процедуры</a>
<a class="btn btn-warning" asp-action="AddSymptoms">Добавить симптомы</a>
</p> </p>
<table class="table"> <table class="table">
<thead> <thead>
@ -58,7 +56,7 @@
@Html.DisplayFor(modelItem => item.Dose) @Html.DisplayFor(modelItem => item.Dose)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.MedicinesName) @Html.DisplayFor(modelItem => item.SymptomsId)
</td> </td>
<td> <td>
<a class="btn btn-warning" asp-action="CreateRecipe" asp-route-id="@item.Id">Редактировать</a> <a class="btn btn-warning" asp-action="CreateRecipe" asp-route-id="@item.Id">Редактировать</a>

View File

@ -105,7 +105,7 @@ namespace HospitalRestApi.Controllers
{ {
try try
{ {
_procedure.Update(model); _procedure.Update(GetModelWithMedicines(model));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -114,6 +114,17 @@ namespace HospitalRestApi.Controllers
} }
} }
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;
}
[HttpPost] [HttpPost]
public void DeleteProcedure(ProceduresBindingModel model) public void DeleteProcedure(ProceduresBindingModel model)
{ {
@ -248,7 +259,7 @@ namespace HospitalRestApi.Controllers
{ {
try try
{ {
_recipe.Create(GetModelWithProcedures(model)); _recipe.Create(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -309,11 +320,23 @@ namespace HospitalRestApi.Controllers
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка добавления участника в план питания."); _logger.LogError(ex, "Ошибка добавления процедуры в рецепт.");
throw;
}
}
[HttpPost]
public void AddMedicines(Tuple<ProceduresSearchModel, MedicinesViewModel> model)
{
try
{
_procedure.AddMedicines(model.Item1, model.Item2);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка добавления лекарства в процедуру.");
throw; throw;
} }
} }
private RecipesBindingModel GetModelWithProcedures( RecipesBindingModel model) private RecipesBindingModel GetModelWithProcedures( RecipesBindingModel model)
{ {
var medicines = _procedure.ReadList(new ProceduresSearchModel { Ids = model.RecipeProcedures.Keys.ToArray() }); var medicines = _procedure.ReadList(new ProceduresSearchModel { Ids = model.RecipeProcedures.Keys.ToArray() });
@ -324,6 +347,32 @@ namespace HospitalRestApi.Controllers
} }
return model; return model;
} }
[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;
}
}
} }
} }

View File

@ -1,6 +1,7 @@
using HospitalBusinessLogic.BusinessLogics; using HospitalBusinessLogic.BusinessLogics;
using HospitalContracts.BusinessLogicsContracts; using HospitalContracts.BusinessLogicsContracts;
using HospitalContracts.StoragesContracts; using HospitalContracts.StoragesContracts;
using HospitalDataBaseImplements;
using HospitalDataBaseImplements.Implements; using HospitalDataBaseImplements.Implements;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
@ -42,6 +43,7 @@ builder.Services.AddSwaggerGen(c =>
var app = builder.Build(); var app = builder.Build();
LoaderFromXML.LoadSymptoms();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())

View File

@ -1,8 +1,10 @@
using HospitalDataModels.Models; using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace HospitalContracts.BindingModels namespace HospitalContracts.BindingModels
@ -13,5 +15,13 @@ namespace HospitalContracts.BindingModels
public string ProceduresName { get; set; } = string.Empty; public string ProceduresName { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty; public string Type { get; set; } = string.Empty;
public int ClientId { get; set; } public int ClientId { get; set; }
public Dictionary<int, IMedicinesModel> ProcedureMedicine
{
get;
set;
} = new();
} }
} }

View File

@ -14,18 +14,12 @@ namespace HospitalContracts.BindingModels
public DateTime Date { get; set; } = DateTime.Now; public DateTime Date { get; set; } = DateTime.Now;
public string ModeOfApplication { get; set; } = string.Empty; public string ModeOfApplication { get; set; } = string.Empty;
public int ClientId { get; set; } public int ClientId { get; set; }
public int MedicinesId { get; set; }
//public Dictionary<int, ISymptomsModel> RecipeSymptoms
//{
// get;
// set;
//} = new();
public Dictionary<int, IProceduresModel> RecipeProcedures public Dictionary<int, IProceduresModel> RecipeProcedures
{ {
get; get;
set; set;
} = new(); } = new();
public int SymptomsId { get; set; }
} }
} }

View File

@ -1,6 +1,7 @@
using HospitalContracts.BindingModels; using HospitalContracts.BindingModels;
using HospitalContracts.SearchModels; using HospitalContracts.SearchModels;
using HospitalContracts.ViewModels; using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -13,6 +14,7 @@ namespace HospitalContracts.BusinessLogicsContracts
{ {
List<ProceduresViewModel>? ReadList(ProceduresSearchModel? model); List<ProceduresViewModel>? ReadList(ProceduresSearchModel? model);
ProceduresViewModel? ReadElement(ProceduresSearchModel model); ProceduresViewModel? ReadElement(ProceduresSearchModel model);
bool AddMedicines(ProceduresSearchModel model, IMedicinesModel member);
bool Create(ProceduresBindingModel model); bool Create(ProceduresBindingModel model);
bool Update(ProceduresBindingModel model); bool Update(ProceduresBindingModel model);
bool Delete(ProceduresBindingModel model); bool Delete(ProceduresBindingModel model);

View File

@ -14,7 +14,7 @@ namespace HospitalContracts.BusinessLogicsContracts
{ {
List<RecipesViewModel>? ReadList(RecipesSearchModel? model); List<RecipesViewModel>? ReadList(RecipesSearchModel? model);
RecipesViewModel? ReadElement(RecipesSearchModel model); RecipesViewModel? ReadElement(RecipesSearchModel model);
bool AddProcedures(RecipesSearchModel model, IProceduresModel member); bool AddProcedures(RecipesSearchModel model, IProceduresModel procedure);
bool Create(RecipesBindingModel model); bool Create(RecipesBindingModel model);
bool Update(RecipesBindingModel model); bool Update(RecipesBindingModel model);
bool Delete(RecipesBindingModel model); bool Delete(RecipesBindingModel model);

View File

@ -11,5 +11,7 @@ namespace HospitalContracts.SearchModels
public int? Id { get; set; } public int? Id { get; set; }
public string? MedicinesName { get; set; } public string? MedicinesName { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
public int[]? Ids { get; set; }
} }
} }

View File

@ -12,7 +12,7 @@ namespace HospitalContracts.ViewModels
{ {
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название лекарства")] [DisplayName("Название лекарства")]
public string MedicinesName { get; set; } = string.Empty; public string MedicinesName { get; set; }
[DisplayName("Группа")] [DisplayName("Группа")]
public string Group { get; set; } = string.Empty; public string Group { get; set; } = string.Empty;
public int ClientId { get; set; } public int ClientId { get; set; }

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace HospitalContracts.ViewModels namespace HospitalContracts.ViewModels
@ -16,5 +17,17 @@ namespace HospitalContracts.ViewModels
[DisplayName("Тип процедуры")] [DisplayName("Тип процедуры")]
public string Type { get; set; } = string.Empty; public string Type { get; set; } = string.Empty;
public int ClientId { get; set; } public int ClientId { get; set; }
public Dictionary<int, IMedicinesModel> ProcedureMedicine
{
get;
set;
} = new();
public ProceduresViewModel() { }
[JsonConstructor]
public ProceduresViewModel(Dictionary<int, MedicinesViewModel> ProcedureMedicine)
{
this.ProcedureMedicine = ProcedureMedicine.ToDictionary(x => x.Key, x => x.Value as IMedicinesModel);
}
} }
} }

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace HospitalContracts.ViewModels namespace HospitalContracts.ViewModels
@ -20,20 +21,22 @@ namespace HospitalContracts.ViewModels
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Способ приготовления")] [DisplayName("Способ приготовления")]
public string ModeOfApplication { get; set; } = string.Empty; public string ModeOfApplication { get; set; } = string.Empty;
[DisplayName("Лекарство")]
public string MedicinesName { get; set; } = string.Empty;
public int MedicinesId { get; set; }
//[DisplayName("Симптом")]
//public Dictionary<int, ISymptomsModel> RecipeSymptoms
//{
// get;
// set;
//} = new();
[DisplayName("Процедура")] [DisplayName("Процедура")]
public Dictionary<int, IProceduresModel> RecipeProcedures public Dictionary<int, IProceduresModel> RecipeProcedures
{ {
get; get;
set; set;
} = new(); } = new();
[DisplayName("Симптом")]
public int SymptomsId { get; set; }
public RecipesViewModel() { }
[JsonConstructor]
public RecipesViewModel(Dictionary<int, ProceduresViewModel> RecipeProcedures)
{
this.RecipeProcedures = RecipeProcedures.ToDictionary(x => x.Key, x => x.Value as IProceduresModel);
}
} }
} }

View File

@ -14,6 +14,6 @@ namespace HospitalContracts.ViewModels
[DisplayName("Симптом")] [DisplayName("Симптом")]
public string SymptomName { get; set; } = string.Empty; public string SymptomName { get; set; } = string.Empty;
[DisplayName("Описание")] [DisplayName("Описание")]
public string Description { get; set; } = string.Empty; public string? Description { get; set; } = string.Empty;
} }
} }

View File

@ -22,8 +22,8 @@ namespace HospitalDataBaseImplements
public virtual DbSet<Illness> Illnesses { set; get; } public virtual DbSet<Illness> Illnesses { set; get; }
public virtual DbSet<IllnessKurse> IllnessKurse { set; get; } public virtual DbSet<IllnessKurse> IllnessKurse { set; get; }
public virtual DbSet<IllnessSymptoms> IllnessSymptomses { set; get; } public virtual DbSet<IllnessSymptoms> IllnessSymptomses { set; get; }
public virtual DbSet<RecipesSymptoms> RecipesSymptoms { set; get; }
public virtual DbSet<RecipesProcedures> RecipesProcedures { set; get; } public virtual DbSet<RecipesProcedures> RecipesProcedures { set; get; }
public virtual DbSet<ProcedureMedicine> ProcedureMedicine { set; get; }
public virtual DbSet<Symptoms> Symptomses { set; get; } public virtual DbSet<Symptoms> Symptomses { set; get; }
public virtual DbSet<Recipes> Recipes { set; get; } public virtual DbSet<Recipes> Recipes { set; get; }
public virtual DbSet<Medicines> Medicines { set; get; } public virtual DbSet<Medicines> Medicines { set; get; }

View File

@ -42,7 +42,7 @@ namespace HospitalDataBaseImplements.Implements
return null; return null;
} }
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
return context.Medicines return context.Medicines.Include(x => x.Client)
.FirstOrDefault(x => .FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.MedicinesName) && x.MedicinesName == (!string.IsNullOrEmpty(model.MedicinesName) && x.MedicinesName ==
model.MedicinesName) || model.MedicinesName) ||
@ -51,19 +51,23 @@ namespace HospitalDataBaseImplements.Implements
} }
public MedicinesViewModel? Insert(MedicinesBindingModel model) public MedicinesViewModel? Insert(MedicinesBindingModel model)
{ {
using var context = new HospitalDatabase();
var newMedicine = Medicines.Create(model); var newMedicine = Medicines.Create(model);
if (newMedicine == null) if (newMedicine == null)
{ {
return null; return null;
} }
using var context = new HospitalDatabase();
context.Medicines.Add(newMedicine); context.Medicines.Add(newMedicine);
context.SaveChanges(); context.SaveChanges();
return newMedicine.GetViewModel; return context.Medicines.Include(x => x.Client).FirstOrDefault(x => x.Id == newMedicine.Id)
?.GetViewModel;
} }
public MedicinesViewModel? Update(MedicinesBindingModel model) public MedicinesViewModel? Update(MedicinesBindingModel model)
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var medicine = context.Medicines.FirstOrDefault(x => x.Id == model.Id); var medicine = context.Medicines.FirstOrDefault(x => x.Id == model.Id);
if (medicine == null) if (medicine == null)
{ {
@ -73,6 +77,12 @@ namespace HospitalDataBaseImplements.Implements
context.SaveChanges(); context.SaveChanges();
return medicine.GetViewModel; return medicine.GetViewModel;
} }
catch
{
transaction.Rollback();
throw;
}
}
public MedicinesViewModel? Delete(MedicinesBindingModel model) public MedicinesViewModel? Delete(MedicinesBindingModel model)
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();

View File

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
namespace HospitalDataBaseImplements.Implements namespace HospitalDataBaseImplements.Implements
{ {
@ -17,7 +18,8 @@ namespace HospitalDataBaseImplements.Implements
public List<ProceduresViewModel> GetFullList() public List<ProceduresViewModel> GetFullList()
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
return context.Procedures.Include(x => x.Client) return context.Procedures.Include(x => x.Client).Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -41,7 +43,7 @@ namespace HospitalDataBaseImplements.Implements
return null; return null;
} }
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
return context.Procedures return context.Procedures.Include(x => x.Client)
.FirstOrDefault(x => .FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ProceduresName) && x.ProceduresName == (!string.IsNullOrEmpty(model.ProceduresName) && x.ProceduresName ==
model.ProceduresName) || model.ProceduresName) ||
@ -58,11 +60,17 @@ namespace HospitalDataBaseImplements.Implements
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
context.Procedures.Add(newProcedures); context.Procedures.Add(newProcedures);
context.SaveChanges(); context.SaveChanges();
return newProcedures.GetViewModel; return context.Procedures.Include(x => x.Client)
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine).FirstOrDefault(x => x.Id == newProcedures.Id)
?.GetViewModel;
} }
public ProceduresViewModel? Update(ProceduresBindingModel model) public ProceduresViewModel? Update(ProceduresBindingModel model)
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var procedure = context.Procedures.FirstOrDefault(x => x.Id == model.Id); var procedure = context.Procedures.FirstOrDefault(x => x.Id == model.Id);
if (procedure == null) if (procedure == null)
{ {
@ -70,12 +78,22 @@ namespace HospitalDataBaseImplements.Implements
} }
procedure.Update(model); procedure.Update(model);
context.SaveChanges(); context.SaveChanges();
procedure.UpdateMedicines(context, model);
transaction.Commit();
return procedure.GetViewModel; return procedure.GetViewModel;
} }
catch
{
transaction.Rollback();
throw;
}
}
public ProceduresViewModel? Delete(ProceduresBindingModel model) public ProceduresViewModel? Delete(ProceduresBindingModel model)
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
var element = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id); var element = context.Procedures.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)
{ {
context.Procedures.Remove(element); context.Procedures.Remove(element);

View File

@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
namespace HospitalDataBaseImplements.Implements namespace HospitalDataBaseImplements.Implements
{ {
@ -17,7 +18,8 @@ namespace HospitalDataBaseImplements.Implements
public RecipesViewModel? Delete(RecipesBindingModel model) public RecipesViewModel? Delete(RecipesBindingModel model)
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
var element = context.Recipes.Include(x => x.Procedures).FirstOrDefault(rec => rec.Id == model.Id); var element = context.Recipes.Include(x => x.Procedures).Include(x => x.Symptoms)
.Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)
{ {
context.Recipes.Remove(element); context.Recipes.Remove(element);
@ -38,11 +40,11 @@ namespace HospitalDataBaseImplements.Implements
Include(x => x.Client). Include(x => x.Client).
Include(x => x.Procedures). Include(x => x.Procedures).
ThenInclude(x => x.Procedure). ThenInclude(x => x.Procedure).
Include(x => x.Medicines). Include(x => x.Symptoms).
FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel; .GetViewModel;
} }
//НУЖЕН ТУТ ЕЩЕ ОДИН ТУ ЛИСТ???
public List<RecipesViewModel> GetFilteredList(RecipesSearchModel model) public List<RecipesViewModel> GetFilteredList(RecipesSearchModel model)
{ {
if (model is null) if (model is null)
@ -54,9 +56,9 @@ namespace HospitalDataBaseImplements.Implements
return context.Recipes. return context.Recipes.
Include(x => x.Procedures). Include(x => x.Procedures).
ThenInclude(x => x.Procedure) ThenInclude(x => x.Procedure)
.Include(x => x.Medicines) .Include(x => x.Symptoms)
.Include(x => x.Client) .Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId).ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -66,8 +68,9 @@ namespace HospitalDataBaseImplements.Implements
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
return context.Recipes.Include(x => x.Procedures). return context.Recipes.Include(x => x.Procedures).
ThenInclude(x => x.Procedure) ThenInclude(x => x.Procedure)
.Include(x => x.Medicines)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Symptoms)
.ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -75,25 +78,28 @@ namespace HospitalDataBaseImplements.Implements
public RecipesViewModel? Insert(RecipesBindingModel model) public RecipesViewModel? Insert(RecipesBindingModel model)
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
var newDrugCourse = Recipes.Create(model); var newRecipe = Recipes.Create(model);
if (newDrugCourse == null) if (newRecipe == null)
{ {
return null; return null;
} }
context.Recipes.Add(newDrugCourse); context.Recipes.Add(newRecipe);
context.SaveChanges(); context.SaveChanges();
return context.Recipes return context.Recipes
.Include(x => x.Procedures) .Include(x => x.Procedures)
.ThenInclude(x => x.Procedure) .ThenInclude(x => x.Procedure)
.Include(x => x.Medicines) .Include(x => x.Symptoms)
.Include(x => x.Client) .Include(x => x.Client)
.FirstOrDefault(x => x.Id == newDrugCourse.Id) .FirstOrDefault(x => x.Id == newRecipe.Id)
?.GetViewModel; ?.GetViewModel;
} }
public RecipesViewModel? Update(RecipesBindingModel model) public RecipesViewModel? Update(RecipesBindingModel model)
{ {
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var recipe = context.Recipes.FirstOrDefault(x => x.Id == model.Id); var recipe = context.Recipes.FirstOrDefault(x => x.Id == model.Id);
if (recipe == null) if (recipe == null)
{ {
@ -101,7 +107,15 @@ namespace HospitalDataBaseImplements.Implements
} }
recipe.Update(model); recipe.Update(model);
context.SaveChanges(); context.SaveChanges();
recipe.UpdateProcedures(context, model);
transaction.Commit();
return recipe.GetViewModel; return recipe.GetViewModel;
} }
catch
{
transaction.Rollback();
throw;
}
}
} }
} }

View File

@ -10,9 +10,9 @@ namespace HospitalDataBaseImplements
{ {
public class LoaderFromXML public class LoaderFromXML
{ {
private static readonly string IllnessFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Illness.xml"); // private static readonly string IllnessFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Illness.xml");
private static readonly string SymptomsFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Symptoms.xml"); private static readonly string SymptomsFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Symptoms.xml");
private static readonly string KursesFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Kurses.xml"); // private static readonly string KursesFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Kurses.xml");
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction) private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{ {
@ -26,35 +26,35 @@ namespace HospitalDataBaseImplements
/// Чтение пациентов из XML-файла /// Чтение пациентов из XML-файла
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static void LoadIllness() // (запуск после загрузки курсов) //public static void LoadIllness() // (запуск после загрузки курсов)
{ //{
using var context = new HospitalDatabase(); // using var context = new HospitalDatabase();
if (context.Illnesses.ToList().Count > 0) // if (context.Illnesses.ToList().Count > 0)
return; // return;
var list = LoadData(IllnessFileName, "Illness", x => Illness.Create(x)!)!; // var list = LoadData(IllnessFileName, "Illness", x => Illness.Create(x)!)!;
list.ForEach(x => // list.ForEach(x =>
{ // {
context.Illnesses.Add(x); // context.Illnesses.Add(x);
}); // });
context.SaveChanges(); // context.SaveChanges();
} //}
/// <summary> /// <summary>
/// Чтение лечений из XML-файла /// Чтение лечений из XML-файла
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static void LoadKurses() // (запуск после загрузки симптомов) //public static void LoadKurses() // (запуск после загрузки симптомов)
{
using var context = new HospitalDatabase();
if (context.Kurse.ToList().Count > 0)
return;
//var list = LoadData(KursesFileName, "Kurses", x => Kurses.Create(context, x)!)!;
//list.ForEach(x =>
//{ //{
// context.Kurse.Add(x); // using var context = new HospitalDatabase();
//}); // if (context.Kurse.ToList().Count > 0)
//context.SaveChanges(); // return;
} // //var list = LoadData(KursesFileName, "Kurses", x => Kurses.Create(context, x)!)!;
// //list.ForEach(x =>
// //{
// // context.Kurse.Add(x);
// //});
// //context.SaveChanges();
//}
/// <summary> /// <summary>
/// Чтение поцедур из XML-файла /// Чтение поцедур из XML-файла
/// </summary> /// </summary>
@ -64,12 +64,12 @@ namespace HospitalDataBaseImplements
using var context = new HospitalDatabase(); using var context = new HospitalDatabase();
if (context.Symptomses.ToList().Count > 0) if (context.Symptomses.ToList().Count > 0)
return; return;
//var list = LoadData(SymptomsFileName, "Symptoms", x => Symptoms.Create(x)!)!; var list = LoadData(SymptomsFileName, "Symptoms", x => Symptoms.Create(x)!)!;
//list.ForEach(x => list.ForEach(x =>
//{ {
// context.Symptomses.Add(x); context.Symptomses.Add(x);
//}); });
//context.SaveChanges(); context.SaveChanges();
} }
} }
} }

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace HospitalDataBaseImplements.Migrations namespace HospitalDataBaseImplements.Migrations
{ {
[DbContext(typeof(HospitalDatabase))] [DbContext(typeof(HospitalDatabase))]
[Migration("20230520015950_InitialCreate")] [Migration("20230525103233_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -172,6 +172,29 @@ namespace HospitalDataBaseImplements.Migrations
b.ToTable("Medicines"); b.ToTable("Medicines");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.ProcedureMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureMedicine");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -216,18 +239,18 @@ namespace HospitalDataBaseImplements.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<int>("MedicinesId")
.HasColumnType("int");
b.Property<string>("ModeOfApplication") b.Property<string>("ModeOfApplication")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<int>("SymptomsId")
.HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("MedicinesId"); b.HasIndex("SymptomsId");
b.ToTable("Recipes"); b.ToTable("Recipes");
}); });
@ -255,29 +278,6 @@ namespace HospitalDataBaseImplements.Migrations
b.ToTable("RecipesProcedures"); b.ToTable("RecipesProcedures");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("RecipesId")
.HasColumnType("int");
b.Property<int>("SymptomsId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RecipesId");
b.HasIndex("SymptomsId");
b.ToTable("RecipesSymptoms");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -358,6 +358,25 @@ namespace HospitalDataBaseImplements.Migrations
b.Navigation("Client"); b.Navigation("Client");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.ProcedureMedicine", b =>
{
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicine")
.WithMany("Procedures")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDataBaseImplements.Models.Procedures", "Procedure")
.WithMany("Medicines")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Procedure");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b =>
{ {
b.HasOne("HospitalDataBaseImplements.Models.Client", "Client") b.HasOne("HospitalDataBaseImplements.Models.Client", "Client")
@ -377,15 +396,15 @@ namespace HospitalDataBaseImplements.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines") b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms")
.WithMany() .WithMany()
.HasForeignKey("MedicinesId") .HasForeignKey("SymptomsId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Medicines"); b.Navigation("Symptoms");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b =>
@ -407,25 +426,6 @@ namespace HospitalDataBaseImplements.Migrations
b.Navigation("Recipe"); b.Navigation("Recipe");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b =>
{
b.HasOne("HospitalDataBaseImplements.Models.Recipes", "Recipe")
.WithMany()
.HasForeignKey("RecipesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms")
.WithMany()
.HasForeignKey("SymptomsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Recipe");
b.Navigation("Symptoms");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b =>
{ {
b.Navigation("Kurses"); b.Navigation("Kurses");
@ -438,6 +438,16 @@ namespace HospitalDataBaseImplements.Migrations
b.Navigation("IllnessKurses"); b.Navigation("IllnessKurses");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b =>
{
b.Navigation("Procedures");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b =>
{
b.Navigation("Medicines");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b =>
{ {
b.Navigation("Procedures"); b.Navigation("Procedures");

View File

@ -122,6 +122,35 @@ namespace HospitalDataBaseImplements.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable(
name: "Recipes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Dose = table.Column<string>(type: "nvarchar(max)", nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false),
ModeOfApplication = table.Column<string>(type: "nvarchar(max)", nullable: false),
SymptomsId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Recipes", x => x.Id);
table.ForeignKey(
name: "FK_Recipes_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Recipes_Symptomses_SymptomsId",
column: x => x.SymptomsId,
principalTable: "Symptomses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Kurse", name: "Kurse",
columns: table => new columns: table => new
@ -145,60 +174,31 @@ namespace HospitalDataBaseImplements.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Recipes", name: "ProcedureMedicine",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
Dose = table.Column<string>(type: "nvarchar(max)", nullable: false), MedicineId = table.Column<int>(type: "int", nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false), ProcedureId = table.Column<int>(type: "int", nullable: false)
ClientId = table.Column<int>(type: "int", nullable: false),
MedicinesId = table.Column<int>(type: "int", nullable: false),
ModeOfApplication = table.Column<string>(type: "nvarchar(max)", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Recipes", x => x.Id); table.PrimaryKey("PK_ProcedureMedicine", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_Recipes_Clients_ClientId", name: "FK_ProcedureMedicine_Medicines_MedicineId",
column: x => x.ClientId, column: x => x.MedicineId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Recipes_Medicines_MedicinesId",
column: x => x.MedicinesId,
principalTable: "Medicines", principalTable: "Medicines",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProcedureMedicine_Procedures_ProcedureId",
column: x => x.ProcedureId,
principalTable: "Procedures",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict); onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable(
name: "IllnessKurse",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
IllnessId = table.Column<int>(type: "int", nullable: false),
KurseId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_IllnessKurse", x => x.Id);
table.ForeignKey(
name: "FK_IllnessKurse_Illnesses_IllnessId",
column: x => x.IllnessId,
principalTable: "Illnesses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_IllnessKurse_Kurse_KurseId",
column: x => x.KurseId,
principalTable: "Kurse",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "RecipesProcedures", name: "RecipesProcedures",
columns: table => new columns: table => new
@ -226,27 +226,27 @@ namespace HospitalDataBaseImplements.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "RecipesSymptoms", name: "IllnessKurse",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
RecipesId = table.Column<int>(type: "int", nullable: false), IllnessId = table.Column<int>(type: "int", nullable: false),
SymptomsId = table.Column<int>(type: "int", nullable: false) KurseId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_RecipesSymptoms", x => x.Id); table.PrimaryKey("PK_IllnessKurse", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_RecipesSymptoms_Recipes_RecipesId", name: "FK_IllnessKurse_Illnesses_IllnessId",
column: x => x.RecipesId, column: x => x.IllnessId,
principalTable: "Recipes", principalTable: "Illnesses",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_RecipesSymptoms_Symptomses_SymptomsId", name: "FK_IllnessKurse_Kurse_KurseId",
column: x => x.SymptomsId, column: x => x.KurseId,
principalTable: "Symptomses", principalTable: "Kurse",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
@ -281,6 +281,16 @@ namespace HospitalDataBaseImplements.Migrations
table: "Medicines", table: "Medicines",
column: "ClientId"); column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_ProcedureMedicine_MedicineId",
table: "ProcedureMedicine",
column: "MedicineId");
migrationBuilder.CreateIndex(
name: "IX_ProcedureMedicine_ProcedureId",
table: "ProcedureMedicine",
column: "ProcedureId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Procedures_ClientId", name: "IX_Procedures_ClientId",
table: "Procedures", table: "Procedures",
@ -292,9 +302,9 @@ namespace HospitalDataBaseImplements.Migrations
column: "ClientId"); column: "ClientId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Recipes_MedicinesId", name: "IX_Recipes_SymptomsId",
table: "Recipes", table: "Recipes",
column: "MedicinesId"); column: "SymptomsId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_RecipesProcedures_ProcedureId", name: "IX_RecipesProcedures_ProcedureId",
@ -305,16 +315,6 @@ namespace HospitalDataBaseImplements.Migrations
name: "IX_RecipesProcedures_RecipesId", name: "IX_RecipesProcedures_RecipesId",
table: "RecipesProcedures", table: "RecipesProcedures",
column: "RecipesId"); column: "RecipesId");
migrationBuilder.CreateIndex(
name: "IX_RecipesSymptoms_RecipesId",
table: "RecipesSymptoms",
column: "RecipesId");
migrationBuilder.CreateIndex(
name: "IX_RecipesSymptoms_SymptomsId",
table: "RecipesSymptoms",
column: "SymptomsId");
} }
/// <inheritdoc /> /// <inheritdoc />
@ -327,10 +327,10 @@ namespace HospitalDataBaseImplements.Migrations
name: "IllnessSymptomses"); name: "IllnessSymptomses");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "RecipesProcedures"); name: "ProcedureMedicine");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "RecipesSymptoms"); name: "RecipesProcedures");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Kurse"); name: "Kurse");
@ -345,10 +345,10 @@ namespace HospitalDataBaseImplements.Migrations
name: "Recipes"); name: "Recipes");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Symptomses"); name: "Medicines");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Medicines"); name: "Symptomses");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Clients"); name: "Clients");

View File

@ -169,6 +169,29 @@ namespace HospitalDataBaseImplements.Migrations
b.ToTable("Medicines"); b.ToTable("Medicines");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.ProcedureMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureMedicine");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -213,18 +236,18 @@ namespace HospitalDataBaseImplements.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<int>("MedicinesId")
.HasColumnType("int");
b.Property<string>("ModeOfApplication") b.Property<string>("ModeOfApplication")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<int>("SymptomsId")
.HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("MedicinesId"); b.HasIndex("SymptomsId");
b.ToTable("Recipes"); b.ToTable("Recipes");
}); });
@ -252,29 +275,6 @@ namespace HospitalDataBaseImplements.Migrations
b.ToTable("RecipesProcedures"); b.ToTable("RecipesProcedures");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("RecipesId")
.HasColumnType("int");
b.Property<int>("SymptomsId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RecipesId");
b.HasIndex("SymptomsId");
b.ToTable("RecipesSymptoms");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -355,6 +355,25 @@ namespace HospitalDataBaseImplements.Migrations
b.Navigation("Client"); b.Navigation("Client");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.ProcedureMedicine", b =>
{
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicine")
.WithMany("Procedures")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDataBaseImplements.Models.Procedures", "Procedure")
.WithMany("Medicines")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Procedure");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b =>
{ {
b.HasOne("HospitalDataBaseImplements.Models.Client", "Client") b.HasOne("HospitalDataBaseImplements.Models.Client", "Client")
@ -374,15 +393,15 @@ namespace HospitalDataBaseImplements.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines") b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms")
.WithMany() .WithMany()
.HasForeignKey("MedicinesId") .HasForeignKey("SymptomsId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Medicines"); b.Navigation("Symptoms");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b =>
@ -404,25 +423,6 @@ namespace HospitalDataBaseImplements.Migrations
b.Navigation("Recipe"); b.Navigation("Recipe");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b =>
{
b.HasOne("HospitalDataBaseImplements.Models.Recipes", "Recipe")
.WithMany()
.HasForeignKey("RecipesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms")
.WithMany()
.HasForeignKey("SymptomsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Recipe");
b.Navigation("Symptoms");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b =>
{ {
b.Navigation("Kurses"); b.Navigation("Kurses");
@ -435,6 +435,16 @@ namespace HospitalDataBaseImplements.Migrations
b.Navigation("IllnessKurses"); b.Navigation("IllnessKurses");
}); });
modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b =>
{
b.Navigation("Procedures");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b =>
{
b.Navigation("Medicines");
});
modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b =>
{ {
b.Navigation("Procedures"); b.Navigation("Procedures");

View File

@ -14,12 +14,15 @@ namespace HospitalDataBaseImplements.Models
public class Medicines : IMedicinesModel public class Medicines : IMedicinesModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required]
public int ClientId { get; private set; } public int ClientId { get; private set; }
public virtual Client Client { get; set; }
[Required] [Required]
public string MedicinesName { get; private set; } = string.Empty; public string MedicinesName { get; private set; } = string.Empty;
[Required] [Required]
public string Group { get; private set; } = string.Empty; public string Group { get; private set; } = string.Empty;
public virtual Client Client { get; set; }
[ForeignKey("MedicineId")]
public virtual List<ProcedureMedicine> Procedures { get; set; } = new();
public static Medicines? Create(MedicinesBindingModel model) public static Medicines? Create(MedicinesBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -7,14 +7,14 @@ using System.Threading.Tasks;
namespace HospitalDataBaseImplements.Models namespace HospitalDataBaseImplements.Models
{ {
public class RecipesSymptoms public class ProcedureMedicine
{ {
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public int RecipesId { get; set; } public int MedicineId { get; set; }
[Required] [Required]
public int SymptomsId { get; set; } public int ProcedureId { get; set; }
public virtual Recipes Recipe { get; set; } = new(); public virtual Medicines Medicine { get; set; } = new();
public virtual Symptoms Symptoms { get; set; } = new(); public virtual Procedures Procedure { get; set; } = new();
} }
} }

View File

@ -4,6 +4,7 @@ using HospitalDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -15,11 +16,29 @@ namespace HospitalDataBaseImplements.Models
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
public int ClientId { get; private set; } public int ClientId { get; private set; }
public virtual Client Client { get; set; }
[Required] [Required]
public string ProceduresName { get; private set; } = string.Empty; public string ProceduresName { get; private set; } = string.Empty;
[Required] [Required]
public string Type { get; private set; } = string.Empty; public string Type { get; private set; } = string.Empty;
public virtual Client Client { get; set; }
private Dictionary<int, IMedicinesModel>? _procedureMedicine = null;
[NotMapped]
public Dictionary<int, IMedicinesModel> ProcedureMedicine
{
get
{
if (_procedureMedicine == null)
{
_procedureMedicine = Medicines
.ToDictionary(rec => rec.MedicineId, rec =>
rec.Medicine as IMedicinesModel);
}
return _procedureMedicine;
}
}
[ForeignKey("ProcedureId")]
public virtual List<ProcedureMedicine> Medicines { get; set; } = new();
public static Procedures? Create(ProceduresBindingModel model) public static Procedures? Create(ProceduresBindingModel model)
{ {
if (model == null) if (model == null)
@ -60,5 +79,32 @@ namespace HospitalDataBaseImplements.Models
ProceduresName = ProceduresName, ProceduresName = ProceduresName,
Type = Type Type = Type
}; };
public void UpdateMedicines(HospitalDatabase context, ProceduresBindingModel model)
{
var procedureMedicine = context.ProcedureMedicine.Where(rec => rec.ProcedureId == model.Id).ToList();
if (procedureMedicine != null && procedureMedicine.Count > 0)
{
context.ProcedureMedicine.RemoveRange(procedureMedicine.Where(rec
=> !model.ProcedureMedicine.ContainsKey(rec.MedicineId)));
context.SaveChanges();
}
var procedure = context.Procedures.First(x => x.Id == Id);
var existingMedicineIds = procedureMedicine?.Select(x => x.MedicineId).ToList();
foreach (var rec in model.ProcedureMedicine)
{
if (existingMedicineIds != null && !existingMedicineIds.Contains(rec.Key))
{
context.ProcedureMedicine.Add(new ProcedureMedicine
{
Procedure = procedure,
Medicine = context.Medicines.First(x => x.Id == rec.Key),
});
}
}
context.SaveChanges();
_procedureMedicine = null;
}
} }
} }

View File

@ -21,12 +21,13 @@ namespace HospitalDataBaseImplements.Models
public string Dose { get; private set; } = string.Empty; public string Dose { get; private set; } = string.Empty;
[Required] [Required]
public DateTime Date { get; private set; } = DateTime.Now; public DateTime Date { get; private set; } = DateTime.Now;
[Required]
public int ClientId { get; set; } public int ClientId { get; set; }
public virtual Medicines Medicines { get; set; } = new();
public int MedicinesId { get; private set; }
[Required] [Required]
public string ModeOfApplication { get; private set; } = string.Empty; public string ModeOfApplication { get; private set; } = string.Empty;
public Client Client { get; set; } [Required]
public int SymptomsId { get; private set; }
private Dictionary<int, IProceduresModel>? _recipeProcedures = null; private Dictionary<int, IProceduresModel>? _recipeProcedures = null;
[NotMapped] [NotMapped]
public Dictionary<int, IProceduresModel> RecipeProcedures public Dictionary<int, IProceduresModel> RecipeProcedures
@ -43,59 +44,49 @@ namespace HospitalDataBaseImplements.Models
} }
[ForeignKey("RecipesId")] [ForeignKey("RecipesId")]
public virtual List<RecipesProcedures> Procedures { get; set; } = new(); public virtual List<RecipesProcedures> Procedures { get; set; } = new();
public Client Client { get; set; }
//private Dictionary<int, ISymptomsModel>? _recipeSymptoms = null; public Symptoms Symptoms { get; set; }
//[NotMapped]
//public Dictionary<int, ISymptomsModel> RecipeSymptoms
//{
// get
// {
// if (_recipeSymptoms == null)
// {
// _recipeSymptoms = Symptoms.ToDictionary(recPC => recPC.SymptomsId, recPC => (recPC.Symptoms as ISymptomsModel));
// }
// return _recipeSymptoms;
// }
//}
//public virtual List<RecipesSymptoms> Symptoms { get; set; } = new();
public static Recipes? Create(RecipesBindingModel model) public static Recipes? Create(RecipesBindingModel model)
{
if (model == null)
{
return null;
}
return new Recipes()
{
Id = model.Id,
SymptomsId = model.SymptomsId,
Dose = model.Dose,
ClientId = model.ClientId,
ModeOfApplication = model.ModeOfApplication
};
}
public static Recipes Create(RecipesViewModel model)
{ {
return new Recipes() return new Recipes()
{ {
Id = model.Id, Id = model.Id,
SymptomsId = model.SymptomsId,
Dose = model.Dose, Dose = model.Dose,
Date = model.Date, ClientId = model.ClientId,
ModeOfApplication = model.ModeOfApplication, ModeOfApplication = model.ModeOfApplication
ClientId = model.ClientId
//Symptoms = model.RecipeSymptoms.Select(x => new RecipesSymptoms
//{
// Symptoms = context.Symptomses.First(y => y.Id == x.Key),
//}).ToList()
}; };
} }
public void Update(RecipesBindingModel model) public void Update(RecipesBindingModel model)
{ {
Date = model.Date; Date = model.Date;
MedicinesId = model.MedicinesId; Dose = model.Dose;
ModeOfApplication = model.ModeOfApplication;
} }
public RecipesViewModel GetViewModel public RecipesViewModel GetViewModel => new()
{
get
{
using var context = new HospitalDatabase();
return new RecipesViewModel
{ {
Id = Id, Id = Id,
Date = Date, Date = Date,
ClientId = ClientId, ClientId = ClientId,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, ModeOfApplication = ModeOfApplication,
MedicinesId = MedicinesId, Dose = Dose,
RecipeProcedures = RecipeProcedures, SymptomsId = SymptomsId
//RecipeSymptoms = RecipeSymptoms
}; };
}
}
public void UpdateProcedures(HospitalDatabase context, RecipesBindingModel model) public void UpdateProcedures(HospitalDatabase context, RecipesBindingModel model)
{ {
var recipeProcedures = context.RecipesProcedures.Where(rec => rec.RecipesId == model.Id).ToList(); var recipeProcedures = context.RecipesProcedures.Where(rec => rec.RecipesId == model.Id).ToList();
@ -117,26 +108,5 @@ namespace HospitalDataBaseImplements.Models
} }
_recipeProcedures = null; _recipeProcedures = null;
} }
//public void UpdateSymptomses(HospitalDatabase context, RecipesBindingModel model)
//{
// var recipeSymptomses = context.RecipesSymptoms.Where(rec => rec.RecipesId == model.Id).ToList();
// if (recipeSymptomses != null && recipeSymptomses.Count > 0)
// { // удалили те, которых нет в модели
// context.RecipesSymptoms.RemoveRange(recipeSymptomses.Where(rec
// => !model.RecipeSymptoms.ContainsKey(rec.SymptomsId)));
// context.SaveChanges();
// }
// var recipe = context.Recipes.First(x => x.Id == Id);
// foreach (var pc in model.RecipeSymptoms)
// {
// context.RecipesSymptoms.Add(new RecipesSymptoms
// {
// Recipe = recipe,
// Symptoms = context.Symptomses.First(x => x.Id == pc.Key)
// });
// context.SaveChanges();
// }
// _recipeSymptoms = null;
//}
} }
} }

View File

@ -8,6 +8,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
namespace HospitalDataBaseImplements.Models namespace HospitalDataBaseImplements.Models
{ {
@ -40,6 +41,18 @@ namespace HospitalDataBaseImplements.Models
Description = model.Description Description = model.Description
}; };
} }
public static Symptoms? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Symptoms()
{
SymptomName = element.Element("SymptomName")!.Value,
Description = element.Element("Description")!.Value
};
}
public void Update(SymptomsBindingModel model) public void Update(SymptomsBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -1,91 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Illness>
<Illness Id="1">
<IllnessName>Ветрянка</IllnessName>
<Form>Тяжелая</Form>
<Symptoms>
<SymptomId >1</SymptomId>
<SymptomId >2</SymptomId>
<SymptomId >3</SymptomId>
</Symptoms>
<Kurses>
<KurseId >1</KurseId>
<KurseId >2</KurseId>
</Kurses>
</Illness>
<Illness Id="2">
<IllnessName>Воспаление аппендицита</IllnessName>
<Form>Легкая</Form>
<Symptoms>
<SymptomId >1</SymptomId>
</Symptoms>
<Kurses>
<KurseId >1</KurseId>
</Kurses>
</Illness>
<Illness Id="3">
<IllnessName>ОРВИ</IllnessName>
<Form>Средняя</Form>
<Symptoms>
<SymptomId >1</SymptomId>
<SymptomId >2</SymptomId>
</Symptoms>
<Kurses>
<KurseId >1</KurseId>
<KurseId >3</KurseId>
</Kurses>
</Illness>
<Illness Id="4">
<IllnessName>Отравление</IllnessName>
<Form>Тяжелая</Form>
<Symptoms>
<SymptomId >1</SymptomId>
<SymptomId >2</SymptomId>
<SymptomId >3</SymptomId>
<SymptomId >4</SymptomId>
<SymptomId >5</SymptomId>
<SymptomId >6</SymptomId>
</Symptoms>
<Kurses>
<KurseId >1</KurseId>
<KurseId >2</KurseId>
<KurseId >3</KurseId>
<KurseId >4</KurseId>
</Kurses>
</Illness>
<Illness Id="5">
<IllnessName>Перелом</IllnessName>
<Form>Средняя</Form>
<Symptoms>
<SymptomId >3</SymptomId>
</Symptoms>
<Kurses>
<KurseId >1</KurseId>
<KurseId >2</KurseId>
</Kurses>
</Illness>
<Illness Id="6">
<IllnessName>Мигрень</IllnessName>
<Form>Тяжелая</Form>
<Symptoms>
<SymptomId >1</SymptomId>
<SymptomId >3</SymptomId>
<SymptomId >4</SymptomId>
</Symptoms>
<Kurses>
<KurseId >1</KurseId>
<KurseId >3</KurseId>
<KurseId >4</KurseId>
</Kurses>
</Illness>
<Illness Id="7">
<IllnessName>Астма</IllnessName>
<Form>Легкая</Form>
<Symptoms>
<SymptomId >5</SymptomId>
</Symptoms>
<Kurses>
<KurseId >5</KurseId>
</Kurses>
</Illness>
</Illness>

View File

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Kurses>
<Kurses Id="1">
<CountInDay>4</CountInDay>
<Duration>1 месяц</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
<Kurses Id="2">
<CountInDay>3</CountInDay>
<Duration>1 месяц</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
<Kurses Id="3">
<CountInDay>1</CountInDay>
<Duration>2 месяца</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
<Kurses Id="4">
<CountInDay>7</CountInDay>
<Duration>1 неделя</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
<Kurses Id="5">
<CountInDay>2</CountInDay>
<Duration>10 дней</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
<Kurses Id="6">
<CountInDay>5</CountInDay>
<Duration>3 недели</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
<Kurses Id="7">
<CountInDay>3</CountInDay>
<Duration>20 дней</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
<Kurses Id="8">
<CountInDay>2</CountInDay>
<Duration>1,5 недели</Duration>
<MedicinesId>1</MedicinesId>
</Kurses>
</Kurses>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Symptoms>
<Symptoms Id="1">
<SymptomName>Кашель</SymptomName>
<Description>Сухой</Description>
</Symptoms>
<Symptoms Id="2">
<SymptomName>Отечность</SymptomName>
<Description>Ноги</Description>
</Symptoms>
<Symptoms Id="3">
<SymptomName>Заложенность носа</SymptomName>
<Description>2 ноздри</Description>
</Symptoms>
<Symptoms Id="4">
<SymptomName>Тошнота</SymptomName>
<Description>Прозрачные выделения</Description>
</Symptoms>
<Symptoms Id="5">
<SymptomName>Боль в сердце</SymptomName>
<Description>Постоянная</Description>
</Symptoms>
<Symptoms Id="6">
<SymptomName>Боль в животе</SymptomName>
<Description>Умеренная</Description>
</Symptoms>
<Symptoms Id="7">
<SymptomName>Боль</SymptomName>
<Description>Тяжелая</Description>
</Symptoms>
<Symptoms Id="8">
<SymptomName>Головокружение</SymptomName>
<Description>При нагрузках</Description>
</Symptoms>
</Symptoms>

View File

@ -12,6 +12,5 @@ namespace HospitalDataModels.Models
string Form { get; } string Form { get; }
Dictionary<int, ISymptomsModel> IllnessSymptoms { get; } Dictionary<int, ISymptomsModel> IllnessSymptoms { get; }
Dictionary<int, IKurseModel> IllnessKurse { get; } Dictionary<int, IKurseModel> IllnessKurse { get; }
//int ClientId { get; }
} }
} }

View File

@ -12,6 +12,5 @@ namespace HospitalDataModels.Models
int CountInDay { get; } int CountInDay { get; }
int MedicinesId { get; } int MedicinesId { get; }
string MedicinesName { get; } string MedicinesName { get; }
//int ClientId { get; }
} }
} }

View File

@ -11,5 +11,6 @@ namespace HospitalDataModels.Models
string ProceduresName { get; } string ProceduresName { get; }
string Type { get; } string Type { get; }
int ClientId { get; } int ClientId { get; }
Dictionary<int, IMedicinesModel> ProcedureMedicine { get; }
} }
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace HospitalDataModels.Models namespace HospitalDataModels.Models
@ -11,9 +12,9 @@ namespace HospitalDataModels.Models
string Dose { get; } string Dose { get; }
DateTime Date { get; } DateTime Date { get; }
string ModeOfApplication { get; } string ModeOfApplication { get; }
int MedicinesId { get; }
int ClientId { get; } int ClientId { get; }
int SymptomsId { get; }
Dictionary<int, IProceduresModel> RecipeProcedures { get; } Dictionary<int, IProceduresModel> RecipeProcedures { get; }
//Dictionary<int, ISymptomsModel> RecipeSymptoms { get; }
} }
} }

View File

@ -9,7 +9,6 @@ namespace HospitalDataModels.Models
public interface ISymptomsModel: IId public interface ISymptomsModel: IId
{ {
string SymptomName { get; } string SymptomName { get; }
string Description { get; } string? Description { get; }
//int ClientId { get; }
} }
} }