Example #1
0
        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; }
        }
Example #2
0
        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);
        }
Example #3
0
        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;
            }
        }
Example #4
0
        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; }
        }
Example #5
0
        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);
            }
        }