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; }
        }
        /// <summary>
        /// Finds existing patient interventions that are in an open state. This is specifically used for spawn logic.
        /// </summary>
        /// <param name="patientGoalId">string</param>
        /// <param name="entityID">string</param>
        /// <returns>PatientInterventionData</returns>
        public object FindByTemplateId(string patientGoalId, string entityID)
        {
            PatientInterventionData interventionData = null;

            try
            {
                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>
                    {
                        Query.EQ(MEPatientIntervention.PatientGoalIdProperty, ObjectId.Parse(patientGoalId)),
                        Query.EQ(MEPatientIntervention.TemplateIdProperty, ObjectId.Parse(entityID)),
                        // Open = 1, Completed = 2, Removed =3
                        Query.EQ(MEPatientIntervention.StatusProperty, 1),
                        Query.EQ(MEPatientIntervention.DeleteFlagProperty, false),
                        Query.EQ(MEPatientIntervention.TTLDateProperty, BsonNull.Value)
                    };

                    var mQuery = Query.And(queries);
                    var b      = ctx.PatientInterventions.Collection.Find(mQuery).FirstOrDefault();

                    if (b != null)
                    {
                        interventionData = new PatientInterventionData
                        {
                            Id            = b.Id.ToString(),
                            Description   = b.Description,
                            PatientGoalId = b.PatientGoalId.ToString(),
                            CategoryId    = b.CategoryId == null ? null : b.CategoryId.ToString(),
                            AssignedToId  = b.AssignedToId == null ? null : b.AssignedToId.ToString(),
                            BarrierIds    = Helper.ConvertToStringList(b.BarrierIds),
                            StatusId      = ((int)b.Status),
                            StatusDate    = b.StatusDate,
                            StartDate     = b.StartDate,
                            DueDate       = b.DueDate,
                            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(interventionData.PatientGoalId))).SetFields(MEPatientGoal.PatientIdProperty, MEPatientGoal.NameProperty).FirstOrDefault();
                        if (mePG != null)
                        {
                            interventionData.PatientId = mePG.PatientId.ToString();
                            interventionData.GoalName  = mePG.Name;
                        }
                    }
                }
                return(interventionData);
            }
            catch (Exception) { throw; }
        }
 public IEnumerable <object> Find(string Id)
 {
     try
     {
         List <PatientInterventionData> interventionsDataList = null;
         List <IMongoQuery>             queries = new List <IMongoQuery>();
         queries.Add(Query.EQ(MEPatientIntervention.PatientGoalIdProperty, ObjectId.Parse(Id)));
         queries.Add(Query.EQ(MEPatientIntervention.DeleteFlagProperty, false));
         queries.Add(Query.EQ(MEPatientIntervention.TTLDateProperty, BsonNull.Value));
         IMongoQuery mQuery = Query.And(queries);
         using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
         {
             List <MEPatientIntervention> meInterventions = ctx.PatientInterventions.Collection.Find(mQuery).ToList();
             if (meInterventions != null)
             {
                 string goalName  = string.Empty;
                 string patientId = 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;
                     patientId = mePG.PatientId.ToString();
                 }
                 interventionsDataList = new List <PatientInterventionData>();
                 foreach (MEPatientIntervention b in meInterventions)
                 {
                     PatientInterventionData interventionData = new PatientInterventionData
                     {
                         Id            = b.Id.ToString(),
                         Description   = b.Description,
                         PatientGoalId = b.PatientGoalId.ToString(),
                         CategoryId    = b.CategoryId == null ? null : b.CategoryId.ToString(),
                         AssignedToId  = b.AssignedToId == null ? null : b.AssignedToId.ToString(),
                         BarrierIds    = Helper.ConvertToStringList(b.BarrierIds),
                         StatusId      = ((int)b.Status),
                         StatusDate    = b.StatusDate,
                         StartDate     = b.StartDate,
                         ClosedDate    = b.ClosedDate,
                         CreatedById   = b.RecordCreatedBy.ToString(),
                         DeleteFlag    = b.DeleteFlag,
                         GoalName      = goalName,
                         PatientId     = patientId
                     };
                     interventionsDataList.Add(interventionData);
                 }
             }
         }
         return(interventionsDataList);
     }
     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; }
 }
示例#5
0
        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; }
 }
示例#7
0
        public object FindByID(string entityID)
        {
            GoalData goalData = null;

            try
            {
                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEGoal.IdProperty, ObjectId.Parse(entityID)));
                    queries.Add(Query.EQ(MEGoal.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(MEGoal.TTLDateProperty, BsonNull.Value));
                    IMongoQuery mQuery = Query.And(queries);
                    MEGoal      meG    = ctx.Goals.Collection.Find(mQuery).FirstOrDefault();

                    goalData = AutoMapper.Mapper.Map <GoalData>(meG);
                }
                return(goalData);
            }
            catch (Exception) { throw; }
        }
        public object Initialize(object newEntity)
        {
            PutInitializeTaskRequest ptr  = (PutInitializeTaskRequest)newEntity;
            PatientTaskData          task = null;
            MEPatientTask            pat  = null;

            try
            {
                pat = new MEPatientTask(this.UserId)
                {
                    Id            = ObjectId.GenerateNewId(),
                    PatientGoalId = ObjectId.Parse(ptr.PatientGoalId),
                    TTLDate       = System.DateTime.UtcNow.AddDays(_initializeDays),
                    StatusDate    = DateTime.UtcNow,
                    DeleteFlag    = false
                                    //,
                                    //LastUpdatedOn = DateTime.UtcNow,
                                    //UpdatedBy = ObjectId.Parse(this.UserId)
                };

                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    ctx.PatientTasks.Collection.Insert(pat);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientTask.ToString(),
                                             pat.Id.ToString(),
                                             Common.DataAuditType.Insert,
                                             ptr.ContractNumber);

                    task = new PatientTaskData
                    {
                        Id = pat.Id.ToString()
                    };
                }
                return(task);
            }
            catch (Exception) { throw; }
        }
        public object FindByID(string entityID)
        {
            try
            {
                InterventionData   interventionData = null;
                List <IMongoQuery> queries          = new List <IMongoQuery>();
                queries.Add(Query.EQ(MEIntervention.IdProperty, ObjectId.Parse(entityID)));
                queries.Add(Query.EQ(MEIntervention.DeleteFlagProperty, false));
                queries.Add(Query.EQ(MEIntervention.TTLDateProperty, BsonNull.Value));
                IMongoQuery mQuery = Query.And(queries);

                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    MEIntervention b = ctx.Interventions.Collection.Find(mQuery).FirstOrDefault();
                    if (b != null)
                    {
                        interventionData = new InterventionData
                        {
                            Id             = b.Id.ToString(),
                            Description    = b.Description,
                            TemplateGoalId = b.TemplateGoalId.ToString(),
                            StartDateRange = b.StartDateRange,
                            CategoryId     = b.CategoryId == null ? null : b.CategoryId.ToString(),
                            AssignedToId   = b.AssignedToId == null ? null : b.AssignedToId.ToString(),
                            BarrierIds     = Helper.ConvertToStringList(b.BarrierIds),
                            StatusId       = ((int)b.Status),
                            StatusDate     = b.StatusDate,
                            StartDate      = b.StartDate,
                            //ClosedDate = b.ClosedDate,
                            CreatedById = b.RecordCreatedBy.ToString(),
                            DeleteFlag  = b.DeleteFlag
                        };
                    }
                }
                return(interventionData);
            }
            catch (Exception) { throw; }
        }
 public IEnumerable <object> Find(string Id)
 {
     try
     {
         List <PatientBarrierData> barriersDataList = null;
         List <IMongoQuery>        queries          = new List <IMongoQuery>();
         queries.Add(Query.EQ(MEPatientBarrier.PatientGoalIdProperty, ObjectId.Parse(Id)));
         queries.Add(Query.EQ(MEPatientBarrier.DeleteFlagProperty, false));
         queries.Add(Query.EQ(MEPatientBarrier.TTLDateProperty, BsonNull.Value));
         IMongoQuery mQuery = Query.And(queries);
         using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
         {
             List <MEPatientBarrier> meBarriers = ctx.PatientBarriers.Collection.Find(mQuery).ToList();
             if (meBarriers != null)
             {
                 barriersDataList = new List <PatientBarrierData>();
                 foreach (MEPatientBarrier b in meBarriers)
                 {
                     PatientBarrierData barrierData = new PatientBarrierData
                     {
                         Id            = b.Id.ToString(),
                         Name          = b.Name,
                         PatientGoalId = b.PatientGoalId.ToString(),
                         CategoryId    = b.CategoryId == null ? null : b.CategoryId.ToString(),
                         StatusId      = ((int)b.Status),
                         StatusDate    = b.StatusDate,
                         DeleteFlag    = b.DeleteFlag,
                         Details       = b.Details
                     };
                     barriersDataList.Add(barrierData);
                 }
             }
         }
         return(barriersDataList);
     }
     catch (Exception) { throw; }
 }
示例#11
0
        public object Initialize(object newEntity)
        {
            PutInitializeGoalDataRequest request = (PutInitializeGoalDataRequest)newEntity;
            PatientGoalData patientGoalData      = null;
            MEPatientGoal   mePg = null;

            try
            {
                mePg = new MEPatientGoal(this.UserId)
                {
                    Id        = ObjectId.GenerateNewId(),
                    PatientId = ObjectId.Parse(request.PatientId),
                    TTLDate   = System.DateTime.UtcNow.AddDays(_initializeDays)
                                //,
                                //LastUpdatedOn = DateTime.UtcNow,
                                //UpdatedBy = ObjectId.Parse(this.UserId)
                };

                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    ctx.PatientGoals.Collection.Insert(mePg);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientGoal.ToString(),
                                             mePg.Id.ToString(),
                                             Common.DataAuditType.Insert,
                                             request.ContractNumber);

                    patientGoalData = new PatientGoalData
                    {
                        Id = mePg.Id.ToString()
                    };
                }
                return(patientGoalData);
            }
            catch (Exception) { throw; }
        }
 public IEnumerable <object> FindByType(int TypeId)
 {
     try
     {
         List <CustomAttributeData> customAttributesList = null;
         List <IMongoQuery>         queries = new List <IMongoQuery>();
         queries.Add(Query.EQ(MEAttributeLibrary.TypeProperty, TypeId));
         queries.Add(Query.EQ(MEAttributeLibrary.DeleteFlagProperty, false));
         IMongoQuery mQuery = Query.And(queries);
         using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
         {
             List <MEAttributeLibrary> meAttributes = ctx.AttributesLibrary.Collection.Find(mQuery).ToList();
             if (meAttributes != null)
             {
                 customAttributesList = new List <CustomAttributeData>();
                 foreach (MEAttributeLibrary b in meAttributes)
                 {
                     CustomAttributeData data = new CustomAttributeData
                     {
                         Id          = b.Id.ToString(),
                         Name        = b.Name,
                         Type        = ((int)(b.Type)),
                         ControlType = ((int)(b.ControlType)),
                         Order       = b.Order,
                         Options     = b.Options,
                         Required    = b.Required
                     };
                     customAttributesList.Add(data);
                 }
                 customAttributesList = customAttributesList.OrderBy(o => o.Order).ToList();
             }
         }
         return(customAttributesList);
     }
     catch (Exception) { throw; };
 }
示例#13
0
        public IEnumerable <object> FindGoalsWithAProgramId(string entityId)
        {
            List <PatientGoalData> goals = null;

            try
            {
                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.In(MEPatientGoal.ProgramProperty, new List <BsonValue> {
                        BsonValue.Create(ObjectId.Parse(entityId))
                    }));
                    queries.Add(Query.EQ(MEPatientGoal.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(MEPatientGoal.TTLDateProperty, BsonNull.Value));
                    IMongoQuery          mQuery  = Query.And(queries);
                    List <MEPatientGoal> meGoals = ctx.PatientGoals.Collection.Find(mQuery).ToList();
                    if (meGoals != null && meGoals.Count > 0)
                    {
                        goals = new List <PatientGoalData>();
                        foreach (MEPatientGoal mePG in meGoals)
                        {
                            PatientGoalData data = new PatientGoalData
                            {
                                Id         = mePG.Id.ToString(),
                                PatientId  = mePG.PatientId.ToString(),
                                Name       = mePG.Name,
                                ProgramIds = Helper.ConvertToStringList(mePG.ProgramIds)
                            };
                            goals.Add(data);
                        }
                    }
                }
                return(goals);
            }
            catch (Exception ex) { throw ex; }
        }
示例#14
0
 public IEnumerable <object> Find(string Id)
 {
     try
     {
         List <PatientGoalViewData> goalsViewDataList = null;
         List <IMongoQuery>         queries           = new List <IMongoQuery>();
         queries.Add(Query.EQ(MEPatientGoal.PatientIdProperty, ObjectId.Parse(Id)));
         queries.Add(Query.EQ(MEPatientGoal.DeleteFlagProperty, false));
         queries.Add(Query.EQ(MEPatientGoal.TTLDateProperty, BsonNull.Value));
         IMongoQuery mQuery = Query.And(queries);
         using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
         {
             List <MEPatientGoal> meGoals = ctx.PatientGoals.Collection.Find(mQuery).ToList();
             if (meGoals != null)
             {
                 goalsViewDataList = new List <PatientGoalViewData>();
                 foreach (MEPatientGoal b in meGoals)
                 {
                     PatientGoalViewData goalViewData = new PatientGoalViewData
                     {
                         Id           = b.Id.ToString(),
                         PatientId    = b.PatientId.ToString(),
                         FocusAreaIds = Helper.ConvertToStringList(b.FocusAreaIds),
                         Name         = b.Name,
                         StatusId     = ((int)b.Status),
                         TemplateId   = b.TemplateId.ToString()
                     };
                     goalsViewDataList.Add(goalViewData);
                 }
                 goalsViewDataList = goalsViewDataList.OrderByDescending(o => o.Id).ToList();
             }
         }
         return(goalsViewDataList);
     }
     catch (Exception) { throw; }
 }
        public object Update(object entity)
        {
            bool result = false;
            PutUpdateBarrierRequest pbr = (PutUpdateBarrierRequest)entity;
            PatientBarrierData      pb  = pbr.Barrier;

            try
            {
                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    var q = MB.Query <MEPatientBarrier> .EQ(b => b.Id, ObjectId.Parse(pb.Id));

                    // Set the StatusDate to Now if the status is changed.
                    MEPatientBarrier existingPB = ctx.PatientBarriers.Collection.Find(q).SetFields(MEPatientBarrier.StatusProperty).FirstOrDefault();
                    if (existingPB != null)
                    {
                        if ((int)existingPB.Status != pb.StatusId)
                        {
                            pb.StatusDate = DateTime.UtcNow;
                        }
                    }

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEPatientBarrier.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                    uv.Add(MB.Update.Set(MEPatientBarrier.VersionProperty, pbr.Version));
                    uv.Add(MB.Update.Set(MEPatientBarrier.LastUpdatedOnProperty, System.DateTime.UtcNow));
                    if (pb.Name != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.NameProperty, pb.Name));
                    }
                    if (pb.Details != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.DetailProperty, pb.Details));
                    }
                    if (pb.PatientGoalId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.PatientGoalIdProperty, ObjectId.Parse(pb.PatientGoalId)));
                    }
                    if (pb.StatusId != 0)
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.StatusProperty, pb.StatusId));
                    }
                    if (pb.StatusDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.StatusDateProperty, pb.StatusDate));
                    }
                    if (pb.CategoryId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.CategoryProperty, ObjectId.Parse(pb.CategoryId)));
                    }
                    uv.Add(MB.Update.Set(MEPatientBarrier.DeleteFlagProperty, pb.DeleteFlag));
                    DataAuditType type;
                    if (pb.DeleteFlag)
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays)));
                        type = Common.DataAuditType.Delete;
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientBarrier.TTLDateProperty, BsonNull.Value));
                        type = Common.DataAuditType.Update;
                    }
                    IMongoUpdate update = MB.Update.Combine(uv);

                    ctx.PatientBarriers.Collection.Update(q, update);

                    AuditHelper.LogDataAudit(pbr.UserId,
                                             MongoCollectionName.PatientBarrier.ToString(),
                                             pb.Id.ToString(),
                                             type,
                                             pbr.ContractNumber);
                    result = true;
                }
                return(result as object);
            }
            catch (Exception ex) { throw new Exception("PatientGoalDD:MongoPatientBarrierRepository:Update()" + ex.Message, ex.InnerException); }
        }
        public IEnumerable <object> Search(object request, List <string> patientGoalIds)
        {
            List <PatientInterventionData>     list        = null;
            GetPatientInterventionsDataRequest dataRequest = (GetPatientInterventionsDataRequest)request;

            try
            {
                using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientIntervention.DeleteFlagProperty, false));
                    if (!string.IsNullOrEmpty(dataRequest.AssignedToId))
                    {
                        queries.Add(Query.EQ(MEPatientIntervention.AssignedToProperty, ObjectId.Parse(dataRequest.AssignedToId)));
                    }
                    if (!string.IsNullOrEmpty(dataRequest.CreatedById))
                    {
                        queries.Add(Query.EQ(MEPatientIntervention.RecordCreatedByProperty, ObjectId.Parse(dataRequest.CreatedById)));
                    }
                    if (dataRequest.StatusIds != null && dataRequest.StatusIds.Count > 0)
                    {
                        queries.Add(Query.In(MEPatientIntervention.StatusProperty, new BsonArray(dataRequest.StatusIds)));
                    }
                    if (patientGoalIds != null && patientGoalIds.Count > 0)
                    {
                        List <BsonValue> bsonList = Helper.ConvertToBsonValueList(patientGoalIds);
                        queries.Add(Query.In(MEPatientIntervention.PatientGoalIdProperty, bsonList));
                    }
                    IMongoQuery mQuery = Query.And(queries);
                    List <MEPatientIntervention> meInterventions = null;
                    meInterventions = ctx.PatientInterventions.Collection.Find(mQuery).ToList();

                    if (meInterventions != null && meInterventions.Count > 0)
                    {
                        //We get the Patient Goals for the found interventions
                        List <MEPatientGoal> mePatientGoals = null;
                        mQuery         = Query.In(MEPatientGoal.IdProperty, meInterventions.Select(x => BsonValue.Create(x.PatientGoalId)).ToList());
                        mePatientGoals = ctx.PatientGoals.Collection.Find(mQuery).ToList();

                        list = new List <PatientInterventionData>();
                        foreach (MEPatientIntervention b in meInterventions)
                        {
                            PatientInterventionData interventionData = new PatientInterventionData
                            {
                                Id            = b.Id.ToString(),
                                Description   = b.Description,
                                PatientGoalId = b.PatientGoalId.ToString(),
                                CategoryId    = b.CategoryId == null ? null : b.CategoryId.ToString(),
                                AssignedToId  = b.AssignedToId == null ? null : b.AssignedToId.ToString(),
                                BarrierIds    = Helper.ConvertToStringList(b.BarrierIds),
                                StatusId      = ((int)b.Status),
                                StatusDate    = b.StatusDate,
                                StartDate     = b.StartDate,
                                DueDate       = b.DueDate,
                                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(interventionData.PatientGoalId))).SetFields(MEPatientGoal.PatientIdProperty, MEPatientGoal.NameProperty).FirstOrDefault();
                            var mePG = mePatientGoals.FirstOrDefault(x => x.Id == b.PatientGoalId);
                            if (mePG != null)
                            {
                                interventionData.PatientId = mePG.PatientId.ToString();
                                interventionData.GoalName  = mePG.Name;
                            }
                            list.Add(interventionData);
                        }
                    }
                }
                return(list);
            }
            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; }
        }
示例#19
0
        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; }
        }