private void AddPumpProgram(Guid userId, PumpProgram program) { if (program.ProgramTimeSlots != null || program.ProgramTimeSlots.Count > 0) { program.NumOfSegments = program.ProgramTimeSlots.Count; MemoryMappings.AddPumpProgram(userId, 0, program); } }
public void CreatePumpProgramsMapping() { try { var dataSet = TableAgent.DataSet.Tables[FbTableName].Rows; RecordCount = TableAgent.RowCount; foreach (DataRow row in dataSet) { // get userid from old aspnetdb matching on patientid #####.##### var patId = row["PATIENTID"].ToString(); var userId = MemoryMappings.GetUserIdFromPatientInfo(MigrationVariables.CurrentSiteId, patId); if (!mHelper.HasPatientMigrated(patId)) { if (userId != Guid.Empty) { var CreationDate = (row["CREATEDATE"] is DBNull) ? DateTime.MinValue : mu.ParseFirebirdDateTime(row["CREATEDATE"].ToString()); var Source = (row["SOURCE"] is DBNull) ? String.Empty : row["SOURCE"].ToString(); var Valid = mu.ParseFirebirdBoolean(row["ACTIVEPROGRAM"].ToString()); for (int i = 1; i < 8; i++) { var pKey = (row[$"PROG{i}KEYID"] is DBNull) ? 0 : mu.ParseInt(row[$"PROG{i}KEYID"].ToString()); if (pKey != 0) { for (int s = 0; s < 1; s++) { PumpProgram p = new PumpProgram(); p.CreationDate = CreationDate; p.Source = Source; p.Valid = true; p.IsEnabled = Valid; p.ProgramKey = pKey; p.NumOfSegments = 7; p.ProgramName = $"Prog {pKey}"; if (s == 0) { p.ProgramTypeId = 1; p.ProgramTimeSlots = GetBasalPrgTimeSlots(userId, CreationDate); } if (s == 1) { p.ProgramTypeId = 2; p.ProgramTimeSlots = GetBolusPrgTimeSlots(userId, CreationDate); } if (CreationDate != DateTime.MinValue && pKey != 0 && p.ProgramTimeSlots.Count > 0) { MemoryMappings.AddPumpProgram(userId, pKey, p); } else { MappingStatistics.LogFailedMapping("PATIENTPUMPPROGRAM", row["KEYID"].ToString(), "PumpPrograms", typeof(PumpProgram), JsonConvert.SerializeObject(p), "Unable to add PumpProgram to database because creation date was null."); FailedCount++; } } } } } } } MappingStatistics.LogMappingStat("PATIENTPUMPPROGRAM", RecordCount, "PumpPrograms", MemoryMappings.GetAllPumpPrograms().Count, FailedCount); } catch (Exception e) { throw new Exception("Error creating PumpProgram mapping.", e); } }