public void Process_Action_With_Action_Spawn_Activated_Returned() { IPlanManager pm = new PlanManager { PEUtils = new StubPlanElementUtils(), EndPointUtils = new StubPlanElementEndpointUtils() }; ObjectId actionId = ObjectId.Parse("538ca77dfe7a59112c3649e4"); PostProcessActionRequest request = new PostProcessActionRequest { ContractNumber = "InHealth001", PatientId = "123456789012345678901234", ProgramId = "000000000000000000000000", UserId = "111111111111111111111111", Version = 1.0, Action = new Actions { Id = actionId.ToString(), Completed = true, ElementState = 4, Name = "test action from stub", Description = "action Description", Text = "test action 1", AttrEndDate = DateTime.UtcNow.AddDays(10), AttrStartDate = DateTime.UtcNow, AssignDate = DateTime.UtcNow, SpawnElement = new List <SpawnElement> { new SpawnElement { ElementId = "111116789012345678901234", ElementType = 3 } }, Steps = new List <Step> { new Step { Id = "000000000011111111111234", ElementState = 1 } } } }; PostProcessActionResponse response = pm.ProcessActionResults(request); Assert.IsNotNull(response.PlanElems); Assert.IsNotNull(response.PlanElems.Actions); Assert.AreEqual(actionId.ToString(), response.PlanElems.Actions[0].Id); }
public PostProcessActionResponse Post(PostProcessActionRequest request) { var response = new PostProcessActionResponse(); var intm = new PlanManager(); ValidateTokenResponse result = null; try { request.Token = base.Request.Headers["Token"] as string; result = Security.IsUserValidated(request.Version, request.Token, request.ContractNumber); if (result.UserId.Trim() != string.Empty) { request.UserId = result.UserId; response = intm.ProcessActionResults(request); } else { throw new UnauthorizedAccessException(); } } catch (Exception ex) { CommonFormatter.FormatExceptionResponse(response, base.Response, ex); if ((ex is WebServiceException) == false) { intm.LogException(ex); } } finally { List <string> patientIds = null; if (!string.IsNullOrEmpty(response.PatientId)) { patientIds = new List <string> { response.PatientId }; } if (result != null) { AuditHelper.LogAuditData(request, result.SQLUserId, patientIds, System.Web.HttpContext.Current.Request, request.GetType().Name); } } return(response); }
public void Set_Action_State_Changed_To_Complete() { IPlanManager pm = new PlanManager { PEUtils = new StubPlanElementUtils(), EndPointUtils = new StubPlanElementEndpointUtils() }; PostProcessActionRequest request = new PostProcessActionRequest { ContractNumber = "InHealth001", PatientId = "123456789012345678901234", ProgramId = "000000000000000000000000", UserId = "111111111111111111111111", Version = 1.0, Action = new DTO.Actions { Id = "000000000000000000000000", Completed = true, ElementState = 4, Name = "test action from stub", Description = "action Description", Text = "test action 1", AttrEndDate = DateTime.UtcNow.AddDays(10), AttrStartDate = DateTime.UtcNow, AssignDate = System.DateTime.UtcNow, Steps = new List <Step> { new Step { Id = "000000000011111111111234", ElementState = 1 } } } }; PostProcessActionResponse response = pm.ProcessActionResults(request); Assert.IsNotNull(response); }
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); } }
public void Process_Action_With_Task_Spawn_by_step() { IPlanManager pm = new PlanManager { PEUtils = new StubPlanElementUtils(), EndPointUtils = new StubPlanElementEndpointUtils(), StepProcessor = new StubStepPlanProcessor() { ElementActivationStrategy = new StubElementActivationStrategy(), PEUtils = new StubPlanElementUtils() } }; //mappers Mapper.CreateMap <Task, PatientTask>() .ForMember(d => d.CustomAttributes, opt => opt.MapFrom(src => src.CustomAttributes.ConvertAll( c => new CustomAttribute { Id = c.Id, Values = c.Values }))); Mapper.CreateMap <PatientTaskData, PatientTask>().ForMember(d => d.CustomAttributes, opt => opt.MapFrom(src => src.CustomAttributes.ConvertAll( c => new CustomAttribute { Id = c.Id, Values = c.Values }))); Mapper.CreateMap <PatientTask, PatientTaskData>() .ForMember(d => d.CustomAttributes, opt => opt.MapFrom(src => src.CustomAttributes.ConvertAll( c => new CustomAttribute { Id = c.Id, Values = c.Values }))); Mapper.CreateMap <TaskData, Task>() .ForMember(d => d.CustomAttributes, opt => opt.MapFrom(src => src.CustomAttributes.ConvertAll( c => new CustomAttribute { Id = c.Id, Values = c.Values }))); Mapper.CreateMap <GoalData, Goal>() .ForMember(d => d.CustomAttributes, opt => opt.MapFrom(src => src.CustomAttributes.ConvertAll( c => new CustomAttribute { Id = c.Id, Values = c.Values }))); Mapper.CreateMap <Goal, PatientGoal>() .ForMember(d => d.CustomAttributes, opt => opt.MapFrom(src => src.CustomAttributes.ConvertAll( c => new CustomAttribute { Id = c.Id, Values = c.Values }))); Mapper.CreateMap <PatientGoalData, PatientGoal>() .ForMember(d => d.CustomAttributes, opt => opt.MapFrom(src => src.CustomAttributes.ConvertAll( c => new CustomAttribute { Id = c.Id, Values = c.Values }))) .ForMember(d => d.Barriers, opt => opt.MapFrom(src => src.BarriersData.ConvertAll( c => new PatientBarrier { Id = c.Id, CategoryId = c.CategoryId, DeleteFlag = c.DeleteFlag, Name = c.Name, PatientGoalId = c.PatientGoalId, StatusDate = c.StatusDate, StatusId = c.StatusId, Details = c.Details }))) .ForMember(d => d.Tasks, opt => opt.MapFrom(src => src.TasksData.ConvertAll( c => new PatientTask { Id = c.Id, BarrierIds = c.BarrierIds, ClosedDate = c.ClosedDate, CreatedById = c.CreatedById, CustomAttributes = c.CustomAttributes.ConvertAll( ca => new CustomAttribute { ControlType = ca.ControlType, Id = ca.Id, Name = ca.Name, Order = ca.Order, Required = ca.Required, Type = ca.Type, Values = ca.Values, Options = NGUtils.FormatOptions(ca.Options) }), DeleteFlag = c.DeleteFlag, Description = c.Description, GoalName = c.GoalName, PatientGoalId = c.PatientGoalId, StartDate = c.StartDate, StatusDate = c.StatusDate, StatusId = c.StatusId, TargetDate = c.TargetDate, TargetValue = c.TargetValue, Details = c.Details }))) .ForMember(d => d.Interventions, opt => opt.MapFrom(src => src.InterventionsData.ConvertAll( c => new PatientIntervention { AssignedToId = c.AssignedToId, BarrierIds = c.BarrierIds, CategoryId = c.CategoryId, ClosedDate = c.ClosedDate, CreatedById = c.CreatedById, DeleteFlag = c.DeleteFlag, Description = c.Description, GoalName = c.GoalName, Id = c.Id, PatientGoalId = c.PatientGoalId, PatientId = c.PatientId, StartDate = c.StartDate, DueDate = c.DueDate, StatusDate = c.StatusDate, StatusId = c.StatusId, Details = c.Details }))); ObjectId actionId = ObjectId.Parse("538ca77dfe7a59112c3649e4"); PostProcessActionRequest request = new PostProcessActionRequest { ContractNumber = "InHealth001", PatientId = "123456789012345678901234", ProgramId = "000000000000000000000000", UserId = "111111111111111111111111", Version = 1.0, Action = new DTO.Actions { Id = actionId.ToString(), Completed = true, ElementState = 4, Name = "test action from stub", Description = "action Description", Text = "test action 1", AttrEndDate = DateTime.UtcNow.AddDays(10), AttrStartDate = DateTime.UtcNow, AssignDate = System.DateTime.UtcNow, Steps = new List <Step> { new Step { Id = "000000000011111111111234", Completed = true, ElementState = 1, SpawnElement = new List <SpawnElement> { new SpawnElement { ElementId = "5463cd99fe7a592668f67a15", ElementType = 501, Tag = "" } } } } } }; PostProcessActionResponse response = pm.ProcessActionResults(request); Assert.IsNotNull(response.PlanElems); Assert.IsNotNull(response.PlanElems.Actions); Assert.IsNotNull(response.PlanElems.Interventions); }