Example #1
0
        /// <summary>
        /// Add or Update caseaction to database
        /// </summary>
        /// <param name="caseaction">data to save</param>
        public void InsertOrUpdate(CaseAction caseaction)
        {
            bool isNew = false;

            if (caseaction.CaseSmartGoalServiceProviderID > 0)
            {
                caseaction.CaseProgressNoteID = null;
                caseaction.CaseSmartGoalID    = null;
            }
            if (caseaction.CaseProgressNoteID == 0)
            {
                caseaction.CaseProgressNoteID = null;
            }
            if (caseaction.CaseSmartGoalID == 0)
            {
                caseaction.CaseSmartGoalID = null;
            }
            caseaction.LastUpdateDate = DateTime.Now;
            if (caseaction.ID == default(int))
            {
                isNew = true;
                //set the date when this record was created
                caseaction.CreateDate = caseaction.LastUpdateDate;
                //set the id of the worker who has created this record
                caseaction.CreatedByWorkerID = caseaction.LastUpdatedByWorkerID;
                //add a new record to database
                context.CaseAction.Add(caseaction);
            }
            else
            {
                //update an existing record to database
                context.Entry(caseaction).State = System.Data.Entity.EntityState.Modified;
            }
            Save();
            if (caseaction.CaseProgressNoteID.HasValue && caseaction.CaseProgressNoteID.Value > 0)
            {
                CaseWorker primaryWorker = caseworkerRepository.FindPrimary(caseaction.CaseID);
                if (primaryWorker != null)
                {
                    string             caseLink           = "/CaseManagement/CaseProgressNote/Edit?noteID=" + caseaction.CaseProgressNoteID.Value + "&CaseID=" + caseaction.CaseID + "&CaseMemberID=" + caseaction.CaseMemberID;
                    WorkerNotification workerNotification = new WorkerNotification()
                    {
                        IsRead                = false,
                        LastUpdateDate        = DateTime.Now,
                        LastUpdatedByWorkerID = caseaction.LastUpdatedByWorkerID,
                        ReferenceLink         = caseLink,
                        WorkerID              = primaryWorker.WorkerID
                    };
                    if (isNew)
                    {
                        workerNotification.Notification = "A new action has been added to a progress note. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the note detail.";
                    }
                    else
                    {
                        workerNotification.Notification = "A progress note action has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the note detail.";
                    }
                    workernotificationRepository.InsertOrUpdate(workerNotification);
                    workernotificationRepository.Save();
                }
            }
            else if (caseaction.CaseSmartGoalServiceProviderID.HasValue && caseaction.CaseSmartGoalServiceProviderID.Value > 0)
            {
                CaseSmartGoalServiceProvider casesmartgoalserviceprovider = casesmartgoalserviceproviderRepository.Find(caseaction.CaseSmartGoalServiceProviderID.Value);
                if (casesmartgoalserviceprovider != null && casesmartgoalserviceprovider.WorkerID.HasValue && casesmartgoalserviceprovider.WorkerID.Value > 0)
                {
                    string             caseLink           = "/CaseManagement/CaseSmartGoalServiceProvider/Index?casesmartgoalId=" + casesmartgoalserviceprovider.CaseSmartGoalID + "&CaseID=" + caseaction.CaseID + "&CaseMemberID=" + caseaction.CaseMemberID;
                    WorkerNotification workerNotification = new WorkerNotification()
                    {
                        IsRead                = false,
                        LastUpdateDate        = DateTime.Now,
                        LastUpdatedByWorkerID = casesmartgoalserviceprovider.LastUpdatedByWorkerID,
                        ReferenceLink         = caseLink,
                        WorkerID              = casesmartgoalserviceprovider.WorkerID.Value
                    };
                    if (isNew)
                    {
                        workerNotification.Notification = "A new action has been added to a service provider. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the service provider detail.";
                    }
                    else
                    {
                        workerNotification.Notification = "A service provider action has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the service provider detail.";
                    }
                    workernotificationRepository.InsertOrUpdate(workerNotification);
                    workernotificationRepository.Save();
                }
            }

            if (caseaction.CaseWorkerID.HasValue && caseaction.CaseWorkerID.Value > 0)
            {
                int workerID = 0;
                if (caseaction.CaseSmartGoalServiceProviderID.HasValue && caseaction.CaseSmartGoalServiceProviderID.Value > 0)
                {
                    CaseSmartGoalServiceProvider casesmartgoalserviceprovider = casesmartgoalserviceproviderRepository.Find(caseaction.CaseSmartGoalServiceProviderID.Value);
                    if (casesmartgoalserviceprovider != null && casesmartgoalserviceprovider.WorkerID.HasValue)
                    {
                        workerID = casesmartgoalserviceprovider.WorkerID.Value;
                    }
                }
                if (workerID == 0)
                {
                    CaseWorker caseWorker = caseworkerRepository.Find(caseaction.CaseWorkerID.Value);
                    if (caseWorker != null)
                    {
                        workerID = caseWorker.WorkerID;
                    }
                }
                if (workerID > 0)
                {
                    string     caseLink   = "/CaseManagement/CaseAction/Index?CaseID=" + caseaction.CaseID + "&CaseMemberID=" + caseaction.CaseMemberID;
                    WorkerToDo workerToDo = new WorkerToDo()
                    {
                        LastUpdateDate        = DateTime.Now,
                        LastUpdatedByWorkerID = caseaction.LastUpdatedByWorkerID,
                        ReferenceLink         = caseLink,
                        WorkerID    = workerID,
                        IsCompleted = false,
                    };
                    if (isNew)
                    {
                        workerToDo.Subject = "A new action has been assigned to you. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the detail.";
                    }
                    else if (caseaction.IsCompleted)
                    {
                        workerToDo.Subject = "An action assigned to you has been completed. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the detail.";
                    }
                    else
                    {
                        workerToDo.Subject = "An action assigned to you has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the detail.";
                    }
                    workertodoRepository.InsertOrUpdate(workerToDo);
                    workertodoRepository.Save();
                }
            }
        }
Example #2
0
        public ActionResult Index(int casesmartgoalId, int caseId, int?caseMemberId, int?casesmartgoalserviceproviderId)
        {
            //<JL:add:06/02/2017>
            var  varCase   = caseRepository.Find(caseId);
            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(caseId, CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalServiceProvider, Constants.Actions.Index, true);

            if (!hasAccess)
            {
                WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }));
            }
            //<JL:add:06/02/2017>

            //create a new instance of caseSmartGoalServiceProvider
            CaseSmartGoalServiceProvider caseSmartGoalServiceProvider = new CaseSmartGoalServiceProvider();

            if (casesmartgoalserviceproviderId.HasValue)
            {
                caseSmartGoalServiceProvider = casesmartgoalserviceproviderRepository.Find(casesmartgoalserviceproviderId.Value);
                if (caseSmartGoalServiceProvider != null)
                {
                    casesmartgoalId = caseSmartGoalServiceProvider.CaseSmartGoalID;
                }
            }
            caseSmartGoalServiceProvider.CaseID          = caseId;
            caseSmartGoalServiceProvider.CaseSmartGoalID = casesmartgoalId;
            if (caseMemberId.HasValue)
            {
                caseSmartGoalServiceProvider.CaseMemberID = caseMemberId.Value;
            }
            CaseSmartGoal caseSmartGoal = casesmartgoalRepository.Find(casesmartgoalId);

            if (caseSmartGoal != null)
            {
                caseSmartGoalServiceProvider.QualityOfLifeCategoryID = caseSmartGoal.QualityOfLifeCategoryID;
            }
            if (caseSmartGoalServiceProvider.CaseMemberID == 0 && caseSmartGoal != null && caseSmartGoal.CaseGoal != null)
            {
                caseSmartGoalServiceProvider.CaseMemberID = caseSmartGoal.CaseGoal.CaseMemberID;
            }
            if (caseSmartGoal != null)
            {
                List <CaseSmartGoalAssignment> goalAssignmentList = casesmartgoalRepository.FindAllCaseSmartGoalAssignmentByCaseSmargGoalID(caseSmartGoal.ID);
                if (goalAssignmentList != null)
                {
                    foreach (CaseSmartGoalAssignment goalAssignment in goalAssignmentList)
                    {
                        caseSmartGoal.SmartGoalName = caseSmartGoal.SmartGoalName.Concate(",", goalAssignment.SmartGoal.Name);
                    }
                }
            }
            if (caseSmartGoal != null && caseSmartGoal.CaseGoal != null && caseSmartGoal.CaseGoal.CaseMember != null)
            {
                caseSmartGoal.CaseMemberName = caseSmartGoal.CaseGoal.CaseMember.FirstName + " " + caseSmartGoal.CaseGoal.CaseMember.LastName;
            }
            caseSmartGoalServiceProvider.CaseSmartGoal = caseSmartGoal;
            caseSmartGoalServiceProvider.ServiceTypeID = 1;
            caseSmartGoalServiceProvider.CaseSmartGoalServiceLevelOutcome = new CaseSmartGoalServiceLevelOutcome();
            caseSmartGoalServiceProvider.CaseSmartGoalServiceLevelOutcome.CaseSmartGoalID = casesmartgoalId;

            caseSmartGoalServiceProvider.CaseAction = new CaseAction();
            //return view result
            ViewBag.ServiceProviderID = casesmartgoalserviceproviderId.ToString(true);
            if (caseMemberId.HasValue && caseMemberId.Value > 0)
            {
                caseSmartGoalServiceProvider.CaseMemberID = caseMemberId.Value;
                CaseMember caseMember = casememberRepository.Find(caseSmartGoalServiceProvider.CaseMemberID);
                if (caseMember != null)
                {
                    ViewBag.DisplayID = caseMember.DisplayID;
                    if (caseMember.Case != null)
                    {
                        caseSmartGoalServiceProvider.RegionID = caseMember.Case.RegionID;
                    }
                }
            }
            else
            {
                //var varCase = caseRepository.Find(caseId);
                if (varCase != null)
                {
                    ViewBag.DisplayID = varCase.DisplayID;
                    caseSmartGoalServiceProvider.RegionID = varCase.RegionID;
                }
            }
            //if (!caseSmartGoalServiceProvider.IsUsed)
            //{
            //    caseSmartGoalServiceProvider.IsProposed = true;
            //}
            return(View(caseSmartGoalServiceProvider));
        }