Добавлено связывание рецептов и лечений
This commit is contained in:
parent
675971d32f
commit
a7b969b191
@ -1,4 +1,5 @@
|
|||||||
using HospitalDataModels.Models;
|
using HospitalDataModels.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace HospitalContracts.ViewModels
|
namespace HospitalContracts.ViewModels
|
||||||
@ -10,5 +11,13 @@ namespace HospitalContracts.ViewModels
|
|||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
public Dictionary<int, IProcedureModel> TreatmentProcedures { get; set; } = new();
|
public Dictionary<int, IProcedureModel> TreatmentProcedures { get; set; } = new();
|
||||||
|
|
||||||
|
public TreatmentViewModel() { }
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
|
public TreatmentViewModel(Dictionary<int, ProcedureViewModel> TreatmentProcedures)
|
||||||
|
{
|
||||||
|
this.TreatmentProcedures = TreatmentProcedures.ToDictionary(x => x.Key, x => x.Value as IProcedureModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
Hospital/HospitalRestApi/Controllers/TreatmentController.cs
Normal file
34
Hospital/HospitalRestApi/Controllers/TreatmentController.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using HospitalContracts.BusinessLogicContracts;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HospitalRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class TreatmentController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ITreatmentLogic _logic;
|
||||||
|
|
||||||
|
public TreatmentController(ITreatmentLogic logic)
|
||||||
|
{
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<TreatmentViewModel>? GetTreatments()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _logic.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ namespace HospitalWeb.Controllers
|
|||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines");
|
ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines");
|
||||||
|
ViewBag.Treatments = APIClient.GetRequest<List<TreatmentViewModel>>($"api/treatment/gettreatments");
|
||||||
if (!id.HasValue)
|
if (!id.HasValue)
|
||||||
{
|
{
|
||||||
return View(new RecipeViewModel());
|
return View(new RecipeViewModel());
|
||||||
|
@ -31,7 +31,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<table id="medicinesTable">
|
<div class="col-4">Добавление лекарств</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="treatments" name="treatments" class="form-control" asp-items="@(new SelectList(@ViewBag.Treatments,"Id", "Name"))"></select>
|
||||||
|
<button type="button" onclick="addTreatment()">Добавить лечение</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<table id="medicinesTable" class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Название</th>
|
<th>Название</th>
|
||||||
@ -47,6 +54,27 @@
|
|||||||
<button type="button" class="btn btn-danger" data-id="@medicine.Key" onclick="removeMedicine('@medicine.Key')">Удалить</button>
|
<button type="button" class="btn btn-danger" data-id="@medicine.Key" onclick="removeMedicine('@medicine.Key')">Удалить</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<table id="treatmentsTable" class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Название</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var treatment in Model.RecipeTreatments)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@treatment.Value.Name</td>
|
||||||
|
<td>
|
||||||
|
<button type="button" class="btn btn-danger" data-id="@treatment.Key" onclick="removeTreatment('@treatment.Key')">Удалить</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -61,6 +89,10 @@
|
|||||||
{
|
{
|
||||||
<input type="hidden" name="RecipeMedicines[@medicine]" value="@medicine"/>
|
<input type="hidden" name="RecipeMedicines[@medicine]" value="@medicine"/>
|
||||||
}
|
}
|
||||||
|
@foreach (var treatment in Model.RecipeTreatments.Keys)
|
||||||
|
{
|
||||||
|
<input type="hidden" name="RecipeTreatments[@treatment]" value="@treatment"/>
|
||||||
|
}
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
@section scripts {
|
@section scripts {
|
||||||
@ -91,6 +123,32 @@
|
|||||||
$('#medicinesTable button[data-id="' + medicineId + '"]').closest('tr').remove();
|
$('#medicinesTable button[data-id="' + medicineId + '"]').closest('tr').remove();
|
||||||
$('#recipe-form input[name="RecipeMedicines[' + medicineId + ']"]').remove();
|
$('#recipe-form input[name="RecipeMedicines[' + medicineId + ']"]').remove();
|
||||||
}
|
}
|
||||||
|
var recipeTreatments = @Json.Serialize(Model.RecipeTreatments);
|
||||||
|
function addTreatment() {
|
||||||
|
var treatmentId = $('#treatments').val();
|
||||||
|
var treatmentName = $('#treatments option:selected').text();
|
||||||
|
if (recipeTreatments.hasOwnProperty(treatmentId)) {
|
||||||
|
alert('This treatment is already added.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
recipeTreatments[treatmentId] = { Id: treatmentId, Name: treatmentName };
|
||||||
|
var row = $('<tr>').append($('<td>').text(treatmentName));
|
||||||
|
var removeButton = $('<button>').text('Удалить').attr('data-id', treatmentId).attr('class', 'btn btn-danger').click((function(id) {
|
||||||
|
return function() {
|
||||||
|
removeTreatment(id);
|
||||||
|
};
|
||||||
|
})(treatmentId));
|
||||||
|
row.append($('<td>').append(removeButton));
|
||||||
|
|
||||||
|
$('#treatmentsTable tbody').append(row);
|
||||||
|
var input = $('<input>').attr('type', 'hidden').attr('name', 'RecipeTreatments[' + treatmentId + ']').val(treatmentId);
|
||||||
|
$('#recipe-form').append(input);
|
||||||
|
}
|
||||||
|
function removeTreatment(treatmentId) {
|
||||||
|
delete recipeTreatments[treatmentId];
|
||||||
|
$('#treatmentsTable button[data-id="' + treatmentId + '"]').closest('tr').remove();
|
||||||
|
$('#recipe-form input[name="RecipeTreatments[' + treatmentId + ']"]').remove();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user