Esempio n. 1
0
        public void SaveChanges()
        {
            try
            {
                var stats    = new SqlTableStats("InsuranceProviders");
                var conStats = new SqlTableStats("InsuranceContacts");
                var addStats = new SqlTableStats("InsuranceAddresses");

                TransactionManager.DatabaseContext.InsuranceProviders.AddRange(CompletedMappings);
                stats.PreSaveCount    = TransactionManager.DatabaseContext.ChangeTracker.Entries <InsuranceProvider>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                conStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <InsuranceContact>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                addStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <InsuranceAddress>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount    = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;
                conStats.PostSaveCount = (saved > conStats.PreSaveCount) ? conStats.PreSaveCount : saved;
                addStats.PostSaveCount = (saved > addStats.PreSaveCount) ? addStats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
                MappingStatistics.SqlTableStatistics.Add(conStats);
                MappingStatistics.SqlTableStatistics.Add(addStats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating InsuranceProvider entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving InsuranceProvider entity", e);
            }
        }
        public void SaveChanges()
        {
            try
            {
                var stats = new SqlTableStats
                {
                    Tablename = "Institutions",
                };

                TransactionManager.DatabaseContext.Institutions.AddRange(CompletedMappings);
                stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Institution>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating Institution entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving Institution entity", e);
            }
        }
        public void SaveChanges()
        {
            try
            {
                Array.ForEach(tempCompanyId.ToArray(), a => a.Item2.CompanyId = nHelper.GetInsuranceCompanyId(a.Item1));

                var stats = new SqlTableStats
                {
                    Tablename    = "InsurancePlans",
                    PreSaveCount = CompletedMappings.Count()
                };

                // Ensure pateint id exist (has been commited) before updating database
                var q = from cm in CompletedMappings
                        from ps in map.GetPatients()
                        where cm.UserId == ps.UserId
                        select cm;

                TransactionManager.DatabaseContext.InsurancePlans.AddRange(q);
                stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <InsurancePlan>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating InsurancePlan entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving InsurancePlan entity", e);
            }
        }
        private void SaveCompletedPumpSettingMappings()
        {
            try
            {
                using (var ctx = new NuMedicsGlobalEntities())
                {
                    var stats = new SqlTableStats("PumpSettings");

                    ctx.PumpSettings.AddRange(CompletedPumpSettingMappings);
                    stats.PreSaveCount = ctx.ChangeTracker.Entries <PumpSetting>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();

                    var saved = ctx.SaveChanges();
                    stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                    MappingStatistics.SqlTableStatistics.Add(stats);
                }
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating PumpSetting entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving PumpSetting entity", e);
            }

            SaveCompletedPumpProgramMappings();
        }
        public void SaveChanges()
        {
            try
            {
                var stats = new SqlTableStats
                {
                    Tablename    = "PatientPhoneNumbers",
                    PreSaveCount = CompletedMappings.Count()
                };

                // Ensure pateint id exist (has been commited) before updating database
                var q = from cm in CompletedMappings
                        from ps in map.GetPatients()
                        where cm.UserId == ps.UserId
                        select cm;

                TransactionManager.DatabaseContext.PatientPhoneNumbers.AddRange(q);
                stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <PatientPhoneNumber>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating PatientPhonenumber entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving PatientPhonenumber entity", e);
            }
        }
Esempio n. 6
0
        public void SaveChanges()
        {
            try
            {
                var stats   = new SqlTableStats("CareSettings");
                var dcStats = new SqlTableStats("DiabetesControlTypes");

                // Ensure pateint id exist (has been commited) before updating database
                var q = from cm in CompletedMappings
                        from ps in mu.GetPatients()
                        where cm.UserId == ps.UserId
                        select cm;

                TransactionManager.DatabaseContext.CareSettings.AddRange(q);
                stats.PreSaveCount   = TransactionManager.DatabaseContext.ChangeTracker.Entries <CareSetting>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                dcStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <DiabetesControlType>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();

                stats.PostSaveCount   = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;
                dcStats.PostSaveCount = (saved > dcStats.PreSaveCount) ? dcStats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
                MappingStatistics.SqlTableStatistics.Add(dcStats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating CareSetting entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving CareSetting entity", e);
            }
        }
        public void SaveChanges()
        {
            try
            {
                var stats = new SqlTableStats
                {
                    Tablename    = "BloodGlucoseReadings",
                    PreSaveCount = CompletedBGMappings.Count
                };

                // Ensure pateint id exist (has been commited) before updating database
                var q = from cm in CompletedBGMappings
                        from ps in mu.GetPatients()
                        where cm.UserId == ps.UserId
                        select cm;

                TransactionManager.DatabaseContext.BloodGlucoseReadings.AddRange(q);
                stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <BloodGlucoseReading>()
                                     .Where(w => w.State == System.Data.Entity.EntityState.Added)
                                     .Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
                SaveTotalDailyInsulinDeliveries();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e)
            {
                throw new Exception("Error validating Blood Glucose Reading mapped entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving Blood Glucose Reading mapped entity", e);
            }
        }
        private void SaveDeviceSettings()
        {
            try
            {
                var stats = new SqlTableStats
                {
                    Tablename    = "DeviceSettings",
                    PreSaveCount = CompletedDeviceSettingsMappings.Count
                };

                var q = from cm in CompletedDeviceSettingsMappings
                        from ps in mu.GetPatients()
                        where cm.UserId == ps.UserId
                        select cm;

                TransactionManager.DatabaseContext.DeviceSettings.AddRange(q);
                stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <DeviceSetting>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
                SaveReadingEvents();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e)
            {
                throw new Exception("Error validating Device Settings mapped entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving Device Settings mapped entity", e);
            }
        }
Esempio n. 9
0
        public void SaveChanges()
        {
            try
            {
                var stats    = new SqlTableStats("Subscriptions");
                var payStats = new SqlTableStats("Payments");
                var chkStats = new SqlTableStats("Checks");
                var palStats = new SqlTableStats("PayPal");

                // Ensure pateint id exist (has been commited) before updating database
                var q = from cm in CompletedMappings
                        from ps in mu.GetPatients()
                        where cm.UserId == ps.UserId
                        select cm;
                // Ensure subscription has a matching institution id associated
                var r = from m in q
                        from i in TransactionManager.DatabaseContext.Institutions
                        where m.InstitutionId == i.InstitutionId
                        select m;

                TransactionManager.DatabaseContext.Subscriptions.AddRange(r);

                stats.PreSaveCount    = TransactionManager.DatabaseContext.ChangeTracker.Entries <Subscription>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                payStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Payment>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                chkStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Check>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                palStats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <PayPal>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount    = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;
                payStats.PostSaveCount = (saved > payStats.PreSaveCount) ? payStats.PreSaveCount : saved;
                chkStats.PostSaveCount = (saved > chkStats.PreSaveCount) ? chkStats.PreSaveCount : saved;
                palStats.PostSaveCount = (saved > palStats.PreSaveCount) ? palStats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
                MappingStatistics.SqlTableStatistics.Add(payStats);
                MappingStatistics.SqlTableStatistics.Add(chkStats);
                MappingStatistics.SqlTableStatistics.Add(palStats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating Subscription entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving Subscription entity", e);
            }
        }
        public void SaveChanges()
        {
            try
            {
                var stats    = new SqlTableStats("PatientDevices");
                var rhStats  = new SqlTableStats("ReadingHeaders");
                var dmStats  = new SqlTableStats("DiabetesManagementData");
                var pmpstats = new SqlTableStats("Pumps");

                // Ensure pateint id exist (has been commited) before updating database
                var q = from cm in CompletedMappings
                        from ps in mu.GetPatients()
                        where cm.UserId == ps.UserId
                        select cm;

                TransactionManager.DatabaseContext.PatientDevices.AddRange(q);
                stats.PreSaveCount    = TransactionManager.DatabaseContext.ChangeTracker.Entries <PatientDevice>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                rhStats.PreSaveCount  = TransactionManager.DatabaseContext.ChangeTracker.Entries <ReadingHeader>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                dmStats.PreSaveCount  = TransactionManager.DatabaseContext.ChangeTracker.Entries <DiabetesManagementData>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                pmpstats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Pump>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();

                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount    = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;
                rhStats.PostSaveCount  = (saved > rhStats.PreSaveCount) ? rhStats.PreSaveCount : saved;
                dmStats.PostSaveCount  = (saved > dmStats.PreSaveCount) ? dmStats.PreSaveCount : saved;
                pmpstats.PostSaveCount = (saved > pmpstats.PreSaveCount) ? pmpstats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
                MappingStatistics.SqlTableStatistics.Add(rhStats);
                MappingStatistics.SqlTableStatistics.Add(dmStats);
                MappingStatistics.SqlTableStatistics.Add(pmpstats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating PatientDevice entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving PatientDevice entity", e);
            }

            SaveCompletedPumpSettingMappings();
        }
Esempio n. 11
0
        public void SaveChanges()
        {
            try
            {
                var stats     = new SqlTableStats("Patients");
                var instStats = new SqlTableStats("Patients_Institutions");
                var addStats  = new SqlTableStats("PatientAddresses");

                Guid instId = nHelper.GetInstitutionId(MigrationVariables.CurrentSiteId);

                //save MRID collection
                var mrids = MemoryMappings.GetAllMRIDs();
                Array.ForEach(mrids.ToArray(), m => { m.InstitutionId = instId; });

                TransactionManager.DatabaseContext.MedicalRecordIdentifiers.AddRange(mrids);

                ////Set instition id for each patient
                var institution = TransactionManager.DatabaseContext.Institutions.FirstOrDefault(f => f.LegacySiteId == MigrationVariables.CurrentSiteId);
                Parallel.ForEach(CompletedMappings, c => { c.Institutions.Add(institution); c.InstitutionId = instId; });

                TransactionManager.DatabaseContext.Patients.AddRange(CompletedMappings);
                stats.PreSaveCount     = TransactionManager.DatabaseContext.ChangeTracker.Entries <Patient>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                instStats.PreSaveCount = stats.PreSaveCount;
                addStats.PreSaveCount  = TransactionManager.DatabaseContext.ChangeTracker.Entries <PatientAddress>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();

                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount     = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;
                instStats.PostSaveCount = (saved > instStats.PreSaveCount) ? instStats.PreSaveCount : saved;
                addStats.PostSaveCount  = (saved > addStats.PreSaveCount) ? addStats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
                MappingStatistics.SqlTableStatistics.Add(instStats);
                MappingStatistics.SqlTableStatistics.Add(addStats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating Patients entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving Patients entity", e);
            }
        }
Esempio n. 12
0
        public void SaveChanges()
        {
            try
            {
                Array.ForEach(tempMappings.ToArray(), a =>
                {
                    var careSetting = mu.FindPatientCareSetting(a.Item1);
                    if (careSetting != null)
                    {
                        var careId             = careSetting.CareSettingsId;
                        a.Item2.CareSettingsId = careSetting.CareSettingsId;
                    }
                    else
                    {
                        tempMappings.Remove(a);
                    }

                    CompletedMappings = tempMappings.Select(s => s.Item2).ToList();
                });

                var stats = new SqlTableStats
                {
                    Tablename    = "DailyTimeSlots",
                    PreSaveCount = CompletedMappings.Count()
                };

                TransactionManager.DatabaseContext.DailyTimeSlots.AddRange(CompletedMappings);
                stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <DailyTimeSlot>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating TimeSlot entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving TimeSlot entity", e);
            }
        }
        public void SaveChanges()
        {
            try
            {
                // loop through mappings to assign clinicians to saved users
                Array.ForEach(CompletedMappings.ToArray(), c => {
                    User user  = nHelper.GetUser(c.UserId);
                    var siteId = MemoryMappings.GetSiteIdFromPatientInfo(c.UserId);
                    var instId = nHelper.GetInstitutionId(siteId);

                    if (instId != Guid.Empty)
                    {
                        c.InstitutionId = instId;

                        var usr       = TransactionManager.DatabaseContext.Users.Where(u => u.UserId == c.UserId).FirstOrDefault();
                        usr.Clinician = c;
                    }
                });

                var stats = new SqlTableStats
                {
                    Tablename    = "Clinicians",
                    PreSaveCount = CompletedMappings.Count()
                };

                stats.PreSaveCount = TransactionManager.DatabaseContext.ChangeTracker.Entries <Clinician>().Where(w => w.State == System.Data.Entity.EntityState.Added).Count();
                var saved = TransactionManager.DatabaseContext.SaveChanges();
                stats.PostSaveCount = (saved > stats.PreSaveCount) ? stats.PreSaveCount : saved;

                MappingStatistics.SqlTableStatistics.Add(stats);
            }
            catch (DbEntityValidationException e)
            {
                throw new Exception("Error validating Clinician entity", e);
            }
            catch (Exception e)
            {
                throw new Exception("Error saving Clinician entity", e);
            }
        }