Пример #1
0
        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);
            }
        }