private void ExtractTermBolus(ICollection <DataRow> rows) { var exceptions = new ConcurrentQueue <Exception>(); Parallel.ForEach(rows, (row) => { try { Guid keyId = MemoryMappings.GetReadingHeaderKeyId(row["DOWNLOADKEYID"].ToString()); Guid userId = MemoryMappings.GetUserIdFromPatientInfo(MigrationVariables.CurrentSiteId, row["PATIENTKEYID"].ToString()); if (!keyId.Equals(Guid.Empty)) { var bd = new BolusDelivery(); var dd = new BolusDeliveryData(); dd.Name = "TERM_BOLUS"; dd.Value = (row["READINGNOTE"] is DBNull) ? String.Empty : row["READINGNOTE"].ToString(); dd.Date = (row["READINGDATETIME"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["READINGDATETIME"].ToString()); bd.ReadingKeyId = keyId; bd.UserId = userId; bd.StartDateTime = (row["READINGDATETIME"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["READINGDATETIME"].ToString()); bd.AmountDelivered = 0; bd.AmountSuggested = 0; bd.Duration = 0; bd.Type = "BolusDeliveryData"; bd.BolusDeliveryDatas.Add(dd); BolusDeliveries.Add(bd); } else { var primeKey = $"{row["DOWNLOADKEYID"].ToString()}-{row["SEQ"].ToString()}"; MappingStatistics.LogFailedMapping("METERREADING", primeKey, "BOLUSDELIVERY", typeof(BolusDelivery), String.Empty, "Failed to map TERM_BOLUS reading, unable to parse key id."); } } catch (Exception e) { throw; } }); if (exceptions.Count > 0) { throw new AggregateException(exceptions); } }
private void ExtractBolus(ICollection <DataRow> rows) { var exceptions = new ConcurrentQueue <Exception>(); Parallel.ForEach(rows, (row) => { try { Guid keyId = MemoryMappings.GetReadingHeaderKeyId(row["DOWNLOADKEYID"].ToString()); Guid userId = MemoryMappings.GetUserIdFromPatientInfo(MigrationVariables.CurrentSiteId, row["PATIENTKEYID"].ToString()); DateTime date = (row["READINGDATETIME"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["READINGDATETIME"].ToString()); if (!keyId.Equals(Guid.Empty)) { Dictionary <string, string> bolusData = GetBolusData(row["METERSENT"].ToString()); var carb = new BolusCarb { Date = date, CarbValue = mu.ParseInt(bolusData["Carbs"]) }; var bgTar = new BGTarget { Date = date, TargetBG = mu.ParseInt(bolusData["Target BG"]) }; var ic = new InsulinCarbRatio { Date = date, ICRatio = mu.ParseInt(bolusData["IC Ratio"]) }; var cf = new CorrectionFactor { Date = date, CorrectionFactorValue = mu.ParseInt(bolusData["Correct"]) }; var iCorr = new InsulinCorrection { Date = date, InsulinCorrectionValue = mu.ParseInt(bolusData["Correction"]), InsulinCorrectionAbove = mu.ParseInt(bolusData["Correction Above"]) }; var bd = new BolusDelivery(); double dCarbs = mu.ParseDouble(bolusData["Carbs"]); double dIC = mu.ParseDouble(bolusData["IC Ratio"]); bd.ReadingKeyId = keyId; bd.UserId = userId; bd.StartDateTime = (row["READINGDATETIME"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["READINGDATETIME"].ToString()); bd.AmountDelivered = mu.ParseDouble(bolusData["Total"]); bd.AmountSuggested = (dCarbs == 0.0) ? 0.0 : (dCarbs / dIC); bd.Duration = mu.ParseInt(bolusData["Extended Duration"]); bd.Type = "BolusDeliveryData"; bolusData.Remove("Carbs"); bolusData.Remove("Target BG"); bolusData.Remove("IC Ratio"); bolusData.Remove("Correct"); bolusData.Remove("Correction"); bolusData.Remove("Correct Above"); for (int i = 0; i < bolusData.Count; i++) { bd.BolusDeliveryDatas.Add(new BolusDeliveryData { Date = date, Name = bolusData.ElementAt(i).Key, Value = (String.IsNullOrEmpty(bolusData.ElementAt(i).Value)) ? String.Empty : bolusData.ElementAt(i).Value.Trim() }); } bd.BGTarget = bgTar; bd.BolusCarb = carb; bd.InsulinCarbRatio = ic; bd.InsulinCorrection = iCorr; bd.CorrectionFactor = cf; BolusDeliveries.Add(bd); } else { var primeKey = $"{row["DOWNLOADKEYID"].ToString()}-{row["SEQ"].ToString()}"; MappingStatistics.LogFailedMapping("METERREADING", primeKey, "BOLUSDELIVERY", typeof(BolusDelivery), String.Empty, "Failed to map BOLUS reading, unable to parse key id."); } } catch (Exception e) { exceptions.Enqueue(e); } }); if (exceptions.Count > 0) { throw new AggregateException(exceptions); } }