diff --git a/Hospital/HospitalDatabaseImplement/Models/Disease.cs b/Hospital/HospitalDatabaseImplement/Models/Disease.cs index 602b750..674b2fb 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Disease.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Disease.cs @@ -40,7 +40,7 @@ namespace HospitalDatabaseImplement.Models } return new Disease() { - Id = model.Id, + //Id = model.Id, Name = model.Name, Description = model.Description, DoctorId = model.DoctorId diff --git a/Hospital/HospitalDatabaseImplement/Models/Patient.cs b/Hospital/HospitalDatabaseImplement/Models/Patient.cs index ac46c49..bb05c9d 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Patient.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Patient.cs @@ -72,7 +72,7 @@ namespace HospitalDatabaseImplement.Models { return new Patient() { - Id = model.Id, + // Id = model.Id, FIO = model.FIO, Address = model.Address, diff --git a/Hospital/HospitalDatabaseImplement/Models/Recipe.cs b/Hospital/HospitalDatabaseImplement/Models/Recipe.cs index 5a564d8..19f5ca0 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Recipe.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Recipe.cs @@ -52,7 +52,7 @@ namespace HospitalDatabaseImplement.Modelss { return new Recipe() { - Id = model.Id, + //Id = model.Id, IssueDate = model.IssueDate, Description = model.Description, DiseaseId = model.DiseaseId, diff --git a/Hospital/HospitalDoctorApp/Controllers/HomeController.cs b/Hospital/HospitalDoctorApp/Controllers/HomeController.cs index 615c626..224d186 100644 --- a/Hospital/HospitalDoctorApp/Controllers/HomeController.cs +++ b/Hospital/HospitalDoctorApp/Controllers/HomeController.cs @@ -1,5 +1,7 @@ using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; using HospitalContracts.ViewModels; +using HospitalDataModels.Models; using HospitalDoctorApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -13,34 +15,15 @@ namespace HospitalDoctorApp.Controllers public HomeController(ILogger logger) { _logger = logger; + } - - - - [HttpGet] - public IActionResult CreatePatient() - { - return View(); - } - [HttpGet] - public IActionResult CreateDisease() - { - return View(); - } - [HttpGet] - public IActionResult CreateRecipe() - { - return View(); - } - public IActionResult Index() { if (APIClient.Doctor == null) { return Redirect("~/Home/Enter"); } - return -View(APIClient.GetRequest>($"api/visit/getpatients?doctorId={APIClient.Doctor.Id}")); + return View(APIClient.GetRequest>($"api/patient/getpatients?doctorId={APIClient.Doctor.Id}")); } public IActionResult IndexRecipes() @@ -50,7 +33,7 @@ View(APIClient.GetRequest>($"api/visit/getpatients?doctor return Redirect("~/Home/Enter"); } return -View(APIClient.GetRequest>($"api/animal/getrecipelist?doctorId={APIClient.Doctor.Id}")); +View(APIClient.GetRequest>($"api/recipe/getrecipelist?doctorId={APIClient.Doctor.Id}")); } public IActionResult IndexDiseases() @@ -161,5 +144,392 @@ View(APIClient.GetRequest>($"api/disease/getdiseases?dise Response.Redirect("Index"); } #endregion + + #region Создание + public IActionResult CreatePatient() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/"); + } + return View(); + } + public IActionResult CreateRecipe() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/"); + } + return View(); + } + public IActionResult CreateDisease() + { + ViewBag.Recipes = APIClient.GetRequest>("api/recipe/getrecipelist"); + return View(); + } + + [HttpPost] + public void CreatePatient(string name, string address, DateTime patientdate) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(address)) + { + throw new Exception("Ошибка в введенных данных"); + } + APIClient.PostRequest("api/patient/createpatient", new PatientBindingModel + { + FIO = name, + BirthDate = patientdate, + Address = address, + DoctorId = APIClient.Doctor.Id + }); + Response.Redirect("Index"); + } + [HttpPost] + public void CreateRecipe(string description, DateTime issueDate) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(description)) + { + throw new Exception("Ошибка в введенных данных"); + } + APIClient.PostRequest("api/recipe/createrecipe", new RecipeBindingModel + { + Description = description, + IssueDate = issueDate, + DoctorId = APIClient.Doctor.Id + }); + Response.Redirect("IndexRecipes"); + } + [HttpPost] + public void CreateDisease(int doctorId, string name, string description) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Ошибка в введенных данных"); + } + if (string.IsNullOrEmpty(description)) + { + throw new Exception("Ошибка в введенных данных"); + } + APIClient.PostRequest("api/disease/createdisease", new DiseaseBindingModel + { + Name = name, + DoctorId = doctorId, + + Description = description + }); + Response.Redirect("IndexDiseases"); + } + #endregion + + #region Удаление + public IActionResult DeletePatient() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Patients = APIClient.GetRequest>("api/patient/getpatients"); + return View(); + } + + [HttpPost] + public void DeletePatient(int patient) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + APIClient.PostRequest("api/patient/deletepatient", new PatientBindingModel + { + Id = patient + }); + Response.Redirect("Index"); + } + + public IActionResult DeleteRecipe() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipelist?doctorid={APIClient.Doctor.Id}"); + return View(); + } + public IActionResult DeleteDisease() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Diseases = APIClient.GetRequest>($"api/disease/getdiseases?doctorid={APIClient.Doctor.Id}"); + return View(); + } + + [HttpPost] + public void DeleteRecipe(int recipe) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + APIClient.PostRequest("api/recipe/deleterecipe", new RecipeBindingModel + { + Id = recipe + }); + Response.Redirect("IndexRecipes"); + } + [HttpPost] + public void DeleteDisease(int disease) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + APIClient.PostRequest("api/disease/deletedisease", new DiseaseBindingModel + { + Id = disease + }); + Response.Redirect("IndexDiseases"); + } + #endregion + + #region Обновление + public IActionResult UpdatePatient() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Patients = APIClient.GetRequest>("api/patient/getpatients"); + return View(); + } + + [HttpPost] + public void UpdatePatient(int patient, string name, string address, DateTime birthdate) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Ошибка в введенных данных"); + } + APIClient.PostRequest("api/patient/updatepatient", new PatientBindingModel + { + Id = patient, + FIO = name, + Address = address, + BirthDate = birthdate, + }); + Response.Redirect("Index"); + } + public IActionResult UpdateRecipe() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipelist?doctorid={APIClient.Doctor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateRecipe(int recipe, string description, DateTime issuedate) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + + if (string.IsNullOrEmpty(description)) + { + throw new Exception("Ошибка в введенных данных"); + } + APIClient.PostRequest("api/recipe/updaterecipe", new RecipeBindingModel + { + Id = recipe, + Description = description, + IssueDate = issuedate + + }); + Response.Redirect("IndexRecipes"); + } + + public IActionResult UpdateDisease() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Diseases = APIClient.GetRequest>($"api/disease/getdiseases?doctorid={APIClient.Doctor.Id}"); + return View(); + } + + [HttpPost] + public void UpdateDisease(int disease, string description, string name) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(description)) + { + throw new Exception("Ошибка в введенных данных"); + } + APIClient.PostRequest("api/disease/updatedisease", new DiseaseBindingModel + { + + Id = disease, + Name = name, + Description = description, + + + + }); + Response.Redirect("IndexDisease"); + } + #endregion + + #region Промежуточные таблицы + public IActionResult PatientRecipes() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipelist?doctorid={APIClient.Doctor.Id}"); + ViewBag.Patients = APIClient.GetRequest>($"api/patient/getpatients"); + return View(); + } + [HttpPost] + public void PatientRecipes(int recipe, string description, DateTime date, + List patients) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + + if (string.IsNullOrEmpty(description)) + { + throw new Exception("Ошибка в введенных данных"); + } + Dictionary v = new Dictionary(); + foreach (int patient in patients) + { + v.Add(patient, new PatientSearchModel { Id = patient } as IPatientModel); + } + APIClient.PostRequest("api/recipe/updaterecipe?isconnection=true", new RecipeBindingModel + { + Id = recipe, + Description = description, + IssueDate = date, + DoctorId = APIClient.Doctor.Id, + RecipePatients = v + }); + Response.Redirect("IndexRecipes"); + } + public IActionResult ProcedurePatients() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Patients = APIClient.GetRequest>($"api/patient/getpatients?doctorid={APIClient.Doctor.Id}"); + ViewBag.Procedures = APIClient.GetRequest>($"api/procedure/getprocedures"); + return View(); + } + [HttpPost] + public void ProcedurePatients(int patient, string name, DateTime date, + List procedures) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + + if (string.IsNullOrEmpty(name) || date == new DateTime()) + { + throw new Exception("Ошибка в введенных данных"); + } + Dictionary s = new Dictionary(); + foreach (int procedure in procedures) + { + s.Add(procedure, new ProcedureSearchModel { Id = procedure } as IProcedureModel); + } + APIClient.PostRequest("api/patient/updatepatient?isconnection=true", new PatientBindingModel + { + Id = patient, + FIO = name, + BirthDate = date, + DoctorId = APIClient.Doctor.Id, + PatientProcedures = s + }); + Response.Redirect("Index"); + } + #endregion + + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + + [HttpGet] + public Tuple>? GetPatient(int patientId) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + var result = APIClient.GetRequest>>($"api/patient/getpatient?patientid={patientId}"); + if (result == null) + { + return default; + } + + return result; + } + [HttpGet] + public Tuple>? GetRecipe(int recipeId) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + var result = APIClient.GetRequest>>($"api/recipe/getrecipe?recipeid={recipeId}"); + if (result == null) + { + return default; + } + + return result; + } + [HttpGet] + public Tuple>? GetProcedure(int procedureId) + { + if (APIClient.Doctor == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + var result = APIClient.GetRequest>>($"api/procedure/getprocedure?procedureid={procedureId}"); + if (result == null) + { + return default; + } + + return result; + } } } + diff --git a/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml b/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml index e1f741e..3d365eb 100644 --- a/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml +++ b/Hospital/HospitalDoctorApp/Views/Home/Index.cshtml @@ -18,12 +18,12 @@ return; }

- Редактировать пациента - Удалить пациента + Редактировать пациента + Удалить пациента Связать пацииента и процедуру

- Создать пациента + Создать пациента

diff --git a/Hospital/HospitalRestApi/Controllers/DiseaseController.cs b/Hospital/HospitalRestApi/Controllers/DiseaseController.cs new file mode 100644 index 0000000..92b107e --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/DiseaseController.cs @@ -0,0 +1,86 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; + +namespace VetClinicRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class DiseaseController : Controller + { + private readonly ILogger _logger; + private readonly IDiseaseLogic _disease; + + public DiseaseController(ILogger logger, + IDiseaseLogic disease) + { + _logger = logger; + _disease = disease; + } + + [HttpGet] + public List? GetDiseases(int? doctorId) + { + try + { + if (!doctorId.HasValue) + return _disease.ReadList(null); + return _disease.ReadList(new DiseaseSearchModel + { + DoctorId = doctorId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка по доктору id ={ Id}", doctorId); + throw; + } + } + + [HttpPost] + public void CreateDisease(DiseaseBindingModel model) + { + try + { + _disease.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания прививки"); + throw; + } + } + + [HttpPost] + public bool UpdateDisease(DiseaseBindingModel model) + { + try + { + return _disease.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить привику"); + throw; + } + } + + [HttpPost] + public bool DeleteDisease(DiseaseBindingModel model) + { + try + { + return _disease.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления привики"); + throw; + } + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalRestApi/Controllers/PatientController.cs b/Hospital/HospitalRestApi/Controllers/PatientController.cs new file mode 100644 index 0000000..a34df06 --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/PatientController.cs @@ -0,0 +1,105 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; + +namespace VetClinicRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class PatientController : Controller + { + private readonly ILogger _logger; + private readonly IPatientLogic _patient; + public PatientController(ILogger logger, IPatientLogic patient) + { + _logger = logger; + _patient = patient; + } + + [HttpGet] + public Tuple>? GetPatient(int PatientId) + { + try + { + var elem = _patient.ReadElement(new PatientSearchModel { Id = PatientId }); + if (elem == null) + return null; + var res = Tuple.Create(elem, elem.PatientProcedures.Select(x => x.Value.Name).ToList()); + res.Item1.PatientProcedures = null; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения визита по id={Id}", PatientId); + throw; + } + } + [HttpGet] + public List GetPatients(int? doctorId = null) + { + try + { + List res; + if (!doctorId.HasValue) + res = _patient.ReadList(null); + else + res = _patient.ReadList(new PatientSearchModel { DoctorId = doctorId }); + foreach (var patient in res) + patient.PatientProcedures = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка визитов"); + throw; + } + } + [HttpPost] + public bool CreatePatient(PatientBindingModel model) + { + try + { + return _patient.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать визит"); + throw; + } + } + + [HttpPost] + public bool UpdatePatient(bool isConnection, PatientBindingModel model) + { + try + { + if (!isConnection) + model.PatientProcedures = null!; + return _patient.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить визит"); + throw; + } + } + + [HttpPost] + public bool DeletePatient(PatientBindingModel model) + { + try + { + return _patient.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления визита"); + throw; + } + } + } +} diff --git a/Hospital/HospitalRestApi/Controllers/RecipeController.cs b/Hospital/HospitalRestApi/Controllers/RecipeController.cs new file mode 100644 index 0000000..f9a172c --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/RecipeController.cs @@ -0,0 +1,108 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; + +namespace VetClinicRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class RecipeController : Controller + { + private readonly ILogger _logger; + private readonly IRecipeLogic _recipe; + public RecipeController(ILogger logger, IRecipeLogic recipe) + { + _logger = logger; + _recipe = recipe; + } + + [HttpGet] + public Tuple>? GetRecipe(int recipeId) + { + try + { + var elem = _recipe.ReadElement(new RecipeSearchModel { Id = recipeId }); + if (elem == null) + return null; + var res = Tuple.Create(elem, elem.RecipePatients.Select(x => x.Value.FIO).ToList()); + res.Item1.RecipePatients = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения рецепта по id={Id}", recipeId); + throw; + } + } + + [HttpGet] + public List? GetRecipeList(int? doctorId = null) + { + try + { + List res; + if (!doctorId.HasValue) + res = _recipe.ReadList(null); + else + res = _recipe.ReadList(new RecipeSearchModel { DoctorId = doctorId }); + foreach (var recipe in res) + recipe.RecipePatients = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка рецептов"); + throw; + } + } + [HttpPost] + public bool CreateRecipe(RecipeBindingModel model) + { + try + { + return _recipe.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать рецепт"); + throw; + } + } + + [HttpPost] + public bool UpdateRecipe(bool isConnection, RecipeBindingModel model) + { + try + { + if (!isConnection) + model.RecipePatients = null!; + return _recipe.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить рецепт"); + throw; + } + } + + [HttpPost] + public bool DeleteRecipe(RecipeBindingModel model) + { + try + { + return _recipe.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления рецепта"); + throw; + } + } + + + } +} diff --git a/Hospital/PharmacistApp/PharmacistApp.csproj b/Hospital/PharmacistApp/PharmacistApp.csproj index 841d0d4..803cab2 100644 --- a/Hospital/PharmacistApp/PharmacistApp.csproj +++ b/Hospital/PharmacistApp/PharmacistApp.csproj @@ -7,11 +7,11 @@ - + - + @@ -20,7 +20,6 @@ - diff --git a/Hospital/PharmacistApp/Views/Home/Register.cshtml b/Hospital/PharmacistApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..e02abfc --- /dev/null +++ b/Hospital/PharmacistApp/Views/Home/Register.cshtml @@ -0,0 +1 @@ + diff --git a/Hospital/PharmacistApp/Views/Home/Registr.cshtml b/Hospital/PharmacistApp/Views/Home/Registr.cshtml deleted file mode 100644 index d5bf6be..0000000 --- a/Hospital/PharmacistApp/Views/Home/Registr.cshtml +++ /dev/null @@ -1,48 +0,0 @@ -@{ - ViewData["Title"] = "Register"; -} - -< div class= "text-center" > - - < h2 class= "display-4" > Регистрация - -< form method = "post" > - - < div class= "row" > - - < div class= "col-4" > Email: - - < div class= "col-8" >< input type = "text" name = "email" /> - - - - < div class= "row" > - - < div class= "col-4" > Пароль: - - < div class= "col-8" >< input type = "password" name = "password" /> - - - - < div class= "row" > - - < div class= "col-4" > ФИО: - - < div class= "col-8" >< input type = "text" name = "fio" /> - - - - < div class= "row" > - - < div class= "col-8" > - - < div class= "col-4" > - - < input type = "submit" value = "Регистрация" - - class= "btn btn-primary" /> - - - - - \ No newline at end of file diff --git a/Hospital/PharmacistApp/appsettings.json b/Hospital/PharmacistApp/appsettings.json index a47a897..a83c37f 100644 --- a/Hospital/PharmacistApp/appsettings.json +++ b/Hospital/PharmacistApp/appsettings.json @@ -6,5 +6,5 @@ } }, "AllowedHosts": "*", - "IPAddress": "http://localhost:5025/" + "IPAddress": "http://localhost:5029/" }