public static IMongoQuery ExpressionQueryBuilder(Interface.APIExpression expression) { IMongoQuery mQuery = null; 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); } return(mQuery); }
public Tuple <string, IEnumerable <object> > Select(Interface.APIExpression expression) { IMongoQuery mQuery = null; List <object> patViews = 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 (PatientMongoContext ctx = new PatientMongoContext(_dbName)) { List <MECohortPatientView> cpvs = ctx.CohortPatientViews.Collection.Find(mQuery).ToList(); if (cpvs != null) { cpvs.ForEach(cpv => { patViews.Add(new CohortPatientViewData { Id = cpv.Id.ToString(), LastName = cpv.LastName, PatientID = cpv.PatientID.ToString(), SearchFields = PatientsUtils.GetSearchFields(cpv.SearchFields), Version = cpv.Version }); }); } } return(new Tuple <string, IEnumerable <object> >(expression.ExpressionID, patViews)); }
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); } }