public void UndoDelete(object entity) { UndoDeletePatientSystemsDataRequest request = (UndoDeletePatientSystemsDataRequest)entity; try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { var query = MB.Query <MEPatientSystem> .EQ(b => b.Id, ObjectId.Parse(request.PatientSystemId)); var builder = new List <MB.UpdateBuilder>(); builder.Add(MB.Update.Set(MEPatientSystem.TTLDateProperty, BsonNull.Value)); builder.Add(MB.Update.Set(MEPatientSystem.DeleteFlagProperty, false)); builder.Add(MB.Update.Set(MEPatientSystem.LastUpdatedOnProperty, DateTime.UtcNow)); builder.Add(MB.Update.Set(MEPatientSystem.UpdatedByProperty, ObjectId.Parse(this.UserId))); IMongoUpdate update = MB.Update.Combine(builder); ctx.PatientSystems.Collection.Update(query, update); AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.PatientSystem.ToString(), request.PatientSystemId.ToString(), Common.DataAuditType.UndoDelete, request.ContractNumber); } } catch (Exception) { throw; } }
public object FindByExternalRecordId(string externalRecordId) { PatientSystemData data = null; try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientSystem.ExternalRecordIdProperty, externalRecordId)); queries.Add(Query.EQ(MEPatientSystem.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientSystem.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); MEPatientSystem mePS = ctx.PatientSystems.Collection.Find(mQuery).FirstOrDefault(); if (mePS != null) { data = new PatientSystemData { Id = mePS.Id.ToString(), }; } } return(data); } catch (Exception) { throw; } }
public object FindByID(string entityID) { SystemData data = null; if (!string.IsNullOrEmpty(entityID)) { try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MESystem.IdProperty, ObjectId.Parse(entityID))); queries.Add(Query.EQ(MESystem.DeleteFlagProperty, false)); queries.Add(Query.EQ(MESystem.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); MESystem s = ctx.Systems.Collection.Find(mQuery).FirstOrDefault(); if (s != null) { data = new SystemData { Id = s.Id.ToString(), Field = s.Field, Name = s.Name, DisplayLabel = s.DisplayLabel, Primary = s.Primary, StatusId = (int)s.Status }; } } } catch (Exception) { throw; } } return(data); }
public object InsertAll(List <object> entities) { BulkInsertResult result = new BulkInsertResult(); List <string> insertedIds = new List <string>(); List <string> errorMessages = new List <string>(); try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { var bulk = ctx.PatientSystems.Collection.InitializeUnorderedBulkOperation(); foreach (PatientSystemData data in entities) { MEPatientSystem mePS = new MEPatientSystem(this.UserId, data.CreatedOn) { PatientId = ObjectId.Parse(data.PatientId), Value = Helper.TrimAndLimit(data.Value, 100), Status = (Status)data.StatusId, Primary = data.Primary, SystemId = ObjectId.Parse(data.SystemId), DataSource = Helper.TrimAndLimit(data.DataSource, 50), DeleteFlag = false, ExternalRecordId = data.ExternalRecordId, LastUpdatedOn = data.UpdatedOn, UpdatedBy = ParseObjectId(data.UpdatedById) }; bulk.Insert(mePS.ToBsonDocument()); insertedIds.Add(mePS.Id.ToString()); } BulkWriteResult bwr = bulk.Execute(); } // TODO: Auditing. } catch (BulkWriteException bwEx) { // Get the error messages for the ones that failed. foreach (BulkWriteError er in bwEx.WriteErrors) { errorMessages.Add(er.Message); } } catch (Exception ex) { string aseProcessID = ConfigurationManager.AppSettings.Get("ASEProcessID") ?? "0"; Helper.LogException(int.Parse(aseProcessID), ex); } result.ProcessedIds = insertedIds; result.ErrorMessages = errorMessages; return(result); }
public object Insert(object newEntity) { InsertPatientSystemDataRequest request = newEntity as InsertPatientSystemDataRequest; PatientSystemData data = request.PatientSystemsData; string Id = null; try { if (data != null) { if (string.IsNullOrEmpty(data.Value) || string.IsNullOrWhiteSpace(data.Value)) { throw new ArgumentException("Patient System value is missing"); } if (data.StatusId == 0) { throw new ArgumentException("Patient System status is missing"); } using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { MEPatientSystem mePS = new MEPatientSystem(this.UserId, data.CreatedOn) { PatientId = ObjectId.Parse(data.PatientId), Value = Helper.TrimAndLimit(data.Value, 100), Status = (Status)data.StatusId, Primary = data.Primary, SystemId = ObjectId.Parse(data.SystemId), DataSource = Helper.TrimAndLimit(data.DataSource, 50), DeleteFlag = false, ExternalRecordId = data.ExternalRecordId, LastUpdatedOn = data.UpdatedOn }; ctx.PatientSystems.Collection.Insert(mePS); AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.PatientSystem.ToString(), mePS.Id.ToString(), DataAuditType.Insert, request.ContractNumber); Id = mePS.Id.ToString(); } } return(Id); } catch (Exception) { throw; } }
public List <PatientSystemData> Select(List <string> Ids) { List <PatientSystemData> psList = null; try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.In(MEPatientSystem.IdProperty, new BsonArray(Helper.ConvertToObjectIdList(Ids)))); queries.Add(Query.EQ(MEPatientSystem.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientSystem.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); List <MEPatientSystem> mePatients = ctx.PatientSystems.Collection.Find(mQuery).ToList(); if (mePatients != null && mePatients.Count > 0) { psList = new List <PatientSystemData>(); foreach (MEPatientSystem mePS in mePatients) { PatientSystemData data = new PatientSystemData { Id = mePS.Id.ToString(), PatientId = mePS.PatientId.ToString(), Value = mePS.Value, StatusId = (int)mePS.Status, Primary = mePS.Primary, ExternalRecordId = mePS.ExternalRecordId, SystemId = mePS.SystemId.ToString(), DataSource = mePS.DataSource, CreatedById = mePS.RecordCreatedBy.ToString(), CreatedOn = mePS.RecordCreatedOn, UpdatedById = mePS.UpdatedBy == null ? null : mePS.UpdatedBy.ToString(), UpdatedOn = mePS.LastUpdatedOn }; psList.Add(data); } } } return(psList); } catch (Exception) { throw; } }
public IEnumerable <object> SelectAll() { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientSystem.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientSystem.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); List <MEPatientSystem> mePatSys = ctx.PatientSystems.Collection.Find(mQuery).ToList(); List <PatientSystemOldData> patSys = null; if (mePatSys != null && mePatSys.Count > 0) { patSys = mePatSys.Select(a => Mapper.Map <PatientSystemOldData>(a)).ToList(); } return(patSys); } }
public IEnumerable <object> FindByPatientId(string patientId) { List <PatientSystemData> dataList = null; try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientSystem.PatientIdProperty, ObjectId.Parse(patientId))); queries.Add(Query.EQ(MEPatientSystem.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientSystem.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); List <MEPatientSystem> mePatientSystems = ctx.PatientSystems.Collection.Find(mQuery).ToList(); if (mePatientSystems != null && mePatientSystems.Count > 0) { dataList = new List <PatientSystemData>(); foreach (MEPatientSystem mePS in mePatientSystems) { dataList.Add(new PatientSystemData { Id = mePS.Id.ToString(), PatientId = mePS.PatientId.ToString(), Value = mePS.Value, StatusId = (int)mePS.Status, Primary = mePS.Primary, ExternalRecordId = mePS.ExternalRecordId, SystemId = mePS.SystemId.ToString(), DataSource = mePS.DataSource, CreatedById = mePS.RecordCreatedBy.ToString(), CreatedOn = mePS.RecordCreatedOn, UpdatedById = mePS.UpdatedBy == null ? null : mePS.UpdatedBy.ToString(), UpdatedOn = mePS.LastUpdatedOn }); } } } return(dataList); } catch (Exception) { throw; } }
public object FindByID(string entityID) { PatientSystemData data = null; try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientSystem.IdProperty, ObjectId.Parse(entityID))); queries.Add(Query.EQ(MEPatientSystem.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientSystem.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); MEPatientSystem mePS = ctx.PatientSystems.Collection.Find(mQuery).FirstOrDefault(); if (mePS != null) { data = new PatientSystemData { Id = mePS.Id.ToString(), PatientId = mePS.PatientId.ToString(), Value = mePS.Value, StatusId = (int)mePS.Status, Primary = mePS.Primary, ExternalRecordId = mePS.ExternalRecordId, SystemId = mePS.SystemId.ToString(), DataSource = mePS.DataSource, CreatedById = mePS.RecordCreatedBy.ToString(), CreatedOn = mePS.RecordCreatedOn, UpdatedById = mePS.UpdatedBy == null ? null : mePS.UpdatedBy.ToString(), UpdatedOn = mePS.LastUpdatedOn }; } } return(data); } catch (Exception) { throw; } }
public IEnumerable <object> Find(object entity) { GetSystemsDataRequest request = (GetSystemsDataRequest)entity; List <SystemData> dataList = null; try { using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MESystem.DeleteFlagProperty, false)); queries.Add(Query.EQ(MESystem.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); List <MESystem> meSS = ctx.Systems.Collection.Find(mQuery).ToList(); if (meSS != null && meSS.Count > 0) { dataList = new List <SystemData>(); meSS.ForEach(s => { SystemData ssData = new SystemData { Id = s.Id.ToString(), Field = s.Field, Name = s.Name, DisplayLabel = s.DisplayLabel, Primary = s.Primary, StatusId = (int)s.Status }; dataList.Add(ssData); }); } } return((IEnumerable <object>)dataList); } catch (Exception) { throw; } }
public object Update(object entity) { UpdatePatientSystemDataRequest request = (UpdatePatientSystemDataRequest)entity; PatientSystemData data = request.PatientSystemsData; bool result = false; try { if (data != null) { if (string.IsNullOrEmpty(data.Value) || string.IsNullOrWhiteSpace(data.Value)) { throw new ArgumentException("Patient System value is missing"); } if (data.StatusId == 0) { throw new ArgumentException("Patient System status is missing"); } using (PatientSystemMongoContext ctx = new PatientSystemMongoContext(ContractDBName)) { var q = MB.Query <MEPatientSystem> .EQ(b => b.Id, ObjectId.Parse(data.Id)); var uv = new List <MB.UpdateBuilder>(); uv.Add(MB.Update.Set(MEPatientSystem.UpdatedByProperty, ObjectId.Parse(this.UserId))); uv.Add(MB.Update.Set(MEPatientSystem.VersionProperty, request.Version)); uv.Add(MB.Update.Set(MEPatientSystem.LastUpdatedOnProperty, System.DateTime.UtcNow)); if (!string.IsNullOrEmpty(data.PatientId)) { uv.Add(MB.Update.Set(MEPatientSystem.PatientIdProperty, ObjectId.Parse(data.PatientId))); } uv.Add(MB.Update.Set(MEPatientSystem.ValueProperty, Helper.TrimAndLimit(data.Value, 100))); if (!string.IsNullOrEmpty(data.DataSource)) { uv.Add(MB.Update.Set(MEPatientSystem.DataSourceProperty, Helper.TrimAndLimit(data.DataSource, 50))); } else { uv.Add(MB.Update.Set(MEPatientSystem.DataSourceProperty, BsonNull.Value)); } if (data.StatusId != 0) { uv.Add(MB.Update.Set(MEPatientSystem.StatusProperty, data.StatusId)); } uv.Add(MB.Update.Set(MEPatientSystem.PrimaryProperty, data.Primary)); if (!string.IsNullOrEmpty(data.SystemId)) { uv.Add(MB.Update.Set(MEPatientSystem.SystemIdProperty, ObjectId.Parse(data.SystemId))); } IMongoUpdate update = MB.Update.Combine(uv); WriteConcernResult res = ctx.PatientSystems.Collection.Update(q, update); if (res.Ok == false) { throw new Exception("Failed to update a patient system: " + res.ErrorMessage); } else { AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.PatientSystem.ToString(), data.Id, DataAuditType.Update, request.ContractNumber); } result = true; } } return(result); } catch (Exception) { throw; } }
public PatientNoteRepositoryFactory(string contract, string userid) { _contract = contract; _userId = userid; _context = new PatientSystemMongoContext(_contract); }