public IEnumerable <object> Search(object request, List <string> patientGoalIds) { List <PatientTaskData> list = null; GetPatientTasksDataRequest dataRequest = (GetPatientTasksDataRequest)request; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientTask.DeleteFlagProperty, false)); if (dataRequest.StatusIds != null && dataRequest.StatusIds.Count > 0) { queries.Add(Query.In(MEPatientTask.StatusProperty, new BsonArray(dataRequest.StatusIds))); } if (patientGoalIds != null && patientGoalIds.Count > 0) { List <BsonValue> bsonList = Helper.ConvertToBsonValueList(patientGoalIds); queries.Add(Query.In(MEPatientTask.PatientGoalIdProperty, bsonList)); } IMongoQuery mQuery = Query.And(queries); List <MEPatientTask> meTasks = null; meTasks = ctx.PatientTasks.Collection.Find(mQuery).ToList(); if (meTasks != null && meTasks.Count > 0) { list = new List <PatientTaskData>(); foreach (MEPatientTask t in meTasks) { PatientTaskData taskData = new PatientTaskData { Id = t.Id.ToString(), TargetValue = t.TargetValue, PatientGoalId = t.PatientGoalId.ToString(), StatusId = ((int)t.Status), TargetDate = t.TargetDate, BarrierIds = Helper.ConvertToStringList(t.BarrierIds), Description = t.Description, StatusDate = t.StatusDate, StartDate = t.StartDate, CustomAttributes = DTOUtil.GetCustomAttributeIdAndValues(t.Attributes), ClosedDate = t.ClosedDate, CreatedById = t.RecordCreatedBy.ToString(), DeleteFlag = t.DeleteFlag, Details = t.Details }; var mePG = ctx.PatientGoals.Collection.Find(Query.EQ(MEPatientGoal.IdProperty, ObjectId.Parse(taskData.PatientGoalId))).SetFields(MEPatientGoal.NameProperty).FirstOrDefault(); if (mePG != null) { taskData.GoalName = mePG.Name; } list.Add(taskData); } } } return(list); } catch (Exception) { throw; } }
public object FindByTemplateId(string patientGoalId, string entityID) { PatientTaskData taskData = null; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <IMongoQuery> queries = new List <IMongoQuery> { Query.EQ(MEPatientTask.PatientGoalIdProperty, ObjectId.Parse(patientGoalId)), Query.EQ(MEPatientTask.TemplateIdProperty, ObjectId.Parse(entityID)), Query.In(MEPatientTask.StatusProperty, new BsonArray { 1, 3 }), Query.EQ(MEPatientTask.DeleteFlagProperty, false), Query.EQ(MEPatientTask.TTLDateProperty, BsonNull.Value) }; var mQuery = Query.And(queries); var b = ctx.PatientTasks.Collection.Find(mQuery).FirstOrDefault(); if (b != null) { taskData = new PatientTaskData { Id = b.Id.ToString(), Description = b.Description, PatientGoalId = b.PatientGoalId.ToString(), BarrierIds = Helper.ConvertToStringList(b.BarrierIds), StatusId = ((int)b.Status), StatusDate = b.StatusDate, StartDate = b.StartDate, TargetValue = b.TargetValue, CustomAttributes = DTOUtil.GetCustomAttributeIdAndValues(b.Attributes), TargetDate = b.TargetDate, ClosedDate = b.ClosedDate, CreatedById = b.RecordCreatedBy.ToString(), DeleteFlag = b.DeleteFlag, Details = b.Details }; var mePG = ctx.PatientGoals.Collection.Find(Query.EQ(MEPatientGoal.IdProperty, ObjectId.Parse(taskData.PatientGoalId))).SetFields(MEPatientGoal.PatientIdProperty, MEPatientGoal.NameProperty).FirstOrDefault(); if (mePG != null) { taskData.GoalName = mePG.Name; } } } return(taskData); } catch (Exception) { throw; } }
public IEnumerable <object> Find(string Id) { try { List <PatientTaskData> tasksDataList = null; List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientTask.PatientGoalIdProperty, ObjectId.Parse(Id))); queries.Add(Query.EQ(MEPatientTask.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientTask.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <MEPatientTask> meTasks = ctx.PatientTasks.Collection.Find(mQuery).ToList(); if (meTasks != null) { string goalName = string.Empty; var mePG = ctx.PatientGoals.Collection.Find(Query.EQ(MEPatientGoal.IdProperty, ObjectId.Parse(Id))).SetFields(MEPatientGoal.NameProperty).FirstOrDefault(); if (mePG != null) { goalName = mePG.Name; } tasksDataList = new List <PatientTaskData>(); foreach (MEPatientTask t in meTasks) { PatientTaskData taskData = new PatientTaskData { Id = t.Id.ToString(), TargetValue = t.TargetValue, PatientGoalId = t.PatientGoalId.ToString(), StatusId = ((int)t.Status), TargetDate = t.TargetDate, BarrierIds = Helper.ConvertToStringList(t.BarrierIds), Description = t.Description, StatusDate = t.StatusDate, StartDate = t.StartDate, CustomAttributes = DTOUtil.GetCustomAttributeIdAndValues(t.Attributes), ClosedDate = t.ClosedDate, CreatedById = t.RecordCreatedBy.ToString(), DeleteFlag = t.DeleteFlag, GoalName = goalName, Details = t.Details }; tasksDataList.Add(taskData); } } } return(tasksDataList); } catch (Exception) { throw; } }
public object FindByTemplateId(string patientId, string entityID) { PatientGoalData goalData = null; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <IMongoQuery> queries = new List <IMongoQuery> { Query.EQ(MEPatientGoal.PatientIdProperty, ObjectId.Parse(patientId)), Query.EQ(MEPatientGoal.TemplateIdProperty, ObjectId.Parse(entityID)), Query.In(MEPatientGoal.StatusProperty, new BsonArray { 1, 3 }), Query.EQ(MEPatientGoal.DeleteFlagProperty, false), Query.EQ(MEPatientGoal.TTLDateProperty, BsonNull.Value) }; var mQuery = Query.And(queries); var mePG = ctx.PatientGoals.Collection.Find(mQuery).FirstOrDefault(); if (mePG != null) { goalData = new PatientGoalData { Id = mePG.Id.ToString(), PatientId = mePG.PatientId.ToString(), TemplateId = mePG.TemplateId.ToString(), FocusAreaIds = Helper.ConvertToStringList(mePG.FocusAreaIds), Name = mePG.Name, SourceId = (mePG.SourceId == null) ? null : mePG.SourceId.ToString(), ProgramIds = Helper.ConvertToStringList(mePG.ProgramIds), TypeId = ((int)mePG.Type), StatusId = ((int)mePG.Status), StartDate = mePG.StartDate, EndDate = mePG.EndDate, TargetDate = mePG.TargetDate, TargetValue = mePG.TargetValue, CustomAttributes = DTOUtil.GetCustomAttributeIdAndValues(mePG.Attributes), Details = mePG.Details }; } } return(goalData); } catch (Exception) { throw; } }
public object FindByID(string entityID) { try { PatientTaskData taskData = null; List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientTask.IdProperty, ObjectId.Parse(entityID))); queries.Add(Query.EQ(MEPatientTask.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientTask.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { MEPatientTask t = ctx.PatientTasks.Collection.Find(mQuery).FirstOrDefault(); if (t != null) { taskData = new PatientTaskData { Id = t.Id.ToString(), TargetValue = t.TargetValue, PatientGoalId = t.PatientGoalId.ToString(), StatusId = ((int)t.Status), TargetDate = t.TargetDate, BarrierIds = Helper.ConvertToStringList(t.BarrierIds), Description = t.Description, StatusDate = t.StatusDate, StartDate = t.StartDate, CustomAttributes = DTOUtil.GetCustomAttributeIdAndValues(t.Attributes), ClosedDate = t.ClosedDate, CreatedById = t.RecordCreatedBy.ToString(), DeleteFlag = t.DeleteFlag, Details = t.Details }; var mePG = ctx.PatientGoals.Collection.Find(Query.EQ(MEPatientGoal.IdProperty, ObjectId.Parse(taskData.PatientGoalId))).SetFields(MEPatientGoal.NameProperty).FirstOrDefault(); if (mePG != null) { taskData.GoalName = mePG.Name; } } } return(taskData); } catch (Exception) { throw; } }
public object Update(object entity) { bool result = false; PutUpdateInterventionRequest ir = (PutUpdateInterventionRequest)entity; PatientInterventionData pi = ir.Intervention; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { var q = MB.Query <MEPatientIntervention> .EQ(b => b.Id, ObjectId.Parse(pi.Id)); // Set the StatusDate to Now if the status is changed. MEPatientIntervention existingPI = ctx.PatientInterventions.Collection.Find(q).SetFields(MEPatientIntervention.StatusProperty).FirstOrDefault(); if (existingPI != null) { if ((int)existingPI.Status != pi.StatusId) { pi.StatusDate = DateTime.UtcNow; } if ((pi.StatusId == (int)InterventionStatus.Removed || pi.StatusId == (int)InterventionStatus.Completed)) { if (existingPI.Status != (InterventionStatus)pi.StatusId) { pi.ClosedDate = DateTime.UtcNow; } } else { pi.ClosedDate = null; } } var uv = new List <MB.UpdateBuilder>(); uv.Add(MB.Update.Set(MEPatientIntervention.VersionProperty, ir.Version)); uv.Add(MB.Update.Set(MEPatientIntervention.LastUpdatedOnProperty, System.DateTime.UtcNow)); uv.Add(MB.Update.Set(MEPatientIntervention.UpdatedByProperty, ObjectId.Parse(this.UserId))); if (pi.TemplateId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.TemplateIdProperty, ObjectId.Parse(pi.TemplateId))); } if (pi.Description != null) { uv.Add(MB.Update.Set(MEPatientIntervention.DescriptionProperty, pi.Description)); } if (pi.Details != null) { uv.Add(MB.Update.Set(MEPatientIntervention.DetailProperty, pi.Details)); } if (pi.StartDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.StartDateProperty, pi.StartDate)); } else { uv.Add(MB.Update.Set(MEPatientIntervention.StartDateProperty, BsonNull.Value)); } if (pi.DueDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.DueDateProperty, pi.DueDate)); } else { uv.Add(MB.Update.Set(MEPatientIntervention.DueDateProperty, BsonNull.Value)); } if (pi.StatusDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.StatusDateProperty, pi.StatusDate)); } if (pi.StatusId != 0) { uv.Add(MB.Update.Set(MEPatientIntervention.StatusProperty, pi.StatusId)); } if (pi.CategoryId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.CategoryProperty, ObjectId.Parse(pi.CategoryId))); } if (pi.AssignedToId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.AssignedToProperty, ObjectId.Parse(pi.AssignedToId))); } if (pi.BarrierIds != null) { uv.Add(MB.Update.SetWrapped <List <ObjectId> >(MEPatientIntervention.BarriersProperty, DTOUtil.ConvertObjectId(pi.BarrierIds))); } if (pi.PatientGoalId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.PatientGoalIdProperty, ObjectId.Parse(pi.PatientGoalId))); } if (pi.ClosedDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.ClosedDateProperty, pi.ClosedDate)); } else { uv.Add(MB.Update.Set(MEPatientIntervention.ClosedDateProperty, BsonNull.Value)); } uv.Add(MB.Update.Set(MEPatientIntervention.DeleteFlagProperty, pi.DeleteFlag)); DataAuditType type; if (pi.DeleteFlag) { uv.Add(MB.Update.Set(MEPatientIntervention.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays))); type = Common.DataAuditType.Delete; } else { uv.Add(MB.Update.Set(MEPatientIntervention.TTLDateProperty, BsonNull.Value)); type = Common.DataAuditType.Update; } IMongoUpdate update = MB.Update.Combine(uv); ctx.PatientInterventions.Collection.Update(q, update); AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.PatientIntervention.ToString(), pi.Id.ToString(), type, ir.ContractNumber); result = true; } return(result as object); } catch (Exception) { throw; } }
public object Update(object entity) { bool result = false; PutUpdateTaskRequest ptr = (PutUpdateTaskRequest)entity; PatientTaskData pt = ptr.Task; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { var q = MB.Query <MEPatientTask> .EQ(b => b.Id, ObjectId.Parse(pt.Id)); // Set the StatusDate to Now if the status is changed. Set the ClosedDate depending on the Status. MEPatientTask existingPB = ctx.PatientTasks.Collection.Find(q).SetFields(MEPatientTask.StatusProperty).FirstOrDefault(); if (existingPB != null) { if ((int)existingPB.Status != pt.StatusId) { pt.StatusDate = DateTime.UtcNow; } if ((pt.StatusId == (int)GoalTaskStatus.Met || pt.StatusId == (int)GoalTaskStatus.Abandoned)) { if (existingPB.Status != (GoalTaskStatus)pt.StatusId) { pt.ClosedDate = DateTime.UtcNow; } } else { pt.ClosedDate = null; } } var uv = new List <MB.UpdateBuilder>(); uv.Add(MB.Update.Set(MEPatientTask.UpdatedByProperty, ObjectId.Parse(this.UserId))); uv.Add(MB.Update.Set(MEPatientTask.VersionProperty, ptr.Version)); uv.Add(MB.Update.Set(MEPatientTask.LastUpdatedOnProperty, System.DateTime.UtcNow)); if (pt.Description != null) { uv.Add(MB.Update.Set(MEPatientTask.DescriptionProperty, pt.Description)); } if (pt.Details != null) { uv.Add(MB.Update.Set(MEPatientTask.DetailProperty, pt.Details)); } if (pt.StartDate != null) { uv.Add(MB.Update.Set(MEPatientTask.StartDateProperty, pt.StartDate)); } else { uv.Add(MB.Update.Set(MEPatientTask.StartDateProperty, BsonNull.Value)); } if (pt.StatusDate != null) { uv.Add(MB.Update.Set(MEPatientTask.StatusDateProperty, pt.StatusDate)); } if (pt.StatusId != 0) { uv.Add(MB.Update.Set(MEPatientTask.StatusProperty, pt.StatusId)); } if (pt.TargetDate != null) { uv.Add(MB.Update.Set(MEPatientTask.TargetDateProperty, pt.TargetDate)); } else { uv.Add(MB.Update.Set(MEPatientTask.TargetDateProperty, BsonNull.Value)); } if (pt.TargetValue != null) { uv.Add(MB.Update.Set(MEPatientTask.TargetValueProperty, pt.TargetValue)); } if (pt.CustomAttributes != null) { uv.Add(MB.Update.SetWrapped <List <MAttribute> >(MEPatientTask.AttributesProperty, DTOUtil.GetAttributes(pt.CustomAttributes))); } if (pt.BarrierIds != null) { uv.Add(MB.Update.SetWrapped <List <ObjectId> >(MEPatientTask.BarriersProperty, DTOUtil.ConvertObjectId(pt.BarrierIds))); } if (pt.ClosedDate != null) { uv.Add(MB.Update.Set(MEPatientTask.ClosedDateProperty, pt.ClosedDate)); } else { uv.Add(MB.Update.Set(MEPatientTask.ClosedDateProperty, BsonNull.Value)); } uv.Add(MB.Update.Set(MEPatientTask.DeleteFlagProperty, pt.DeleteFlag)); if (pt.TemplateId != null) { uv.Add(MB.Update.Set(MEPatientTask.TemplateIdProperty, ObjectId.Parse(pt.TemplateId))); } DataAuditType type; if (pt.DeleteFlag) { uv.Add(MB.Update.Set(MEPatientTask.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays))); type = Common.DataAuditType.Delete; } else { uv.Add(MB.Update.Set(MEPatientTask.TTLDateProperty, BsonNull.Value)); type = Common.DataAuditType.Update; } IMongoUpdate update = MB.Update.Combine(uv); ctx.PatientTasks.Collection.Update(q, update); AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.PatientTask.ToString(), pt.Id, type, ptr.ContractNumber); result = true; } return(result as object); } catch (Exception) { throw; } }
public object Update(object entity) { bool result = false; PutUpdateGoalDataRequest pgr = (PutUpdateGoalDataRequest)entity; PatientGoalData pt = pgr.Goal; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { var q = MB.Query <MEPatientGoal> .EQ(b => b.Id, ObjectId.Parse(pt.Id)); var uv = new List <MB.UpdateBuilder>(); uv.Add(MB.Update.Set(MEPatientGoal.TTLDateProperty, BsonNull.Value)); uv.Add(MB.Update.Set(MEPatientGoal.DeleteFlagProperty, false)); uv.Add(MB.Update.Set(MEPatientGoal.VersionProperty, pgr.Version)); uv.Add(MB.Update.Set(MEPatientGoal.LastUpdatedOnProperty, DateTime.UtcNow)); uv.Add(MB.Update.Set(MEPatientGoal.UpdatedByProperty, ObjectId.Parse(this.UserId))); if (pt.PatientId != null) { uv.Add(MB.Update.Set(MEPatientGoal.PatientIdProperty, ObjectId.Parse(pt.PatientId))); } if (pt.FocusAreaIds != null) { uv.Add(MB.Update.SetWrapped <List <ObjectId> >(MEPatientGoal.FocusAreaProperty, DTOUtil.ConvertObjectId(pt.FocusAreaIds))); } if (pt.Name != null) { uv.Add(MB.Update.Set(MEPatientGoal.NameProperty, pt.Name)); } if (pt.SourceId != null) { uv.Add(MB.Update.Set(MEPatientGoal.SourceProperty, ObjectId.Parse(pt.SourceId))); } if (pt.ProgramIds != null) { uv.Add(MB.Update.SetWrapped <List <ObjectId> >(MEPatientGoal.ProgramProperty, DTOUtil.ConvertObjectId(pt.ProgramIds))); } if (pt.TypeId != null) { uv.Add(MB.Update.Set(MEPatientGoal.TypeProperty, pt.TypeId)); } if (pt.StatusId != 0) { uv.Add(MB.Update.Set(MEPatientGoal.StatusProperty, pt.StatusId)); } if (pt.TargetValue != null) { uv.Add(MB.Update.Set(MEPatientGoal.TargetValueProperty, pt.TargetValue)); } if (pt.StartDate != null) { uv.Add(MB.Update.Set(MEPatientGoal.StartDateProperty, pt.StartDate)); } else { uv.Add(MB.Update.Set(MEPatientGoal.StartDateProperty, BsonNull.Value)); } if (pt.EndDate != null) { uv.Add(MB.Update.Set(MEPatientGoal.EndDateProperty, pt.EndDate)); } else { uv.Add(MB.Update.Set(MEPatientGoal.EndDateProperty, BsonNull.Value)); } if (pt.TargetDate != null) { uv.Add(MB.Update.Set(MEPatientGoal.TargetDateProperty, pt.TargetDate)); } else { uv.Add(MB.Update.Set(MEPatientGoal.TargetDateProperty, BsonNull.Value)); } if (pt.CustomAttributes != null) { uv.Add(MB.Update.SetWrapped <List <MAttribute> >(MEPatientGoal.AttributesProperty, DTOUtil.GetAttributes(pt.CustomAttributes))); } IMongoUpdate update = MB.Update.Combine(uv); ctx.PatientGoals.Collection.Update(q, update); AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.PatientGoal.ToString(), pt.Id.ToString(), Common.DataAuditType.Update, pgr.ContractNumber); result = true; } return(result as object); } catch (Exception) { throw; } }