Esempio n. 1
0
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                #region

                //Goal goalTemp = null;
                //Intervention interventionTemp = null;
                //PatientIntervention patientInt = null;
                //PatientIntervention newPInt = null;
                //ToDoData todo = null;

                //try
                //{
                //    // get patientintervention template by id
                //    interventionTemp = EndpointUtil.GetGoalById(pe.ElementId, userId, arg.DomainRequest);
                //}
                //catch(Exception ex)
                //{
                //    throw new ArgumentException(ex.Message);
                //}

                //try
                //{
                //    // get template Goal from Goal endpoint
                //    patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(pe.ElementId, arg.PatientId, userId, arg.DomainRequest);
                //}
                //catch (Exception ex)
                //{
                //    throw new ArgumentException(ex.Message);
                //}

                //try
                //{
                //    //Open = 1, Met = 2, NotMet =3, Abandoned =4
                //    if (patientGoal == null || (patientGoal.StatusId == 2 || patientGoal.StatusId == 4))
                //    {
                //        newPGoal = Mapper.Map<PatientGoal>(goalTemp);
                //        newPGoal.ProgramIds = new List<string> {arg.Program.Id};
                //        newPGoal.PatientId = arg.PatientId;
                //        newPGoal.StatusId = 1;

                //        try
                //        {
                //            // register new patientobservation
                //            // initialize patientgoal and get id
                //            var iPG = GoalsEndpointUtil.GetInitialGoalRequest(new GetInitializeGoalRequest
                //            {
                //                Context = "NG",
                //                ContractNumber = arg.DomainRequest.ContractNumber,
                //                PatientId = arg.PatientId,
                //                Token = arg.DomainRequest.Token,
                //                UserId = arg.DomainRequest.UserId,
                //                Version = arg.DomainRequest.Version
                //            });

                //            // update patientgoal
                //            if (iPG == null)
                //                throw new ArgumentException("Failed to Initialize patient goal");

                //            newPGoal.Id = iPG.Id;

                //            GoalsEndpointUtil.PostUpdateGoalRequest(new PostPatientGoalRequest
                //            {
                //                ContractNumber = arg.DomainRequest.ContractNumber,
                //                Goal = newPGoal,
                //                PatientGoalId = iPG.Id,
                //                PatientId = arg.PatientId,
                //                Token = arg.DomainRequest.Token,
                //                UserId = arg.DomainRequest.UserId,
                //                Version = arg.DomainRequest.Version
                //            });
                //        }
                //        catch (Exception ex)
                //        {
                //            throw new Exception(ex.Message, ex.InnerException);
                //        }
                //    }
                //}
                //catch (Exception ex)
                //{
                //    throw new ArgumentException("PatientGoal Hydration Error." + ex.Message);
                //}

                #endregion

                Task        taskTemplate        = null;
                Goal        goalTemplate        = null;
                PatientGoal patientGoal         = null;
                PatientGoal newPGoal            = null;
                PatientTask existingPatientTask = null;

                // get template intervention
                taskTemplate = EndpointUtil.GetTaskById(pe.ElementId, userId, arg.DomainRequest);

                // get template goal
                goalTemplate = EndpointUtil.GetGoalById(taskTemplate.TemplateGoalId, userId, arg.DomainRequest);

                // find if patientgoal exists
                patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(goalTemplate.Id, arg.PatientId, userId, arg.DomainRequest);

                if (patientGoal != null)
                {
                    // find if patientintervention exists
                    existingPatientTask = EndpointUtil.GetOpenNotMetPatientTaskByTemplateId(patientGoal.Id,
                                                                                            taskTemplate.Id, arg.PatientId, userId, arg.DomainRequest);
                }

                PatientTask   pTsk  = existingPatientTask;
                PatientGoal   pGoal = patientGoal;
                List <object> items = null;
                if (InsertTaskAllowed(existingPatientTask))
                {
                    // check to see that goal exists
                    if (InsertPatientGoalAllowed(patientGoal))
                    {
                        // 1) insert patient goal
                        pGoal = PlanUtils.InsertPatientGoal(arg, goalTemplate);
                    }
                    // insert patient intervention
                    pTsk  = PlanUtils.InsertPatientTask(arg, pGoal, taskTemplate);
                    items = CreateItemsBag(pTsk, pGoal);
                }

                var spawnType = new SpawnType {
                    Type = _alertType.ToString(), Tag = items
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:TaskActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                Intervention        interventionTemplate        = null;
                Goal                goalTemplate                = null;
                PatientGoal         patientGoal                 = null;
                PatientGoal         newPGoal                    = null;
                PatientIntervention existingPatientIntervention = null;

                try
                {
                    // get template intervention
                    interventionTemplate = EndpointUtil.GetInterventionById(pe.ElementId, userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new Exception("AD:InterventionActivationRule:GetInterventionById()::" + ex.Message, ex.InnerException);
                }

                try
                {
                    // get template goal
                    goalTemplate = EndpointUtil.GetGoalById(interventionTemplate.TemplateGoalId, userId,
                                                            arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new Exception("AD:InterventionActivationRule:GetGoalById()::" + ex.Message, ex.InnerException);
                }

                try
                {
                    // find if patientgoal exists
                    patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(goalTemplate.Id, arg.PatientId,
                                                                                    userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new Exception("AD:InterventionActivationRule:GetOpenNotMetPatientGoalByTemplateId()::" + ex.Message, ex.InnerException);
                }

                if (patientGoal != null)
                {
                    try
                    {
                        // find if patientintervention exists
                        existingPatientIntervention =
                            EndpointUtil.GetOpenNotMetPatientInterventionByTemplateId(patientGoal.Id,
                                                                                      interventionTemplate.Id, arg.PatientId, userId, arg.DomainRequest);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(
                                  "AD:InterventionActivationRule:GetOpenNotMetPatientInterventionByTemplateId()::" +
                                  ex.Message, ex.InnerException);
                    }
                }

                PatientIntervention pIntr = existingPatientIntervention;
                PatientGoal         pGoal = patientGoal;
                List <object>       items = null;
                if (InsertInterventionAllowed(pIntr))
                {
                    // check to see that goal exists
                    if (InsertPatientGoalAllowed(patientGoal))
                    {
                        // 1) insert patient goal
                        pGoal = PlanUtils.InsertPatientGoal(arg, goalTemplate);
                    }

                    pIntr = PlanUtils.InsertPatientIntervention(arg, pGoal, interventionTemplate);

                    items = CreateItemsBag(pIntr, pGoal);
                }

                var spawnType = new SpawnType {
                    Type = _alertType.ToString(), Tag = items
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:InterventionActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }
Esempio n. 3
0
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                Goal        goalTemp    = null;
                PatientGoal patientGoal = null;
                PatientGoal newPGoal    = null;
                ToDoData    todo        = null;

                try
                {
                    // get template Goal from Goal endpoint
                    goalTemp = EndpointUtil.GetGoalById(pe.ElementId, userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(ex.Message);
                }

                try
                {
                    // get patient Goal from template id
                    // this will only return patientgoals that are open or notmet state
                    patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(pe.ElementId, arg.PatientId, userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(ex.Message);
                }

                try
                {
                    //Open = 1, Met = 2, NotMet =3, Abandoned =4
                    if (patientGoal == null) // || (patientGoal.StatusId == 2 || patientGoal.StatusId == 4))
                    {
                        newPGoal            = Mapper.Map <PatientGoal>(goalTemp);
                        newPGoal.ProgramIds = new List <string> {
                            arg.Program.Id
                        };
                        newPGoal.PatientId  = arg.PatientId;
                        newPGoal.TemplateId = goalTemp.Id;
                        newPGoal.StartDate  = PlanUtils.HandleDueDate(goalTemp.StartDateRange);
                        newPGoal.TargetDate = PlanUtils.HandleDueDate(goalTemp.TargetDateRange);
                        newPGoal.StatusId   = 1;

                        try
                        {
                            // initialize patientgoal and get id
                            var iPG = GoalsEndpointUtil.GetInitialGoalRequest(new GetInitializeGoalRequest
                            {
                                Context        = "NG",
                                ContractNumber = arg.DomainRequest.ContractNumber,
                                PatientId      = arg.PatientId,
                                Token          = arg.DomainRequest.Token,
                                UserId         = arg.DomainRequest.UserId,
                                Version        = arg.DomainRequest.Version
                            });

                            // update patientgoal
                            if (iPG == null)
                            {
                                throw new ArgumentException("Failed to Initialize patient goal");
                            }

                            newPGoal.Id = iPG.Id;

                            GoalsEndpointUtil.PostUpdateGoalRequest(new PostPatientGoalRequest
                            {
                                ContractNumber = arg.DomainRequest.ContractNumber,
                                Goal           = newPGoal,
                                PatientGoalId  = iPG.Id,
                                PatientId      = arg.PatientId,
                                Token          = arg.DomainRequest.Token,
                                UserId         = arg.DomainRequest.UserId,
                                Version        = arg.DomainRequest.Version
                            });
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message, ex.InnerException);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("PatientGoal Hydration Error." + ex.Message);
                }


                var spawnType = new SpawnType {
                    Type = _alertType.ToString(), Tag = new List <object> {
                        newPGoal
                    }
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:ToDoActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }