Commit 5f496869 authored by hasan khaddour's avatar hasan khaddour

update f

parent 2aeaaeea
......@@ -8,17 +8,24 @@ namespace ApplicationCore.Entities
{
public class Medicine : EntityBase
{
public String Name { get; set; }
public String TradeName { get; set; }
public String ScintificName { get; set; }
public String ManufactureName { get; set; }
public String SideEffect { get; set; }
public String Description { get; set; }
public int Price { get; set; }
public String Image { get; set; }
public int Dosage { get; set; }
public Category Category { get; set; }
public MedicineType MedicineType { get; set; }
#region Relations
public ICollection<Ingredient> Ingredients { get; set; }
//public ICollection<Patient> Patients { get; set; }
public ICollection<MedicalState> MedicalStates { get; set; }
public ICollection<MedicalStateMedicine> MedicalStateMedicines { get; set; }
public ICollection<MedicineIngredient> MedicineIngredients { get; set; }
public ICollection<Patient> Patients { get; set; }
public ICollection<PatientMedicine> PatientMedicines { get; set; }
// public ICollection<PatientMedicine> PatientMedicines { get; set; }
public void AddIngredient(Ingredient ingredient , int ratio ) {
MedicineIngredients.Add(
......@@ -31,7 +38,7 @@ namespace ApplicationCore.Entities
}
#endregion Relations
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationCore.Entities
{
public class MedicalState : EntityBase
{
public int PatientId { get; set; }
public Patient Patient { get; set; }
public String StateName { get; set; }
public String StateDescription { get; set; }
public DateTime PrescriptionTime { get; set; }
public ICollection<Medicine> Medicines { get; set; }
public ICollection<MedicalStateMedicine> MedicalStateMedicines { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationCore.Entities
{
public class MedicalStateMedicine : EntityBase
{
public int MedicineId { get; set; }
public int MedicalStateId { get; set; }
#region Navigation
public Medicine Medicine { get; set; }
public MedicalState MedicalState { get; set; }
#endregion Navigation
}
}
......@@ -13,8 +13,11 @@ namespace ApplicationCore.Entities
public String UserId { get; set; }
public User User { get; set; }
public String BIO { get; set; }
public ICollection<Medicine> Medicines { get; set; }
public ICollection<PatientMedicine> PatientMedicines { get; set; }
#region Relations
public ICollection<MedicalState> MedicalStates { get; set; }
// public ICollection<Medicine> Medicines { get; set; }
// public ICollection<PatientMedicine> PatientMedicines { get; set; }
#endregion Relations
}
}
......@@ -11,13 +11,13 @@ namespace ApplicationCore.Interfaces.IServices
public interface IPatientService
{
public IEnumerable<Medicine> GetPatientMedicines(int patientId);
public Medicine GetMedicineDetails(int id, params Expression<Func<Medicine, object>>[] includeProperties);
public IEnumerable<MedicalState> GetPatientMedicalStates(int patientId);
public MedicalState GetMedicalStateDetails(int id, params Expression<Func<MedicalState, object>>[] includeProperties);
public IEnumerable<Patient> GetAll(params Expression<Func<Patient, object>>[] includeProperties);
public void AddMedicine(int patientId, Medicine medicine);
public void AddMedicalState(int patientId, MedicalState medicalState);
public Patient GetById(int id, params Expression<Func<Patient, object>>[] includeProperties);
public void Insert(Patient owner);
public void Update(Patient owner);
public void Insert(Patient patient);
public void Update(Patient patient);
public void Delete(int id);
public bool PatientExists(int id);
......
......@@ -14,52 +14,50 @@ namespace ApplicationCore.Services.PatientService
public class PatientService : IPatientService
{
private readonly IUnitOfWork<Patient> _patientUnitOfWork;
private readonly IUnitOfWork<Medicine> _medicineUnitOfWork;
private readonly IUnitOfWork<MedicalState> _medicalStateUnitOfWork;
private PatientMedicinesSpecification _patientMedicinesSpecification;
private MedicineIngredientSpecification _medicineIngredientSpecification;
private MedicalStateSpecification _medicalStateSpecification;
public PatientService(IUnitOfWork<Patient> patientUnitOfWork, IUnitOfWork<Medicine> medicineUnitOfWork)
public PatientService(
IUnitOfWork<Patient> patientUnitOfWork,
IUnitOfWork<MedicalState> medicalStateUnitOfWork)
{
_patientUnitOfWork = patientUnitOfWork;
_medicineUnitOfWork = medicineUnitOfWork;
_medicalStateUnitOfWork = medicalStateUnitOfWork;
_patientMedicinesSpecification = new PatientMedicinesSpecification();
_medicineIngredientSpecification = new MedicineIngredientSpecification();
_medicalStateSpecification = new MedicalStateSpecification();
}
public IEnumerable<Medicine> GetPatientMedicines(int patientId) {
public IEnumerable<MedicalState> GetPatientMedicalStates(int patientId) {
return _patientUnitOfWork.Entity
.GetById(
patientId,_patientMedicinesSpecification
).Medicines.AsEnumerable();
).MedicalStates.AsEnumerable();
}
public Medicine GetMedicineDetails(int id, params Expression<Func<Medicine, object>>[] includeProperties)
public MedicalState GetMedicalStateDetails(int id, params Expression<Func<MedicalState, object>>[] includeProperties)
{
return _medicineUnitOfWork.Entity.GetById(id,_medicineIngredientSpecification);
return _medicalStateUnitOfWork.Entity.GetById(id,_medicalStateSpecification);
}
public IEnumerable<Patient> GetAll(params Expression<Func<Patient, object>>[] includeProperties) {
return _patientUnitOfWork.Entity.GetAll(_patientMedicinesSpecification);
}
public void AddMedicine(int patientId, Medicine medicine) {
public void AddMedicalState (int patientId, MedicalState medicalState) {
var ptient = _patientUnitOfWork.Entity.GetById(patientId,_patientMedicinesSpecification);
if (medicine.Id != 0)
if (medicalState.Id != 0)
foreach (var i in ptient.Medicines)
foreach (var i in ptient.MedicalStates)
{
if (i.Id.Equals(medicine.Id))
if (i.Id.Equals(medicalState.Id))
return;
}
ptient.PatientMedicines
.Add(new PatientMedicine{
Medicine = medicine,
Patient =ptient ,
PrescripDate=DateTime.Now
});
ptient.MedicalStates
.Add(medicalState
);
_patientUnitOfWork.Entity.Update(ptient);
_patientUnitOfWork.Save();
}
......@@ -68,19 +66,19 @@ namespace ApplicationCore.Services.PatientService
return _patientUnitOfWork.Entity.GetById(id, _patientMedicinesSpecification);
}
public void Insert(Patient owner)
public void Insert(Patient patient)
{
_patientUnitOfWork.Entity.Insert(owner);
_patientUnitOfWork.Entity.Insert(patient);
_patientUnitOfWork.Save();
}
public void Update(Patient owner)
public void Update(Patient patient)
{
_patientUnitOfWork.Entity.Update(owner);
_patientUnitOfWork.Entity.Update(patient);
_patientUnitOfWork.Save();
}
public void Delete(int id)
......
using ApplicationCore.Entities;
using ApplicationCore.Specification.BaseSpecification;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationCore.Specification
{
class MedicalStateSpecification : BaseSpecification<MedicalState>
{
public MedicalStateSpecification()
{
AddInclude(p => p.MedicalStateMedicines);
AddInclude(p => p.Medicines);
AddInclude(p => p.Patient);
AddThenInclude("MedicalStateMedicines.Medicine");
}
}
{
}
}
......@@ -17,7 +17,7 @@ namespace ApplicationCore.Specification
AddInclude(p => p.MedicineIngredients);
AddInclude(p => p.Category);
AddInclude(p => p.MedicineType);
AddInclude(p => p.Patients);
AddInclude(p => p.MedicalStates);
AddInclude(p => p.Ingredients);
AddThenInclude("MedicineIngredients.Ingredient");
......
......@@ -12,9 +12,10 @@ namespace ApplicationCore.Specification
{
public PatientMedicinesSpecification()
{
AddInclude(p => p.Medicines);
AddInclude(p => p.MedicalStates);
AddInclude(p => p.User);
AddInclude(p=> p.PatientMedicines);
AddThenInclude("MedicalStates.Medicines");
}
......
......@@ -23,6 +23,7 @@ namespace Infrastructure.Data
public DbSet<Ingredient> Ingredients { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<MedicineType> MedicineTypes { get; set; }
public DbSet<MedicalState> MedicalStates { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
......@@ -49,17 +50,22 @@ namespace Infrastructure.Data
);
modelBuilder.Entity<Patient>()
.HasMany(e => e.MedicalStates)
.WithOne(e => e.Patient);
modelBuilder.Entity<MedicalState>()
.HasMany(e => e.Medicines)
.WithMany(e => e.Patients)
.UsingEntity<PatientMedicine>(
.WithMany(e => e.MedicalStates)
.UsingEntity<MedicalStateMedicine>(
l => l.HasOne<Medicine>(e => e.Medicine)
.WithMany(e => e.PatientMedicines)
.WithMany(e => e.MedicalStateMedicines)
.HasForeignKey(e => e.MedicineId),
r => r.HasOne<Patient>(e => e.Patient)
.WithMany(e => e.PatientMedicines)
.HasForeignKey(e => e.PatientId)
r => r.HasOne<MedicalState>(e => e.MedicalState)
.WithMany(e => e.MedicalStateMedicines)
.HasForeignKey(e => e.MedicalStateId)
);
modelBuilder.Entity<Patient>()
.HasOne(o => o.User);
......@@ -109,7 +115,7 @@ namespace Infrastructure.Data
);
#endregion Roles
#region User
PasswordHasher<User> ph = new PasswordHasher<User>();
var ph = new PasswordHasher<IdentityUser>();
var admin = new User
{
......@@ -119,7 +125,8 @@ namespace Infrastructure.Data
Avatar = "avatar.jpg",
Email = "hasan@b",
UserName="Hasan.Bahjat",
NormalizedEmail="hasan@b",
PasswordHash = ph.HashPassword(null, "123@Aa"),
NormalizedEmail ="hasan@b",
NormalizedUserName= "Hasan.Bahjat",
CreationTime = DateTime.Now
......@@ -131,16 +138,14 @@ namespace Infrastructure.Data
LastName = "Khaddour",
Avatar = "avatar1.jpg",
Email = "hasan.bahjat@mail.y",
PasswordHash= ph.HashPassword(null, "123@Aa"),
UserName = "Hasan.Khaddour",
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.khaddour",
CreationTime = DateTime.Now
};
admin.PasswordHash = ph.HashPassword(admin, "123@Aa");
PatientAccount.PasswordHash = ph.HashPassword(PatientAccount, "123@Aa");
modelBuilder.Entity<User>()
.HasData(
admin,
......@@ -161,24 +166,52 @@ namespace Infrastructure.Data
);
#endregion Patients
#region Categories
var c1 = new Category { Id = 1, Name = "Antibiotic" };
var c2 = new Category { Id = 2, Name = "Painkiller" };
modelBuilder.Entity<Category>().HasData(
c1 ,c2
);
#endregion Categories
#region MedicineType
modelBuilder.Entity<MedicineType>().HasData(
new MedicineType { Id = 1, TypeName = "Tablet" },
new MedicineType { Id = 2, TypeName = "Syrup" }
);
#endregion MedicineType
#region Ingredients
modelBuilder.Entity<Ingredient>().HasData(
new Ingredient { Id = 1, Name = "Amoxicillin" },
new Ingredient { Id = 2, Name = "Paracetamol" }
);
modelBuilder.Entity<MedicineIngredient>().HasData(
new MedicineIngredient { MedicineId = 1, IngredientId = 1 },
new MedicineIngredient { MedicineId = 2, IngredientId = 2 }
);
#endregion Ingredients
#region Medicines
var med = new Medicine
{
Id=-1,
Name = "Augmentine",
Id=1,
ScintificName = "Augmentine",
TradeName="Augmentine",
ManufactureName="Ibin Sina",
SideEffect="No. ",
Category=c1 ,
Image="med1.png",
Dosage = 12,
Price = 2500,
};
var c = new Category { Id = 1, Name = "Augmentine" };
modelBuilder.Entity<Category>().HasData(c);
// med.Category = c;
modelBuilder.Entity<Medicine>().HasData(med);
#endregion Medicines
#region MedicalState
#endregion MedicalState
}
}
}
......@@ -21,14 +21,19 @@ namespace WebPresentation.Controllers
{
private readonly PatientService _patientService;
private readonly MedicineService _medicineService;
private readonly UserManager<User> _userManager;
public HomeController(UserManager<User> userManager,IUnitOfWork<Patient> patientUnitOfWork, IUnitOfWork<Medicine> medicineUnitOfWork):base(userManager)
public HomeController(
UserManager<User> userManager,
IUnitOfWork<Patient> patientUnitOfWork,
IUnitOfWork<Medicine> medicineUnitOfWork,
IUnitOfWork<MedicalState> medicalStateUnitOfWork
):base(userManager)
{
_userManager = userManager;
_patientService = new PatientService(patientUnitOfWork,medicineUnitOfWork);
_medicineService = new MedicineService(medicineUnitOfWork);
_patientService = new PatientService(patientUnitOfWork,medicalStateUnitOfWork);
}
......@@ -39,9 +44,7 @@ namespace WebPresentation.Controllers
var ownesr = _patientService
.GetAll(
u => u.User ,
u => u.Medicines
)
)
.Where(
u => u.User.Id == userId
)
......@@ -50,13 +53,9 @@ namespace WebPresentation.Controllers
return View(ownesr);
}
public IActionResult MedicineDetails(int id ) {
var s = _patientService.GetMedicineDetails(
id,
i => i.MedicineIngredients,
i => i.Ingredients ,
i => i.Category,
i => i.MedicineType);
public IActionResult MedicalStateDetails(int id ) {
var s = _patientService.GetMedicalStateDetails(
id);
if (s is null) {
return NotFound();
}
......@@ -68,13 +67,13 @@ namespace WebPresentation.Controllers
return View();
}
public IActionResult AddMedicine(int id) {
public IActionResult AddMedicalState(int id) {
var userId = _userManager.GetUserId(User);
var patient = _patientService.GetAll(u => u.User, u => u.Medicines)
var patient = _patientService.GetAll()
.Where(u => u.User.Id ==userId ).FirstOrDefault();
var m =_medicineService.GetMedicineDetails(id);
_patientService.AddMedicine(patient.Id, m);
var m =_patientService.GetMedicalStateDetails(id);
_patientService.AddMedicalState(patient.Id, m);
return RedirectToAction("Index","Home");
......
......@@ -26,11 +26,12 @@ namespace WebPresentation.Controllers
public MedicineController(UserManager<User> userManager,
IUnitOfWork<Patient> patientUnitOfWork,
IUnitOfWork<Medicine> medicineUnitOfWork,
IUnitOfWork<MedicalState> medicalStateUnitOfWork,
IUnitOfWork<Ingredient>ingredientUnitOfWork):base(userManager)
{
_ingredientService =new IngredientService( ingredientUnitOfWork);
_medicineService = new MedicineService( medicineUnitOfWork);
_patientService = new PatientService(patientUnitOfWork,medicineUnitOfWork);
_patientService = new PatientService(patientUnitOfWork,medicalStateUnitOfWork);
}
......
......@@ -15,7 +15,6 @@
ViewData["userName"] = Model.User.FirstName + " " + Model.User.LastName;
ViewBag.owner = Model;
var top = Model.Medicines.Where(t => t.Dosage > 0).ToList();
var i = 1;
}
......@@ -64,29 +63,29 @@
<!-- Portfolio Grid Items -->
<div class="row d-flex flex-wrap justify-content-sm-center">
@if (Model.Medicines.Count() == 0)
@if (Model.MedicalStates.Count() == 0)
{
<h2 class="text-center">You dont have any Medicine</h2>
<h2 class="text-center">You dont have any MedicalState</h2>
<img src="~/img/portfolio/noData.jpg" class="figure-img" />
}
else
@foreach (var item in Model.Medicines)
@foreach (var item in Model.MedicalStates)
{
<div class="col-lg-4">
<div class="card m-3">
<img src="/img/portfolio/@item.Image"
<img src="/img/portfolio/flappy.png"
class="card-img-top img-fluid" style="max-height:250px "
alt="Waterfall" />
<div class="card-body">
<h5 class="card-title">@item.Name</h5>
<h5 class="card-title">@item.StateName</h5>
<p class="card-text">
@item.Description
@item.StateDescription
<br />
Price : @item.Price <br />
Date : @item.PrescriptionTime <br />
Type : @item.MedicineType
Medicines : @item.Medicines.Count()
</p>
<a href="#" class="btn btn-primary" data-toggle="modal" data-target="#item-@(item.Id)">go to descriptiuon </a>
......@@ -171,7 +170,7 @@
</section>
<!-- Modals -->
@foreach (var item in Model.Medicines)
@foreach (var item in Model.MedicalStates)
{
<!-- Portfolio Modal -->
<div class="portfolio-modal modal fade" id="item-@(item.Id)" tabindex="-1" role="dialog" aria-labelledby="label-@item.Id" aria-hidden="true">
......@@ -188,7 +187,7 @@
<div class="row justify-content-center">
<div class="col-lg-8">
<!-- Portfolio Modal - Title -->
<h2 class="portfolio-modal-title text-secondary text-uppercase mb-0">@item.Name </h2>
<h2 class="portfolio-modal-title text-secondary text-uppercase mb-0">@item.StateName </h2>
<!-- Icon Divider -->
<div class="divider-custom">
<div class="divider-custom-line"></div>
......@@ -198,13 +197,13 @@
<div class="divider-custom-line"></div>
</div>
<!-- Portfolio Modal - Image -->
<img class="img-fluid rounded mb-5" src=@("/img/portfolio/"+item.Image ) ) alt="">
<img class="img-fluid rounded mb-5" src="/img/portfolio/ecole.png" alt="">
<!-- Portfolio Modal - Text -->
<p class="mb-5">medicine Description : @item.Description</p>
<p class="mb-5">medicine price : @item.Price</p>
<p class="mb-5">medicine Dosage : @item.Dosage</p>
<p class="mb-5">State Description : @item.StateDescription</p>
<p class="mb-5">State Name : @item.StateName</p>
<p class="mb-5">State Time : @item.PrescriptionTime</p>
<a asp-action="MedicineDetails" role="button" class="btn btn-primary" asp-controller="Home" asp-route-id="@item.Id">View More </a>
<a asp-action="MedicalStateDetails" role="button" class="btn btn-primary" asp-controller="Home" asp-route-id="@item.Id">View More </a>
<button class="btn btn-primary" href="#" data-dismiss="modal">
<i class="fas fa-times fa-fw"></i>
Close Window
......
@model Medicine
@model MedicalState
@{
ViewData["Title"] = "Medicine Details ";
ViewData["Title"] = "Medical State Details ";
var a = 0;
......@@ -15,9 +15,9 @@
<div class="row g-0">
<div class="col-md-4 gradient-custom text-center text-black"
style="border-top-left-radius: .5rem; border-bottom-left-radius: .5rem;">
<img src="~/img/portfolio/@Model.Image"
<img src="~/img/portfolio/ecole.png"
alt="Avatar" class="img-fluid my-5" style="width: 80px;" />
<h5>@Model.Name</h5>
<h5>@Model.</h5>
<p>For: @(Model.Category is null ? "":Model.Category.Name)</p>
<a asp-action="Edit" asp-route-id="@Model.Id">
<i class="far fa-edit mb-5"></i>
......
......@@ -16,9 +16,16 @@
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
<div class="col-5">
<label asp-for="TradeName" class="control-label"></label>
<input asp-for="TradeName" class="form-control" />
<span asp-validation-for="TradeName" class="text-danger"></span>
</div>
<div class="col-5">
<label asp-for="ScintificName" class="control-label"></label>
<input asp-for="ScintificName" class="form-control" />
<span asp-validation-for="ScintificName" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment