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

update domain models

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