Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        private List <ResponseDetail> FormatResponseDetails(List <Response> rsps)
        {
            try
            {
                var rs = new List <ResponseDetail>();

                rsps.ForEach(r =>
                {
                    var rd = new DD.ResponseDetail
                    {
                        Id           = r.Id,
                        NextStepId   = r.NextStepId,
                        Nominal      = r.Nominal,
                        Order        = r.Order,
                        Required     = r.Required,
                        SpawnElement = NGUtils.GetDDSpawnElement(r.SpawnElement),
                        StepId       = r.StepId,
                        Text         = r.Text,
                        Value        = r.Value,
                        Selected     = r.Selected,
                        Delete       = r.Delete
                    };
                    rs.Add(rd);
                });
                return(rs);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:PlanElementEndpointUtil:FormatResponseDetails()::" + ex.Message,
                                    ex.InnerException);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        public List <Contact> GetCareManagers(GetAllCareManagersRequest request)
        {
            List <Contact> contactList = null;

            try
            {
                IRestClient client = new JsonServiceClient();
                string      url    = Common.Helper.BuildURL(string.Format("{0}/{1}/{2}/{3}/Contact/CareManagers",
                                                                          DDContactServiceUrl,
                                                                          "NG",
                                                                          request.Version,
                                                                          request.ContractNumber), request.UserId);

                //[Route("/{Context}/{Version}/{ContractNumber}/Contact/CareManagers", "GET")]
                GetAllCareManagersDataResponse dataDomainResponse;
                dataDomainResponse =
                    client.Get <GetAllCareManagersDataResponse>(url);

                if (dataDomainResponse != null && dataDomainResponse.Contacts != null)
                {
                    contactList = new List <Contact>();
                    List <ContactData> contactDataList = dataDomainResponse.Contacts;
                    foreach (ContactData cd in contactDataList)
                    {
                        var contact = new Contact
                        {
                            Id            = cd.Id,
                            UserId        = cd.UserId,
                            PreferredName = cd.PreferredName,
                            FirstName     = cd.FirstName,
                            LastName      = cd.LastName,
                            IsUser        = !string.IsNullOrEmpty(cd.UserId) || cd.FirstName == "System",
                            IsPatient     = !string.IsNullOrEmpty(cd.PatientId)
                        };
                        NGUtils.SetContactPreferredName(contact);
                        contactList.Add(contact);
                    }
                }
            }
            catch (WebServiceException wse)
            {
                throw new WebServiceException("AD:GetCareManagers()::" + wse.Message, wse.InnerException);
            }
            return(contactList);
        }
Ejemplo n.º 7
0
        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);
            }
        }