public AD.Program RequestPatientProgramDetail(IProcessActionRequest request) { try { AD.Program pd = null; IRestClient client = new JsonServiceClient(); var url = Common.Helper.BuildURL(string.Format("{0}/{1}/{2}/{3}/Patient/{4}/Program/{5}/Details/?Token={6}", DDProgramServiceUrl, "NG", request.Version, request.ContractNumber, request.PatientId, request.ProgramId, request.Token), request.UserId); GetProgramDetailsSummaryResponse resp = client.Get <GetProgramDetailsSummaryResponse>(url); pd = NGUtils.FormatProgramDetail(resp.Program); return(pd); } catch (Exception ex) { throw new Exception("AD:PlanElementEndpointUtil:RequestPatientProgramDetail()::" + ex.Message, ex.InnerException); } }
public override bool IsSatisfiedBy(T obj) { try { Program p = obj as Program; bool result = true; if (p.Modules != null) { foreach (Module m in p.Modules) { foreach (Actions a in m.Actions) { if (a.ElementState == (int)ElementState.InProgress) // == 4 { result = false; } } } } return(result); } catch (Exception ex) { throw new Exception("AD:PlanElementUtil:IsActionInitial()::" + ex.Message, ex.InnerException); } }
public void Set_Two_Actions_Enabled_AssignTo() { IPlanElementUtils pUtils = new PlanElementUtils(); string modId = ObjectId.GenerateNewId().ToString(); ObjectId assingtoID = ObjectId.GenerateNewId(); AD.Program prog = new AD.Program { AssignToId = assingtoID.ToString(), Modules = new List <AD.Module> { new AD.Module { Id = modId, Actions = new List <AD.Actions> { new AD.Actions { Enabled = true }, new AD.Actions { Enabled = true } } } } }; pUtils.SetElementEnabledState(modId, prog); Assert.AreEqual(assingtoID.ToString(), prog.Modules[0].Actions[0].AssignToId); Assert.AreEqual(assingtoID.ToString(), prog.Modules[0].Actions[1].AssignToId); }
public void Set_One_Action_Enabled() { IPlanElementUtils pUtils = new PlanElementUtils(); string modId = ObjectId.GenerateNewId().ToString(); AD.Program prog = new AD.Program { Modules = new List <AD.Module> { new AD.Module { Id = modId, Actions = new List <AD.Actions> { new AD.Actions { Enabled = true }, new AD.Actions { Enabled = false } } } } }; pUtils.SetElementEnabledState(modId, prog); Assert.IsNotNull(prog.Modules[0].Actions[0].AssignById); }
public static DTO.Program FormatProgramDetail(ProgramDetail program) { try { ProgramDetail p = program; DTO.Program pD = null; pD = new DTO.Program { AssignById = p.AssignBy, AssignDate = p.AssignDate, AssignToId = p.AssignTo, Client = p.Client, Completed = p.Completed, CompletedBy = p.CompletedBy, ContractProgramId = p.ContractProgramId, DateCompleted = p.DateCompleted, Description = p.Description, ElementState = p.ElementState, StateUpdatedOn = p.StateUpdatedOn, EligibilityEndDate = p.EligibilityEndDate, EligibilityRequirements = p.EligibilityRequirements, EligibilityStartDate = p.EligibilityStartDate, Enabled = p.Enabled, StartDate = p.StartDate, EndDate = p.EndDate, AttrEndDate = p.AttrEndDate, AttrStartDate = p.AttrStartDate, AuthoredBy = p.AuthoredBy, TemplateName = p.TemplateName, TemplateVersion = p.TemplateVersion, ProgramVersion = p.ProgramVersion, ProgramVersionUpdatedOn = p.ProgramVersionUpdatedOn, Id = p.Id, Modules = GetADModules(p.Modules), Name = p.Name, Next = p.Next, Objectives = GetADObjectives(p.ObjectivesData), Order = p.Order, PatientId = p.PatientId, Previous = p.Previous, ProgramState = p.ProgramState, ShortName = p.ShortName, SourceId = p.SourceId, SpawnElement = GetADSpawnElements(p.SpawnElement), Status = p.Status, Text = p.Text, Version = p.Version, Archived = p.Archived, ArchivedDate = p.ArchivedDate, ArchiveOriginId = p.ArchiveOriginId }; return(pD); } catch (Exception ex) { throw new Exception("AD:FormatProgramDetail()::" + ex.Message, ex.InnerException); } }
public void Set_One_Action_Enabled_AssignDate() { IPlanElementUtils pUtils = new PlanElementUtils(); string modId = ObjectId.GenerateNewId().ToString(); AD.Program prog = new AD.Program { Modules = new List <AD.Module> { new AD.Module { Id = modId, Actions = new List <AD.Actions> { new AD.Actions { Enabled = true }, new AD.Actions { Enabled = false } } } } }; pUtils.SetElementEnabledState(modId, prog); Assert.AreEqual(DateTime.UtcNow.Date, ((DateTime)prog.Modules[0].Actions[0].AssignDate).Date); }
public void Get_Assigned_Date() { DateTime control = DateTime.UtcNow.Date; IPlanElementUtils peUtil = new PlanElementUtils { }; AD.Module mod = new AD.Module(); AD.Program prog = new AD.Program(); peUtil.SetInitialProperties("123456789012345678901234", mod, false); Assert.AreEqual(DateTime.UtcNow.Date, ((DateTime)mod.AssignDate).Date); }
public PostSaveActionResponse SaveActionResults(PostSaveActionRequest request) { try { // need to refactor this into a mediator. RelatedChanges.Clear(); PostSaveActionResponse response = new PostSaveActionResponse(); Program p = EndPointUtils.RequestPatientProgramDetail(request); Actions action = request.Action; // set elementstates to in progress Module mod = PEUtils.FindElementById(p.Modules, action.ModuleId); // set to in progress if (mod.ElementState == (int)ElementState.NotStarted) //!= 4 { mod.ElementState = (int)ElementState.InProgress; //4; mod.StateUpdatedOn = DateTime.UtcNow; } if (PEUtils.IsActionInitial(p)) { // set program to in progress if (p.ElementState == (int)ElementState.NotStarted) { p.ElementState = (int)ElementState.InProgress; //4; p.StateUpdatedOn = System.DateTime.UtcNow; } } NGUtils.UpdateProgramAction(action, p); AddUniquePlanElementToProcessedList(mod); // save EndPointUtils.SaveAction(request, action.Id, p, false); //response.Program = p; response.Saved = true; 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); } }
private static Actions GetActionById(AD.Program p, string actionId) { Actions action = null; try { action = p.Modules.SelectMany(module => module.Actions).Where(act => act.Id == actionId).FirstOrDefault(); return(action); } catch (Exception ex) { throw new Exception("AD:PlanElementEndpointUtil:GetActionById()::" + ex.Message, ex.InnerException); } }
public void Get_Assigned_To_Null() { string assignedTO = null; IPlanElementUtils peUtil = new PlanElementUtils { }; AD.Module mod = new AD.Module(); AD.Program prog = new AD.Program { AssignToId = assignedTO }; peUtil.SetInitialProperties(assignedTO, mod, false); Assert.AreEqual(assignedTO, mod.AssignToId); }
public void Set_Assigned_Date_Null() { string assignedTO = null; IPlanElementUtils peUtil = new PlanElementUtils { }; AD.Module mod = new AD.Module(); AD.Program prog = new AD.Program { AssignToId = assignedTO }; peUtil.SetInitialProperties(assignedTO, mod, false); Assert.AreEqual(DateTime.UtcNow.Date, ((DateTime)mod.AssignDate).Date); }
public void Get_Assigned_To() { ObjectId? assignedTO = new ObjectId(); IPlanElementUtils peUtil = new PlanElementUtils { }; AD.Module mod = new AD.Module(); AD.Program prog = new AD.Program { AssignToId = assignedTO.ToString() }; peUtil.SetInitialProperties(assignedTO.ToString(), mod, false); Assert.AreEqual(assignedTO.ToString(), mod.AssignToId); }
public void Clone_With_StateChangeDate() { DateTime control = DateTime.UtcNow.Date; IPlanElementUtils peUtil = new PlanElementUtils { }; AD.Program program = new AD.Program { ElementState = 1, StateUpdatedOn = control }; peUtil.CloneProgram(program); DateTime sample = ((DateTime)program.StateUpdatedOn).Date; Assert.AreEqual(control, sample); }
private void SaveResponsesFromProgramAction(AD.Program p, string actionId, IProcessActionRequest request, bool repeat) { try { Actions act = GetActionById(p, actionId); SaveResponses(act, request, repeat); // clear response collections foreach (Step stp in act.Steps) { stp.Responses = null; } } catch (Exception ex) { throw new Exception("AD:PlanElementEndpointUtil:SaveResponsesFromProgramAction()::" + ex.Message, ex.InnerException); } }
public void Set_AssignedTo_CM_Already_Assigned_In_Program() { string assignedTO = ObjectId.GenerateNewId().ToString(); IPlanElementUtils peUtil = new PlanElementUtils { }; DateTime assigned = DateTime.UtcNow; AD.Actions act = new AD.Actions { AssignDate = assigned }; AD.Program prog = new AD.Program { AssignToId = assignedTO }; peUtil.SetInitialProperties(assignedTO, act, false); Assert.AreEqual(assignedTO, act.AssignToId); }
public void Set_Assigned_To_No_CM_Assigned_In_Program() { string assignedTO = null; IPlanElementUtils peUtil = new PlanElementUtils { }; DateTime assigned = DateTime.UtcNow; AD.Actions act = new AD.Actions { AssignDate = assigned }; AD.Program prog = new AD.Program { AssignToId = assignedTO }; peUtil.SetInitialProperties(assignedTO, act, false); Assert.IsNull(act.AssignToId); }
public void Set_Assigned_Date_Already_Assigned() { string assignedDate = null; IPlanElementUtils peUtil = new PlanElementUtils { }; DateTime assigned = DateTime.UtcNow; AD.Actions act = new AD.Actions { AssignDate = assigned }; AD.Program prog = new AD.Program { AssignToId = assignedDate }; peUtil.SetInitialProperties(assignedDate, act, false); Assert.AreEqual(assigned.Date, ((DateTime)act.AssignDate).Date); }
public static Actions UpdateProgramAction(Actions ac, DTO.Program p) { DTO.Program pr = p; DTO.Actions act = null; pr.Modules.ForEach(m => { foreach (Actions a in m.Actions) { bool replaced = ReplaceAction(ac, m, a); if (replaced) { act = a; break; } } }); return(act); }
public void SetProgramAttributes_DoNot_Set_Program_State_state_1() { IPlanElementUtils pUtils = new PlanElementUtils { ProgramAttributeStrategy = new ProgramAttributeStrategy() }; var pe = new AD.PlanElement { Enabled = false }; var progAttr = new ProgramAttributeData(); var prog = new AD.Program { Name = "test" }; pUtils.SetProgramAttributes(new AD.SpawnElement { Tag = "1", ElementType = 10, ElementId = "1234" }, prog, "user", progAttr); Assert.AreEqual(0, prog.ElementState); }
public void ProcessWorkflow(IPlanElement planElem, Program program, string userId, string patientId, Actions action, IAppDomainRequest request) { try { OnPlanElement(new PlanElementEventArg { PlanElement = planElem, Program = program, UserId = userId, PatientId = patientId, Action = action, DomainRequest = request }); } catch (Exception ex) { throw new Exception("AD:PlanProcessor:ProcessWorkflow()::" + ex.Message, ex.InnerException); } }
public override void Execute(SpawnElement r, Program program, string userId, ProgramAttributeData progAttr) { try { if (r.Tag == null) { throw new ArgumentException("Cannot set attribute of type " + r.ElementType + ". Tag value is null."); } progAttr.Eligibility = (!string.IsNullOrEmpty(r.Tag)) ? Convert.ToInt32(r.Tag) : 0; } catch (Exception ex) { throw new Exception("AD:SetProgramAttributes()::Eligibility" + ex.Message, ex.InnerException); } int state; // no = 1, yes = 2 var isNum = int.TryParse(r.Tag, out state); if (!isNum) { return; } // program is closed due to ineligibility switch (state) { case 1: //program.ElementState = (int) DataDomain.Program.DTO.ElementState.Completed; //5; //program.StateUpdatedOn = System.DateTime.UtcNow; progAttr.Eligibility = 1; //program.AttrEndDate = System.DateTime.UtcNow; break; case 2: //program.ElementState = (int) DataDomain.Program.DTO.ElementState.InProgress; //4; //program.StateUpdatedOn = System.DateTime.UtcNow; progAttr.Eligibility = 2; break; } }
public void Set_Element_State_Change_Date() { IPlanElementUtils peUtil = new PlanElementUtils { }; AD.SpawnElement spwn = new AD.SpawnElement { ElementId = "123456789012345678901234", ElementType = 12, Tag = "3" }; AD.Program program = new AD.Program { ElementState = 1 }; ProgramAttributeData progAttr = new ProgramAttributeData(); peUtil.SetProgramAttributes(spwn, program, "UserId", progAttr); DateTime control = DateTime.UtcNow.Date; DateTime sample = ((DateTime)program.StateUpdatedOn).Date; Assert.AreEqual(control, sample); }
public void Update_Action_Assign_To() { IPlanElementUtils pUtils = new PlanElementUtils(); var targetAction = ObjectId.GenerateNewId().ToString(); AD.Program prog = new AD.Program { Id = ObjectId.GenerateNewId().ToString(), Modules = new List <AD.Module> { new AD.Module { Id = ObjectId.GenerateNewId().ToString(), Actions = new List <AD.Actions> { new AD.Actions { Id = targetAction, ElementState = 2 }, new AD.Actions { Id = ObjectId.GenerateNewId().ToString() } } }, new AD.Module { Id = ObjectId.GenerateNewId().ToString(), Actions = new List <AD.Actions> { new AD.Actions { Id = ObjectId.GenerateNewId().ToString() }, new AD.Actions { Id = ObjectId.GenerateNewId().ToString() } } }, } }; var assignToId = ObjectId.GenerateNewId().ToString(); AD.PlanElement pe = new AD.PlanElement { Id = targetAction, AssignToId = assignToId }; var planElems = new DTO.PlanElements { Actions = new List <DTO.Actions>(), Modules = new List <DTO.Module>(), Programs = new List <DTO.Program>(), Steps = new List <DTO.Step>() }; pUtils.UpdatePlanElementAttributes(prog, pe, "111111111111111111111111", planElems); Assert.AreEqual(assignToId, prog.Modules[0].Actions[0].AssignToId); }
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 ProgramDetail SaveAction(IProcessActionRequest request, string actionId, Program p, bool repeat) { throw new NotImplementedException(); }
public ProgramDetail SaveAction(IProcessActionRequest request, string actionId, AD.Program p, bool repeat) { try { // save responses from action steps SaveResponsesFromProgramAction(p, actionId, request, repeat); var pD = NGUtils.FormatProgramDetail(p); var client = new JsonServiceClient(); var url = Common.Helper.BuildURL(string.Format(@"{0}/{1}/{2}/{3}/Patient/{4}/Programs/{5}/Update", DDProgramServiceUrl, "NG", request.Version, request.ContractNumber, request.PatientId, request.ProgramId, request.Token), request.UserId); var response = client.Put <DD.PutProgramActionProcessingResponse>( url, new PutProgramActionProcessingRequest { Program = pD, UserId = request.UserId }); return(response.program); } catch (Exception ex) { throw new Exception("AD:PlanElementEndpointUtil:SaveAction()::" + ex.Message, ex.InnerException); } }
public abstract void Execute(SpawnElement r, Program program, string userId, ProgramAttributeData progAttr);
public void Run(SpawnElement r, Program program, string userId, ProgramAttributeData progAttr) { _rules.First(a => a.ProgramAttributeType == r.ElementType).Execute(r, program, userId, progAttr); }
public void HydratePlanElementLists(List <object> processedElements, DTO.PlanElements planElems) { object _obj = null; try { if (planElems == null) { throw new ArgumentException("planElems is null."); } if (processedElements == null) { throw new ArgumentException("processedElements is null."); } if (processedElements != null && processedElements.Count > 0) { foreach (Object obj in processedElements) { _obj = obj; if (obj.GetType() == typeof(Program)) { try { if (!planElems.Programs.Contains(obj)) { Program p = CloneProgram((Program)obj); planElems.Programs.Add(p); } } catch (Exception ex) { throw new ArgumentException("plan elems programs collection null" + ex.Message); } } else if (obj.GetType() == typeof(Module)) { try { if (!planElems.Modules.Contains(obj)) { Module m = CloneModule((Module)obj); planElems.Modules.Add(m); } } catch (Exception ex) { throw new ArgumentException("plan elems modules collection null" + ex.Message); } } else if (obj.GetType() == typeof(Actions)) { try { if (!planElems.Actions.Contains(obj)) { Actions a = CloneAction((Actions)obj); planElems.Actions.Add(a); } } catch (Exception ex) { throw new ArgumentException("plan elems actions collection null" + ex.Message); } } else if (obj.GetType() == typeof(Step)) { try { if (!planElems.Steps.Contains(obj)) { Step s = CloneStep((Step)obj); planElems.Steps.Add(s); } } catch (Exception ex) { throw new ArgumentException("plan elems step collection null" + ex.Message); } } else if (obj.GetType() == typeof(PatientGoal)) { try { if (!planElems.Goals.Contains(obj)) { PatientGoal s = CloneGoal((PatientGoal)obj); planElems.Goals.Add(s); } } catch (Exception ex) { throw new ArgumentException("plan elems patientgoal collection null" + ex.Message); } } else if (obj.GetType() == typeof(PatientIntervention)) { try { if (!planElems.Interventions.Contains(obj)) { PatientIntervention s = CloneIntervention((PatientIntervention)obj); planElems.Interventions.Add(s); } } catch (Exception ex) { throw new ArgumentException("plan elems PatientIntervention collection null" + ex.Message); } } else if (obj.GetType() == typeof(PatientTask)) { try { if (!planElems.Tasks.Contains(obj)) { PatientTask s = CloneTask((PatientTask)obj); planElems.Tasks.Add(s); } } catch (Exception ex) { throw new ArgumentException("plan elems patienttask collection null" + ex.Message); } } } } } catch (Exception ex) { throw new Exception("AD:PlanElementUtil:HydratePlanElementLists()::" + _obj.GetType().ToString() + ex.Message, ex.InnerException); } }