public void AddDiabetesManagementDataTest()
        {
            //Arrange
            var dm = Builder <DiabetesManagementData> .CreateNew().Build();

            //Act
            MemoryMappings.AddDiabetesManagementData(dm);
            var getDm = MemoryMappings.GetAllDiabetesManagementData().FirstOrDefault(f => f.DMDataId == dm.DMDataId);

            //Assert
            Assert.IsNotNull(getDm);
        }
        public void GetAllDiabetesManagementDataTest()
        {
            //Arrange
            var dm = Builder <DiabetesManagementData> .CreateListOfSize(10).Build();

            //Act
            foreach (var d in dm)
            {
                MemoryMappings.AddDiabetesManagementData(d);
            }

            //Assert
            Assert.AreEqual(10, dm.Count);
        }
Beispiel #3
0
        public void CreateDMDataMapping()
        {
            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 dm = new DiabetesManagementData
                            {
                                UserId         = userId,
                                LowBGLevel     = (row["LOWBGLEVEL"] is DBNull) ? 19 : (Int16)row["LOWBGLEVEL"],
                                HighBGLevel    = (row["HIGHBGLEVEL"] is DBNull) ? 201 : (Int16)row["HIGHBGLEVEL"],
                                PremealTarget  = (row["PREMEALTARGET"] is DBNull) ? 50 : (Int32)row["PREMEALTARGET"],
                                PostmealTarget = (row["POSTMEALTARGET"] is DBNull) ? 50 : (Int32)row["POSTMEALTARGET"],
                                ModifiedDate   = (row["LASTMODIFIEDDATE"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["LASTMODIFIEDDATE"].ToString()),
                                ModifiedUserId = (row["LASTMODIFIEDBYUSER"] is DBNull) ? Guid.Empty : mu.ParseGUID(row["LASTMODIFIEDBYUSER"].ToString())
                            };

                            // add to temp collection for addition with "PatientDevicesMapping"
                            MemoryMappings.AddDiabetesManagementData(dm);

                            var ibId = mu.FindInsulinBrandId(row["INSULINBRAND"].ToString());
                            var imId = mu.FindInsulinMethodId(row["INSULINMETHOD"].ToString());

                            CareSetting careset = new CareSetting();
                            careset.UserId                 = userId;
                            careset.HyperglycemicLevel     = (row["HYPERGLYCEMICLEVEL"] is DBNull) ? 0 : (Int16)row["HYPERGLYCEMICLEVEL"];
                            careset.HypoglycemicLevel      = (row["HYPOGLYCEMICLEVEL"] is DBNull) ? 0 : (Int16)row["HYPOGLYCEMICLEVEL"];
                            careset.InsulinMethod          = imId;
                            careset.InsulinBrand           = ibId;
                            careset.DiabetesManagementType = (row["DMTYPE"] is DBNull) ? String.Empty : row["DMTYPE"].ToString();
                            careset.DateModified           = (row["LASTMODIFIEDDATE"] is DBNull) ? new DateTime(1800, 1, 1) : mu.ParseFirebirdDateTime(row["LASTMODIFIEDDATE"].ToString());
                            careset.LastUpdatedByUser      = (row["LASTMODIFIEDBYUSER"] is DBNull) ? Guid.Empty : mu.ParseGUID(row["LASTMODIFIEDBYUSER"].ToString());

                            var ct = (row["DMCONTROLTYPE"] is DBNull) ? mu.ParseDMControlTypes(0) : mu.ParseDMControlTypes((Int32)row["DMCONTROLTYPE"]);
                            foreach (var item in ct)
                            {
                                DiabetesControlType dct = new DiabetesControlType();
                                dct.ControlName       = item.Key;
                                dct.DMDataId          = dm.DMDataId;
                                dct.IsEnabled         = (item.Value) ? true : false;
                                dct.LastUpdatedByUser = userId;

                                careset.DiabetesControlTypes.Add(dct);
                            }

                            if (CanAddToContext(careset.UserId, careset.HyperglycemicLevel, careset.HypoglycemicLevel))
                            {
                                CompletedMappings.Add(careset);
                            }
                            else
                            {
                                MappingStatistics.LogFailedMapping("DMDATA", patId, "CareSettings", typeof(CareSetting), JsonConvert.SerializeObject(careset), "Unable to add Care Setting to database.");
                                FailedCount++;
                            }
                        }
                    }
                }

                MappingStatistics.LogMappingStat("DMDATA", RecordCount, "CareSettings", CompletedMappings.Count, FailedCount);
            }
            catch (Exception e)
            {
                throw new Exception("Error creating CareSetting mapping.", e);
            }
        }