public PostRepeatActionResponse RepeatAction(PostRepeatActionRequest request) { try { RelatedChanges.Clear(); ProcessedElements.Clear(); var response = new PostRepeatActionResponse(); response.PlanElems = new PlanElements(); var p = EndPointUtils.RequestPatientProgramDetail(request); // get module reference Module mod = PEUtils.FindElementById(p.Modules, request.Action.ModuleId); IPlanElementStrategy strategy = new StatePlanElementStrategy(new SetModulePropertiesForRepeat(mod)); // clone and insert new action var cAction = PEUtils.CloneRepeatAction(request.Action, mod.AssignToId); cAction.CompletedBy = "CM"; AddUniquePlanElementToProcessedList(cAction); // insert action update var action = NGUtils.UpdateProgramAction(request.Action, p); AddUniquePlanElementToProcessedList(request.Action); // insert action into module and update references ReplaceActionReferenceInModule(request.Action.Id, cAction, mod); strategy.Evoke(); AddUniquePlanElementToProcessedList(mod); // save var pdetail = EndPointUtils.SaveAction(request, cAction.Id, p, true); // create element changed lists PEUtils.HydratePlanElementLists(ProcessedElements, response.PlanElems); response.PlanElems.Attributes = PEUtils.GetAttributes(pdetail.Attributes); response.RelatedChanges = RelatedChanges; response.PatientId = request.PatientId; response.Version = request.Version; return(response); } catch (Exception ex) { throw new Exception("AD:InterviewManager:ProcessActionResults()::" + ex.Message, ex.InnerException); } }
public PostProcessActionResponse ProcessActionResults(PostProcessActionRequest request) { try { // need to refactor this into a mediator. RelatedChanges.Clear(); ProcessedElements.Clear(); PostProcessActionResponse response = new PostProcessActionResponse(); response.PlanElems = new PlanElements(); Program p = EndPointUtils.RequestPatientProgramDetail(request); Actions action = request.Action; if (action.Completed) { // 1) pre-process // set program starting date if (IsInitialAction.IsSatisfiedBy(p)) { p.AttrStartDate = DateTime.UtcNow; //PlanElementUtil.SetStartDateForProgramAttributes(request.ProgramId, request); } // get module reference Module mod = PEUtils.FindElementById(p.Modules, action.ModuleId); // set module to in progress if (mod.ElementState == (int)ElementState.NotStarted) //!= 4 { mod.ElementState = (int)ElementState.InProgress; //4; mod.StateUpdatedOn = DateTime.UtcNow; } // 2) set in progress state //new ResponseSpawnAllowed<Step>().IsSatisfiedBy(s) if (PEUtils.IsActionInitial(p)) //if (new IsActionInitialSpecification<Program>().IsSatisfiedBy(p)) { // set program to in progress if (p.ElementState == (int)ElementState.NotStarted) { p.ElementState = (int)ElementState.InProgress; //4; p.StateUpdatedOn = DateTime.UtcNow; } } // 3) set action state to completed action.ElementState = (int)ElementState.Completed; action.StateUpdatedOn = DateTime.UtcNow; // 4) insert action update var act = NGUtils.UpdateProgramAction(action, p); //// create a responsibility chain to process each elemnt in the hierachy ProgramPlanProcessor pChain = InitializeProgramChain(); // 5) process steps action.Steps.ForEach( s => pChain.ProcessWorkflow((IPlanElement)s, p, request.UserId, request.PatientId, action, request)); // 6) process action pChain.ProcessWorkflow((IPlanElement)action, p, request.UserId, request.PatientId, action, request); // 7) process module if (mod != null) { // set enabled status for action dependencies PEUtils.SetEnabledStatusByPrevious(mod.Actions, mod.AssignToId, mod.Enabled); // set enable/visibility of actions after action processing. pChain.ProcessWorkflow((IPlanElement)mod, p, request.UserId, request.PatientId, action, request); AddUniquePlanElementToProcessedList(mod); } // post processing // // 8) set module visibility for modules PEUtils.SetEnabledStatusByPrevious(p.Modules, p.AssignToId, p.Enabled); // 9) evaluate program status if (PEUtils.IsProgramCompleted(p, request.UserId)) { p.Completed = true; pChain.ProcessWorkflow((IPlanElement)p, p, request.UserId, request.PatientId, action, request); } // 10) register changed action AddUniquePlanElementToProcessedList(action); } else { // need to update this on the p level. action.ElementState = (int)ElementState.InProgress; //4; // in progress } AddUniquePlanElementToProcessedList(p); // save var pdetail = EndPointUtils.SaveAction(request, action.Id, p, false); // create element changed lists PEUtils.HydratePlanElementLists(ProcessedElements, response.PlanElems); response.PlanElems.Attributes = PEUtils.GetAttributes(pdetail.Attributes); response.RelatedChanges = RelatedChanges; response.PatientId = request.PatientId; response.Version = request.Version; return(response); } catch (Exception ex) { throw new Exception("AD:InterviewManager:ProcessActionResults()::" + ex.Message, ex.InnerException); } }