Beispiel #1
0
        public void Delete(object entity)
        {
            DeletePatientAllergyDataRequest request = (DeletePatientAllergyDataRequest)entity;

            try
            {
                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    var q = MB.Query <MEPatientAllergy> .EQ(b => b.Id, ObjectId.Parse(request.Id));

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEPatientAllergy.TTLDateProperty, DateTime.UtcNow.AddDays(_expireDays)));
                    uv.Add(MB.Update.Set(MEPatientAllergy.LastUpdatedOnProperty, DateTime.UtcNow));
                    uv.Add(MB.Update.Set(MEPatientAllergy.DeleteFlagProperty, true));
                    uv.Add(MB.Update.Set(MEPatientAllergy.UpdatedByProperty, ObjectId.Parse(this.UserId)));

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

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientAllergy.ToString(),
                                             request.Id.ToString(),
                                             DataAuditType.Delete,
                                             request.ContractNumber);
                }
            }
            catch (Exception) { throw; }
        }
Beispiel #2
0
        public object FindByID(string entityID)
        {
            PatientAllergyData data = null;

            try
            {
                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientAllergy.IdProperty, ObjectId.Parse(entityID)));
                    IMongoQuery      mQuery = Query.And(queries);
                    MEPatientAllergy mePA   = ctx.PatientAllergies.Collection.Find(mQuery).FirstOrDefault();
                    if (mePA != null)
                    {
                        data = AutoMapper.Mapper.Map <PatientAllergyData>(mePA);
                        // get corresponding allergy name and type.
                        if (data != null)
                        {
                            getAllergyDetails(data, ctx, mePA.AllergyId);
                        }
                    }
                }
                return(data);
            }
            catch (Exception) { throw; }
        }
        public object Initialize(object newEntity)
        {
            PutInitializeAllergyDataRequest request = (PutInitializeAllergyDataRequest)newEntity;
            AllergyData data = null;

            try
            {
                MEAllergy meA = new MEAllergy(this.UserId)
                {
                    Name       = request.AllergyName,
                    TTLDate    = System.DateTime.UtcNow.AddDays(_initializeDays),
                    DeleteFlag = false
                };

                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    ctx.Allergies.Collection.Insert(meA);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.Allergy.ToString(),
                                             meA.Id.ToString(),
                                             DataAuditType.Insert,
                                             request.ContractNumber);

                    data = new AllergyData
                    {
                        Id   = meA.Id.ToString(),
                        Name = meA.Name.ToUpper()
                    };
                }
                return(data);
            }
            catch (Exception) { throw; }
        }
Beispiel #4
0
        public object FindByPatientId(object request)
        {
            List <PatientAllergyData>      list        = null;
            GetPatientAllergiesDataRequest dataRequest = (GetPatientAllergiesDataRequest)request;

            try
            {
                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientAllergy.PatientIdProperty, ObjectId.Parse(dataRequest.PatientId)));
                    queries.Add(Query.EQ(MEPatientAllergy.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(MEPatientAllergy.TTLDateProperty, BsonNull.Value));
                    if (dataRequest.StatusIds != null && dataRequest.StatusIds.Count > 0)
                    {
                        queries.Add(Query.In(MEPatientAllergy.StatusProperty, new BsonArray(dataRequest.StatusIds)));
                    }
                    IMongoQuery             mQuery = Query.And(queries);
                    List <MEPatientAllergy> mePAs  = ctx.PatientAllergies.Collection.Find(mQuery).ToList();
                    if (mePAs != null && mePAs.Count > 0)
                    {
                        list = new List <PatientAllergyData>();
                        List <ObjectId> aids = new List <ObjectId>();
                        if (dataRequest.TypeIds != null && dataRequest.TypeIds.Count > 0)
                        {
                            // get allergy details by typeId.
                            List <MEAllergy> allergiesByType = ctx.Allergies.Collection.Find(Query.EQ(MEAllergy.TypeIdsProperty, new BsonArray(dataRequest.TypeIds))).ToList();
                            aids = allergiesByType.Select(i => i.Id).ToList();
                        }
                        mePAs.ForEach(p =>
                        {
                            MEPatientAllergy meData = null;
                            if (dataRequest.TypeIds != null && dataRequest.TypeIds.Count > 0)
                            {
                                if (aids.Contains(p.AllergyId))
                                {
                                    meData = p;
                                }
                            }
                            else
                            {
                                meData = p;
                            }
                            if (meData != null)
                            {
                                PatientAllergyData data = AutoMapper.Mapper.Map <PatientAllergyData>(meData);
                                // get corresponding allergy name and type.
                                if (data != null)
                                {
                                    getAllergyDetails(data, ctx, p.AllergyId);
                                }
                                list.Add(data);
                            }
                        });
                    }
                }
                return(list);
            }
            catch (Exception) { throw; }
        }
Beispiel #5
0
        private static void getAllergyDetails(PatientAllergyData data, AllergyMongoContext ctx, ObjectId aid)
        {
            MEAllergy meA = ctx.Allergies.Collection.Find(Query.EQ(MEAllergy.IdProperty, aid)).FirstOrDefault();

            if (meA != null)
            {
                data.AllergyName    = meA.Name.ToUpper();
                data.AllergyTypeIds = Helper.ConvertToStringList(meA.TypeIds);
            }
        }
        public object Update(object entity)
        {
            bool result = false;
            PutAllergyDataRequest pa = (PutAllergyDataRequest)entity;
            AllergyData           pt = pa.AllergyData;

            try
            {
                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    var q = MB.Query <MEAllergy> .EQ(b => b.Id, ObjectId.Parse(pt.Id));

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEAllergy.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                    uv.Add(MB.Update.Set(MEAllergy.VersionProperty, pa.Version));
                    uv.Add(MB.Update.Set(MEAllergy.LastUpdatedOnProperty, System.DateTime.UtcNow));
                    if (pt.TypeIds != null && pt.TypeIds.Count > 0)
                    {
                        uv.Add(MB.Update.SetWrapped <List <ObjectId> >(MEAllergy.TypeIdsProperty, Helper.ConvertToObjectIdList(pt.TypeIds)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEAllergy.TypeIdsProperty, BsonNull.Value));
                    }
                    uv.Add(MB.Update.Set(MEAllergy.DeleteFlagProperty, pt.DeleteFlag));
                    DataAuditType type;
                    if (pt.DeleteFlag)
                    {
                        uv.Add(MB.Update.Set(MEAllergy.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays)));
                        type = DataAuditType.Delete;
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEAllergy.TTLDateProperty, BsonNull.Value));
                        type = DataAuditType.Update;
                    }
                    IMongoUpdate update = MB.Update.Combine(uv);
                    ctx.Allergies.Collection.Update(q, update);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.Allergy.ToString(),
                                             pt.Id,
                                             type,
                                             pa.ContractNumber);

                    result = true;
                }
                return(result as object);
            }
            catch (Exception) { throw; }
        }
        public IEnumerable <object> SelectAll()
        {
            using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
            {
                List <IMongoQuery> queries = new List <IMongoQuery>();
                queries.Add(Query.EQ(MEAllergy.DeleteFlagProperty, false));
                queries.Add(Query.EQ(MEAllergy.TTLDateProperty, BsonNull.Value));
                IMongoQuery mQuery = Query.And(queries);

                List <MEAllergy> meAllgy = ctx.Allergies.Collection.Find(mQuery).ToList();

                List <AllergyData> allgs = null;
                if (meAllgy != null && meAllgy.Count > 0)
                {
                    allgs = meAllgy.Select(a => Mapper.Map <AllergyData>(a)).ToList();
                }

                return(allgs);
            }
        }
        public object FindByID(string entityID)
        {
            AllergyData data = null;

            try
            {
                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEAllergy.IdProperty, ObjectId.Parse(entityID)));
                    IMongoQuery mQuery = Query.And(queries);
                    MEAllergy   meA    = ctx.Allergies.Collection.Find(mQuery).FirstOrDefault();
                    if (meA != null)
                    {
                        data = AutoMapper.Mapper.Map <AllergyData>(meA);
                    }
                }
                return(data);
            }
            catch (Exception) { throw; }
        }
 public object Insert(object newEntity)
 {
     try
     {
         object result = null;
         using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
         {
             var allgr = new MEAllergy(UserId)
             {
                 Name = ((AllergyData)newEntity).Name
             };
             ctx.Allergies.Insert(allgr);
             result = Mapper.Map <AllergyData>(allgr);
         }
         return(result);
     }
     catch (Exception ex)
     {
         throw new Exception("AllergyDD:MongoAllergyRepository:Insert()::" + ex.Message, ex.InnerException);
     }
 }
Beispiel #10
0
        public object Initialize(object newEntity)
        {
            PutInitializePatientAllergyDataRequest request = (PutInitializePatientAllergyDataRequest)newEntity;
            PatientAllergyData data = null;

            try
            {
                MEPatientAllergy mePA = new MEPatientAllergy(this.UserId)
                {
                    PatientId  = ObjectId.Parse(request.PatientId),
                    AllergyId  = ObjectId.Parse(request.AllergyId),
                    TTLDate    = System.DateTime.UtcNow.AddDays(_initializeDays),
                    SystemName = request.SystemName,
                    DeleteFlag = false
                };

                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    ctx.PatientAllergies.Collection.Insert(mePA);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientAllergy.ToString(),
                                             mePA.Id.ToString(),
                                             DataAuditType.Insert,
                                             request.ContractNumber);

                    data = new PatientAllergyData
                    {
                        Id         = mePA.Id.ToString(),
                        PatientId  = mePA.PatientId.ToString(),
                        AllergyId  = mePA.AllergyId.ToString(),
                        SystemName = mePA.SystemName
                    };
                    // get corresponding allergy name and type.
                    getAllergyDetails(data, ctx, mePA.AllergyId);
                }
                return(data);
            }
            catch (Exception) { throw; }
        }
        public static IMongoAllergyRepository GetAllergyRepository(IDataDomainRequest request, RepositoryType type)
        {
            try
            {
                IMongoAllergyRepository repo = null;

                switch (type)
                {
                case RepositoryType.Allergy:
                {
                    //var db = AppHostBase.Instance.Container.ResolveNamed<string>(Constants.Domain);
                    var context = new AllergyMongoContext(request.ContractNumber);
                    repo = new MongoAllergyRepository <AllergyMongoContext>(context)
                    {
                        UserId = request.UserId, ContractDBName = request.ContractNumber
                    };
                    break;
                }

                case RepositoryType.PatientAllergy:
                {
                    //var db = AppHostBase.Instance.Container.ResolveNamed<string>(Constants.Domain);
                    var context = new AllergyMongoContext(request.ContractNumber);
                    repo = new MongoPatientAllergyRepository <AllergyMongoContext>(context)
                    {
                        UserId = request.UserId, ContractDBName = request.ContractNumber
                    };
                    break;
                }
                }
                return(repo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #12
0
        public object Update(object entity)
        {
            bool result = false;
            PutPatientAllergyDataRequest pa = (PutPatientAllergyDataRequest)entity;
            PatientAllergyData           pt = pa.PatientAllergyData;

            try
            {
                using (AllergyMongoContext ctx = new AllergyMongoContext(ContractDBName))
                {
                    var q = MB.Query <MEPatientAllergy> .EQ(b => b.Id, ObjectId.Parse(pt.Id));

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEPatientAllergy.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                    uv.Add(MB.Update.Set(MEPatientAllergy.VersionProperty, pa.Version));
                    uv.Add(MB.Update.Set(MEPatientAllergy.LastUpdatedOnProperty, System.DateTime.UtcNow));
                    if (pt.PatientId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.PatientIdProperty, ObjectId.Parse(pt.PatientId)));
                    }
                    if (pt.AllergyId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.AllergyIdProperty, ObjectId.Parse(pt.AllergyId)));
                    }
                    if (pt.SeverityId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.SeverityIdProperty, ObjectId.Parse(pt.SeverityId)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.SeverityIdProperty, BsonNull.Value));
                    }
                    if (pt.ReactionIds != null && pt.ReactionIds.Count > 0)
                    {
                        uv.Add(MB.Update.SetWrapped <List <ObjectId> >(MEPatientAllergy.ReactionIdsProperty, Helper.ConvertToObjectIdList(pt.ReactionIds)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.ReactionIdsProperty, BsonNull.Value));
                    }
                    if (pt.StartDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.StartDateProperty, pt.StartDate));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.StartDateProperty, BsonNull.Value));
                    }
                    if (pt.EndDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.EndDateProperty, pt.EndDate));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.EndDateProperty, BsonNull.Value));
                    }
                    if (pt.StatusId != 0)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.StatusProperty, pt.StatusId));
                    }
                    if (pt.SourceId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.SourceIdProperty, ObjectId.Parse(pt.SourceId)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.SourceIdProperty, BsonNull.Value));
                    }

                    if (pt.DataSource != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.DataSourceProperty, pt.DataSource));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.DataSourceProperty, BsonNull.Value));
                    }

                    if (pt.ExternalRecordId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.ExternalRecordIdProperty, pt.ExternalRecordId));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.ExternalRecordIdProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(pt.CodingSystemId))
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.CodingSystemProperty, ObjectId.Parse(pt.CodingSystemId)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.CodingSystemProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(pt.Code))
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.CodeProperty, pt.Code));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.CodeProperty, BsonNull.Value));
                    }
                    if (pt.Notes != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.NotesProperty, pt.Notes));
                    }
                    if (pt.SystemName != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.SystemProperty, pt.SystemName));
                    }
                    uv.Add(MB.Update.Set(MEPatientAllergy.DeleteFlagProperty, pt.DeleteFlag));
                    DataAuditType type;
                    if (pt.DeleteFlag)
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays)));
                        type = DataAuditType.Delete;
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientAllergy.TTLDateProperty, BsonNull.Value));
                        type = DataAuditType.Update;
                    }
                    IMongoUpdate update = MB.Update.Combine(uv);
                    ctx.PatientAllergies.Collection.Update(q, update);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientAllergy.ToString(),
                                             pt.Id,
                                             type,
                                             pa.ContractNumber);

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