public override void Execute() { try { OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Loading Systems.", IsError = false }); ConcurrentBag <ESystem> sSys = new ConcurrentBag <ESystem>(); ConcurrentBag <MESystem> syss; using (PatientSystemMongoContext smct = new PatientSystemMongoContext(Contract)) { syss = new ConcurrentBag <MESystem>(smct.Systems.Collection.FindAllAs <MESystem>().ToList()); } //Parallel.ForEach(syss, sys => foreach (MESystem sys in syss)//.Where(t => !t.DeleteFlag )) { try { sSys.Add(new ESystem { MongoId = sys.Id.ToString(), DisplayLabel = sys.DisplayLabel, Field = sys.Field, Name = sys.Name, Primary = sys.Primary.ToString(), Status = sys.Status.ToString(), Version = sys.Version, UpdatedBy = sys.UpdatedBy == null ? string.Empty : sys.UpdatedBy.ToString(), RecordCreatedBy = sys.RecordCreatedBy.ToString(), RecordCreatedOn = sys.RecordCreatedOn, DeleteFlag = sys.DeleteFlag.ToString(), TTLDate = sys.TTLDate, LastUpdatedOn = sys.LastUpdatedOn }); } catch (Exception ex) { OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] " + ex.Message + ": " + ex.StackTrace, IsError = true }); } }//); SaveSubcollection(sSys); } catch (Exception ex) { throw ex; //SimpleLog.Log(new ArgumentException("LoadPatientPrograms()", ex)); } }
public override void Execute() { try { OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Loading Patients.", IsError = false }); ConcurrentBag <MEPatient> patients; using (PatientMongoContext pmctx = new PatientMongoContext(Contract)) { patients = new ConcurrentBag <MEPatient>(Utils.GetMongoCollectionList(pmctx.Patients.Collection, 50000)); } OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Patient mongo collection loaded.", IsError = false }); ConcurrentBag <MEPatientSystem> patientSystems = null; using (PatientSystemMongoContext psctx = new PatientSystemMongoContext(Contract)) { patientSystems = new ConcurrentBag <MEPatientSystem>(Utils.GetMongoCollectionList(psctx.PatientSystems.Collection, 50000)); } OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Patient system mongo collection loaded.", IsError = false }); Dictionary <ObjectId, string> dic = new Dictionary <ObjectId, string>(); foreach (var s in patientSystems.Where(s => !dic.ContainsKey(s.PatientId))) { dic.Add(s.PatientId, s.Id.ToString()); } #region //set patients //ConcurrentBag<EPatient> patientMap = new ConcurrentBag<EPatient>(); List <EPatient> patientMap = new List <EPatient>(); var pList = patients.ToList(); OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Creating Patient bulk load set.", IsError = false }); //Parallel.ForEach(pList, pt => foreach (MEPatient pt in pList) { try { string mongoPatientSystemId = dic.ContainsKey(pt.Id) ? dic[pt.Id] : null; patientMap.Add(new EPatient { MongoId = pt.Id.ToString(), FirstName = pt.FirstName, MiddleName = pt.MiddleName, LastName = pt.LastName, PreferredName = pt.PreferredName, Suffix = pt.Suffix, DateOfBirth = String.IsNullOrEmpty(pt.DOB) ? null : pt.DOB, Gender = pt.Gender, Priority = pt.Priority.ToString(), Version = Convert.ToInt32(pt.Version), MongoUpdatedBy = pt.UpdatedBy == null ? string.Empty : pt.UpdatedBy.Value.ToString(), LastUpdatedOn = pt.LastUpdatedOn ?? null, MongoRecordCreatedBy = pt.RecordCreatedBy.ToString(), RecordCreatedOn = ParseDate(pt.RecordCreatedOn), Delete = pt.DeleteFlag.ToString(), Background = pt.Background, TTLDate = pt.TTLDate ?? null, LSSN = pt.LastFourSSN, //== null ? null : (int?)Convert.ToInt32(pt.LastFourSSN), FSSN = pt.FullSSN, ClinicalBackGround = pt.ClinicalBackground, DataSource = pt.DataSource, MongoMaritalStatusId = pt.MaritalStatusId == null ? string.Empty : pt.MaritalStatusId.Value.ToString(), Protected = pt.Protected.ToString(), Deceased = pt.Deceased.ToString(), Status = pt.Status.ToString(), MongoReasonId = pt.ReasonId == null ? string.Empty : pt.ReasonId.Value.ToString(), StatusDataSource = pt.StatusDataSource, MongoPatientSystemId = mongoPatientSystemId, ExtraElements = null }); } catch (Exception ex) { OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Error in Loading Patient information" + ex.Message + ": " + ex.StackTrace, IsError = true }); } }//); OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Finished creating Patient bulk load set.", IsError = false }); SaveSubcollection(patientMap); #endregion //set patientsystems OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Creating patient system bulk load set.", IsError = false }); //ConcurrentBag<EPatientSystem> patientSystemMap = new ConcurrentBag<EPatientSystem>(); List <EPatientSystem> patientSystemMap = new List <EPatientSystem>(); List <MEPatientSystem> psList = patientSystems.ToList(); foreach (MEPatientSystem ps in patientSystems) { try { patientSystemMap.Add(new EPatientSystem { MongoPatientId = ps.PatientId.ToString(), MongoId = ps.Id.ToString(), Label = ps.DisplayLabel, //SystemId = pt.SystemId.ToString(), SystemName = ps.SystemName, MongoUpdatedBy = ps.UpdatedBy == null ? string.Empty : ps.UpdatedBy.Value.ToString(), LastUpdatedOn = ps.LastUpdatedOn ?? null, MongoRecordCreatedBy = ps.RecordCreatedBy.ToString(), RecordCreatedOn = ParseDate(ps.RecordCreatedOn).Value, Version = Convert.ToInt32(ps.Version), TTLDate = ps.TTLDate, Delete = ps.DeleteFlag.ToString(), Value = ps.Value, DataSource = ps.DataSource, Status = ps.Status.ToString(), Primary = ps.Primary.ToString(), SysId = ps.SystemId.ToString() }); } catch (Exception ex) { OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Error in Loading Patient information" + ex.Message + ": " + ex.StackTrace, IsError = true }); } }//); OnDocColEvent(new ETLEventArgs { Message = "[" + Contract + "] Finished creating Patient system bulk load set.", IsError = false }); SaveSystemSubcollection(patientSystemMap); } catch (Exception ex) { throw ex; } }