Exemplo n.º 1
0
        public List <PatientAllergyData> UpdatePatientAllergies(PutPatientAllergiesDataRequest request)
        {
            try
            {
                List <PatientAllergyData> result = null;
                var repo = AllergyRepositoryFactory.GetAllergyRepository(request, RepositoryType.PatientAllergy);

                if (request.PatientAllergiesData != null && request.PatientAllergiesData.Count > 0)
                {
                    result = new List <PatientAllergyData>();
                    request.PatientAllergiesData.ForEach(p =>
                    {
                        PutPatientAllergyDataRequest req = new PutPatientAllergyDataRequest
                        {
                            Context            = request.Context,
                            ContractNumber     = request.ContractNumber,
                            PatientAllergyData = p,
                            UserId             = request.UserId,
                            Version            = request.Version
                        };
                        bool status = (bool)repo.Update(req);
                        if (status)
                        {
                            PatientAllergyData data = (PatientAllergyData)repo.FindByID(req.PatientAllergyData.Id);
                            result.Add(data);
                        }
                    });
                }
                return(result);
            }
            catch (Exception ex) { throw ex; }
        }
Exemplo n.º 2
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; }
        }