Beispiel #1
0
        public object FindByExternalRecordId(string externalRecordId)
        {
            ToDoData data = null;

            try
            {
                using (SchedulingMongoContext ctx = new SchedulingMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(METoDo.ExternalRecordIdProperty, externalRecordId));
                    queries.Add(Query.EQ(METoDo.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(METoDo.TTLDateProperty, BsonNull.Value));
                    IMongoQuery mQuery = Query.And(queries);
                    METoDo      mePN   = ctx.ToDos.Collection.Find(mQuery).FirstOrDefault();
                    if (mePN != null)
                    {
                        data = new ToDoData
                        {
                            Id = mePN.Id.ToString(),
                        };
                    }
                }
                return(data);
            }
            catch (Exception) { throw; }
        }
Beispiel #2
0
        public object FindByID(string entityID, bool includeDeletedToDo)
        {
            ToDoData todoData = null;

            try
            {
                using (SchedulingMongoContext ctx = new SchedulingMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    if (!includeDeletedToDo)
                    {
                        queries.Add(Query.EQ(METoDo.DeleteFlagProperty, false));
                    }
                    queries.Add(Query.EQ(METoDo.IdProperty, ObjectId.Parse(entityID)));
                    IMongoQuery mQuery = Query.And(queries);
                    METoDo      meToDo = ctx.ToDos.Collection.Find(mQuery).FirstOrDefault();
                    if (meToDo != null)
                    {
                        todoData = new ToDoData
                        {
                            AssignedToId     = meToDo.AssignedToId == null ? string.Empty : meToDo.AssignedToId.ToString(),
                            CategoryId       = meToDo.Category.ToString(),
                            ClosedDate       = meToDo.ClosedDate,
                            CreatedById      = meToDo.RecordCreatedBy.ToString(),
                            CreatedOn        = meToDo.RecordCreatedOn,
                            Description      = meToDo.Description,
                            DueDate          = meToDo.DueDate,
                            StartTime        = meToDo.StartTime,
                            Duration         = meToDo.Duration,
                            Id               = meToDo.Id.ToString(),
                            PatientId        = meToDo.PatientId == null ? string.Empty : meToDo.PatientId.ToString(),
                            PriorityId       = (int)meToDo.Priority,
                            ProgramIds       = Helper.ConvertToStringList(meToDo.ProgramIds),
                            StatusId         = (int)meToDo.Status,
                            Title            = meToDo.Title,
                            UpdatedOn        = meToDo.LastUpdatedOn,
                            ExternalRecordId = meToDo.ExternalRecordId,
                            DeleteFlag       = meToDo.DeleteFlag
                        };
                    }
                }
                return(todoData);
            }
            catch (Exception) { throw; }
        }
Beispiel #3
0
        public object InsertAll(List <object> entities)
        {
            BulkInsertResult result        = new BulkInsertResult();
            List <string>    insertedIds   = new List <string>();
            List <string>    errorMessages = new List <string>();

            try
            {
                using (SchedulingMongoContext ctx = new SchedulingMongoContext(_dbName))
                {
                    var bulk = ctx.ToDos.Collection.InitializeUnorderedBulkOperation();
                    foreach (ToDoData t in entities)
                    {
                        METoDo meToDo = new METoDo(this.UserId, t.CreatedOn)
                        {
                            Status       = (Status)t.StatusId,
                            Priority     = (Priority)t.PriorityId,
                            Description  = t.Description,
                            Title        = t.Title,
                            LoweredTitle = t.Title != null?t.Title.ToLower() : null,
                                               DueDate          = t.DueDate,
                                               StartTime        = t.StartTime,
                                               Duration         = t.Duration,
                                               ProgramIds       = Helper.ConvertToObjectIdList(t.ProgramIds),
                                               DeleteFlag       = false,
                                               LastUpdatedOn    = t.UpdatedOn,
                                               ExternalRecordId = t.ExternalRecordId
                        };

                        if (!string.IsNullOrEmpty(t.AssignedToId))
                        {
                            meToDo.AssignedToId = ObjectId.Parse(t.AssignedToId);
                        }
                        if (!string.IsNullOrEmpty(t.CategoryId))
                        {
                            meToDo.Category = ObjectId.Parse(t.CategoryId);
                        }
                        if (!string.IsNullOrEmpty(t.PatientId))
                        {
                            meToDo.PatientId = ObjectId.Parse(t.PatientId);
                        }
                        if (!string.IsNullOrEmpty(t.SourceId))
                        {
                            meToDo.SourceId = ObjectId.Parse(t.SourceId);
                        }
                        if (t.ClosedDate != null)
                        {
                            meToDo.ClosedDate = t.ClosedDate;
                        }
                        bulk.Insert(meToDo.ToBsonDocument());
                        insertedIds.Add(meToDo.Id.ToString());
                    }
                    BulkWriteResult bwr = bulk.Execute();
                }
                // TODO: Auditing.
            }
            catch (BulkWriteException bwEx)
            {
                // Get the error messages for the ones that failed.
                foreach (BulkWriteError er in bwEx.WriteErrors)
                {
                    errorMessages.Add(er.Message);
                }
            }
            catch (Exception ex)
            {
                string aseProcessID = ConfigurationManager.AppSettings.Get("ASEProcessID") ?? "0";
                Helper.LogException(int.Parse(aseProcessID), ex);
            }
            result.ProcessedIds  = insertedIds;
            result.ErrorMessages = errorMessages;
            return(result);
        }
Beispiel #4
0
        public object Insert(object newEntity)
        {
            PutInsertToDoDataRequest request = (PutInsertToDoDataRequest)newEntity;
            ToDoData todoData = request.ToDoData;
            string   id       = null;
            METoDo   meToDo   = null;

            try
            {
                if (todoData != null)
                {
                    meToDo = new METoDo(this.UserId, todoData.CreatedOn)
                    {
                        Status       = (Status)todoData.StatusId,
                        Priority     = (Priority)todoData.PriorityId,
                        Description  = todoData.Description,
                        Title        = todoData.Title,
                        LoweredTitle = todoData.Title != null?todoData.Title.ToLower() : null,
                                           DueDate          = todoData.DueDate,
                                           StartTime        = todoData.StartTime,
                                           Duration         = todoData.Duration,
                                           ProgramIds       = Helper.ConvertToObjectIdList(todoData.ProgramIds),
                                           DeleteFlag       = false,
                                           LastUpdatedOn    = todoData.UpdatedOn,
                                           ExternalRecordId = todoData.ExternalRecordId
                    };

                    if (!string.IsNullOrEmpty(todoData.AssignedToId))
                    {
                        meToDo.AssignedToId = ObjectId.Parse(todoData.AssignedToId);
                    }
                    if (!string.IsNullOrEmpty(todoData.CategoryId))
                    {
                        meToDo.Category = ObjectId.Parse(todoData.CategoryId);
                    }
                    if (!string.IsNullOrEmpty(todoData.PatientId))
                    {
                        meToDo.PatientId = ObjectId.Parse(todoData.PatientId);
                    }
                    if (!string.IsNullOrEmpty(todoData.SourceId))
                    {
                        meToDo.SourceId = ObjectId.Parse(todoData.SourceId);
                    }
                    if (todoData.ClosedDate != null)
                    {
                        meToDo.ClosedDate = todoData.ClosedDate;
                    }

                    using (SchedulingMongoContext ctx = new SchedulingMongoContext(_dbName))
                    {
                        ctx.ToDos.Collection.Insert(meToDo);

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

                        id = meToDo.Id.ToString();
                    }
                }
                return(id);
            }
            catch (Exception) { throw; }
        }
Beispiel #5
0
        public object Update(object entity)
        {
            PutUpdateToDoDataRequest request = (PutUpdateToDoDataRequest)entity;
            ToDoData todoData = request.ToDoData;
            bool     result   = false;

            try
            {
                if (todoData != null)
                {
                    using (SchedulingMongoContext ctx = new SchedulingMongoContext(_dbName))
                    {
                        var q = MB.Query <METoDo> .EQ(b => b.Id, ObjectId.Parse(todoData.Id));

                        // Set the ClosedDate if the status is changed.
                        METoDo existingToDo = ctx.ToDos.Collection.Find(q).SetFields(METoDo.StatusProperty).FirstOrDefault();
                        if (existingToDo != null)
                        {
                            if ((todoData.StatusId == (int)Status.Met || todoData.StatusId == (int)Status.Abandoned))
                            {
                                if (existingToDo.Status != (Status)todoData.StatusId)
                                {
                                    todoData.ClosedDate = DateTime.UtcNow;
                                }
                            }
                            else
                            {
                                todoData.ClosedDate = null;
                            }
                        }
                        var uv = new List <MB.UpdateBuilder>();
                        uv.Add(MB.Update.Set(METoDo.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                        uv.Add(MB.Update.Set(METoDo.VersionProperty, request.Version));
                        uv.Add(MB.Update.Set(METoDo.LastUpdatedOnProperty, System.DateTime.UtcNow));
                        uv.Add(MB.Update.Set(METoDo.TitleProperty, todoData.Title));
                        if (!string.IsNullOrEmpty(todoData.Title))
                        {
                            uv.Add(MB.Update.Set(METoDo.LoweredTitleProperty, todoData.Title.ToLower()));
                        }
                        uv.Add(MB.Update.Set(METoDo.StatusProperty, (Status)todoData.StatusId));
                        uv.Add(MB.Update.Set(METoDo.PriorityProperty, (Priority)todoData.PriorityId));

                        if (!string.IsNullOrEmpty(todoData.Description))
                        {
                            uv.Add(MB.Update.Set(METoDo.DescriptionProperty, todoData.Description));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.DescriptionProperty, BsonNull.Value));
                        }
                        if (todoData.DueDate != null)
                        {
                            uv.Add(MB.Update.Set(METoDo.DueDateProperty, todoData.DueDate));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.DueDateProperty, BsonNull.Value));
                        }
                        if (todoData.StartTime != null)
                        {
                            uv.Add(MB.Update.Set(METoDo.StartTimeProperty, todoData.StartTime));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.StartTimeProperty, BsonNull.Value));
                        }
                        if (todoData.Duration != null)
                        {
                            uv.Add(MB.Update.Set(METoDo.DurationProperty, todoData.Duration));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.DurationProperty, BsonNull.Value));
                        }
                        if (todoData.ClosedDate != null)
                        {
                            uv.Add(MB.Update.Set(METoDo.ClosedDateProperty, todoData.ClosedDate));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.ClosedDateProperty, BsonNull.Value));
                        }
                        if (todoData.ProgramIds != null)
                        {
                            uv.Add(MB.Update.SetWrapped(METoDo.ProgramProperty, Helper.ConvertToObjectIdList(todoData.ProgramIds)));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.ProgramProperty, BsonNull.Value));
                        }

                        if (!string.IsNullOrEmpty(todoData.PatientId))
                        {
                            uv.Add(MB.Update.Set(METoDo.PatientIdProperty, ObjectId.Parse(todoData.PatientId)));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.PatientIdProperty, BsonNull.Value));
                        }
                        if (!string.IsNullOrEmpty(todoData.CategoryId))
                        {
                            uv.Add(MB.Update.Set(METoDo.CatgegoryProperty, ObjectId.Parse(todoData.CategoryId)));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.CatgegoryProperty, BsonNull.Value));
                        }
                        if (!string.IsNullOrEmpty(todoData.AssignedToId))
                        {
                            uv.Add(MB.Update.Set(METoDo.AssignedToProperty, ObjectId.Parse(todoData.AssignedToId)));
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.AssignedToProperty, BsonNull.Value));
                        }
                        uv.Add(MB.Update.Set(METoDo.DeleteFlagProperty, todoData.DeleteFlag));
                        DataAuditType type;
                        if (todoData.DeleteFlag)
                        {
                            uv.Add(MB.Update.Set(METoDo.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays)));
                            type = Common.DataAuditType.Delete;
                        }
                        else
                        {
                            uv.Add(MB.Update.Set(METoDo.TTLDateProperty, BsonNull.Value));
                            type = Common.DataAuditType.Update;
                        }
                        IMongoUpdate       update = MB.Update.Combine(uv);
                        WriteConcernResult res    = ctx.ToDos.Collection.Update(q, update);
                        if (res.Ok == false)
                        {
                            throw new Exception("Failed to update a ToDo: " + res.ErrorMessage);
                        }
                        else
                        {
                            AuditHelper.LogDataAudit(this.UserId,
                                                     MongoCollectionName.ToDo.ToString(),
                                                     todoData.Id,
                                                     type,
                                                     request.ContractNumber);
                        }

                        result = true;
                    }
                }
                return(result);
            }
            catch (Exception) { throw; }
        }