Exemplo n.º 1
0
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                Schedule todoTemp = null;
                ToDoData todo     = null;

                if (!PatientToDoExists(arg, pe.ElementId))
                {
                    try
                    {
                        // get template todo from schedule endpoint
                        todoTemp = EndpointUtil.GetScheduleToDoById(pe.ElementId, userId, arg.DomainRequest);
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException(ex.Message);
                    }

                    var prog = new System.Collections.Generic.List <string>();
                    if (arg.Program != null)
                    {
                        prog.Add(arg.Program.Id);
                    }

                    string patientId = null;
                    if (arg.Program != null)
                    {
                        patientId = arg.Program.PatientId;
                    }

                    try
                    {
                        todo = new ToDoData
                        {
                            SourceId    = todoTemp.Id,
                            Title       = todoTemp.Title,
                            CategoryId  = todoTemp.CategoryId,
                            CreatedById = userId,
                            StatusId    = todoTemp.StatusId,
                            Description = todoTemp.Description,
                            PriorityId  = todoTemp.PriorityId,
                            DueDate     = HandleDueDate(todoTemp.DueDateRange),
                            StartTime   = todoTemp.StartTime,
                            Duration    = todoTemp.Duration,
                            PatientId   = patientId,
                            ProgramIds  = prog,
                            CreatedOn   = DateTime.UtcNow
                        };

                        SetDefaultAssignment(userId, todoTemp, todo);

                        // modified for ENG-709
                        if (todo.StatusId == 2 || todo.StatusId == 4)
                        {
                            todo.ClosedDate = DateTime.UtcNow;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException("ToDoData Hydration Error." + ex.Message);
                    }

                    try
                    {
                        // register new todo
                        var result = EndpointUtil.PutInsertToDo(todo, arg.UserId, arg.DomainRequest);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message, ex.InnerException);
                    }
                }
                var spawnType = new SpawnType {
                    Type = _alertType.ToString()
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:ToDoActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }