public object FindByEntityExistsID(string patientID, string progId)
        {
            try
            {
                List <MEPatientProgram> pp = null;

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var findQ = MB.Query.And(
                        MB.Query <MEPatientProgram> .EQ(b => b.PatientId, ObjectId.Parse(patientID)),
                        MB.Query <MEPatientProgram> .EQ(b => b.DeleteFlag, false),
                        MB.Query <MEPatientProgram> .EQ(b => b.ContractProgramId, ObjectId.Parse(progId)),
                        MB.Query.In(MEPatientProgram.StateProperty, new List <BsonValue> {
                        BsonValue.Create(ElementState.NotStarted), BsonValue.Create(ElementState.Started), BsonValue.Create(ElementState.InProgress), BsonValue.Create(ElementState.Closed)
                    }));

                    pp = ctx.PatientPrograms.Collection.Find(findQ).ToList();
                }
                return(pp);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:FindByEntityExistsID()::" + ex.Message, ex.InnerException);
            }
        }
Пример #2
0
 public object GetLimitedProgramFields(string objectId)
 {
     try
     {
         MEProgram cp = null;
         using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
         {
             var query = MB.Query.And(
                 MB.Query <MEProgram> .EQ(b => b.Id, ObjectId.Parse(objectId)),
                 MB.Query <MEProgram> .EQ(b => b.DeleteFlag, false)
                 );
             cp = ctx.Programs.Collection.Find(query).SetFields(
                 MEProgram.AuthoredByProperty,
                 MEProgram.TemplateNameProperty,
                 MEProgram.TemplateVersionProperty,
                 MEProgram.ProgramVersionProperty,
                 MEProgram.ProgramVersionUpdatedOnProperty,
                 MEProgram.ObjectivesInfoProperty
                 ).FirstOrDefault();
         }
         return(cp);
     }
     catch (Exception ex)
     {
         throw new Exception("DD:Program:GetLimitedProgramFields()::" + ex.Message, ex.InnerException);
     }
 }
Пример #3
0
        public List <ProgramInfo> GetActiveProgramsInfoList(GetAllActiveProgramsRequest request)
        {
            List <ProgramInfo> result = new List <ProgramInfo>();

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    IMongoQuery             mQuery = Query.EQ(MEProgram.StatusProperty, 1);
                    MongoCursor <MEProgram> fnd    = ctx.Programs.Collection.Find(mQuery);

                    result = ctx.Programs.Collection.Find(mQuery).Select(r => new ProgramInfo
                    {
                        Name         = r.Name,
                        Id           = r.Id.ToString(),
                        ShortName    = r.ShortName,
                        Status       = (int)r.Status,
                        ElementState = (int)r.State,
                        AttrEndDate  = r.AttributeEndDate
                    }).ToList();
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ContractProgramRepository:GetActiveProgramsInfoList()::" + ex.Message, ex.InnerException);
            }
        }
        public bool Save(object entity)
        {
            bool             success = false;
            MEPatientProgram p       = (MEPatientProgram)entity;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    ctx.PatientPrograms.Collection.Save(p);
                    success = true;

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientProgram.ToString(),
                                             p.Id.ToString(),
                                             Common.DataAuditType.Update,
                                             _dbName);
                }
                return(success);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:Save()::" + ex.Message, ex.InnerException);
            }
        }
Пример #5
0
 public object FindByID(string entityID)
 {
     try
     {
         ContractProgram program = null;
         using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
         {
             program = (from p in ctx.Programs
                        where p.Id == ObjectId.Parse(entityID)
                        select new ContractProgram
             {
                 Delete = p.DeleteFlag,
                 Id = p.Id.ToString(),
                 Name = p.Name,
                 ShortName = p.ShortName,
                 Status = (int)p.Status
             }).FirstOrDefault();
         }
         return(program);
     }
     catch (Exception ex)
     {
         throw new Exception("DD:ContractProgramRepository:FindByID()::" + ex.Message, ex.InnerException);
     }
 }
Пример #6
0
        public DTO.Program FindByName(string entityName)
        {
            try
            {
                DTO.Program result = null;

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var findcp = MB.Query <MEProgram> .EQ(b => b.Name, entityName);

                    MEProgram cp = ctx.Programs.Collection.Find(findcp).FirstOrDefault();

                    if (cp != null)
                    {
                        result = new DTO.Program
                        {
                            ProgramID = cp.Id.ToString()
                        };
                    }
                    else
                    {
                        throw new ArgumentException("ProgramName is not valid or is missing from the records.");
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:FindByName()::" + ex.Message, ex.InnerException);
            }
        }
        public void UndoDelete(object entity)
        {
            UndoDeletePatientProgramDataRequest request = (UndoDeletePatientProgramDataRequest)entity;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var query = MB.Query <MEPatientProgram> .EQ(b => b.Id, ObjectId.Parse(request.PatientProgramId));

                    var builder = new List <MB.UpdateBuilder>();
                    builder.Add(MB.Update.Set(MEPatientProgram.TTLDateProperty, BsonNull.Value));
                    builder.Add(MB.Update.Set(MEPatientProgram.DeleteFlagProperty, false));
                    builder.Add(MB.Update.Set(MEPatientProgram.LastUpdatedOnProperty, DateTime.UtcNow));
                    builder.Add(MB.Update.Set(MEPatientProgram.UpdatedByProperty, ObjectId.Parse(this.UserId)));

                    IMongoUpdate update = MB.Update.Combine(builder);
                    ctx.PatientPrograms.Collection.Update(query, update);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientProgram.ToString(),
                                             request.PatientProgramId.ToString(),
                                             Common.DataAuditType.UndoDelete,
                                             request.ContractNumber);
                }
            }
            catch (Exception) { throw; }
        }
Пример #8
0
        public object Insert(object newEntity)
        {
            MEPatientProgramResponse mer = newEntity as MEPatientProgramResponse;
            bool res = false;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    ctx.PatientProgramResponses.Collection.Insert(mer);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientProgramResponse.ToString(),
                                             mer.Id.ToString(),
                                             Common.DataAuditType.Insert,
                                             _dbName);

                    res = true;
                }
                return(res as object);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramResponseRepository:Insert()::" + ex.Message, ex.InnerException);
            }
        }
Пример #9
0
        public object InsertAsBatch(object newEntity)
        {
            List <MEPatientProgramResponse> mers = newEntity as List <MEPatientProgramResponse>;
            bool res = false;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    ctx.PatientProgramResponses.Collection.InsertBatch(mers);

                    List <string> ids = new List <string>();
                    mers.ForEach(r =>
                    {
                        ids.Add(r.Id.ToString());
                    });

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientProgramResponse.ToString(),
                                             ids,
                                             Common.DataAuditType.Insert,
                                             _dbName);

                    res = true;
                }
                return(res as object);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramResponseRepository:InsertAsBatch()::" + ex.Message, ex.InnerException);
            }
        }
Пример #10
0
        public List <Module> GetProgramModules(ObjectId progId)
        {
            try
            {
                List <Module> mods = null;

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var findcp = MB.Query <MEProgram> .EQ(b => b.Id, progId);

                    MEProgram cp = ctx.Programs.Collection.Find(findcp).FirstOrDefault();

                    if (cp != null)
                    {
                        mods = cp.Modules;
                    }
                    else
                    {
                        throw new ArgumentException("ProgramId is not valid or is missing from the records.");
                    }
                }
                return(mods);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:GetProgramModules()::" + ex.Message, ex.InnerException);
            }
        }
        public object FindByID(string entityID)
        {
            try
            {
                MEPatientProgram result = null;

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var findcp = MB.Query.And(
                        MB.Query <MEPatientProgram> .EQ(b => b.Id, ObjectId.Parse(entityID)),
                        MB.Query <MEPatientProgram> .EQ(b => b.DeleteFlag, false));
                    MEPatientProgram cp = ctx.PatientPrograms.Collection.Find(findcp).FirstOrDefault();

                    if (cp != null)
                    {
                        result = cp;
                    }
                    else
                    {
                        throw new ArgumentException("ProgramID is not valid or is missing from the records.");
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:FindByID()::" + ex.Message, ex.InnerException);
            }
        }
Пример #12
0
        public object Update(object entity)
        {
            MEResponse resp   = (MEResponse)entity;
            bool       result = false;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var q = MB.Query <MEResponse> .EQ(b => b.Id, resp.Id);

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEResponse.NextStepIdProperty, resp.NextStepId));
                    uv.Add(MB.Update.Set(MEResponse.StepIdProperty, resp.StepId));
                    uv.Add(MB.Update.Set(MEResponse.NominalProperty, resp.Nominal));
                    uv.Add(MB.Update.Set(MEResponse.RequiredProperty, resp.Required));
                    uv.Add(MB.Update.Set(MEResponse.DeleteFlagProperty, false));
                    uv.Add(MB.Update.Set(MEResponse.SelectedProperty, resp.Selected));

                    uv.Add(MB.Update.Set(MEResponse.LastUpdatedOnProperty, DateTime.UtcNow));
                    uv.Add(MB.Update.Set(MEResponse.UpdatedByProperty, ObjectId.Parse(this.UserId)));

                    if (resp.Order != 0)
                    {
                        uv.Add(MB.Update.Set(MEResponse.OrderProperty, resp.Order));
                    }
                    if (resp.Text != null)
                    {
                        uv.Add(MB.Update.Set(MEResponse.TextProperty, resp.Text));
                    }
                    if (resp.Value != null)
                    {
                        uv.Add(MB.Update.Set(MEResponse.ValueProperty, resp.Value));
                    }
                    if (resp.Spawn != null)
                    {
                        uv.Add(MB.Update.SetWrapped <List <SpawnElement> >(MEResponse.SpawnElementProperty, resp.Spawn));
                    }

                    IMongoUpdate       update = MB.Update.Combine(uv);
                    WriteConcernResult res    = ctx.Responses.Collection.Update(q, update);
                    if (res.Ok)
                    {
                        result = true;
                        AuditHelper.LogDataAudit(this.UserId,
                                                 MongoCollectionName.Response.ToString(),
                                                 resp.Id.ToString(),
                                                 Common.DataAuditType.Update,
                                                 "");
                    }
                }
                return(result as object);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ResponseRepository:Update()::" + ex.Message, ex.InnerException);
            }
        }
Пример #13
0
        public Tuple <string, IEnumerable <object> > Select(Interface.APIExpression expression)
        {
            try
            {
                IMongoQuery   mQuery = null;
                List <object> pAtts  = new List <object>();

                mQuery = MongoDataUtil.ExpressionQueryBuilder(expression);

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    // check to see which properties from planelement we need.
                    List <MEProgramAttribute> pa = ctx.ProgramAttributes.Collection.Find(mQuery).ToList();

                    if (pa != null)
                    {
                        pa.ForEach(cp => pAtts.Add(new ProgramAttributeData
                        {
                            Id = cp.Id.ToString(),
                            DidNotEnrollReason = cp.DidNotEnrollReason,
                            //DisEnrollReason = cp.DisEnrollReason,
                            Eligibility = (int)cp.Eligibility,
                            //EligibilityEndDate = cp.EligibilityEndDate,
                            //EligibilityOverride = (int)cp.EligibilityOverride,
                            //EligibilityRequirements = cp.EligibilityRequirements,
                            //EligibilityStartDate = cp.EligibilityStartDate,
                            //  AttrEndDate = cp.EndDate, , Sprint 12
                            Enrollment       = (int)cp.Enrollment,
                            GraduatedFlag    = (int)cp.GraduatedFlag,
                            IneligibleReason = cp.IneligibleReason,
                            Locked           = (int)cp.Locked,
                            OptOut           = cp.OptOut,
                            //OptOutDate = cp.OptOutDate,
                            //OptOutReason = cp.OptOutReason,
                            OverrideReason = cp.OverrideReason,
                            PlanElementId  = cp.PlanElementId.ToString(),
                            Population     = cp.Population,
                            RemovedReason  = cp.RemovedReason,
                            Status         = (int)cp.Status
                        }));
                    }
                }

                return(new Tuple <string, IEnumerable <object> >(expression.ExpressionID, pAtts));
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramAttributeRepository:Select()::" + ex.Message, ex.InnerException);
            }
        }
Пример #14
0
 public IEnumerable <object> Find(string Id)
 {
     try
     {
         List <MEResponse>  responses = null;
         List <IMongoQuery> queries   = new List <IMongoQuery>();
         queries.Add(Query.EQ(MEResponse.StepIdProperty, ObjectId.Parse(Id)));
         IMongoQuery mQuery = Query.And(queries);
         using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
         {
             responses = ctx.Responses.Collection.Find(mQuery).ToList();
         }
         return(responses);
     }
     catch (Exception) { throw; }
 }
 public IEnumerable <object> SelectAll()
 {
     try
     {
         List <MEPatientProgram> cps = null;
         using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
         {
             cps = ctx.PatientPrograms.Collection.FindAll().ToList();
         }
         return(cps);
     }
     catch (Exception ex)
     {
         throw new Exception("DD:PatientProgramRepository:SelectAll()::" + ex.Message, ex.InnerException);
     }
 }
Пример #16
0
 public object FindByPlanElementID(string entityID)
 {
     try
     {
         MEProgramAttribute cp = null;
         using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
         {
             List <IMongoQuery> queries = new List <IMongoQuery>();
             queries.Add(Query.EQ(MEProgramAttribute.PlanElementIdProperty, ObjectId.Parse(entityID)));
             queries.Add(Query.EQ(MEProgramAttribute.DeleteFlagProperty, false));
             IMongoQuery mQuery = Query.And(queries);
             cp = ctx.ProgramAttributes.Collection.Find(mQuery).FirstOrDefault();
         }
         return(cp);
     }
     catch (Exception) { throw; }
 }
        public object Insert(object newEntity)
        {
            try
            {
                MEPatientProgram nmePP = (MEPatientProgram)newEntity;
                ProgramInfo      pi    = null;
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    nmePP.UpdatedBy     = null;
                    nmePP.LastUpdatedOn = null;
                    ctx.PatientPrograms.Collection.Insert(nmePP);

                    // update programid in modules
                    var q = MB.Query <MEPatientProgram> .EQ(b => b.Id, nmePP.Id);

                    nmePP.Modules.ForEach(s => s.ProgramId  = nmePP.Id);
                    nmePP.Modules.ForEach(s => s.Objectives = null);
                    ctx.PatientPrograms.Collection.Update(q, MB.Update.SetWrapped <List <Module> >(MEPatientProgram.ModulesProperty, nmePP.Modules));

                    // hydrate response object
                    pi = new ProgramInfo
                    {
                        Id        = nmePP.Id.ToString(),
                        Name      = nmePP.Name,
                        ShortName = nmePP.ShortName,
                        Status    = (int)nmePP.Status,
                        PatientId = nmePP.PatientId.ToString(),
                        //ProgramState = (int)nmePP.ProgramState, // depricated - Use Element state instead.
                        ElementState    = (int)nmePP.State,
                        ProgramSourceId = (nmePP.SourceId == null) ? null : nmePP.SourceId.ToString()
                    };

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientProgram.ToString(),
                                             nmePP.Id.ToString(),
                                             Common.DataAuditType.Insert,
                                             _dbName);
                }
                return(pi);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgram:Insert()::" + ex.Message, ex.InnerException);
            }
        }
Пример #18
0
        public object FindByID(string entityID)
        {
            try
            {
                MEProgram cp = null;
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var findcp = MB.Query <MEProgram> .EQ(b => b.Id, ObjectId.Parse(entityID));

                    cp = ctx.Programs.Collection.Find(findcp).FirstOrDefault();
                }
                return(cp);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:Program:FindByID()::" + ex.Message, ex.InnerException);
            }
        }
        public IEnumerable <object> FindByPatientId(string patientId)
        {
            List <MEPatientProgram> mePPList = null;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientProgram.PatientIdProperty, ObjectId.Parse(patientId)));
                    queries.Add(Query.EQ(MEPatientProgram.DeleteFlagProperty, false));
                    IMongoQuery mQuery = Query.And(queries);
                    mePPList = ctx.PatientPrograms.Collection.Find(mQuery).ToList();
                }
                return(mePPList);
            }
            catch (Exception) { throw; }
        }
Пример #20
0
        public IEnumerable <object> FindByStepId(string entityID)
        {
            List <MEPatientProgramResponse> response = null;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientProgramResponse.StepIdProperty, ObjectId.Parse(entityID)));
                    // Excluding deleteflag query. Night-952
                    //queries.Add(Query.EQ(MEPatientProgramResponse.DeleteFlagProperty, false));
                    IMongoQuery mQuery = Query.And(queries);
                    response = ctx.PatientProgramResponses.Collection.Find(mQuery).ToList();
                }
                return(response);
            }
            catch (Exception ex) { throw ex; }
        }
Пример #21
0
        public object Insert(object newEntity)
        {
            try
            {
                ResponseDetail rs  = (ResponseDetail)newEntity;
                MEResponse     mer = new MEResponse(this.UserId)
                {
                    Id            = ObjectId.Parse(rs.Id),
                    NextStepId    = ObjectId.Parse(rs.NextStepId),
                    Nominal       = rs.Nominal,
                    Order         = rs.Order,
                    Required      = rs.Required,
                    Spawn         = DTOUtils.GetSpawnElements(rs.SpawnElement),
                    StepId        = ObjectId.Parse(rs.StepId),
                    Text          = rs.Text,
                    Value         = rs.Value,
                    DeleteFlag    = true,
                    LastUpdatedOn = DateTime.UtcNow,
                    Version       = 1.0,
                    UpdatedBy     = ObjectId.Parse(this.UserId)
                };

                bool res = false;

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    ctx.Responses.Collection.Insert(mer);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.Response.ToString(),
                                             mer.Id.ToString(),
                                             Common.DataAuditType.Insert,
                                             "");

                    res = true;
                }
                return(res as object);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ResponseRepository:Insert()::" + ex.Message, ex.InnerException);
            }
        }
Пример #22
0
        public object FindByID(string entityID)
        {
            MEResponse response = null;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var findcp = MB.Query <MEResponse> .EQ(b => b.Id, ObjectId.Parse(entityID));

                    response = ctx.Responses.Collection.Find(findcp).FirstOrDefault();
                }

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ResponseRepository:FindById()::" + ex.Message, ex.InnerException);
            }
        }
Пример #23
0
        public Tuple <string, IEnumerable <object> > Select(Interface.APIExpression expression)
        {
            try
            {
                IMongoQuery   mQuery = null;
                List <object> rps;

                mQuery = MongoDataUtil.ExpressionQueryBuilder(expression);

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    rps = ctx.Responses.Collection.Find(mQuery).ToList <object>();
                }

                return(new Tuple <string, IEnumerable <object> >(expression.ExpressionID, rps));
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ResponseRepository:Select()::" + ex.Message, ex.InnerException);
            }
        }
        public IEnumerable <object> Find(List <ObjectId> Ids)
        {
            try
            {
                List <MEPatientProgramResponse> responses = null;

                IList <IMongoQuery> queries = new List <IMongoQuery>();

                IMongoQuery      mQuery   = null;
                List <BsonValue> bsonList = ConvertToBsonValueList(Ids);
                if (bsonList != null)
                {
                    mQuery = Query.In(MEPatientProgramResponse.StepIdProperty, bsonList);
                }

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    responses = ctx.PatientProgramResponses.Collection.Find(mQuery).ToList();
                }
                return(responses);
            }
            catch (Exception) { throw; }
        }
Пример #25
0
        public object Update(object entity)
        {
            ProgramAttributeData mepa = (ProgramAttributeData)entity;
            bool result = false;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var q = MB.Query <MEProgramAttribute> .EQ(b => b.PlanElementId, ObjectId.Parse(mepa.PlanElementId));

                    var uv = new List <MB.UpdateBuilder>();
                    // state
                    //if (mepa.AssignedBy != null) uv.Add(MB.Update.Set(MEProgramAttribute.AssignByProperty, mepa.AssignedBy));
                    //if (mepa.AssignedTo != null) uv.Add(MB.Update.Set(MEProgramAttribute.AssignToProperty, mepa.AssignedTo));
                    //if (mepa.AssignedOn != null) uv.Add(MB.Update.Set(MEProgramAttribute.AssignDateProperty, mepa.AssignedOn));
                    if (mepa.Population != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.PopulationProperty, mepa.Population));
                    }
                    if (mepa.Completed != 0)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.CompletedProperty, mepa.Completed));
                    }
                    if (mepa.CompletedBy != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.CompletedByProperty, mepa.CompletedBy));
                    }
                    if (mepa.DateCompleted != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.CompletedOnProperty, mepa.DateCompleted));
                    }
                    if (mepa.RemovedReason != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.RemovedReasonProperty, mepa.RemovedReason));
                    }
                    if (mepa.GraduatedFlag != 0)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.GraduatedFlagProperty, mepa.GraduatedFlag));
                    }
                    if (mepa.Locked != 0)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.LockedProperty, mepa.Locked));
                    }
                    if (mepa.OverrideReason != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.OverrideReasonProperty, mepa.OverrideReason));
                    }
                    if (mepa.Status != 0)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.StatusProperty, (Status)mepa.Status));
                    }
                    // eligibility
                    //if (mepa.EligibilityEndDate != null) uv.Add(MB.Update.Set(MEProgramAttribute.EligibilityEndDateProperty, mepa.EligibilityEndDate));
                    //if (mepa.EligibilityRequirements != null) uv.Add(MB.Update.Set(MEProgramAttribute.EligibilityRequirementsProperty, mepa.EligibilityRequirements));
                    //if (mepa.EligibilityStartDate != null) uv.Add(MB.Update.Set(MEProgramAttribute.EligibilityStartDateProperty, mepa.EligibilityStartDate));
                    if (mepa.IneligibleReason != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.IneligibleReasonProperty, mepa.IneligibleReason));
                    }
                    //if (mepa.EligibilityOverride != 0) uv.Add(MB.Update.Set(MEProgramAttribute.EligibilityOverrideProperty, (EligibilityOverride)mepa.EligibilityOverride));
                    if (mepa.Eligibility != 0)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.EligibilityProperty, (EligibilityStatus)mepa.Eligibility));
                    }
                    // optout
                    //if (mepa.OptOutDate != null) uv.Add(MB.Update.Set(MEProgramAttribute.OptOutDateProperty, mepa.OptOutDate));
                    if (mepa.OptOut != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.OptOutProperty, mepa.OptOut));
                    }
                    //if (mepa.OptOutReason != null) uv.Add(MB.Update.Set(MEProgramAttribute.OptOutReasonProperty, mepa.OptOutReason));
                    // dates
                    //if (mepa.AttrStartDate != null) uv.Add(MB.Update.Set(MEProgramAttribute.StartDateProperty, mepa.AttrStartDate)); Sprint 12
                    //if (mepa.AttrEndDate != null) uv.Add(MB.Update.Set(MEProgramAttribute.EndDateProperty, mepa.AttrEndDate)); Sprint 12
                    // enrollment
                    if (mepa.Enrollment != 0)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.EnrollmentProperty, (EnrollmentStatus)mepa.Enrollment));
                    }
                    if (mepa.DidNotEnrollReason != null)
                    {
                        uv.Add(MB.Update.Set(MEProgramAttribute.DidNotEnrollReasonProperty, mepa.DidNotEnrollReason));
                    }
                    //if (mepa.DisEnrollReason != null) uv.Add(MB.Update.Set(MEProgramAttribute.DisEnrollReasonProperty, mepa.DisEnrollReason));

                    uv.Add(MB.Update.Set(MEProgramAttribute.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                    uv.Add(MB.Update.Set(MEProgramAttribute.LastUpdatedOnProperty, DateTime.UtcNow));

                    if (uv.Count > 0)
                    {
                        IMongoUpdate update = MB.Update.Combine(uv);
                        ctx.ProgramAttributes.Collection.Update(q, update);

                        AuditHelper.LogDataAudit(this.UserId,
                                                 MongoCollectionName.PatientProgramAttribute.ToString(),
                                                 mepa.PlanElementId,
                                                 MEProgramAttribute.PlanElementIdProperty,
                                                 Common.DataAuditType.Update,
                                                 _dbName);

                        result = true;
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramAttributeRepository:Update()::" + ex.Message, ex.InnerException);
            }
        }
        public object Update(object entity)
        {
            PutProgramActionProcessingRequest p = (PutProgramActionProcessingRequest)entity;
            ProgramDetail pg = p.Program;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var q = MB.Query <MEPatientProgram> .EQ(b => b.Id, ObjectId.Parse(p.ProgramId));

                    List <Module> mods = DTOUtils.CloneAppDomainModules(pg.Modules, this.UserId);

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEPatientProgram.CompletedProperty, pg.Completed));
                    uv.Add(MB.Update.Set(MEPatientProgram.EnabledProperty, pg.Enabled));
                    uv.Add(MB.Update.Set(MEPatientProgram.OrderProperty, pg.Order));
                    //uv.Add(MB.Update.Set(MEPatientProgram.ProgramStateProperty, (ProgramState)pg.ProgramState)); // depricated - Use Element state instead.
                    uv.Add(MB.Update.Set(MEPatientProgram.LastUpdatedOnProperty, System.DateTime.UtcNow));
                    uv.Add(MB.Update.Set(MEPatientProgram.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                    uv.Add(MB.Update.Set(MEPatientProgram.VersionProperty, pg.Version));
                    if (pg.AssignTo != null && !string.IsNullOrEmpty(pg.AssignTo))
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.AssignToProperty, pg.AssignTo));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.AssignToProperty, BsonNull.Value));
                    }

                    if (pg.ElementState != 0)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.StateProperty, (ElementState)pg.ElementState));
                    }
                    if (pg.StateUpdatedOn != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.StateUpdatedOnProperty, pg.StateUpdatedOn));
                    }
                    if (pg.Status != 0)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.StatusProperty, (Status)pg.Status));
                    }
                    if (pg.AssignBy != null && !string.IsNullOrEmpty(pg.AssignBy))
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.AssignByProperty, pg.AssignBy));
                    }
                    if (pg.AssignDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.AssignDateProperty, pg.AssignDate));
                    }
                    if (pg.AttrEndDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.AttributeEndDateProperty, pg.AttrEndDate));
                    }
                    if (pg.AttrStartDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.AttributeStartDateProperty, pg.AttrStartDate));
                    }
                    if (pg.Client != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.ClientProperty, pg.Client));
                    }
                    if (pg.CompletedBy != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.CompletedByProperty, pg.CompletedBy));
                    }
                    if (pg.ContractProgramId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.ContractProgramIdProperty, ObjectId.Parse(pg.ContractProgramId)));
                    }
                    if (pg.DateCompleted != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.CompletedOnProperty, pg.DateCompleted));
                    }
                    if (pg.Description != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.DescriptionProperty, pg.Description));
                    }
                    if (pg.EndDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.EndDateProperty, pg.EndDate));
                    }
                    if (pg.Name != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.NameProperty, pg.Name));
                    }
                    if (pg.Next != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.NextProperty, DTOUtils.ParseObjectId(pg.Next)));
                    }
                    if (pg.Previous != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.PreviousProperty, DTOUtils.ParseObjectId(pg.Previous)));
                    }
                    if (pg.ShortName != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.ShortNameProperty, pg.ShortName));
                    }
                    if (pg.SourceId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.SourceIdProperty, pg.SourceId));
                    }
                    if (pg.StartDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientProgram.StartDateProperty, pg.StartDate));
                    }
                    if (mods != null)
                    {
                        uv.Add(MB.Update.SetWrapped <List <Module> >(MEPatientProgram.ModulesProperty, mods));
                    }
                    if (pg.SpawnElement != null)
                    {
                        uv.Add(MB.Update.SetWrapped <List <SpawnElement> >(MEPatientProgram.SpawnProperty, DTOUtils.GetSpawnElements(pg.SpawnElement)));
                    }
                    if (pg.ObjectivesData != null)
                    {
                        uv.Add(MB.Update.SetWrapped <List <Objective> >(MEPatientProgram.ObjectivesInfoProperty, DTOUtils.GetObjectives(pg.ObjectivesData)));
                    }

                    IMongoUpdate update = MB.Update.Combine(uv);
                    ctx.PatientPrograms.Collection.Update(q, update);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientProgram.ToString(),
                                             p.ProgramId,
                                             Common.DataAuditType.Update,
                                             _dbName);
                }
                return(pg);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:Update()::" + ex.Message, ex.InnerException);
            }
        }
Пример #27
0
        public object Insert(object newEntity)
        {
            bool result               = false;
            ProgramAttributeData pa   = (ProgramAttributeData)newEntity;
            MEProgramAttribute   mepa = null;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    mepa = new MEProgramAttribute(this.UserId)
                    {
                        Status         = (Status)pa.Status,
                        RemovedReason  = pa.OverrideReason,
                        Population     = pa.Population,
                        PlanElementId  = ObjectId.Parse(pa.PlanElementId),
                        OverrideReason = pa.OverrideReason,
                        //OptOutReason = pa.OptOutReason,
                        //OptOutDate = pa.OptOutDate,
                        OptOut           = pa.OptOut,
                        Locked           = (Locked)pa.Locked,
                        IneligibleReason = pa.IneligibleReason,
                        Completed        = (Completed)pa.Completed,
                        //AssignedOn = pa.AssignedOn, Sprint 12
                        CompletedBy        = pa.CompletedBy,
                        DateCompleted      = pa.DateCompleted,
                        DidNotEnrollReason = pa.DidNotEnrollReason,
                        //DisEnrollReason = pa.DisEnrollReason,
                        Eligibility = (EligibilityStatus)pa.Eligibility,
                        //EligibilityEndDate = pa.EligibilityEndDate,
                        //EligibilityOverride = (EligibilityOverride)pa.EligibilityOverride,
                        //EligibilityRequirements = pa.EligibilityRequirements,
                        //EligibilityStartDate = pa.EligibilityStartDate,
                        // EndDate = pa.AttrEndDate, , Sprint 12
                        Enrollment    = (EnrollmentStatus)pa.Enrollment,
                        GraduatedFlag = (Graduated)pa.GraduatedFlag,
                        //  StartDate = pa.AttrStartDate, Sprint 12
                        DeleteFlag = false
                                     //,LastUpdatedOn = DateTime.UtcNow,
                                     //UpdatedBy = ObjectId.Parse(this.UserId)
                    };

                    //if(pa.AssignedBy != null) Sprint 12
                    //{
                    //    mepa.AssignedBy = ObjectId.Parse(pa.AssignedBy);
                    //}

                    //if (pa.AssignedTo != null) Sprint 12
                    //{
                    //    mepa.AssignedTo = ObjectId.Parse(pa.AssignedTo);
                    //}

                    ctx.ProgramAttributes.Collection.Insert(mepa);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientProgramAttribute.ToString(),
                                             mepa.Id.ToString(),
                                             Common.DataAuditType.Insert,
                                             _dbName);

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

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

                SelectExpressionGroupType groupType = SelectExpressionGroupType.AND;

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

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

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

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

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

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