Example #1
0
        public UserBaseInsulinCalcProfileModel ToUserBaseInsulinCalcProfileModel(UserBaseInsulinCalcProfile baseProfile)
        {
            UserBaseInsulinCalcProfileModel returnProfile = null;
            if (baseProfile != null)
            {
                if(baseProfile is PumpInsulinProfile)
                {
                    returnProfile = new PumpInsulinProfileModel()
                    {
                        PumpType = (baseProfile as PumpInsulinProfile).PumpType
                    };
                }
                else if(baseProfile is RapidInsulinProfile)
                {
                    returnProfile = new RapidInsulinProfileModel()
                    {
                        BasalInsulinAmount = (baseProfile as RapidInsulinProfile).BasalInsulinAmount
                    };
                }

                returnProfile.BirthDate = baseProfile.BirthDate;
                returnProfile.DosageUnits = baseProfile.DosageUnits;
                returnProfile.InsulinCarbohydrateRatio = baseProfile.InsulinCarbohydrateRatio;
                returnProfile.MaxSugarRange = baseProfile.MaxSugarRange;
                returnProfile.MinSugarRange = baseProfile.MinSugarRange;
                returnProfile.Sex = baseProfile.Sex;
                returnProfile.UnitReductionValue = baseProfile.UnitReductionValue;
                returnProfile.UnitReductionUnits = baseProfile.UnitReductionUnits;
                returnProfile.Weight = baseProfile.Weight;
            }
            return returnProfile;
        }
 public static bool IfValidParameters(Meal meal, UserBaseInsulinCalcProfile insulinProfile)
 {
     if (meal != null && meal.CarbAmount > 0 && meal.PreMealSugarLevel > 0 && meal.PostMealSugarLevel > 0 &&
         insulinProfile != null && insulinProfile.MaxSugarRange > 0 && insulinProfile.UnitReductionValue > 0 && insulinProfile.InsulinCarbohydrateRatio > 0)
     {
         log.InfoFormat("[AlgorithmCalculations.IfValidParameters] Valid parameters: Meal.Id={0}.", meal.Id.ToString());
         return true;
     }
     else
     {
         log.ErrorFormat("[AlgorithmCalculations.IfValidParameters] Some of input parameters not valid.");
         return false;
     }
 }
        public static AlgorithmResult CalcMealCarbsDeviation(Meal meal, UserBaseInsulinCalcProfile insulinProfile)
        {
            AlgorithmResult result = new AlgorithmResult() { Status = "Unsuccess"};

            if (IfValidParameters(meal, insulinProfile))
            {
                log.InfoFormat("[CalcMealCarbsDeviation] meal.Id={0}, meal.PreMealSugarLevel={1}, meal.PostMealSugarLevel={2}.", meal.Id.ToString(), meal.PreMealSugarLevel, meal.PostMealSugarLevel);
                double unitReductionValue = (insulinProfile.UnitReductionUnits == UnitReductionUnits.mmolL) ?
                    UnitsConverter.MmolLToMgDl(insulinProfile.UnitReductionValue) : insulinProfile.UnitReductionValue;

                double insulinDosage = BaseInsulineFormulas.CalculatingInsulinDose(insulinProfile.MaxSugarRange, meal.PreMealSugarLevel,
                                           insulinProfile.UnitReductionUnits, unitReductionValue, insulinProfile.InsulinCarbohydrateRatio, insulinProfile.DosageUnits, meal.CarbAmount);
                double calculatedCarbsAmount = BaseInsulineFormulas.CalculateMealCarbs(insulinProfile.MaxSugarRange, meal.PostMealSugarLevel,
                                           insulinProfile.UnitReductionUnits, unitReductionValue, insulinProfile.InsulinCarbohydrateRatio, insulinProfile.DosageUnits, insulinDosage);

                result.Status = "Success";
                result.Result = Math.Round(calculatedCarbsAmount - meal.CarbAmount, 2);
            }
            else
            {
                log.ErrorFormat("[CalcMealCarbsDeviation] Error: Some input parameters was invalid.");
            }
            return result;
        }