Commit 9eece958 authored by hasan khaddour's avatar hasan khaddour

update domain models

parent 451f93a6
......@@ -9,7 +9,7 @@ namespace ApplicationCore.DomainModel
public class MedicalStateModel : DomainBase
{
public int PatientId { get; set; }
// public PatientModel Patient { get; set; }
public String StateName { get; set; }
public String StateDescription { get; set; }
public DateTime PrescriptionTime { get; set; }
......
......@@ -10,7 +10,6 @@ namespace ApplicationCore.Interfaces.IServices
{
public interface IIngredientService : IService<IngredientModel>
{
// public Task<IEnumerable<IngredientModel>> GetAllIngredients();
public void AddToMedicine(int ingredientId ,int medicineId , int ratio);
public void AddToMedicine(MedicineIngredientModel medicineIngredientModel);
}
}
......@@ -11,13 +11,8 @@ namespace ApplicationCore.Interfaces.IServices
public interface IMedicalStateService : IService<MedicalStateModel>
{
public IEnumerable<MedicalStateModel> GetAllPatientMedicalStates(int patientId);
public MedicalStateModel AddMedicalStateToPateint(int patientId , MedicalStateModel medicalState);
public void AddMedicine(int medicalStateId, int medicineId);
public void RemoveMedicine(int medicalStateId, int medicineId);
// public MedicalState Update(MedicalState medicalState);
//public MedicalState GetDetails(int medicalStateId);
//public void Delete(int id);
public MedicalStateModel AddToPateint(int patientId , MedicalStateModel medicalState);
}
}
......@@ -10,10 +10,9 @@ namespace ApplicationCore.Interfaces.IServices
{
public interface IMedicineService :IService<MedicineModel>
{
// public Task<IEnumerable<MedicineModel>> GetAllMedicines();
// public void AddMedicine(MedicineModel medicine);
public void AddMedicineIngredient(int medicineId, IngredientModel ingredient);
public MedicineModel GetMedicineIngredentisDetails(int medicineId);
public void AddToMedicalState(MedicalStateMedicineModel medicalStateMedicineModel);
public void RemoveFromMedicalState(MedicalStateMedicineModel medicalStateMedicineModel);
}
}
......@@ -14,6 +14,7 @@ namespace ApplicationCore.Interfaces.IServices
public IEnumerable<MedicalStateModel> GetPatientMedicalStates(int patientId);
public Task<MedicalStateModel> GetMedicalStateDetails(int id);
public Task<Patient> GetByUserID(String id );
// public Task<IEnumerable<PatientModel>>GetAll();
public void AddMedicalState(int patientId, MedicalStateModel medicalState);
// public Patient GetDetails(int id);
......
......@@ -11,16 +11,16 @@ using System.Threading.Tasks;
namespace ApplicationCore.Services
{
public class ServiceBase<T,TModel> : IService<TModel> where T : EntityBase where TModel : DomainBase
public class ServiceBase<TEntity,TModel> : IService<TModel> where TEntity : EntityBase where TModel : DomainBase
{
protected readonly IMapper _mapper;
protected readonly IUnitOfWork<T> _unitOfWork;
protected readonly IUnitOfWork<TEntity> _unitOfWork;
protected ISpecification<T> _specification;
protected ISpecification<TEntity> _specification;
public ServiceBase(
IUnitOfWork<T> unitOfWork,
IUnitOfWork<TEntity> unitOfWork,
IMapper mapper
)
{
......@@ -38,17 +38,17 @@ namespace ApplicationCore.Services
public TModel Create(TModel model )
{
var ing = _unitOfWork.Entity.Insert(_mapper.Map<T>(model));
TEntity entity = _unitOfWork.Entity.Insert(_mapper.Map<TEntity>(model));
_unitOfWork.Save();
return _mapper.Map<TModel>(ing);
return _mapper.Map<TModel>(entity);
}
public TModel Update(TModel model)
{
var r = _unitOfWork.Entity.Update(_mapper.Map<T>(model));
TEntity entity = _unitOfWork.Entity.Update(_mapper.Map<TEntity>(model));
_unitOfWork.Save();
return _mapper.Map<TModel>(r);
return _mapper.Map<TModel>(entity);
}
public async Task<TModel> GetDetails(int id)
......
......@@ -20,16 +20,18 @@ namespace ApplicationCore.Services
IMapper mapper
):base(ingredientUnitOfWork,mapper)
{
_specification = new IngredientSpecification();
_specification = new IngredientWithMedicinesSpecification();
}
public void AddToMedicine(int ingredientId, int medicineId, int ratio) {
var r = _unitOfWork.Entity.GetById(ingredientId,_specification).Result;
r.MedicineIngredients.Add(
new MedicineIngredient { IngredientId = ingredientId , MedicineId=medicineId ,Ratio=ratio}
public async void AddToMedicine(MedicineIngredientModel medicineIngredientModel) {
var medicine = await _unitOfWork.Entity.GetById(medicineIngredientModel.IngredientId,_specification);
MedicineIngredient medicineIngredient = _mapper.Map<MedicineIngredient>(medicineIngredientModel);
medicine.MedicineIngredients.Add(
medicineIngredient
);
_unitOfWork.Entity.Update(r);
_unitOfWork.Entity.Update(medicine);
_unitOfWork.Save();
}
......
......@@ -13,7 +13,7 @@ namespace ApplicationCore.Services
{
private readonly PatientService _patientService;
private readonly IUnitOfWork<Medicine> _medicineUnitOfWork;
private readonly MedicineIngredientSpecification _medicineSpecification;
private readonly MedicineWithIngredientsSpecification _medicineSpecification;
public MedicalStateService(
IUnitOfWork<MedicalState> medicalUnitOfWork,
......@@ -22,12 +22,12 @@ namespace ApplicationCore.Services
IMapper Mapper
):base(medicalUnitOfWork,Mapper)
{
_specification = new MedicalStateSpecification();
_specification = new MedicalStateWithMedicinesSpecification();
_medicineUnitOfWork = medicineUnitOfWork;
_patientService = new PatientService(patientUnitOfWork,medicalUnitOfWork,Mapper);
_medicineSpecification = new MedicineIngredientSpecification();
_medicineSpecification = new MedicineWithIngredientsSpecification();
}
public MedicalStateModel AddMedicalStateToPateint(int patientId , MedicalStateModel medicalStateModel)
public MedicalStateModel AddToPateint(int patientId , MedicalStateModel medicalStateModel)
{
medicalStateModel.PatientId = patientId;
......@@ -38,30 +38,6 @@ namespace ApplicationCore.Services
return _mapper.Map<MedicalStateModel>(r);
}
public void AddMedicine(int MedicalStateId, int medicineId)
{
var m = _unitOfWork.Entity.GetById(MedicalStateId, _specification).Result;
if (m.Medicines is null)
m.Medicines = new List<Medicine>();
var d = _medicineUnitOfWork.Entity.GetById(medicineId,_medicineSpecification ).Result;
m.Medicines.Add(d );
_unitOfWork.Entity.Update(m);
_unitOfWork.Save();
}
public void RemoveMedicine(int MedicalStateId, int medicineId)
{
var m = _unitOfWork.Entity.GetById(MedicalStateId, _specification).Result;
if (m.Medicines is null)
m.Medicines = new List<Medicine>();
var d = _medicineUnitOfWork.Entity.GetById(medicineId, _medicineSpecification).Result;
m.Medicines.Remove(d);
_unitOfWork.Entity.Update(m);
_unitOfWork.Save();
}
public IEnumerable<MedicalStateModel> GetAllPatientMedicalStates(int patientId)
{
......
......@@ -16,26 +16,56 @@ namespace ApplicationCore.Services
{
public class MedicineService : ServiceBase<Medicine,MedicineModel>,IMedicineService
{
private IUnitOfWork<MedicalState> _medicalStateUnitOfWork;
private MedicalStateWithMedicinesSpecification _medicalSpecification;
public MedicineService(
IUnitOfWork<Medicine> medicineUnitOfWork,
IUnitOfWork<MedicalState> medicalStateUnitOfWork,
IMapper Mapper )
:base(medicineUnitOfWork , Mapper)
{
_specification = new MedicineIngredientSpecification();
_medicalStateUnitOfWork = medicalStateUnitOfWork;
_specification = new MedicineWithIngredientsSpecification();
_medicalSpecification = new MedicalStateWithMedicinesSpecification();
}
public void AddMedicineIngredient(int medicineId ,IngredientModel ingredientModel ) {
var s = _unitOfWork.Entity.GetById(medicineId,_specification).Result;
s.Ingredients.Add(_mapper.Map<Ingredient>(ingredientModel));
_unitOfWork.Entity.Update(s);
public void AddToMedicalState(MedicalStateMedicineModel medicalStateMedicineModel)
{
var medicine = _unitOfWork.Entity.GetById(medicalStateMedicineModel.MedicineId, _specification).Result;
//if (medicalState.Medicines is null)
// medicalState.Medicines = new List<Medicine>();
//var medicine = await _medicineUnitOfWork.Entity.GetById(medicalStateMedicineModel.MedicineId, _medicineSpecification);
if (medicine.MedicalStateMedicines is null)
medicine.MedicalStateMedicines = new List<MedicalStateMedicine>();
medicine.MedicalStateMedicines.Add(
_mapper.Map<MedicalStateMedicine>( medicalStateMedicineModel
)
);
_unitOfWork.Entity.Update(medicine);
_unitOfWork.Save();
}
public void RemoveFromMedicalState(MedicalStateMedicineModel medicalStateMedicineModel)
{
var m = _medicalStateUnitOfWork.Entity.GetById(medicalStateMedicineModel.MedicalStateId, _medicalSpecification).Result;
//// throw an exception
//if (m.Medicines is null)
// m.Medicines = new List<Medicine>();
var d = _unitOfWork.Entity.GetById(medicalStateMedicineModel.MedicineId, _specification).Result;
m.Medicines.Remove(d);
_medicalStateUnitOfWork.Entity.Update(m);
_medicalStateUnitOfWork.Save();
}
public MedicineModel GetMedicineIngredentisDetails(int medicineId) {
return _mapper.Map<MedicineModel>(_unitOfWork.Entity
.GetById(medicineId ,
......@@ -43,22 +73,5 @@ namespace ApplicationCore.Services
}
//public void AddIngredient(int medicineId, int ratio , IngredientModel ingredient)
//{
// // var m = _mapper.Map<Medicine>(GetMedicineIngredentisDetails(medicineId));
// var m = _unitOfWork.Entity.GetById(medicineId,_specification).Result;
// _unitOfWork.Save();
// if (ingredient.Id != 0)
// foreach (var i in m.Ingredients)
// {
// if (i.Id.Equals(ingredient.Id))
// return;
// }
// m.AddIngredient(_mapper.Map<Ingredient>(ingredient), ratio);
// _unitOfWork.Entity.Update(m);
// _unitOfWork.Save();
//}
}
}
......@@ -17,7 +17,7 @@ namespace ApplicationCore.Services
public class PatientService : ServiceBase<Patient ,PatientModel> , IPatientService
{
private readonly IUnitOfWork<MedicalState> _medicalStateUnitOfWork;
private MedicalStateSpecification _medicalStateSpecification;
private MedicalStateWithMedicinesSpecification _medicalStateSpecification;
public PatientService(
IUnitOfWork<Patient> patientUnitOfWork,
......@@ -26,8 +26,8 @@ namespace ApplicationCore.Services
:base(patientUnitOfWork , mapper)
{
_medicalStateUnitOfWork = medicalStateUnitOfWork;
_specification = new PatientMedicinesSpecification();
_medicalStateSpecification = new MedicalStateSpecification();
_specification = new PatientWithMedicinesSpecification();
_medicalStateSpecification = new MedicalStateWithMedicinesSpecification();
}
public IEnumerable<MedicalStateModel> GetPatientMedicalStates(int patientId) {
......@@ -38,7 +38,7 @@ namespace ApplicationCore.Services
).Result.MedicalStates.AsEnumerable());
}
public async Task< MedicalStateModel> GetMedicalStateDetails(int id)
{
......@@ -60,6 +60,11 @@ namespace ApplicationCore.Services
return _unitOfWork.Entity.GetById(id) is null ? false : true;
}
public async Task<Patient> GetByUserID(string id)
{
var ps = await _unitOfWork.Entity.GetAll(_specification);
return ps.Where(p => p.UserId == id).FirstOrDefault();
}
}
}
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