public PatientMedSuppData SavePatientMedSupps(PutPatientMedSuppDataRequest request)
        {
            try
            {
                PatientMedSuppData result = null;
                var repo = MedicationRepositoryFactory.GetMedicationRepository(request, RepositoryType.PatientMedSupp);

                if (request.PatientMedSuppData != null)
                {
                    if (request.Insert)
                    {
                        string id = (string)repo.Insert(request);
                        if (!string.IsNullOrEmpty(id))
                        {
                            result = (PatientMedSuppData)repo.FindByID(id);
                        }
                    }
                    else
                    {
                        bool status = (bool)repo.Update(request);
                        if (status)
                        {
                            result = (PatientMedSuppData)repo.FindByID(request.PatientMedSuppData.Id);
                        }
                    }
                }
                return(result);
            }
            catch (Exception ex) { throw ex; }
        }
Beispiel #2
0
        public void SavePatientMedSupps_Test()
        {
            PutPatientMedSuppDataRequest request = new PutPatientMedSuppDataRequest
            {
                Context            = context,
                ContractNumber     = contractNumber,
                UserId             = userId,
                Version            = version,
                Insert             = true,
                PatientMedSuppData = new PatientMedSuppData {
                    CategoryId   = 1,
                    TypeId       = "545bdfa6d433232248966639",
                    DeleteFlag   = false,
                    Dosage       = "2",
                    EndDate      = DateTime.Now.AddDays(3),
                    StartDate    = DateTime.Now,
                    Form         = "TABLET",
                    Name         = "ASPIRIN",
                    Notes        = "This is a test note",
                    PatientId    = "54bdde96fe7a5b27384a9551",
                    PrescribedBy = "Dr. Louis",
                    Reason       = "This is a test reason",
                    Route        = "ORAL",
                    SystemName   = "Engage",
                    Strength     = "30 mg"
                }
            };
            PatientMedSuppData response = cm.SavePatientMedSupps(request);

            Assert.IsTrue(response.Id == "54bdde96fe7a5b27384aaad9");
        }
Beispiel #3
0
        public void SavePatientMedSupp_Test()
        {
            PatientMedSuppData pms = new PatientMedSuppData
            {
                CategoryId     = 1,
                DeleteFlag     = false,
                Dosage         = "One",
                EndDate        = DateTime.UtcNow,
                Form           = "tablet",
                FreqHowOftenId = "545be059d43323224896663a",
                FreqQuantity   = "Twice",
                FreqWhenId     = "545be126d433232248966643",
                Id             = "",
                Name           = "Exilir",
                //NDCs = ,
                Notes     = "This is my note",
                PatientId = "5325d9e9d6a4850adcbba4b1",
                //PharmClasses = ,
                PrescribedBy = "PCP",
                Reason       = "This is my reason",
                Route        = "Oral",
                //SigCode = ,
                SourceId = "544e9976d433231d9c0330ae",
                //StartDate = ,
                StatusId = 1,
                Strength = "90 mg",
                //SystemName = "Engage",
                TypeId = "545bdfa6d433232248966639",
            };


            PutPatientMedSuppDataRequest request = new PutPatientMedSuppDataRequest
            {
                Context            = context,
                ContractNumber     = contractNumber,
                PatientMedSuppData = pms,
                UserId             = userId,
                Version            = version
            };

            //[Route("/{Context}/{Version}/{ContractNumber}/PatientMedSupp/Update", "PUT")]
            PutPatientMedSuppDataResponse response = client.Put <PutPatientMedSuppDataResponse>(
                string.Format("{0}/{1}/{2}/{3}/PatientMedSupp/Update", url, context, version, contractNumber), request);

            Assert.IsNotNull(response);
        }
Beispiel #4
0
        public PutPatientMedSuppDataResponse Put(PutPatientMedSuppDataRequest request)
        {
            PutPatientMedSuppDataResponse response = new PutPatientMedSuppDataResponse {
                Version = request.Version
            };

            try
            {
                RequireUserId(request);
                response.PatientMedSuppData = Manager.SavePatientMedSupps(request);
            }
            catch (Exception ex)
            {
                RaiseException(response, ex);
            }
            return(response);
        }
Beispiel #5
0
        public PatientMedSuppData SavePatientMedSupps(PutPatientMedSuppDataRequest request)
        {
            var repo = StubRepositoryFactory.GetMedicationRepository(request, RepositoryType.PatientMedSupp);

            return((PatientMedSuppData)repo.Insert(request));
        }
        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; }
        }
        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; }
        }