public CohortPatientViewData FindCohortPatientViewByPatientId(string patientId) { CohortPatientViewData data = null; try { using (PatientMongoContext ctx = new PatientMongoContext(_dbName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MECohortPatientView.PatientIDProperty, ObjectId.Parse(patientId))); //queries.Add(Query.EQ(MECohortPatientView.DeleteFlagProperty, false)); Commented out this line as there are few records in Prod that do not contain basic fields like del, ttl, uon, etc. IMongoQuery mQuery = Query.And(queries); MECohortPatientView meCPV = ctx.CohortPatientViews.Collection.Find(mQuery).FirstOrDefault(); if (meCPV != null) { data = new CohortPatientViewData { Id = meCPV.Id.ToString(), LastName = meCPV.LastName, PatientID = meCPV.PatientID.ToString(), AssignedToContactIds = meCPV.AssignedToContactIds }; } } return(data); } catch (Exception) { throw; } }
public object Insert(object newEntity) { PutCohortPatientViewDataRequest cohortRequest = newEntity as PutCohortPatientViewDataRequest; MECohortPatientView patientView = null; using (PatientMongoContext ctx = new PatientMongoContext(_dbName)) { //Does the patient exist in cohortpatientview? IMongoQuery query = Query.And( Query.EQ(MECohortPatientView.PatientIDProperty, ObjectId.Parse(cohortRequest.PatientID)), Query.EQ(MECohortPatientView.LastNameProperty, cohortRequest.LastName)); patientView = ctx.CohortPatientViews.Collection.FindOneAs <MECohortPatientView>(query); if (patientView == null) { patientView = new MECohortPatientView(this.UserId) { PatientID = ObjectId.Parse(cohortRequest.PatientID), LastName = cohortRequest.LastName, Version = cohortRequest.Version, DeleteFlag = false }; if (cohortRequest.SearchFields != null && cohortRequest.SearchFields.Count > 0) { List <SearchField> fields = new List <SearchField>(); foreach (SearchFieldData c in cohortRequest.SearchFields) { fields.Add(new SearchField { Active = c.Active, FieldName = c.FieldName, Value = c.Value }); } patientView.SearchFields = fields; } ctx.CohortPatientViews.Collection.Insert(patientView); AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.CohortPatientView.ToString(), patientView.Id.ToString(), Common.DataAuditType.Insert, cohortRequest.ContractNumber); } } return(new PutCohortPatientViewDataResponse { Id = patientView.Id.ToString() }); }
public object InsertAll(List <object> entities) { List <string> insertedIds = new List <string>(); try { using (PatientMongoContext ctx = new PatientMongoContext(_dbName)) { var bulk = ctx.CohortPatientViews.Collection.InitializeUnorderedBulkOperation(); foreach (CohortPatientViewData cpvData in entities) { MECohortPatientView meCPV = new MECohortPatientView(this.UserId) { PatientID = ObjectId.Parse(cpvData.PatientID), LastName = cpvData.LastName, DeleteFlag = false, AssignedToContactIds = cpvData.AssignedToContactIds }; if (cpvData.SearchFields != null && cpvData.SearchFields.Count > 0) { List <SearchField> fields = new List <SearchField>(); foreach (SearchFieldData c in cpvData.SearchFields) { fields.Add(new SearchField { Active = c.Active, FieldName = c.FieldName, Value = c.Value }); } meCPV.SearchFields = fields; } bulk.Insert(meCPV.ToBsonDocument()); insertedIds.Add(meCPV.Id.ToString()); } BulkWriteResult bwr = bulk.Execute(); } AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.CohortPatientView.ToString(), insertedIds, Common.DataAuditType.Insert, _dbName); } catch (Exception ex) { string aseProcessID = ConfigurationManager.AppSettings.Get("ASEProcessID") ?? "0"; Helper.LogException(int.Parse(aseProcessID), ex); } return(true); }
private void button1_Click(object sender, EventArgs e) { string sqlPatientQuery = string.Format("Select Top {0} ID, FirstName, LastName, CONVERT(VARCHAR, BirthDate, 101) as BirthDate, MiddleInitial, Gender, Suffix From ContactEntities where CategoryCode = 'PT' and DeleteFlag = 0", numPatients.Value.ToString()); string sqlConn = txtSQLConn.Text; List <MEPatient> patients = new List <MEPatient>(); List <MEPatientProblem> patientProblems = new List <MEPatientProblem>(); List <MECohortPatientView> cohortPatients = new List <MECohortPatientView>(); List <MEPatientSystem> patientSystems = new List <MEPatientSystem>(); List <MEContact> patientContacts = new List <MEContact>(); List <Problem> problems = null; List <State> states = null; string mongoConnString = txtMongoConn.Text; MongoDB.Driver.MongoDatabase mongoDB = Phytel.Services.MongoService.Instance.GetDatabase(mongoConnString); mongoDB.GetCollection("Patient").RemoveAll(); mongoDB.GetCollection("PatientProblem").RemoveAll(); mongoDB.GetCollection("CohortPatientView").RemoveAll(); mongoDB.GetCollection("PatientSystem").RemoveAll(); mongoDB.GetCollection("PatientUser").RemoveAll(); mongoDB.GetCollection("Contact").RemoveAll(); //additional collections to clear out since we are reloading patients mongoDB.GetCollection("PatientProgram").RemoveAll(); mongoDB.GetCollection("PatientProgramAttribute").RemoveAll(); mongoDB.GetCollection("PatientProgramResponse").RemoveAll(); mongoDB.GetCollection("PatientBarrier").RemoveAll(); mongoDB.GetCollection("PatientGoal").RemoveAll(); mongoDB.GetCollection("PatientIntervention").RemoveAll(); mongoDB.GetCollection("PatientNote").RemoveAll(); mongoDB.GetCollection("PatientObservation").RemoveAll(); mongoDB.GetCollection("PatientTask").RemoveAll(); mongoDB.GetCollection("PatientProgram").RemoveAll(); IMongoQuery q = Query.EQ("type", 1); problems = GetAllProblems(mongoDB.GetCollection("LookUp")); states = GetAllStates(mongoDB.GetCollection("LookUp")); System.Random rnd = new Random(); int maxNum = problems.Count() - 1; DataSet dsPatients = Phytel.Services.SQLDataService.Instance.ExecuteSQLDirect(sqlConn, sqlPatientQuery, 0); int counter = 0; foreach (DataRow dr in dsPatients.Tables[0].Rows) { counter++; MECohortPatientView currentPatientView = new MECohortPatientView(txtUserID.Text); string patientSystemID = dr["ID"].ToString(); MEPatient patient = new MEPatient(txtUserID.Text, null) { DisplayPatientSystemId = null, FirstName = dr["FirstName"].ToString(), LastName = dr["LastName"].ToString(), Gender = dr["Gender"].ToString().ToUpper(), DOB = dr["BirthDate"].ToString(), MiddleName = dr["MiddleInitial"].ToString(), Suffix = dr["Suffix"].ToString(), PreferredName = dr["FirstName"].ToString() + "o", DeleteFlag = false, TTLDate = null, Version = 1, LastUpdatedOn = DateTime.UtcNow }; List <Address> addresses = new List <Address>(); List <Email> emails = new List <Email>(); List <Phone> phones = new List <Phone>(); List <Phytel.API.DataDomain.Contact.DTO.CommMode> modes = new List <Phytel.API.DataDomain.Contact.DTO.CommMode>(); string sqlAddressQuery = string.Format("select top 1 Address1, Address2, City, [State], ZipCode from Address Where OwnerID = {0}", patientSystemID); string sqlEmailQuery = string.Format("select top 1 Address from Email Where OwnerID = {0}", patientSystemID); string sqlPhoneQuery = string.Format("select top 1 DialString from Phone Where OwnerID = {0}", patientSystemID); DataSet dsAddress = Phytel.Services.SQLDataService.Instance.ExecuteSQLDirect(sqlConn, sqlAddressQuery, 0); DataSet dsEmail = Phytel.Services.SQLDataService.Instance.ExecuteSQLDirect(sqlConn, sqlEmailQuery, 0); DataSet dsPhone = Phytel.Services.SQLDataService.Instance.ExecuteSQLDirect(sqlConn, sqlPhoneQuery, 0); if (dsAddress.Tables[0].Rows.Count > 0) { ObjectId stateID = states.Where(x => x.Code == dsAddress.Tables[0].Rows[0]["State"].ToString()).Select(y => y.DataId).FirstOrDefault(); addresses.Add(new Address { Id = ObjectId.GenerateNewId(), Line1 = dsAddress.Tables[0].Rows[0]["Address1"].ToString(), Line2 = dsAddress.Tables[0].Rows[0]["Address2"].ToString(), City = dsAddress.Tables[0].Rows[0]["City"].ToString(), StateId = stateID, PostalCode = dsAddress.Tables[0].Rows[0]["ZipCode"].ToString(), TypeId = ObjectId.Parse("52e18c2ed433232028e9e3a6") }); } if (dsEmail.Tables[0].Rows.Count > 0) { emails.Add(new Email { TypeId = ObjectId.Parse("52e18c2ed433232028e9e3a6"), Id = ObjectId.GenerateNewId(), Preferred = true, Text = dsEmail.Tables[0].Rows[0]["Address"].ToString() }); } if (dsPhone.Tables[0].Rows.Count > 0) { phones.Add(new Phone { Id = ObjectId.GenerateNewId(), IsText = true, Number = long.Parse(dsPhone.Tables[0].Rows[0]["DialString"].ToString()), PreferredPhone = true, PreferredText = false, TypeId = ObjectId.Parse("52e18c2ed433232028e9e3a6") }); } modes.Add(new Phytel.API.DataDomain.Contact.DTO.CommMode { ModeId = ObjectId.Parse("52e17cc2d433232028e9e38f"), OptOut = false, Preferred = false }); modes.Add(new Phytel.API.DataDomain.Contact.DTO.CommMode { ModeId = ObjectId.Parse("52e17ce6d433232028e9e390"), OptOut = false, Preferred = false }); modes.Add(new Phytel.API.DataDomain.Contact.DTO.CommMode { ModeId = ObjectId.Parse("52e17d08d433232028e9e391"), OptOut = false, Preferred = false }); modes.Add(new Phytel.API.DataDomain.Contact.DTO.CommMode { ModeId = ObjectId.Parse("52e17d10d433232028e9e392"), OptOut = false, Preferred = false }); MEContact patContact = new MEContact(txtUserID.Text, null) { Addresses = addresses, Emails = emails, FirstName = string.Empty, Gender = string.Empty, LastName = string.Empty, MiddleName = string.Empty, PatientId = patient.Id, Phones = phones, PreferredName = string.Empty, TimeZoneId = ObjectId.Parse("52e1817dd433232028e9e39e"), Modes = modes, Version = 1.0 }; MEPatientSystem patSystem = new MEPatientSystem(txtUserID.Text, null) { PatientId = patient.Id, OldSystemId = patientSystemID, SystemName = "Atmosphere", DeleteFlag = false, TTLDate = null, Version = 1.0, DisplayLabel = "ID", LastUpdatedOn = DateTime.UtcNow }; patient.DisplayPatientSystemId = patSystem.Id; patients.Add(patient); patientSystems.Add(patSystem); patientContacts.Add(patContact); currentPatientView.PatientID = patient.Id; currentPatientView.LastName = patient.LastName; currentPatientView.Version = 1.0; currentPatientView.SearchFields = new List <SearchField>(); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "FN", Value = patient.FirstName }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "LN", Value = patient.LastName }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "G", Value = patient.Gender.ToUpper() }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "DOB", Value = patient.DOB }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "MN", Value = patient.MiddleName }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "SFX", Value = patient.Suffix }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "PN", Value = patient.PreferredName }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "PCM" }); List <int> prodIds = new List <int>(); for (int i = 0; i < numProblems.Value; i++) { int probID = rnd.Next(maxNum); while (prodIds.Contains(probID)) { probID = rnd.Next(maxNum); } prodIds.Add(probID); patientProblems.Add(new MEPatientProblem(txtUserID.Text) { PatientID = patient.Id, Active = true, DeleteFlag = false, EndDate = null, Featured = true, LastUpdatedOn = DateTime.UtcNow, Level = 1, ProblemID = problems[probID].DataId, StartDate = null, TTLDate = null, Version = 1.0 }); currentPatientView.SearchFields.Add(new SearchField { Active = true, FieldName = "Problem", Value = problems[probID].DataId.ToString() }); } cohortPatients.Add(currentPatientView); if (counter == 1000) { mongoDB.GetCollection("Patient").InsertBatch(patients); mongoDB.GetCollection("PatientProblem").InsertBatch(patientProblems); mongoDB.GetCollection("CohortPatientView").InsertBatch(cohortPatients); mongoDB.GetCollection("PatientSystem").InsertBatch(patientSystems); mongoDB.GetCollection("Contact").InsertBatch(patientContacts); counter = 0; patients = new List <MEPatient>(); patientProblems = new List <MEPatientProblem>(); cohortPatients = new List <MECohortPatientView>(); patientSystems = new List <MEPatientSystem>(); patientContacts = new List <MEContact>(); } } if (patients.Count > 0) { mongoDB.GetCollection("Patient").InsertBatch(patients); mongoDB.GetCollection("PatientProblem").InsertBatch(patientProblems); mongoDB.GetCollection("CohortPatientView").InsertBatch(cohortPatients); mongoDB.GetCollection("PatientSystem").InsertBatch(patientSystems); mongoDB.GetCollection("Contact").InsertBatch(patientContacts); } }