до обновления бд (из-за курсов)

This commit is contained in:
Екатерина Рогашова 2023-06-19 13:29:55 +04:00
parent 22eecccf08
commit d6d13df913
39 changed files with 890 additions and 237 deletions

View File

@ -96,16 +96,11 @@ namespace HospitalBusinessLogic.BusinessLogics
return;
}
if (model.MedicinesId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор лекарства", nameof(model.MedicinesId));
}
if (model.CountInDay <= 0)
{
throw new ArgumentNullException("Количество приемов в день должно быть больше 0", nameof(model.CountInDay));
}
_logger.LogInformation("Kurse. KurseId:{Id}.CountInDay:{ CountInDay}. MedicinesId: { MedicinesId}. MedicinesName: {MedicinesName}", model.Id, model.CountInDay, model.MedicinesId, model.MedicinesName);
_logger.LogInformation("Kurse. KurseId:{Id}.CountInDay:{ CountInDay}", model.Id, model.CountInDay);
}
}
}

View File

@ -16,10 +16,12 @@ namespace HospitalBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IMedicinesStorage _medicinesStorage;
public MedicinesLogic(ILogger<MedicinesLogic> logger, IMedicinesStorage medicinesStorage)
private readonly IClientLogic _clientLogic;
public MedicinesLogic(ILogger<MedicinesLogic> logger, IMedicinesStorage medicinesStorage, IClientLogic clientLogic)
{
_logger = logger;
_medicinesStorage = medicinesStorage;
_clientLogic = clientLogic;
}
public bool Create(MedicinesBindingModel model)
{

View File

@ -23,7 +23,7 @@ namespace HospitalBusinessLogic.BusinessLogics
_proceduresStorage = proceduresStorage;
}
public bool AddMedicines(ProceduresSearchModel model, IMedicinesModel medicine)
public bool AddMedicineToProcedure(ProceduresSearchModel model, IMedicinesModel medicine)
{
if (model == null)
{

View File

@ -50,6 +50,7 @@ namespace HospitalBusinessLogic.BusinessLogics
ModeOfApplication = element.ModeOfApplication,
Date = element.Date,
ClientId = element.ClientId,
SymptomsId = element.SymptomsId,
RecipeProcedures = element.RecipeProcedures
});

View File

@ -0,0 +1,165 @@
using HospitalBusinessLogic.OfficePackage;
using HospitalBusinessLogic.OfficePackage.HelperModels;
using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicsContracts;
using HospitalContracts.SearchModels;
using HospitalContracts.StoragesContracts;
using HospitalContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IKurseStorage _kurseStorage;
private readonly IMedicinesStorage _medicineStorage;
private readonly IRecipesStorage _recipeStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IKurseStorage kurseStorage, IMedicinesStorage medicineStorage, IRecipesStorage recipeStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
_kurseStorage = kurseStorage;
_medicineStorage = medicineStorage;
_recipeStorage = recipeStorage;
}
public List<ReportKurseMedicinesViewModel> GetKurseMedicines(List<int> Ids)
{
if (Ids == null)
{
return new List<ReportKurseMedicinesViewModel>();
}
var kurses = _kurseStorage.GetFullList();
List<MedicinesViewModel> medicines = new List<MedicinesViewModel>();
foreach (var memId in Ids)
{
var res = _medicineStorage.GetElement(new MedicinesSearchModel { Id = memId });
if (res != null)
{
medicines.Add(res);
}
}
var list = new List<ReportKurseMedicinesViewModel>();
foreach (var medicine in medicines)
{
var record = new ReportKurseMedicinesViewModel
{
MedicinesName = medicine.MedicinesName,
Kurses = new List<Tuple<int, string>>()
};
foreach (var kurse in kurses)
{
if (kurse.KurseMedicine.ContainsKey(medicine.Id))
{
record.Kurses.Add(new Tuple<int, string>(kurse.Id, kurse.Duration));
}
}
list.Add(record);
}
return list;
}
//public List<ReportMembersViewModel> GetMembers(ReportBindingModel model)
//{
// var listAll = new List<ReportMembersViewModel>();
// var listСonferences = _conferenceStorage.GetFilteredList(new ConferenceSearchModel
// {
// OrganiserId = model.OrganiserId,
// DateFrom = model.DateFrom,
// DateTo = model.DateTo
// });
// foreach (var conference in listСonferences)
// {
// foreach (var m in conference.ConferenceMembers.Values)
// {
// listAll.Add(new ReportMembersViewModel
// {
// StartDate = conference.StartDate,
// ConferenceName = conference.ConferenceName,
// MemberFIO = m.MemberFIO
// });
// }
// }
// var listMealPlans = _mealPlanStorage.GetFilteredList(new MealPlanSearchModel
// {
// OrganiserId = model.OrganiserId,
// });
// foreach (var mealPlan in listMealPlans)
// {
// foreach (var mp in mealPlan.MealPlanMembers.Values)
// {
// listAll.Add(new ReportMembersViewModel
// {
// MemberFIO = mp.MemberFIO,
// MealPlanName = mealPlan.MealPlanName,
// MealPlanPrice = mealPlan.MealPlanPrice
// });
// }
// }
// return listAll;
//}
public List<ReportRecipeMedicineViewModel> GetRecipeMedicine(ReportBindingModel model)
{
throw new NotImplementedException();
}
public void SaveMedicinesToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список курсов",
KurseMedicines = GetKurseMedicines(model.Ids)
});
}
public void SaveMedicinesToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список конференций",
KurseMedicines = GetKurseMedicines(model.Ids)
});
}
//public void SaveMembersToPdfFile(ReportBindingModel model)
//{
// if (model.DateFrom == null)
// {
// throw new ArgumentException("Дата начала не задана");
// }
// if (model.DateTo == null)
// {
// throw new ArgumentException("Дата окончания не задана");
// }
// _saveToPdf.CreateDoc(new PdfInfoOrganiser
// {
// FileName = model.FileName,
// Title = "Список участников",
// DateFrom = model.DateFrom!.Value,
// DateTo = model.DateTo!.Value,
// Members = GetMembers(model)
// });
//}
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -36,28 +36,30 @@ namespace HospitalBusinessLogic.OfficePackage
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.KurseId.ToString(),
Text = pc.MedicinesName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var Medicine in pc.Medicines)
foreach (var kurse in pc.Kurses)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = Medicine,
Text = kurse.Item1.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = kurse.Item2,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);

View File

@ -22,22 +22,25 @@ namespace HospitalBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Center
}
});
foreach (var kurse in info.KurseMedicines)
foreach (var km in info.KurseMedicines)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (kurse.Title, new WordTextProperties { Size = "24", Bold = true, }) },
Texts = new List<(string, WordTextProperties)>
{ (km.MedicinesName, new WordTextProperties { Size = "20", Bold=true})},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var medicine in kurse.Medicines)
foreach (var kurse in km.Kurses)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (medicine, new WordTextProperties { Size = "20", Bold = false, }) },
Texts = new List<(string, WordTextProperties)>
{ (kurse.Item1 + " - ", new WordTextProperties { Size = "16", Bold=false}),
(kurse.Item2, new WordTextProperties { Size = "16", Bold=false})},
TextProperties = new WordTextProperties
{
Size = "24",

View File

@ -105,7 +105,74 @@ namespace HospitalClientApp.Controllers
Response.Redirect("Enter");
return;
}
//ОТЧЕТ//
[HttpGet]
public IActionResult ReportWordExel()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<MedicinesViewModel>>($"api/main/getmedicineslist?clientId={APIClient.Client.Id}"));
}
[HttpPost]
public void ReportWordExel(int[] Ids, string type)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (Ids.Length <= 0)
{
throw new Exception("Количество должно быть больше 0");
}
if (string.IsNullOrEmpty(type))
{
throw new Exception("Неверный тип отчета");
}
List<int> res = new List<int>();
foreach (var item in Ids)
{
res.Add(item);
}
if (type == "docx")
{
APIClient.PostRequest("api/report/createreporttowordfile", new ReportBindingModel
{
Ids = res,
FileName = "E:\\ReportsCourseWork\\wordfile.docx"
});
Response.Redirect("GetWordFile");
}
else
{
APIClient.PostRequest("api/report/createreporttoexcelfile", new ReportBindingModel
{
Ids = res,
FileName = "E:\\ReportsCourseWork\\excelfile.xlsx"
});
Response.Redirect("GetExcelFile");
}
}
[HttpGet]
public IActionResult GetWordFile()
{
return new PhysicalFileResult("E:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult GetPdfFile()
{
return new PhysicalFileResult("E:\\ReportsCourseWork\\pdffile.pdf", "application/pdf");
}
public IActionResult GetExcelFile()
{
return new PhysicalFileResult("E:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
/// <summary>
/// ПРОЦЕДУРЫ
/// </summary>
@ -161,22 +228,55 @@ namespace HospitalClientApp.Controllers
}
Response.Redirect("ListProcedures");
}
[HttpGet]
public ProceduresViewModel? GetProcedure(int procedureId)
public Tuple<ProceduresViewModel, string>? GetProcedure(int procedureId)
{
if (APIClient.Client == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<ProceduresViewModel>($"api/main/getprocedure?procedureid={procedureId}");
var result = APIClient.GetRequest<Tuple<ProceduresViewModel, List<Tuple<string>>>>($"api/main/getprocedure?procedureId={procedureId}");
if (result == null)
{
return default;
}
var proceduresName = result.ProceduresName;
var proceduretype = result.Type;
string table = "";
for (int i = 0; i < result.Item2.Count; i++)
{
var medicinesName = result.Item2[i].Item1;
table += "<tr style=\"height: 44px\">";
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{medicinesName}</td>";
table += "</tr>";
}
return Tuple.Create(result.Item1, table);
}
return result;
public IActionResult AddMedicineToProcedure()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(Tuple.Create(APIClient.GetRequest<List<ProceduresViewModel>>($"api/main/getprocedurelist?clientId={APIClient.Client.Id}"),
APIClient.GetRequest<List<MedicinesViewModel>>($"api/main/getmedicinelist?clientId={APIClient.Client.Id}")));
}
[HttpPost]
public void AddMedicineToProcedure(int procedure, int[] medicine)
{
if (APIClient.Client == null)
{
throw new Exception("Необходима авторизация");
}
for (int i = 0; i < medicine.Length; i++)
{
APIClient.PostRequest("api/main/AddMedicineToProcedure", Tuple.Create(
new ProceduresSearchModel() { Id = procedure },
new MedicinesViewModel() { Id = medicine[i] }
));
}
Response.Redirect("ListConferences");
}
[HttpPost]
@ -201,28 +301,41 @@ namespace HospitalClientApp.Controllers
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();
//}
public IActionResult UpdateProcedure()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Procedures = APIClient.GetRequest<List<ProceduresViewModel>>($"api/main/getprocedurelist?clientId={APIClient.Client.Id}");
return View();
}
[HttpPost]
public void UpdateProcedure(int procedure, string procedurename, string type)
{
if (APIClient.Client == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(procedurename))
{
throw new Exception("Название не может быть пустым");
}
if (string.IsNullOrEmpty(type))
{
throw new Exception("Тип не может быть пустым");
}
APIClient.PostRequest("api/main/UpdateProcedure", new ProceduresBindingModel
{
Id = procedure,
ProceduresName = procedurename,
Type = type,
ClientId = APIClient.Client.Id
});
Response.Redirect("ListProcedures");
}
//[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>
@ -235,46 +348,27 @@ namespace HospitalClientApp.Controllers
}
return View(APIClient.GetRequest<List<MedicinesViewModel>>($"api/main/getmedicineslist?clientId={APIClient.Client.Id}"));
}
public IActionResult CreateMedicine(int? id)
public IActionResult CreateMedicine()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
if (!id.HasValue)
{
return View();
}
var model = APIClient.GetRequest<MedicinesViewModel?>($"api/main/getmedicine?id={id}");
return View(model);
return View();
}
[HttpPost]
public void CreateMedicine(int? id, string namemedicine, string group)
public void CreateMedicine(string namemedicine, string group)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (id.HasValue)
APIClient.PostRequest("api/main/createmedicine", new MedicinesBindingModel
{
APIClient.PostRequest("api/main/updatemedicine", new MedicinesBindingModel
{
Id = id.Value,
MedicinesName = namemedicine,
Group = group
});
}
else
{
APIClient.PostRequest("api/main/createmedicine", new MedicinesBindingModel
{
ClientId = APIClient.Client.Id,
MedicinesName = namemedicine,
Group = group
});
}
ClientId = APIClient.Client.Id,
MedicinesName = namemedicine,
Group = group
});
Response.Redirect("ListMedicines");
}
[HttpGet]
@ -289,7 +383,7 @@ namespace HospitalClientApp.Controllers
{
return default;
}
var medicineName = result.MedicinesName;
var medicinename = result.MedicinesName;
var group = result.Group;
return result;
@ -316,6 +410,41 @@ namespace HospitalClientApp.Controllers
ViewBag.Medicines = APIClient.GetRequest<List<MedicinesViewModel>>($"api/main/GetMedicinesList?clientId={APIClient.Client.Id}");
return View();
}
public IActionResult UpdateMedicine()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIClient.GetRequest<List<MedicinesViewModel>>($"api/main/getmedicineslist?clientId={APIClient.Client.Id}");
return View();
}
[HttpPost]
public void UpdateMedicine(int medicine, string medicinename, string group)
{
if (APIClient.Client == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(medicinename))
{
throw new Exception("Название не может быть пустым");
}
if (string.IsNullOrEmpty(group))
{
throw new Exception("Группа не может быть пустой");
}
APIClient.PostRequest("api/main/UpdateMedicine", new MedicinesBindingModel
{
Id = medicine,
MedicinesName = medicinename,
Group = group,
ClientId = APIClient.Client.Id
});
Response.Redirect("ListMedicines");
}
/// <summary>
/// РЕЦЕПТЫ
/// </summary>
@ -378,7 +507,7 @@ namespace HospitalClientApp.Controllers
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<Tuple<RecipesViewModel, List<Tuple<string, string>>>>($"api/main/getrecipe?recipeId={recipeId}");
var result = APIClient.GetRequest<Tuple<RecipesViewModel, List<Tuple<string>>>>($"api/main/getrecipe?recipeId={recipeId}");
if (result == null)
{
return default;
@ -387,10 +516,8 @@ namespace HospitalClientApp.Controllers
for (int i = 0; i < result.Item2.Count; i++)
{
var proceduresName = result.Item2[i].Item1;
var type = result.Item2[i].Item2;
table += "<tr style=\"height: 44px\">";
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{proceduresName}</td>";
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{type}</td>";
table += "</tr>";
}
return Tuple.Create(result.Item1, table);
@ -417,6 +544,42 @@ namespace HospitalClientApp.Controllers
return View();
}
public IActionResult UpdateRecipe()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Recipes = APIClient.GetRequest<List<RecipesViewModel>>($"api/main/GetRecipesList?clientId={APIClient.Client.Id}");
ViewBag.Symptomses = APIClient.GetRequest<List<SymptomsViewModel>>("api/main/getsymptoms");
return View();
}
[HttpPost]
public void UpdateRecipe(int recipe, string dose, string modeofapplication)
{
if (APIClient.Client == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(dose))
{
throw new Exception("Поле не может быть пустым");
}
if (string.IsNullOrEmpty(modeofapplication))
{
throw new Exception("Способ применения не может быть пустым");
}
APIClient.PostRequest("api/main/updaterecipe", new RecipesBindingModel
{
Id = recipe,
Dose = dose,
ModeOfApplication = modeofapplication,
ClientId = APIClient.Client.Id
});
Response.Redirect("ListRecipes");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{

View File

@ -3,18 +3,10 @@
}
@{
if (Model != null)
{
<div class="text-center">
<h2 class="display-4">Редактирование лекарства</h2>
</div>
}
else
{
<div class="text-center">
<h2 class="display-4">Создание лекарства</h2>
</div>
}
}
<form method="post">
<div class="row">

View File

@ -3,17 +3,9 @@
}
@{
if (Model != null)
{
<div class="text-center">
<h2 class="display-4">Редактирование процедуры</h2>
</div>
}
else {
<div class="text-center">
<h2 class="display-4">Создание процедуры</h2>
</div>
}
}
<form method="post">
<div class="row">

View File

@ -8,14 +8,14 @@
<form method ="post">
<div class="mb-3">
<label for="InputEmail1" class="form-label">Email address</label>
<label for="InputEmail1" class="form-label" style="font-size: 30px;">Email address</label>
<input type="email" name="login" class="form-control" id="InputEmail1" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="InputPassword1" class="form-label">Password</label>
<label for="InputPassword1" class="form-label" style="font-size: 30px";>Password</label>
<input type="password" name="password" class="form-control" id="InputPassword1">
</div>
<div class="mb-3" style="width: 100%">
<button type="submit" style="background-color:black;" class="btn btn-primary">Submit</button>
<button type="submit" style="background-color:black; width: 100%; font-size: 30px;" class="btn btn-primary">Войти</button>
</div>
</form>

View File

@ -20,7 +20,7 @@
</div>
<div class="u-container-style u-layout-cell u-size-30 u-layout-cell-2">
<div class="u-container-layout u-valign-top u-container-layout-2"
style="margin-left: 500px">
style="margin-left: 600px">
<img class="u-image u-image-contain u-image-1"
src="~/Images/logo.png"
data-image-width="2388"

View File

@ -21,6 +21,7 @@
<p>
<a class="btn btn-warning" asp-action="CreateMedicine">Создать лекарство</a>
<a class="btn btn-warning" asp-action="DeleteMedicine">Удалить</a>
<a class="btn btn-warning" asp-action="UpdateMedicine">Редактировать</a>
</p>
<table class="table">
<thead>
@ -53,7 +54,7 @@
@Html.DisplayFor(modelItem => item.Group)
</td>
<td>
<a class="btn btn-warning" asp-action="CreateMedicine" asp-route-id="@item.Id">Редактировать</a>
</td>
</tr>
}

View File

@ -21,6 +21,7 @@
<p>
<a class="btn btn-warning" asp-action="CreateProcedure">Создать процедуру</a>
<a class="btn btn-warning" asp-action="DeleteProcedure">Удалить</a>
<a class="btn btn-warning" asp-action="UpdateProcedure">Редактировать</a>
</p>
<table class="table">
<thead>
@ -52,9 +53,6 @@
<td>
@Html.DisplayFor(modelItem => item.Type)
</td>
<td>
<a class="btn btn-warning" asp-action="CreateProcedure" asp-route-id="@item.Id">Редактировать</a>
</td>
</tr>
}
</tbody>

View File

@ -21,6 +21,7 @@
<p>
<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="UpdateRecipe">Редактировать</a>
</p>
<table class="table">
<thead>
@ -34,9 +35,6 @@
<th>
Доза
</th>
<th>
Лекарство
</th>
<th>
</th>
@ -56,10 +54,7 @@
@Html.DisplayFor(modelItem => item.Dose)
</td>
<td>
@Html.DisplayFor(modelItem => item.SymptomsId)
</td>
<td>
<a class="btn btn-warning" asp-action="CreateRecipe" asp-route-id="@item.Id">Редактировать</a>
</td>
</tr>
}

View File

@ -21,6 +21,6 @@
</div>
<div class="mb-3" style="width: 100%">
<button type="submit" style="background-color:black;" class="btn btn-primary"> Регистрация </button>
<button type="submit" style="background-color:black; width: 100%; font-size: 30px;" class="btn btn-primary"> Регистрация </button>
</div>
</form>

View File

@ -0,0 +1,77 @@
@using HospitalContracts.ViewModels
@model List<MedicinesViewModel>
@{
ViewData["Title"] = "ReportWordExel";
}
<div class="text-center">
<h2>
Создание отчета word/exel
</h2>
</div>
<div class="text-center">
<form method="post">
<div>
<label>
Выберите формат файла:
</label>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
<label for="docx">
Word-файл
</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
<label for="xlsx">
Excel-файл
</label>
</div>
</div>
<div>
<div>
<div>
<table class="table">
<thead
>
<tr>
<th>
</th>
<th>
Название
</th>
<th>
Группа
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
<input type="checkbox" class="form-check-input" name="Ids[]" value="@item.Id" id="@item.Id">
</td>
<td>
@Html.DisplayFor(modelItem => item.MedicinesName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Group)
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
<div class="u-align-center u-form-group u-form-submit u-label-top" style="padding-bottom: 120px">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать файл" ></div>
</div>
</form>
</div>

View File

@ -1,10 +1,15 @@
@{
@using HospitalContracts.ViewModels;
@using HospitalDataModels.Models;
@{
ViewData["Title"] = "UpdateMedicine";
}
<div class="text-center">
<h2 class="display-4">Изменения лекарства</h2>
</div>
<form method="post">
<div class="row">
<label class="lable">Лекарство: </label>
@ -17,19 +22,42 @@
<input type="text"
id="medicinename"
placeholder="Введите название процедуры"
name="medicinename"
class="u-input u-input-rectangle" />
name="medicinename" />
</div>
<div class="row">
<label class="lable">Группа</label>
<input type="text"
id="group"
placeholder="Введите группу"
name="group"
class="u-input u-input-rectangle" />
name="group" />
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
<div class="col-4"><input type="submit" class="btn btn-success" value="Сохранить" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var medicine = $('#medicine').val();
if (medicine) {
$.ajax({
method: "GET",
url: "/Home/GetMedicine",
data: { medicineId: medicine },
success: function (result) {
$('#medicinename').val(result.medicinesName);
$('#group').val(result.group);
}
});
};
}
check();
$('#medicine').on('change', function () {
check();
});
</script>
}

View File

@ -1,9 +1,11 @@
@{
@using HospitalContracts.ViewModels;
@using HospitalDataModels.Models;
@{
ViewData["Title"] = "UpdateProcedure";
}
<div class="text-center">
<h2 class="display-4">Изменения процедуры</h2>
<h2 class="display-4">Изменение процедуры</h2>
</div>
<form method="post">
<div class="row">
@ -17,19 +19,52 @@
<input type="text"
id="procedurename"
placeholder="Введите название процедуры"
name="procedurename"
class="u-input u-input-rectangle" />
name="procedurename" />
</div>
<div class="row">
<label class="lable">Тип</label>
<input type="text"
id="type"
placeholder="Тип процедуры"
name="type"
class="u-input u-input-rectangle" />
name="type" />
</div>
<div class="row">
<p class="text-center"><strong>Лекарства</strong></p>
<table id="medicinesTable" class="table table-bordered table-striped">
<tr>
<th>Название</th>
</tr>
<tbody class="u-table-body" id="table-elements">
</tbody>
</table>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
<div class="col-4"><input type="submit" class="btn btn-success" value="Сохранить" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var procedure = $('#procedure').val();
if (procedure) {
$.ajax({
method: "GET",
url: "/Home/GetProcedure",
data: { procedureId: procedure },
success: function (result) {
$('#procedurename').val(result.item1.proceduresName);
$('#type').val(result.item1.type);
$('#table-elements').html(result.item2);
}
});
};
}
check();
$('#procedure').on('change', function () {
check();
});
</script>
}

View File

@ -1,15 +1,18 @@
@{
@using HospitalContracts.ViewModels;
@using HospitalDataModels.Models;
@{
ViewData["Title"] = "UpdateRecipe";
}
<div class="text-center">
<h2 class="display-4">Изменения рецепта</h2>
<h2 class="display-4">Изменение рецепта</h2>
</div>
<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"))"></select>
<select id="recipe" name="recipe" class="form-control" asp-items="@(new SelectList(@ViewBag.Recipes, "Id", "Id"))"></select>
</div>
</div>
<div class="row">
@ -17,23 +20,58 @@
<input type="text"
id="dose"
placeholder="Введите дозу"
name="dose"
class="u-input u-input-rectangle" />
name="dose" />
</div>
<div class="row">
<label class="lable">Способ применения</label>
<input type="text"
id="modeofapplication"
placeholder="Введите способ применения"
name="modeofapplication"
class="u-input u-input-rectangle" />
name="modeofapplication"/>
</div>
<div class="row">
<label class="lable">Лекарство</label>
<select id="medicinename" name="medicinename" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines, "Id","MedicinesName"))"></select>
<label class="lable">Симптомы</label>
<select id="symptoms" name="symptoms" class="form-control" asp-items="@(new SelectList(@ViewBag.Symptomses,"Id", "SymptomName"))"></select>
</div>
<div class="row">
<p class="text-center"><strong>Процедуры</strong></p>
<table id="proceduresTable" class="table table-bordered table-striped">
<tr>
<th>Название</th>
<th>Тип</th>
</tr>
<tbody class="u-table-body" id="table-elements">
</tbody>
</table>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-success" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var recipe = $('#recipe').val();
if (recipe) {
$.ajax({
method: "GET",
url: "/Home/GetRecipe",
data: { recipeId: recipe },
success: function (result) {
$('#dose').val(result.item1.dose);
$('#modeofapplication').val(result.item1.modeOfApplication);
$('#symptoms').val(result.item1.symptoms);
$('#table-elements').html(result.item2);
}
});
};
}
check();
$('#recipe').on('change', function () {
check();
});
</script>
}

View File

@ -37,11 +37,11 @@
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="dropdownMenuLink">
<li>
<a class="dropdown-item"
asp-area="" asp-controller="Home" asp-action="ListProcedures">Процедуры</a>
asp-area="" asp-controller="Home" asp-action="ListMedicines">Лекарства</a>
</li>
<li>
<a class="dropdown-item"
asp-area="" asp-controller="Home" asp-action="ListMedicines">Лекарства</a>
asp-area="" asp-controller="Home" asp-action="ListProcedures">Процедуры</a>
</li>
<li>
<a class="dropdown-item"
@ -57,11 +57,11 @@
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="dropdownMenuLink">
<li>
<a class="dropdown-item"
asp-area="dropdown-item" asp-controller="Home" asp-action="ListMembers">Список участников (pdf)</a>
asp-area="dropdown-item" asp-controller="Home" asp-action="ReportWordExel">Список лекарств (word/exel)</a>
</li>
<li>
<a class="dropdown-item"
asp-area="dropdown-item" asp-controller="Home" asp-action="ListMemberConferenceToFile">Список участников (word/excel)</a>
asp-area="dropdown-item" asp-controller="Home" asp-action="ListMemberConferenceToFile">Список лекарств (pdf)</a>
</li>
</ul>
</div>

View File

@ -70,22 +70,22 @@ namespace HospitalRestApi.Controllers
throw;
}
}
[HttpGet]
public ProceduresViewModel? GetProcedure(int procedureId)
{
try
{
return _procedure.ReadElement(new ProceduresSearchModel
{
Id = procedureId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения процедуры по id={Id}", procedureId);
throw;
}
}
//[HttpGet]
//public ProceduresViewModel? GetProcedure(int procedureId)
//{
// try
// {
// return _procedure.ReadElement(new ProceduresSearchModel
// {
// Id = procedureId
// });
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, "Ошибка получения процедуры по id={Id}", procedureId);
// throw;
// }
//}
[HttpPost]
public void CreateProcedure(ProceduresBindingModel model)
{
@ -105,7 +105,8 @@ namespace HospitalRestApi.Controllers
{
try
{
_procedure.Update(GetModelWithMedicines(model));
model.ProcedureMedicine = null!;
_procedure.Update(model);
}
catch (Exception ex)
{
@ -113,18 +114,34 @@ namespace HospitalRestApi.Controllers
throw;
}
}
private ProceduresBindingModel GetModelWithMedicines(ProceduresBindingModel model)
[HttpGet]
public Tuple<ProceduresViewModel, List<Tuple<string>>>? GetProcedure(int procedureId)
{
var medicines = _medicine.ReadList(new MedicinesSearchModel { Ids = model.ProcedureMedicine.Keys.ToArray() });
if (medicines != null)
try
{
model.ProcedureMedicine = medicines.Where(m => model.ProcedureMedicine.Keys.Contains(m.Id))
.ToDictionary(m => m.Id, m => m as IMedicinesModel);
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;
}
return model;
}
//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]
public void DeleteProcedure(ProceduresBindingModel model)
{
@ -281,29 +298,30 @@ namespace HospitalRestApi.Controllers
throw;
}
}
[HttpGet]
public RecipesViewModel? GetRecipe(int recipeId)
{
try
{
return _recipe.ReadElement(new RecipesSearchModel
{
Id = recipeId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения рецепта по id={Id}", recipeId);
throw;
}
}
//[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)
{
try
{
_recipe.Update(GetModelWithProcedures(model));
model.RecipeProcedures = null!;
_recipe.Update(model);
}
catch (Exception ex)
{
@ -311,6 +329,23 @@ namespace HospitalRestApi.Controllers
throw;
}
}
[HttpGet]
public Tuple<RecipesViewModel, List<Tuple<string>>>? GetRecipe(int recipeId)
{
try
{
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());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения процедуры по id={Id}", recipeId);
throw;
}
}
[HttpPost]
public void AddProcedures(Tuple<RecipesSearchModel, ProceduresViewModel> model)
{
@ -325,11 +360,11 @@ namespace HospitalRestApi.Controllers
}
}
[HttpPost]
public void AddMedicines(Tuple<ProceduresSearchModel, MedicinesViewModel> model)
public void AddMedicineToProcedure(Tuple<ProceduresSearchModel, MedicinesViewModel> model)
{
try
{
_procedure.AddMedicines(model.Item1, model.Item2);
_procedure.AddMedicineToProcedure(model.Item1, model.Item2);
}
catch (Exception ex)
{

View File

@ -0,0 +1,83 @@
using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicsContracts;
using Microsoft.AspNetCore.Mvc;
namespace HospitalRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportController : Controller
{
private readonly ILogger _logger;
private readonly IReportLogic _reportLogic;
//private readonly AbstractMailWorker _mailWorker;
public ReportController(ILogger<ReportController> logger, IReportLogic reportLogic)
{
_logger = logger;
_reportLogic = reportLogic;
//_mailWorker = mailWorker;
}
//[HttpPost]
//public void CreateReportToPdfFile(ReportBindingModel model)
//{
// try
// {
// _reportLogic.SaveMedicinesToPdfFile(new ReportBindingModel
// {
// DateFrom = model.DateFrom,
// DateTo = model.DateTo,
// OrganiserId = model.OrganiserId,
// FileName = "C:\\ReportsCourseWork\\pdffile.pdf",
// });
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, "Ошибка создания отчета");
// throw;
// }
//}
//[HttpPost]
//public void SendPdfToMail(MailSendInfoBindingModel model)
//{
// try
// {
// _mailWorker.MailSendAsync(model);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, "Ошибка отправки письма");
// throw;
// }
//}
[HttpPost]
public void CreateReportToWordFile(ReportBindingModel model)
{
try
{
_reportLogic.SaveMedicinesToWordFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
[HttpPost]
public void CreateReportToExcelFile(ReportBindingModel model)
{
try
{
_reportLogic.SaveMedicinesToExcelFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
}
}

View File

@ -11,8 +11,11 @@ namespace HospitalContracts.BindingModels
{
public int Id { get; set; }
public string Duration { get; set; } = string.Empty;
public int CountInDay { get; set; }
public int MedicinesId { get; set; }
public string MedicinesName { get; set; } = string.Empty;
public int CountInDay { get; set; }
public Dictionary<int, IMedicinesModel> KurseMedicine
{
get;
set;
} = new();
}
}

View File

@ -11,5 +11,7 @@ namespace HospitalContracts.BindingModels
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int ClientId { get; set; }
public List<int>? Ids { get; set; }
}
}

View File

@ -14,7 +14,7 @@ namespace HospitalContracts.BusinessLogicsContracts
{
List<ProceduresViewModel>? ReadList(ProceduresSearchModel? model);
ProceduresViewModel? ReadElement(ProceduresSearchModel model);
bool AddMedicines(ProceduresSearchModel model, IMedicinesModel member);
bool AddMedicineToProcedure(ProceduresSearchModel model, IMedicinesModel member);
bool Create(ProceduresBindingModel model);
bool Update(ProceduresBindingModel model);
bool Delete(ProceduresBindingModel model);

View File

@ -11,12 +11,12 @@ namespace HospitalContracts.BusinessLogicsContracts
public interface IReportLogic
{
/// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются
/// Получение списка лекарств с указанием, в каких курсах используются
/// </summary>
/// <returns></returns>
List<ReportKurseMedicinesViewModel> GetKurseMedicines();
List<ReportKurseMedicinesViewModel> GetKurseMedicines(List<int> Ids);
/// <summary>
/// Получение списка заказов за определенный период
/// Получение списка рецептов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
@ -25,12 +25,12 @@ namespace HospitalContracts.BusinessLogicsContracts
/// Сохранение компонент в файл-Word
/// </summary>
/// <param name="model"></param>
void SaveGiftsToWordFile(ReportBindingModel model);
void SaveMedicinesToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
void SaveGiftComponentToExcelFile(ReportBindingModel model);
void SaveMedicinesToExcelFile(ReportBindingModel model);
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace HospitalContracts.ViewModels
@ -15,8 +16,17 @@ namespace HospitalContracts.ViewModels
public string Duration { get; set; } = string.Empty;
[DisplayName("Срок приема")]
public int CountInDay { get; set; }
public int MedicinesId { get; set; }
[DisplayName("Название лекарства")]
public string MedicinesName { get; set; } = string.Empty;
public Dictionary<int, IMedicinesModel> KurseMedicine
{
get;
set;
} = new();
public KurseViewModel() { }
[JsonConstructor]
public KurseViewModel(Dictionary<int, MedicinesViewModel> KurseMedicine)
{
this.KurseMedicine = KurseMedicine.ToDictionary(x => x.Key, x => x.Value as IMedicinesModel);
}
}
}

View File

@ -8,8 +8,7 @@ namespace HospitalContracts.ViewModels
{
public class ReportKurseMedicinesViewModel
{
public string Title { get; set; } = string.Empty;
public int KurseId { get; set; }
public List<string> Medicines { get; set; } = new();
public string MedicinesName { get; set; } = string.Empty;
public List<Tuple<int, string>> Kurses { get; set; } = new();
}
}

View File

@ -19,6 +19,7 @@ namespace HospitalDataBaseImplements
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Kurses> Kurse { set; get; }
public virtual DbSet<KurseMedicines> KurseMedicines { set; get; }
public virtual DbSet<Illness> Illnesses { set; get; }
public virtual DbSet<IllnessKurse> IllnessKurse { set; get; }
public virtual DbSet<IllnessSymptoms> IllnessSymptomses { set; get; }

View File

@ -34,7 +34,8 @@ namespace HospitalDataBaseImplements.Implements
return null;
}
using var context = new HospitalDatabase();
return context.Kurse.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
return context.Kurse.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<KurseViewModel> GetFilteredList(KurseSearchModel model)
@ -44,8 +45,8 @@ namespace HospitalDataBaseImplements.Implements
return new();
}
using var context = new HospitalDatabase();
return context.Kurse
.Where(x => x.MedicinesName.Contains(model.MedicinesName))
return context.Kurse.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.Select(x => x.GetViewModel)
.ToList();
}
@ -53,7 +54,8 @@ namespace HospitalDataBaseImplements.Implements
public List<KurseViewModel> GetFullList()
{
using var context = new HospitalDatabase();
return context.Kurse.Select(x => x.GetViewModel).ToList();
return context.Kurse.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine).Select(x => x.GetViewModel).ToList();
}
public KurseViewModel? Insert(KurseBindingModel model)
@ -66,7 +68,10 @@ namespace HospitalDataBaseImplements.Implements
using var context = new HospitalDatabase();
context.Kurse.Add(newKurse);
context.SaveChanges();
return newKurse.GetViewModel;
return context.Kurse
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine).FirstOrDefault(x => x.Id == newKurse.Id)
?.GetViewModel;
}
public KurseViewModel? Update(KurseBindingModel model)

View File

@ -65,10 +65,8 @@ namespace HospitalDataBaseImplements.Implements
public MedicinesViewModel? Update(MedicinesBindingModel model)
{
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)
{
return null;
@ -76,12 +74,6 @@ namespace HospitalDataBaseImplements.Implements
medicine.Update(model);
context.SaveChanges();
return medicine.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public MedicinesViewModel? Delete(MedicinesBindingModel model)
{

View File

@ -30,7 +30,8 @@ namespace HospitalDataBaseImplements.Implements
return new();
}
using var context = new HospitalDatabase();
return context.Procedures
return context.Procedures.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
@ -43,7 +44,8 @@ namespace HospitalDataBaseImplements.Implements
return null;
}
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)
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ProceduresName) && x.ProceduresName ==
model.ProceduresName) ||
@ -78,7 +80,10 @@ namespace HospitalDataBaseImplements.Implements
}
procedure.Update(model);
context.SaveChanges();
procedure.UpdateMedicines(context, model);
if (model.ProcedureMedicine != null)
{
procedure.UpdateMedicines(context, model);
}
transaction.Commit();
return procedure.GetViewModel;
}

View File

@ -18,7 +18,7 @@ namespace HospitalDataBaseImplements.Implements
public RecipesViewModel? Delete(RecipesBindingModel model)
{
using var context = new HospitalDatabase();
var element = context.Recipes.Include(x => x.Procedures).Include(x => x.Symptoms)
var element = context.Recipes.Include(x => x.Procedures).ThenInclude(x => x.Procedure).Include(x => x.Symptoms)
.Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
@ -107,7 +107,8 @@ namespace HospitalDataBaseImplements.Implements
}
recipe.Update(model);
context.SaveChanges();
recipe.UpdateProcedures(context, model);
if (model.RecipeProcedures != null)
recipe.UpdateProcedures(context, model);
transaction.Commit();
return recipe.GetViewModel;
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalDataBaseImplements.Models
{
public class KurseMedicines
{
public int Id { get; set; }
[Required]
public int MedicineId { get; set; }
[Required]
public int KurseId { get; set; }
public virtual Medicines Medicine { get; set; } = new();
public virtual Kurses Kurse { get; set; } = new();
}
}

View File

@ -14,10 +14,6 @@ namespace HospitalDataBaseImplements.Models
public class Kurses : IKurseModel
{
public int Id { get; private set; }
[ForeignKey("MedicinesId")]
public int MedicinesId { get; private set; }
public virtual Medicines Medicines { get; set; } = new();
public string MedicinesName { get; private set; } = string.Empty;
[Required]
public string Duration { get; private set; } = string.Empty;
[Required]
@ -25,7 +21,26 @@ namespace HospitalDataBaseImplements.Models
[ForeignKey("KurseId")]
public virtual List<IllnessKurse> IllnessKurses { get; set; } = new();
public static Kurses? Create(KurseBindingModel model)
private Dictionary<int, IMedicinesModel>? _kurseMedicine = null;
[NotMapped]
public Dictionary<int, IMedicinesModel> KurseMedicine
{
get
{
if (_kurseMedicine == null)
{
_kurseMedicine = Medicines
.ToDictionary(rec => rec.MedicineId, rec =>
rec.Medicine as IMedicinesModel);
}
return _kurseMedicine;
}
}
[ForeignKey("KurseId")]
public virtual List<KurseMedicines> Medicines { get; set; } = new();
public static Kurses? Create(KurseBindingModel model)
{
if (model == null)
{
@ -34,7 +49,6 @@ namespace HospitalDataBaseImplements.Models
return new Kurses()
{
Id = model.Id,
MedicinesId = model.MedicinesId,
Duration = model.Duration,
CountInDay = model.CountInDay
};
@ -44,8 +58,6 @@ namespace HospitalDataBaseImplements.Models
return new Kurses
{
Id = model.Id,
MedicinesId = model.MedicinesId,
MedicinesName = model.MedicinesName,
Duration = model.Duration,
CountInDay = model.CountInDay
};
@ -56,15 +68,12 @@ namespace HospitalDataBaseImplements.Models
{
return;
}
MedicinesName = model.MedicinesName;
Duration = model.Duration;
CountInDay = model.CountInDay;
}
public KurseViewModel GetViewModel => new()
{
Id = Id,
MedicinesId = MedicinesId,
MedicinesName = MedicinesName,
Duration = Duration,
CountInDay = CountInDay
};

View File

@ -55,6 +55,7 @@ namespace HospitalDataBaseImplements.Models
}
MedicinesName = model.MedicinesName;
Group = model.Group;
ClientId = model.ClientId;
}
public MedicinesViewModel GetViewModel => new()
{

View File

@ -53,14 +53,18 @@ namespace HospitalDataBaseImplements.Models
Type = model.Type
};
}
public static Procedures Create(ProceduresViewModel model)
public static Procedures Create(HospitalDatabase context, ProceduresViewModel model)
{
return new Procedures
{
Id = model.Id,
ClientId = model.ClientId,
ProceduresName = model.ProceduresName,
Type = model.Type
Type = model.Type,
Medicines = model.ProcedureMedicine.Select(x => new ProcedureMedicine
{
Medicine = context.Medicines.First(y => y.Id == x.Key),
}).ToList()
};
}
public void Update(ProceduresBindingModel model)
@ -77,7 +81,8 @@ namespace HospitalDataBaseImplements.Models
Id = Id,
ClientId = ClientId,
ProceduresName = ProceduresName,
Type = Type
Type = Type,
ProcedureMedicine = ProcedureMedicine
};
public void UpdateMedicines(HospitalDatabase context, ProceduresBindingModel model)
@ -93,15 +98,11 @@ namespace HospitalDataBaseImplements.Models
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

@ -10,7 +10,6 @@ namespace HospitalDataModels.Models
{
string Duration { get; }
int CountInDay { get; }
int MedicinesId { get; }
string MedicinesName { get; }
Dictionary<int, IMedicinesModel> KurseMedicine { get; }
}
}