コード例 #1
0
        public void CreatePumpsMapping()
        {
            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)
                        {
                            List <PumpSetting> settings = null;
                            List <PumpProgram> programs = null;

                            if (MemoryMappings.GetAllPumpSettings().ContainsKey(userId))
                            {
                                var set = MemoryMappings.GetAllPumpSettings().Where(k => k.Key == userId).Single();
                                settings = set.Value;
                            }

                            if (MemoryMappings.GetAllPumpPrograms().ContainsKey(userId))
                            {
                                var allprog = MemoryMappings.GetAllPumpPrograms().Count; //TESTING

                                var prog = MemoryMappings.GetAllPumpPrograms().Where(p => p.Key == userId).Single();
                                var tl   = prog.Value;
                                programs = new List <PumpProgram>();
                                Array.ForEach(tl.ToArray(), a => {
                                    if (a.Item2.ProgramTimeSlots.Count > 0)
                                    {
                                        programs.Add(a.Item2);
                                    }
                                });
                            }

                            var pum = new Pump
                            {
                                UserId          = userId,
                                PumpType        = "Meter",
                                PumpName        = (row["PUMPBRAND"] is DBNull) ? String.Empty : row["PUMPBRAND"].ToString(),
                                PumpStartDate   = mu.ParseFirebirdDateTime(row["PUMPSTARTDATE"].ToString()),
                                PumpInfusionSet = (row["PUMPINFUSIONSET"] is DBNull) ? String.Empty : row["PUMPINFUSIONSET"].ToString(),
                                Cannula         = mu.ParseDouble(row["CANNULA"].ToString()),
                                ReplacementDate = mu.ParseFirebirdDateTime(row["DATEREPLACED"].ToString()),
                                Notes           = (row["NOTES"] is DBNull) ? String.Empty : row["NOTES"].ToString(),
                                PumpSettings    = settings,
                                PumpPrograms    = programs
                            };

                            MemoryMappings.AddPump(pum);

                            if (CanAddToContext(pum.UserId, pum.PumpName))
                            {
                                CompletedMappings.Add(pum);
                            }
                            else
                            {
                                MappingStatistics.LogFailedMapping("PATIENTPUMP", patId, "Pumps", typeof(Pump), JsonConvert.SerializeObject(pum), "Unable to add Pump to database.");
                                FailedCount++;
                            }
                        }
                    }
                }

                MappingStatistics.LogMappingStat("PATIENTPUMP", RecordCount, "Pumps", CompletedMappings.Count, FailedCount);
            }
            catch (Exception)
            {
                throw new Exception("Error creating Pump mapping.");
            }
        }
コード例 #2
0
        public void CreatePumpSettingMapping()
        {
            try
            {
                var dataSet = TableAgent.DataSet.Tables[FbTableName].Rows;
                RecordCount = TableAgent.RowCount;
                var dateSetter = DateTime.Now;

                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);

                    var icDict = new Dictionary <char, ProgramTimeSlot> {
                        { '1', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '2', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '3', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '4', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '5', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '6', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '7', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '8', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } }
                    };

                    var bgDict = new Dictionary <char, ProgramTimeSlot> {
                        { '1', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '2', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '3', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '4', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '5', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '6', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '7', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '8', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } }
                    };

                    var bcDict = new Dictionary <char, ProgramTimeSlot> {
                        { '1', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '2', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '3', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '4', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '5', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '6', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '7', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '8', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } }
                    };

                    var cfDict = new Dictionary <char, ProgramTimeSlot> {
                        { '1', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '2', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '3', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '4', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '5', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '6', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '7', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } },
                        { '8', new ProgramTimeSlot {
                              DateSet = dateSetter
                          } }
                    };

                    PumpProgram icProgram = DefaultPumpProgram();
                    PumpProgram bgProgram = DefaultPumpProgram();
                    PumpProgram bcProgram = DefaultPumpProgram();
                    PumpProgram cfProgram = DefaultPumpProgram();

                    icProgram.ProgramName = "PROG_IC";
                    bgProgram.ProgramName = "PROG_BG";
                    bcProgram.ProgramName = "PROG_BGC";
                    cfProgram.ProgramName = "PROG_CF";

                    icProgram.ProgramTypeId = 4;
                    bgProgram.ProgramTypeId = 5;
                    bcProgram.ProgramTypeId = 7;
                    cfProgram.ProgramTypeId = 3;

                    icProgram.ProgramTimeSlots = new List <ProgramTimeSlot>();
                    bgProgram.ProgramTimeSlots = new List <ProgramTimeSlot>();
                    bcProgram.ProgramTimeSlots = new List <ProgramTimeSlot>();
                    cfProgram.ProgramTimeSlots = new List <ProgramTimeSlot>();

                    if (!mHelper.HasPatientMigrated(patId))
                    {
                        if (userId != Guid.Empty)
                        {
                            var tempList = new List <PumpSetting>();

                            // iterate through table columns and only get columns that are NOT time slots
                            // as these will be settings
                            for (int i = 0; i < row.Table.Columns.Count; i++)
                            {
                                var column = row.Table.Columns[i].ColumnName.Trim();
                                // don't want columns that start with these characters - these are timeslot values which are handled in the 'else' statement
                                var exclude = new List <bool> {
                                    column.StartsWith("ic", StringComparison.OrdinalIgnoreCase),
                                    column.StartsWith("cf", StringComparison.OrdinalIgnoreCase),
                                    column.StartsWith("target", StringComparison.OrdinalIgnoreCase),
                                    column.StartsWith("patientid", StringComparison.OrdinalIgnoreCase)
                                };

                                if (exclude.All(a => !a))
                                {
                                    PumpSetting ps = new PumpSetting();
                                    ps.SettingName  = column;
                                    ps.SettingValue = (row[column] is DBNull) ? String.Empty : row[column].ToString();
                                    ps.Date         = new DateTime(1800, 1, 1);

                                    tempList.Add(ps);

                                    if (CanAddToContext(ps.SettingValue))
                                    {
                                        CompletedMappings.Add(ps);
                                    }
                                    else
                                    {
                                        MappingStatistics.LogFailedMapping("INSULETPUMPSETTINGS", patId, "PumpSettings", typeof(PumpSetting), JsonConvert.SerializeObject(ps), "Pump Setting has no value.");
                                        FailedCount++;
                                    }
                                }
                                else
                                {
                                    if (!(row[column] is DBNull))
                                    {
                                        if (column.StartsWith("cf", StringComparison.OrdinalIgnoreCase) && cfDict.ContainsKey(column.Last()))
                                        {
                                            var cfd = cfDict[column.Last()];
                                            if (column.StartsWith("cfstart", StringComparison.OrdinalIgnoreCase))
                                            {
                                                cfd.StartTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                            }

                                            if (column.StartsWith("cfstop", StringComparison.OrdinalIgnoreCase))
                                            {
                                                cfd.StopTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                            }

                                            if (column.StartsWith("cfvalue", StringComparison.OrdinalIgnoreCase))
                                            {
                                                cfd.Value = mu.ParseDouble(row[column].ToString());
                                            }
                                        }

                                        if (column.StartsWith("ic", StringComparison.OrdinalIgnoreCase) && icDict.ContainsKey(column.Last()))
                                        {
                                            var icd = icDict[column.Last()];
                                            if (column.StartsWith("icstart", StringComparison.OrdinalIgnoreCase))
                                            {
                                                icd.StartTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                            }

                                            if (column.StartsWith("icstop", StringComparison.OrdinalIgnoreCase))
                                            {
                                                icd.StopTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                            }

                                            if (column.StartsWith("icvalue", StringComparison.OrdinalIgnoreCase))
                                            {
                                                icd.Value = mu.ParseDouble(row[column].ToString());
                                            }
                                        }

                                        if (column.StartsWith("target", StringComparison.OrdinalIgnoreCase) && bgDict.ContainsKey(column.Last()) && bcDict.ContainsKey(column.Last()))
                                        {
                                            var bgd = bgDict[column.Last()];
                                            var bcd = bcDict[column.Last()];

                                            if (column.StartsWith("targetbgstart", StringComparison.OrdinalIgnoreCase))
                                            {
                                                bgd.StartTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                                bcd.StartTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                            }

                                            if (column.StartsWith("targetbgstop", StringComparison.OrdinalIgnoreCase))
                                            {
                                                bgd.StopTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                                bcd.StopTime = mu.ParseFirebirdTimespan(row[column].ToString());
                                            }

                                            if (column.StartsWith("targetbg", StringComparison.OrdinalIgnoreCase))
                                            {
                                                bgd.Value = mu.ParseDouble(row[column].ToString());
                                            }

                                            if (column.StartsWith("targetbgcorrect", StringComparison.OrdinalIgnoreCase))
                                            {
                                                bcd.Value = mu.ParseDouble(row[column].ToString());
                                            }
                                        }
                                    }
                                }
                            }

                            // add to Memory Mappings so that Pump object and retieve
                            // a single user should only have a single collections of PumpSettings in the FB database
                            MemoryMappings.AddPumpSetting(userId, tempList);
                        }
                    }

                    //Purge dictionaries
                    PurgeDictionary(icDict);
                    PurgeDictionary(bgDict);
                    PurgeDictionary(bcDict);
                    PurgeDictionary(cfDict);

                    // add dictionary values (ProgramTimeSlots)
                    var icCollection = AddTimeSlots(icProgram.ProgramTimeSlots.ToList(), icDict.Values);
                    foreach (var item in icCollection)
                    {
                        icProgram.ProgramTimeSlots.Add(item);
                    }

                    var bgCollection = AddTimeSlots(bgProgram.ProgramTimeSlots.ToList(), bgDict.Values);
                    foreach (var item in bgCollection)
                    {
                        bgProgram.ProgramTimeSlots.Add(item);
                    }

                    var bcCollection = AddTimeSlots(bcProgram.ProgramTimeSlots.ToList(), bcDict.Values);
                    foreach (var item in bcCollection)
                    {
                        bcProgram.ProgramTimeSlots.Add(item);
                    }

                    var cfCollection = AddTimeSlots(cfProgram.ProgramTimeSlots.ToList(), cfDict.Values);
                    foreach (var item in cfCollection)
                    {
                        cfProgram.ProgramTimeSlots.Add(item);
                    }

                    // add pump programs to memory mappings
                    AddPumpProgram(userId, icProgram);
                    AddPumpProgram(userId, bgProgram);
                    AddPumpProgram(userId, bcProgram);
                    AddPumpProgram(userId, cfProgram);
                }

                MappingStatistics.LogMappingStat("INSULETPUMPSETTINGS", RecordCount, "PumpSettings", CompletedMappings.Count, FailedCount);
            }
            catch (Exception e)
            {
                throw new Exception("Error creating PumpSetting mapping.", e);
            }
        }
コード例 #3
0
        private void ExtractNutrition(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());
                    string eventSubType = (row["EVENTSUBTYPE_1"] is DBNull) ? String.Empty : row["EVENTSUBTYPE_1"].ToString();

                    if (!keyId.Equals(Guid.Empty))
                    {
                        var date = (row["READINGDATETIME"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["READINGDATETIME"].ToString());

                        var nt = new NutritionReading
                        {
                            Date            = date,
                            ReadingDateTime = date,
                            ReadingKeyId    = keyId,
                            UserId          = userId
                        };

                        bool canAdd = true;
                        var cpValue = (row["CLINIPROVALUE"] is DBNull) ? 0 : mu.ParseDouble(row["CLINIPROVALUE"].ToString());

                        switch (eventSubType)
                        {
                        case "NUT_CARBS":
                            nt.Carbohydrates = cpValue;
                            break;

                        case "NUT_FAT":
                            nt.Fat = cpValue;
                            break;

                        case "NUT_CAL":
                            nt.Calories = cpValue;
                            break;

                        case "NUT_PROT":
                            nt.Protien = cpValue;
                            break;

                        default:
                            canAdd = false;
                            NoReadingTypeMatch(row);
                            break;
                        }

                        if (canAdd)
                        {
                            NutritionReadings.Add(nt);
                        }
                    }
                    else
                    {
                        var primeKey = $"{row["DOWNLOADKEYID"].ToString()}-{row["SEQ"].ToString()}";
                        MappingStatistics.LogFailedMapping("METERREADING", primeKey, "NUTRITIONREADINGS", typeof(NutritionReading), String.Empty, "Failed to map nutrition reading, unable to parse key id.");
                    }
                }
                catch (Exception e)
                {
                    exceptions.Enqueue(e);
                }
            });

            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }

            OnNutritionExtractionEvent(new MeterReadingHandlerEventArgs(true));
        }
コード例 #4
0
        public void CreatePumpTimeSlotsMapping()
        {
            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))
                    {
                        // temp collecions
                        var tempBasal = new List <ProgramTimeSlot>();
                        var tempBolus = new List <ProgramTimeSlot>();

                        var keyId       = mu.ParseInt(row["KEYID"].ToString());
                        var programKey  = mu.ParseInt(row["PROGRAMNUMBER"].ToString());
                        var programName = (row["PROGRAMNAME"] is DBNull) ? "Name" : row["PROGRAMNAME"].ToString();
                        var createDate  = (row["CREATEDATE"] is DBNull) ? DateTime.MinValue : mu.ParseFirebirdDateTime(row["CREATEDATE"].ToString());

                        for (int i = 1; i < 25; i++)
                        {
                            DateTime bastart = (row[$"BASAL{i}STARTTIME"] is DBNull) ? DateTime.MinValue : mu.ParseFirebirdDateTime(row[$"BASAL{i}STARTTIME"].ToString());
                            DateTime bastop  = (row[$"BASAL{i}STOPTIME"] is DBNull) ? DateTime.MinValue : mu.ParseFirebirdDateTime(row[$"BASAL{i}STOPTIME"].ToString());

                            if (bastart != DateTime.MinValue && bastop != DateTime.MinValue)
                            {
                                ProgramTimeSlot bats = new ProgramTimeSlot
                                {
                                    Value     = mu.ParseDouble(row[$"BASAL{i}VAL"].ToString()),
                                    StartTime = bastart.TimeOfDay,
                                    StopTime  = bastop.TimeOfDay,
                                    DateSet   = createDate
                                };

                                if (createDate != DateTime.MinValue && IsValid(bats))
                                {
                                    tempBasal.Add(bats);
                                }
                                else
                                {
                                    MappingStatistics.LogFailedMapping("PUMPTIMESLOTS", row["KEYID"].ToString(), "BasalProgramTimeSlots", typeof(ProgramTimeSlot), JsonConvert.SerializeObject(bats), "Unable to add BasalProgramTimeSlot to database because creation date was null.");
                                    FailedCount++;
                                }
                            }

                            if (i < 13)
                            {
                                DateTime botime = (row[$"BOLUS{i}TIME"] is DBNull) ? DateTime.MinValue : mu.ParseFirebirdDateTime(row[$"BOLUS{i}TIME"].ToString());

                                if (botime != DateTime.MinValue)
                                {
                                    ProgramTimeSlot bots = new ProgramTimeSlot
                                    {
                                        Value     = mu.ParseDouble(row[$"BOLUS{i}VAL"].ToString()),
                                        StartTime = botime.TimeOfDay,
                                        DateSet   = createDate
                                    };

                                    if (createDate != DateTime.MinValue && IsValid(bots))
                                    {
                                        tempBolus.Add(bots);
                                    }
                                    else
                                    {
                                        MappingStatistics.LogFailedMapping("PUMPTIMESLOTS", row["KEYID"].ToString(), "BolusProgramTimeSlots", typeof(ProgramTimeSlot), JsonConvert.SerializeObject(bots), "Unable to add BolusProgramTimeSlot to database because creation date was null.");
                                        FailedCount++;
                                    }
                                }
                            }
                        }

                        if (createDate == DateTime.MinValue)
                        {
                            FailedCount++;
                        }

                        Array.ForEach(tempBasal.ToArray(), a =>
                        {
                            MemoryMappings.AddBasalPrgTimeSlot(userId, createDate, a);
                        });

                        Array.ForEach(tempBolus.ToArray(), a =>
                        {
                            MemoryMappings.AddBolusPrgTimeSlot(userId, createDate, a);
                        });
                    }
                }

                MappingStatistics.LogMappingStat("PUMPTIMESLOTS", RecordCount, "BasalProgramTimeSlots", MemoryMappings.GetAllBasalPrgTimeSlots().Count, FailedCount);
                MappingStatistics.LogMappingStat("PUMPTIMESLOTS", RecordCount, "BolusProgramTimeSlots", MemoryMappings.GetAllBolusPrgTimeSlots().Count, FailedCount);
            }
            catch (Exception e)
            {
                throw new Exception("Error creating Pump Program Time Slot mapping.", e);
            }
        }