Ejemplo n.º 1
0
        public MainPlanOfCareViewModel GetPlanOfCare(int PatientId, string UserId, bool isPharmixAdmin)
        {
            var result  = new MainPlanOfCareViewModel();
            var IsAdmin = false;

            if (IsAdminUser(UserId, isPharmixAdmin))
            {
                IsAdmin = true;
            }
            else
            {
                PatientId = _repository.GetContext().Patients.Where(p => p.UserId == UserId).Select(p => p.Id).FirstOrDefault();
            }

            var planOfCare = _repository.GetContext().PlanOfCare.Include(p => p.Pregnancy).Where(p => p.Pregnancy.PatientId == PatientId);

            List <PlanOfCareViewModel> planOfCares = Mapper.Map <List <PlanOfCareViewModel> >(planOfCare);

            var planCount = planOfCares.Count;
            int j         = 4 - planCount;

            for (int i = 1; i <= j; i++)
            {
                var newPlan = new PlanOfCareViewModel {
                    Id = 0
                };
                planOfCares.Add(newPlan);
            }

            result.IsAdmin             = IsAdmin;
            result.PatientId           = PatientId;
            result.PlanOfCareViewModel = planOfCares;

            return(result);
        }
Ejemplo n.º 2
0
        public bool SavePlanOfCare(MainPlanOfCareViewModel model, string UserId)
        {
            var result = false;

            try
            {
                var pregnancy = _repository.GetContext().Pregnancy.Where(p => p.PatientId == model.PatientId).FirstOrDefault();
                foreach (var plan in model.PlanOfCareViewModel)
                {
                    if (plan.Id > 0)
                    {
                        //save existing plan
                        var mapPlan = Mapper.Map <PlanOfCare>(plan);
                        mapPlan.SetUpdateDetails(UserId);

                        _repository.SaveExisting(mapPlan);
                    }
                    else if (plan.Id == 0 && (plan.CreatedDate != null || !string.IsNullOrEmpty(plan.JobTitle) || !string.IsNullOrEmpty(plan.LeadProfessional) || !string.IsNullOrEmpty(plan.ReasonIfChanged)))
                    {
                        //save new plan
                        var newPlan = Mapper.Map <PlanOfCare>(plan);
                        newPlan.SetCreateDetails(UserId);
                        newPlan.PregnancyId = pregnancy.Id;

                        var savePlan = _repository.SaveNew(newPlan);
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }