Ejemplo n.º 1
0
        public GetStepResponseResponse GetStepResponse(GetStepResponseRequest request)
        {
            try
            {
                GetStepResponseResponse response = new GetStepResponseResponse();

                IProgramRepository repo = Factory.GetRepository(request, RepositoryType.PatientProgramResponse); //.GetPatientProgramStepResponseRepository(request);

                MEPatientProgramResponse result = repo.FindByID(request.ResponseId) as MEPatientProgramResponse;

                if (result != null)
                {
                    response.StepResponse = new StepResponse
                    {
                        Id         = result.Id.ToString(),
                        NextStepId = result.NextStepId.ToString(),
                        Nominal    = result.Nominal,
                        Order      = result.Order,
                        Required   = result.Required,
                        Spawn      = DTOUtils.GetResponseSpawnElement(result.Spawn),
                        StepId     = result.StepId.ToString(),
                        Text       = result.Text,
                        Value      = result.Value
                    };
                }

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:DataProgramManager:GetStepResponse()::" + ex.Message, ex.InnerException);
            }
        }
        public Tuple <string, IEnumerable <object> > Select(Interface.APIExpression expression)
        {
            try
            {
                IMongoQuery   mQuery  = null;
                List <object> patList = new List <object>();

                List <SelectExpression> selectExpressions = expression.Expressions.ToList();
                selectExpressions.Where(s => s.GroupID == 1).OrderBy(o => o.ExpressionOrder).ToList();

                SelectExpressionGroupType groupType = SelectExpressionGroupType.AND;

                if (selectExpressions.Count > 0)
                {
                    IList <IMongoQuery> queries = new List <IMongoQuery>();
                    for (int i = 0; i < selectExpressions.Count; i++)
                    {
                        groupType = selectExpressions[0].NextExpressionType;

                        IMongoQuery query = SelectExpressionHelper.ApplyQueryOperators(selectExpressions[i].Type, selectExpressions[i].FieldName, selectExpressions[i].Value);
                        if (query != null)
                        {
                            queries.Add(query);
                        }
                    }

                    mQuery = SelectExpressionHelper.BuildQuery(groupType, queries);
                }

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    //var findcp = Query<MEPatientProgram>.EQ(b => b.Id, ObjectId.Parse(request.PatientProgramId));
                    //MEPatientProgram cp = ctx.PatientPrograms.Collection.Find(findcp).FirstOrDefault();
                    List <MEPatientProgram> cps = ctx.PatientPrograms.Collection.Find(mQuery).ToList();

                    if (cps != null)
                    {
                        cps.ForEach(cp => patList.Add(new ProgramDetail
                        {
                            Id                = cp.Id.ToString(),
                            Client            = cp.Client != null ? cp.Client.ToString() : null,
                            ContractProgramId = cp.ContractProgramId.ToString(),
                            Description       = cp.Description,
                            EndDate           = cp.EndDate,
                            AssignBy          = cp.AssignedBy.ToString(),
                            AssignDate        = cp.AssignedOn,
                            Completed         = cp.Completed,
                            CompletedBy       = cp.CompletedBy,
                            DateCompleted     = cp.DateCompleted,
                            ElementState      = (int)cp.State,
                            StateUpdatedOn    = cp.StateUpdatedOn,
                            Enabled           = cp.Enabled,
                            Next              = cp.Next != null ? cp.Next.ToString() : string.Empty,
                            Order             = cp.Order,
                            Previous          = cp.Previous != null ? cp.Previous.ToString() : string.Empty,
                            SourceId          = cp.SourceId.ToString(),
                            SpawnElement      = DTOUtils.GetResponseSpawnElement(cp.Spawn),
                            Modules           = DTOUtils.GetModules(cp.Modules, _dbName, this.UserId),
                            Name              = cp.Name,
                            PatientId         = cp.PatientId.ToString(),
                            // ProgramState = (int)cp.ProgramState, depricated - Use Element state instead.
                            ShortName = cp.ShortName,
                            StartDate = cp.StartDate,
                            Status    = (int)cp.Status,
                            Version   = cp.Version
                        }));
                    }
                }

                return(new Tuple <string, IEnumerable <object> >(expression.ExpressionID, patList));
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:Select()::" + ex.Message, ex.InnerException);
            }
        }