public object Update(object entity)
        {
            bool result = false;
            var  mlist  = entity as List <MedicationData>;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    var bulk = ctx.Medications.Collection.InitializeUnorderedBulkOperation();

                    foreach (MEMedication fooDoc in ctx.Medications)
                    {
                        var update = new UpdateDocument {
                            { fooDoc.ToBsonDocument() }
                        };
                        update.Set("fmid", ObjectId.Parse(GetMedFamilyId(mlist, fooDoc.Id.ToString())));
                        bulk.Find(Query.EQ("_id", fooDoc.Id)).Upsert().UpdateOne(update);
                    }
                    BulkWriteResult bwr = bulk.Execute();

                    result = true;
                }
                return(result as object);
            }
            catch (Exception) { throw; }
        }
        private List <string> getPharmClassses(MedicationMongoContext ctx, string name)
        {
            List <string>       result = null;
            List <MEMedication> meMs   = ctx.Medications.Collection.Find(Query.EQ(MEMedication.FullNameProperty, name)).SetFields(MEMedication.PharmClassProperty).ToList();

            if (meMs != null && meMs.Count > 0)
            {
                List <string> list = new List <string>();
                meMs.ForEach(m =>
                {
                    if (m.PharmClass != null && m.PharmClass.Count > 0)
                    {
                        m.PharmClass.ForEach(p =>
                        {
                            // Add only unique pharm classes codes & do not add if it is string empty.
                            if (!list.Contains(p) && !string.IsNullOrEmpty(p))
                            {
                                list.Add(p);
                            }
                        });
                    }
                });
                if (list.Count > 0)
                {
                    result = list;
                }
            }
            return(result);
        }
        public object FindByPatientId(object request)
        {
            List <PatientMedFrequencyData>      list        = null;
            GetPatientMedFrequenciesDataRequest dataRequest = (GetPatientMedFrequenciesDataRequest)request;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientMedFrequency.PatientIdProperty, ObjectId.Parse(dataRequest.PatientId)));
                    queries.Add(Query.EQ(MEPatientMedFrequency.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(MEPatientMedFrequency.TTLDateProperty, BsonNull.Value));
                    IMongoQuery mQuery = Query.And(queries);
                    List <MEPatientMedFrequency> meFreqs = ctx.PatientMedFrequencies.Collection.Find(mQuery).ToList();
                    if (meFreqs != null && meFreqs.Count > 0)
                    {
                        list = new List <PatientMedFrequencyData>();
                        meFreqs.ForEach(p =>
                        {
                            PatientMedFrequencyData data = AutoMapper.Mapper.Map <PatientMedFrequencyData>(p);
                            list.Add(data);
                        });
                    }
                }
                return(list);
            }
            catch (Exception) { throw; }
        }
        public object FindByName(object request)
        {
            PostPatientMedFrequencyDataRequest dataRequest = (PostPatientMedFrequencyDataRequest)request;
            string id = null;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    var query =
                        from meFreq in ctx.PatientMedFrequencies.AsQueryable <MEPatientMedFrequency>()
                        where   meFreq.Name.ToLower() == dataRequest.PatientMedFrequencyData.Name.ToLower() &&
                        meFreq.DeleteFlag == false &&
                        meFreq.TTLDate == BsonNull.Value &&
                        meFreq.PatientId == ObjectId.Parse(dataRequest.PatientMedFrequencyData.PatientId)
                        select meFreq;
                    if (query.FirstOrDefault() != null)
                    {
                        id = query.FirstOrDefault().Id.ToString();
                    }
                }
                return(id);
            }
            catch (Exception) { throw; }
        }
        public void UndoDelete(object entity)
        {
            UndoDeletePatientMedSuppsDataRequest request = (UndoDeletePatientMedSuppsDataRequest)entity;

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

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

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

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientMedSupp.ToString(),
                                             request.PatientMedSuppId.ToString(),
                                             DataAuditType.UndoDelete,
                                             request.ContractNumber);
                }
            }
            catch (Exception) { throw; }
        }
        public object Insert(object newEntity)
        {
            var request = newEntity as PostPatientMedFrequencyDataRequest;
            var mm      = request.PatientMedFrequencyData;

            try
            {
                var mePFreq = new MEPatientMedFrequency(this.UserId)
                {
                    Name      = mm.Name,
                    PatientId = ObjectId.Parse(mm.PatientId),
                };

                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    ctx.PatientMedFrequencies.Collection.Insert(mePFreq);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientMedFrequency.ToString(),
                                             mePFreq.Id.ToString(),
                                             DataAuditType.Insert,
                                             request.ContractNumber);
                    return(mePFreq.Id.ToString());
                }
            }
            catch (Exception) { throw; }
        }
Example #7
0
        public object Insert(object newEntity)
        {
            var request = newEntity as PostMedicationMapDataRequest;
            var mm      = request.MedicationMapData;

            try
            {
                var MEMedMap = new MEMedicationMapping(this.UserId)
                {
                    FullName      = string.IsNullOrEmpty(mm.FullName) ? null : mm.FullName.ToUpper(),
                    SubstanceName = mm.SubstanceName,
                    Strength      = mm.Strength,
                    Route         = string.IsNullOrEmpty(mm.Route) ? null : mm.Route.ToUpper(),
                    Form          = string.IsNullOrEmpty(mm.Form) ? null : mm.Form.ToUpper(),
                    Verified      = mm.Verified,
                    Custom        = mm.Custom
                };

                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    ctx.MedicationMaps.Collection.Insert(MEMedMap);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.MedicationMap.ToString(),
                                             MEMedMap.Id.ToString(),
                                             DataAuditType.Insert,
                                             request.ContractNumber);
                    return(AutoMapper.Mapper.Map <MedicationMapData>(MEMedMap));
                }
            }
            catch (Exception) { throw; }
        }
Example #8
0
        public void Delete(object entity)
        {
            DeleteMedicationMapsDataRequest request = (DeleteMedicationMapsDataRequest)entity;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    var query = MB.Query <MEMedicationMapping> .EQ(b => b.Id, ObjectId.Parse(request.Id));

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

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

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.MedicationMap.ToString(),
                                             request.Id.ToString(),
                                             DataAuditType.Delete,
                                             request.ContractNumber);
                }
            }
            catch (Exception) { throw; }
        }
Example #9
0
        public static IMongoMedicationRepository GetMedicationRepository(IDataDomainRequest request, RepositoryType type)
        {
            try
            {
                IMongoMedicationRepository repo = null;

                switch (type)
                {
                case RepositoryType.Medication:
                {
                    var context = new MedicationMongoContext(request.ContractNumber);
                    repo = new MongoMedicationRepository <MedicationMongoContext>(context)
                    {
                        UserId = request.UserId, ContractDBName = request.ContractNumber
                    };
                    break;
                }

                case RepositoryType.MedicationMapping:
                {
                    var context = new MedicationMongoContext(request.ContractNumber);
                    repo = new MongoMedicationMappingRepository <MedicationMongoContext>(context)
                    {
                        UserId = request.UserId, ContractDBName = request.ContractNumber
                    };
                    break;
                }

                case RepositoryType.PatientMedSupp:
                {
                    var context = new MedicationMongoContext(request.ContractNumber);
                    repo = new MongoPatientMedSuppRepository <MedicationMongoContext>(context)
                    {
                        UserId = request.UserId, ContractDBName = request.ContractNumber
                    };
                    break;
                }

                case RepositoryType.PatientMedFrequency:
                {
                    var context = new MedicationMongoContext(request.ContractNumber);
                    repo = new MongoPatientMedFrequencyRepository <MedicationMongoContext>(context)
                    {
                        UserId = request.UserId, ContractDBName = request.ContractNumber
                    };
                    break;
                }
                }
                return(repo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public object Search(object request)
        {
            int result = 0;
            GetPatientMedSuppsCountDataRequest dataRequest = (GetPatientMedSuppsCountDataRequest)request;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    if (string.IsNullOrEmpty(dataRequest.Name))
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.NameProperty, BsonNull.Value));
                    }
                    else
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.NameProperty, dataRequest.Name));
                    }
                    if (string.IsNullOrEmpty(dataRequest.Route))
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.RouteProperty, BsonNull.Value));
                    }
                    else
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.RouteProperty, dataRequest.Route));
                    }
                    if (string.IsNullOrEmpty(dataRequest.Form))
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.FormProperty, BsonNull.Value));
                    }
                    else
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.FormProperty, dataRequest.Form));
                    }
                    if (string.IsNullOrEmpty(dataRequest.Strength))
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.StrengthProperty, BsonNull.Value));
                    }
                    else
                    {
                        queries.Add(Query.EQ(MEPatientMedSupp.StrengthProperty, dataRequest.Strength));
                    }
                    queries.Add(Query.EQ(MEPatientMedSupp.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(MEPatientMedSupp.TTLDateProperty, BsonNull.Value));
                    IMongoQuery             mQuery = Query.And(queries);
                    List <MEPatientMedSupp> list   = ctx.PatientMedSupps.Collection.Find(mQuery).SetFields(MEPatientMedSupp.PatientIdProperty).ToList();
                    result = list.Select(s => s.PatientId).Distinct().Count();
                }
                return(result);
            }
            catch (Exception) { throw; }
        }
        public object InsertAll(List <object> entities)
        {
            try
            {
                var list  = entities.Cast <DTO.MedicationData>();
                var mColl = new List <MEMedication>();

                list.ToList().ForEach(m =>
                {
                    var med = new MEMedication("5368ff2ad4332316288f3e3e")
                    {
                        DeleteFlag            = m.DeleteFlag,
                        EndDate               = m.EndDate,
                        Form                  = m.Form,
                        Version               = m.Version,
                        Unit                  = m.Unit,
                        Strength              = m.Strength,
                        Route                 = m.Route,
                        PharmClass            = m.PharmClass,
                        SubstanceName         = m.SubstanceName,
                        NDC                   = m.NDC,
                        StartDate             = m.StartDate,
                        ProductId             = m.ProductId,
                        FullName              = m.FullName,
                        ProprietaryName       = m.ProprietaryName,
                        ProprietaryNameSuffix = m.ProprietaryNameSuffix
                    };

                    ObjectId objId;
                    if (ObjectId.TryParse(m.FamilyId, out objId))
                    {
                        med.FamilyId = objId;
                    }

                    mColl.Add(med);
                });

                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    object result = null;
                    ctx.Medications.Collection.InsertBatch(mColl);

                    return(result = true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:FindByID()::" + ex.Message, ex.InnerException);
            }
        }
Example #12
0
        public object InsertAll(List <object> entities)
        {
            try
            {
                var list  = entities.Cast <DTO.MedicationMapData>();
                var mColl = new List <MEMedicationMapping>();

                list.ToList().ForEach(mm =>
                {
                    var MEMedMap = new MEMedicationMapping("5368ff2ad4332316288f3e3e")
                    {
                        Custom        = mm.Custom,
                        FullName      = mm.FullName,
                        LastUpdatedOn = mm.LastUpdatedOn,
                        SubstanceName = mm.SubstanceName,
                        TTLDate       = mm.TTLDate,
                        Verified      = mm.Verified,
                        Version       = mm.Version,
                        //UpdatedBy = mm.UpdatedBy,
                        Strength   = mm.Strength,
                        Route      = mm.Route,
                        Form       = mm.Form,
                        DeleteFlag = false
                    };
                    mColl.Add(MEMedMap);
                });

                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    object result = null;
                    ctx.MedicationMaps.Collection.InsertBatch(mColl);

                    var mMapsData = new List <MedicationMapData>();
                    var mMaps     = ctx.MedicationMaps.Collection.FindAll().ToList();

                    mMaps.ForEach(mm => mMapsData.Add(Mapper.Map <MedicationMapData>(mm)));

                    return(mMapsData);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("DD:PatientProgramRepository:FindByID()::" + ex.Message, ex.InnerException);
            }
        }
Example #13
0
        public IEnumerable <object> SelectAll()
        {
            using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
            {
                List <IMongoQuery> queries = new List <IMongoQuery>();
                queries.Add(Query.EQ(MEMedicationMapping.DeleteFlagProperty, false));
                queries.Add(Query.EQ(MEMedicationMapping.TTLDateProperty, BsonNull.Value));
                IMongoQuery mQuery = Query.And(queries);

                List <MEMedicationMapping> meMeds = ctx.MedicationMaps.Collection.Find(mQuery).ToList();

                List <MedicationMapData> medsData = null;
                if (meMeds != null && meMeds.Count > 0)
                {
                    medsData = meMeds.Select(a => Mapper.Map <MedicationMapData>(a)).ToList();
                }

                return(medsData);
            }
        }
        public object FindByID(string entityID)
        {
            PatientMedSuppData data = null;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientMedSupp.IdProperty, ObjectId.Parse(entityID)));
                    IMongoQuery      mQuery = Query.And(queries);
                    MEPatientMedSupp mePMS  = ctx.PatientMedSupps.Collection.Find(mQuery).FirstOrDefault();
                    if (mePMS != null)
                    {
                        data = AutoMapper.Mapper.Map <PatientMedSuppData>(mePMS);
                    }
                }
                return(data);
            }
            catch (Exception) { throw; }
        }
        public object FindByPatientId(object request)
        {
            List <PatientMedSuppData>     list        = null;
            GetPatientMedSuppsDataRequest dataRequest = (GetPatientMedSuppsDataRequest)request;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    queries.Add(Query.EQ(MEPatientMedSupp.PatientIdProperty, ObjectId.Parse(dataRequest.PatientId)));
                    queries.Add(Query.EQ(MEPatientMedSupp.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(MEPatientMedSupp.TTLDateProperty, BsonNull.Value));
                    if (dataRequest.StatusIds != null && dataRequest.StatusIds.Count > 0)
                    {
                        queries.Add(Query.In(MEPatientMedSupp.StatusProperty, new BsonArray(dataRequest.StatusIds)));
                    }
                    if (dataRequest.CategoryIds != null && dataRequest.CategoryIds.Count > 0)
                    {
                        queries.Add(Query.In(MEPatientMedSupp.CategoryProperty, new BsonArray(dataRequest.CategoryIds)));
                    }
                    IMongoQuery             mQuery = Query.And(queries);
                    List <MEPatientMedSupp> mePMSs = ctx.PatientMedSupps.Collection.Find(mQuery).ToList();
                    if (mePMSs != null && mePMSs.Count > 0)
                    {
                        list = new List <PatientMedSuppData>();
                        mePMSs.ForEach(p =>
                        {
                            PatientMedSuppData data = AutoMapper.Mapper.Map <PatientMedSuppData>(p);
                            list.Add(data);
                        });
                    }
                }
                return(list);
            }
            catch (Exception) { throw; }
        }
Example #16
0
        public object Initialize(object newEntity)
        {
            PutInitializeMedicationMapDataRequest request = (PutInitializeMedicationMapDataRequest)newEntity;
            MedicationMapData data = null;

            try
            {
                MEMedicationMapping meMM = new MEMedicationMapping(this.UserId)
                {
                    FullName   = string.IsNullOrEmpty(request.MedicationMapData.FullName) ? null : request.MedicationMapData.FullName.ToUpper(),
                    Strength   = request.MedicationMapData.Strength,
                    Form       = string.IsNullOrEmpty(request.MedicationMapData.Form) ? null : request.MedicationMapData.Form.ToUpper(),
                    Route      = string.IsNullOrEmpty(request.MedicationMapData.Route) ? null : request.MedicationMapData.Route.ToUpper(),
                    TTLDate    = System.DateTime.UtcNow.AddDays(_initializeDays),
                    DeleteFlag = false
                };

                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    ctx.MedicationMaps.Collection.Insert(meMM);

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

                    data = new MedicationMapData
                    {
                        Id       = meMM.Id.ToString(),
                        FullName = meMM.FullName
                    };
                }
                return(data);
            }
            catch (Exception) { throw; }
        }
        public object Insert(object newEntity)
        {
            PutPatientMedSuppDataRequest request = (PutPatientMedSuppDataRequest)newEntity;
            PatientMedSuppData           data    = request.PatientMedSuppData;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    MEPatientMedSupp mePMS = new MEPatientMedSupp(this.UserId)
                    {
                        PatientId = ObjectId.Parse(data.PatientId),
                        //FamilyId = string.IsNullOrEmpty(data.FamilyId) ? (ObjectId?)null : ObjectId.Parse(data.FamilyId),
                        Name               = string.IsNullOrEmpty(data.Name) ? null : data.Name.ToUpper(),
                        CategoryId         = (Category)data.CategoryId,
                        TypeId             = ObjectId.Parse(data.TypeId),
                        StatusId           = (Status)data.StatusId,
                        Dosage             = data.Dosage,
                        Strength           = data.Strength,
                        Route              = string.IsNullOrEmpty(data.Route) ? null : data.Route.ToUpper(),
                        Form               = string.IsNullOrEmpty(data.Form) ? null : data.Form.ToUpper(),
                        PharmClasses       = getPharmClassses(ctx, data.Name),
                        NDCs               = (data.NDCs != null && data.NDCs.Count > 0) ? data.NDCs : null,
                        FreqQuantity       = data.FreqQuantity,
                        FreqHowOftenId     = string.IsNullOrEmpty(data.FreqHowOftenId) ? (ObjectId?)null : ObjectId.Parse(data.FreqHowOftenId),
                        FreqWhenId         = string.IsNullOrEmpty(data.FreqWhenId) ? (ObjectId?)null : ObjectId.Parse(data.FreqWhenId),
                        FrequencyId        = string.IsNullOrEmpty(data.FrequencyId) ? (ObjectId?)null : ObjectId.Parse(data.FrequencyId),
                        SourceId           = ObjectId.Parse(data.SourceId),
                        StartDate          = data.StartDate == null ? (DateTime?)null : data.StartDate,
                        EndDate            = data.EndDate == null ? (DateTime?)null : data.EndDate,
                        Reason             = data.Reason,
                        Notes              = data.Notes,
                        SigCode            = data.SigCode,
                        PrescribedBy       = data.PrescribedBy,
                        SystemName         = data.SystemName,
                        DeleteFlag         = false,
                        DataSource         = data.DataSource,
                        ExternalRecordId   = data.ExternalRecordId,
                        OriginalDataSource = data.OriginalDataSource,
                        Duration           = data.Duration,
                        DurationUnitId     = string.IsNullOrEmpty(data.DurationUnitId) ? (ObjectId?)null : ObjectId.Parse(data.DurationUnitId),
                        OtherDuration      = data.OtherDuration,
                        ReviewId           = string.IsNullOrEmpty(data.ReviewId) ? (ObjectId?)null : ObjectId.Parse(data.ReviewId),
                        RefusalReasonId    = string.IsNullOrEmpty(data.RefusalReasonId) ? (ObjectId?)null : ObjectId.Parse(data.RefusalReasonId),
                        OtherRefusalReason = data.OtherRefusalReason,
                        OrderedBy          = data.OrderedBy,
                        OrderedDate        = data.OrderedDate,
                        PrescribedDate     = data.PrescribedDate,
                        RxNumber           = Helper.TrimAndLimit(data.RxNumber, 50),
                        RxDate             = data.RxDate,
                        Pharmacy           = Helper.TrimAndLimit(data.Pharmacy, 500)
                    };
                    ctx.PatientMedSupps.Collection.Insert(mePMS);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientMedSupp.ToString(),
                                             mePMS.Id.ToString(),
                                             DataAuditType.Insert,
                                             request.ContractNumber);
                    return(mePMS.Id.ToString());
                }
            }
            catch (Exception) { throw; }
        }
        /// <summary>
        /// Find the exact match on name, strength, route and form
        /// If it does not yield any result, find a match on name, route and form.
        /// If it does not yield any result, find a match on name and route.
        /// If it does not yield any result, find a match on name.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public object FindNDCCodes(object request)
        {
            List <MEMedication>          list        = new List <MEMedication>();
            GetMedicationNDCsDataRequest dataRequest = (GetMedicationNDCsDataRequest)request;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    if (!IsNullOrEmpty(new String[] { dataRequest.Name, dataRequest.Strength, dataRequest.Unit, dataRequest.Route, dataRequest.Form }))
                    {
                        // find a match on name, strength, unit, route and form)
                        List <IMongoQuery> query1 = new List <IMongoQuery>();

                        query1.Add(Query.EQ(MEMedication.DeleteFlagProperty, false));
                        query1.Add(Query.EQ(MEMedication.FullNameProperty, dataRequest.Name));
                        query1.Add(Query.EQ(MEMedication.StrengthProperty, dataRequest.Strength));
                        query1.Add(Query.EQ(MEMedication.UnitProperty, dataRequest.Unit));
                        query1.Add(Query.EQ(MEMedication.RouteProperty, dataRequest.Route));
                        query1.Add(Query.EQ(MEMedication.FormProperty, dataRequest.Form));

                        IMongoQuery mQuery1 = Query.And(query1);
                        list = ctx.Medications.Collection.Find(mQuery1).SetFields(MEMedication.NDCProperty).ToList();
                    }
                    if (list.Count == 0 &&
                        !IsNullOrEmpty(new String[] { dataRequest.Name, dataRequest.Strength, dataRequest.Route, dataRequest.Form }))
                    {
                        // find a match on name, strength, route and form)
                        List <IMongoQuery> query2 = new List <IMongoQuery>();

                        query2.Add(Query.EQ(MEMedication.DeleteFlagProperty, false));
                        query2.Add(Query.EQ(MEMedication.FullNameProperty, dataRequest.Name));
                        query2.Add(Query.EQ(MEMedication.StrengthProperty, dataRequest.Strength));
                        query2.Add(Query.EQ(MEMedication.RouteProperty, dataRequest.Route));
                        query2.Add(Query.EQ(MEMedication.FormProperty, dataRequest.Form));

                        IMongoQuery mQuery2 = Query.And(query2);
                        list = ctx.Medications.Collection.Find(mQuery2).SetFields(MEMedication.NDCProperty).ToList();
                    }

                    if (list.Count == 0 && !IsNullOrEmpty(new String[] { dataRequest.Name, dataRequest.Route, dataRequest.Form }))
                    {
                        // find a match on name, route and form.
                        List <IMongoQuery> query3 = new List <IMongoQuery>();

                        query3.Add(Query.EQ(MEMedication.DeleteFlagProperty, false));
                        query3.Add(Query.EQ(MEMedication.FullNameProperty, dataRequest.Name));
                        query3.Add(Query.EQ(MEMedication.RouteProperty, dataRequest.Route));
                        query3.Add(Query.EQ(MEMedication.FormProperty, dataRequest.Form));

                        IMongoQuery mQuery3 = Query.And(query3);
                        list = ctx.Medications.Collection.Find(mQuery3).SetFields(MEMedication.NDCProperty).ToList();
                    }
                    if (list.Count == 0 && !IsNullOrEmpty(new String[] { dataRequest.Name, dataRequest.Route }))
                    {
                        // find a match on name and route.
                        List <IMongoQuery> query4 = new List <IMongoQuery>();
                        query4.Add(Query.EQ(MEMedication.DeleteFlagProperty, false));
                        query4.Add(Query.EQ(MEMedication.FullNameProperty, dataRequest.Name));
                        query4.Add(Query.EQ(MEMedication.RouteProperty, dataRequest.Route));

                        IMongoQuery mQuery4 = Query.And(query4);
                        list = ctx.Medications.Collection.Find(mQuery4).SetFields(MEMedication.NDCProperty).ToList();
                    }
                    if (list.Count == 0)
                    {
                        // find a match on name.
                        List <IMongoQuery> query5 = new List <IMongoQuery>();
                        query5.Add(Query.EQ(MEMedication.DeleteFlagProperty, false));
                        if (!string.IsNullOrEmpty(dataRequest.Name))
                        {
                            query5.Add(Query.EQ(MEMedication.FullNameProperty, dataRequest.Name));
                        }
                        IMongoQuery mQuery5 = Query.And(query5);
                        list = ctx.Medications.Collection.Find(mQuery5).SetFields(MEMedication.NDCProperty).ToList();
                    }
                }
                return(list);
            }
            catch (Exception ex) { throw; }
        }
Example #19
0
        public object Update(object entity)
        {
            bool result = false;
            PutMedicationMapDataRequest pa   = (PutMedicationMapDataRequest)entity;
            MedicationMapData           data = pa.MedicationMapData;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    var q = MB.Query <MEMedicationMapping> .EQ(b => b.Id, ObjectId.Parse(data.Id));

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEMedicationMapping.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                    uv.Add(MB.Update.Set(MEMedicationMapping.VersionProperty, pa.Version));
                    uv.Add(MB.Update.Set(MEMedicationMapping.LastUpdatedOnProperty, System.DateTime.UtcNow));
                    if (!string.IsNullOrEmpty(data.FullName))
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.FullNameProperty, data.FullName.ToUpper()));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.FullNameProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.SubstanceName))
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.SubstanceNameProperty, data.SubstanceName));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.SubstanceNameProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Strength))
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.StrengthProperty, data.Strength));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.StrengthProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Form))
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.FormProperty, data.Form.ToUpper()));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.FormProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Route))
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.RouteProperty, data.Route.ToUpper()));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.RouteProperty, BsonNull.Value));
                    }
                    uv.Add(MB.Update.Set(MEMedicationMapping.CustomProperty, data.Custom));
                    uv.Add(MB.Update.Set(MEMedicationMapping.VerifiedProperty, data.Verified));
                    uv.Add(MB.Update.Set(MEMedicationMapping.DeleteFlagProperty, data.DeleteFlag));
                    DataAuditType type;
                    if (data.DeleteFlag)
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays)));
                        type = DataAuditType.Delete;
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEMedicationMapping.TTLDateProperty, BsonNull.Value));
                        type = DataAuditType.Update;
                    }
                    IMongoUpdate update = MB.Update.Combine(uv);
                    ctx.MedicationMaps.Collection.Update(q, update);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.MedicationMap.ToString(),
                                             data.Id,
                                             type,
                                             pa.ContractNumber);

                    result = true;
                }
                return(result as object);
            }
            catch (Exception) { throw; }
        }
Example #20
0
        public object Search(object request)
        {
            List <MedicationMapData>    list        = null;
            GetMedicationMapDataRequest dataRequest = (GetMedicationMapDataRequest)request;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    List <IMongoQuery> queries = new List <IMongoQuery>();
                    if (!string.IsNullOrEmpty(dataRequest.Name))
                    {
                        queries.Add(Query.EQ(MEMedicationMapping.FullNameProperty, dataRequest.Name.ToUpper()));
                    }
                    if (!string.IsNullOrEmpty(dataRequest.Route))
                    {
                        queries.Add(Query.EQ(MEMedicationMapping.RouteProperty, dataRequest.Route));
                    }
                    if (!string.IsNullOrEmpty(dataRequest.Form))
                    {
                        queries.Add(Query.EQ(MEMedicationMapping.FormProperty, dataRequest.Form));
                    }
                    if (!string.IsNullOrEmpty(dataRequest.Strength))
                    {
                        queries.Add(Query.EQ(MEMedicationMapping.StrengthProperty, dataRequest.Strength));
                    }
                    if (dataRequest.Type != 0)
                    {
                        if (dataRequest.Type == 1)
                        {
                            queries.Add(Query.EQ(MEMedicationMapping.CustomProperty, false));
                        }
                        else if (dataRequest.Type == 2)
                        {
                            queries.Add(Query.EQ(MEMedicationMapping.CustomProperty, true));
                        }
                    }
                    queries.Add(Query.EQ(MEMedicationMapping.DeleteFlagProperty, false));
                    queries.Add(Query.EQ(MEMedicationMapping.TTLDateProperty, BsonNull.Value));
                    IMongoQuery mQuery = Query.And(queries);
                    string[]    fields = { MEMedicationMapping.IdProperty, MEMedicationMapping.FullNameProperty, MEMedicationMapping.RouteProperty, MEMedicationMapping.StrengthProperty, MEMedicationMapping.FormProperty, MEMedicationMapping.CustomProperty };
                    List <MEMedicationMapping> meMMs = null;
                    if (dataRequest.Skip == 0 && dataRequest.Take == 0)
                    {
                        meMMs = ctx.MedicationMaps.Collection.Find(mQuery).SetFields(fields).ToList();
                    }
                    else
                    {
                        meMMs = ctx.MedicationMaps.Collection.Find(mQuery).SetFields(fields).SetSkip(dataRequest.Skip).SetLimit(dataRequest.Take).ToList();
                    }

                    if (meMMs != null && meMMs.Count > 0)
                    {
                        list = new List <MedicationMapData>();
                        meMMs.ForEach(p =>
                        {
                            MedicationMapData data = AutoMapper.Mapper.Map <MedicationMapData>(p);
                            list.Add(data);
                        });
                    }
                }
                return(list);
            }
            catch (Exception) { throw; }
        }
        public object Update(object entity)
        {
            bool result = false;
            PutPatientMedSuppDataRequest request = (PutPatientMedSuppDataRequest)entity;
            PatientMedSuppData           data    = request.PatientMedSuppData;

            try
            {
                using (MedicationMongoContext ctx = new MedicationMongoContext(ContractDBName))
                {
                    var q = MB.Query <MEPatientMedSupp> .EQ(b => b.Id, ObjectId.Parse(data.Id));

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEPatientMedSupp.UpdatedByProperty, ObjectId.Parse(this.UserId)));
                    uv.Add(MB.Update.Set(MEPatientMedSupp.VersionProperty, request.Version));
                    uv.Add(MB.Update.Set(MEPatientMedSupp.LastUpdatedOnProperty, System.DateTime.UtcNow));
                    if (data.PatientId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.PatientIdProperty, ObjectId.Parse(data.PatientId)));
                    }
                    if (!string.IsNullOrEmpty(data.Name))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.NameProperty, data.Name.ToUpper()));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.NameProperty, BsonNull.Value));
                    }
                    //if (data.FamilyId != null)
                    //{
                    //    uv.Add(MB.Update.Set(MEPatientMedSupp.FamilyIdProperty, ObjectId.Parse(data.FamilyId)));
                    //}
                    //else
                    //{
                    //    uv.Add(MB.Update.Set(MEPatientMedSupp.FamilyIdProperty, BsonNull.Value));
                    //}
                    if (data.CategoryId != 0)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.CategoryProperty, data.CategoryId));
                    }
                    if (data.TypeId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.TypeIdProperty, ObjectId.Parse(data.TypeId)));
                    }
                    if (data.StatusId != 0)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.StatusProperty, data.StatusId));
                    }
                    if (!string.IsNullOrEmpty(data.Dosage))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.DosageProperty, data.Dosage));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.DosageProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Strength))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.StrengthProperty, data.Strength));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.StrengthProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Form))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FormProperty, data.Form.ToUpper()));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FormProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Route))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RouteProperty, data.Route.ToUpper()));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RouteProperty, BsonNull.Value));
                    }
                    uv.Add(MB.Update.SetWrapped <List <string> >(MEPatientMedSupp.PharmClassProperty, (data.PharmClasses != null && data.PharmClasses.Count > 0) ? data.PharmClasses : null));
                    uv.Add(MB.Update.SetWrapped <List <string> >(MEPatientMedSupp.NDCProperty, (data.NDCs != null && data.NDCs.Count > 0) ? data.NDCs : null));
                    if (!string.IsNullOrEmpty(data.FreqQuantity))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FreqQuantityProperty, data.FreqQuantity));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FreqQuantityProperty, BsonNull.Value));
                    }
                    if (data.FreqHowOftenId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FreqHowOftenIdProperty, ObjectId.Parse(data.FreqHowOftenId)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FreqHowOftenIdProperty, BsonNull.Value));
                    }
                    if (data.FreqWhenId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FreqWhenIdProperty, ObjectId.Parse(data.FreqWhenId)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FreqWhenIdProperty, BsonNull.Value));
                    }
                    if (data.FrequencyId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FrequencyIdProperty, ObjectId.Parse(data.FrequencyId)));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.FrequencyIdProperty, BsonNull.Value));
                    }
                    if (data.SourceId != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.SourceIdProperty, ObjectId.Parse(data.SourceId)));
                    }
                    if (data.StartDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.StartDateProperty, data.StartDate));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.StartDateProperty, BsonNull.Value));
                    }
                    if (data.EndDate != null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.EndDateProperty, data.EndDate));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.EndDateProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Reason))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.ReasonProperty, data.Reason));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.ReasonProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.SigCode))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.SigProperty, data.SigCode));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.SigProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.Notes))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.NotesProperty, data.Notes));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.NotesProperty, BsonNull.Value));
                    }
                    if (!string.IsNullOrEmpty(data.PrescribedBy))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.PrescribedByProperty, data.PrescribedBy));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.PrescribedByProperty, BsonNull.Value));
                    }

                    if (!string.IsNullOrEmpty(data.DataSource))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.DataSourceProperty, data.DataSource));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.DataSourceProperty, BsonNull.Value));
                    }

                    if (!string.IsNullOrEmpty(data.ExternalRecordId))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.ExternalRecordIdProperty, data.ExternalRecordId));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.ExternalRecordIdProperty, BsonNull.Value));
                    }

                    if (string.IsNullOrEmpty(data.OriginalDataSource))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OriginalDataSourceProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OriginalDataSourceProperty, data.OriginalDataSource));
                    }
                    uv.Add(MB.Update.Set(MEPatientMedSupp.DurationProperty, data.Duration));
                    if (string.IsNullOrEmpty(data.DurationUnitId))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.DurationUnitProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.DurationUnitProperty, ObjectId.Parse(data.DurationUnitId)));
                    }
                    if (string.IsNullOrEmpty(data.OtherDuration))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OtherDurationProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OtherDurationProperty, data.OtherDuration));
                    }
                    if (string.IsNullOrEmpty(data.ReviewId))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.ReviewProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.ReviewProperty, ObjectId.Parse(data.ReviewId)));
                    }
                    if (string.IsNullOrEmpty(data.RefusalReasonId))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RefusalReasonProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RefusalReasonProperty, ObjectId.Parse(data.RefusalReasonId)));
                    }
                    if (string.IsNullOrEmpty(data.OtherRefusalReason))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OtherRefusalReasonProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OtherRefusalReasonProperty, data.OtherRefusalReason));
                    }
                    if (string.IsNullOrEmpty(data.OrderedBy))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OrderedByProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OrderedByProperty, data.OrderedBy));
                    }
                    if (data.OrderedDate == null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OrderedDateProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.OrderedDateProperty, data.OrderedDate));
                    }
                    if (data.PrescribedDate == null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.PrescribedDateProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.PrescribedDateProperty, data.PrescribedDate));
                    }
                    if (data.RxDate == null)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RxDateProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RxDateProperty, data.RxDate));
                    }
                    if (string.IsNullOrEmpty(data.Pharmacy))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.PharmacyProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.PharmacyProperty, Helper.TrimAndLimit(data.Pharmacy, 500)));
                    }
                    if (string.IsNullOrEmpty(data.RxNumber))
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RxNumberProperty, BsonNull.Value));
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.RxNumberProperty, Helper.TrimAndLimit(data.RxNumber, 50)));
                    }
                    uv.Add(MB.Update.Set(MEPatientMedSupp.SystemProperty, data.SystemName));
                    uv.Add(MB.Update.Set(MEPatientMedSupp.DeleteFlagProperty, data.DeleteFlag));
                    DataAuditType type;
                    if (data.DeleteFlag)
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays)));
                        type = DataAuditType.Delete;
                    }
                    else
                    {
                        uv.Add(MB.Update.Set(MEPatientMedSupp.TTLDateProperty, BsonNull.Value));
                        type = DataAuditType.Update;
                    }
                    IMongoUpdate update = MB.Update.Combine(uv);
                    ctx.PatientMedSupps.Collection.Update(q, update);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.PatientMedSupp.ToString(),
                                             data.Id,
                                             type,
                                             request.ContractNumber);

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