commit
423e7e763e
5 changed files with 83 additions and 58 deletions
|
@ -124,10 +124,7 @@ public class QuickWizardEntry {
|
||||||
trend = true;
|
trend = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BolusWizard wizard = new BolusWizard(profile, profileName, tempTarget, carbs(), cob, bg, 0d, 100, true, useCOB() == YES, bolusIOB, basalIOB, superBolus, useTempTarget() == YES, trend);
|
return new BolusWizard(profile, profileName, tempTarget, carbs(), cob, bg, 0d, 100, true, useCOB() == YES, bolusIOB, basalIOB, superBolus, useTempTarget() == YES, trend, "QuickWizard");
|
||||||
wizard.doCalc();
|
|
||||||
wizard.setNotes("QuickWizard");
|
|
||||||
return wizard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String buttonText() {
|
public String buttonText() {
|
||||||
|
|
|
@ -391,10 +391,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
c_cob = cobInfo.displayCob;
|
c_cob = cobInfo.displayCob;
|
||||||
}
|
}
|
||||||
|
|
||||||
wizard = new BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, 100d, bgCheckbox.isChecked(), cobCheckbox.isChecked(), bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), ttCheckbox.isChecked(), bgtrendCheckbox.isChecked());
|
wizard = new BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint, 100d, bgCheckbox.isChecked(), cobCheckbox.isChecked(), bolusIobCheckbox.isChecked(), basalIobCheckbox.isChecked(), superbolusCheckbox.isChecked(), ttCheckbox.isChecked(), bgtrendCheckbox.isChecked(), notesEdit.getText().toString(), SafeParse.stringToInt(editCarbTime.getText()));
|
||||||
wizard.doCalc();
|
|
||||||
wizard.setNotes(notesEdit.getText().toString());
|
|
||||||
wizard.setCarbTime(SafeParse.stringToInt(editCarbTime.getText()));
|
|
||||||
|
|
||||||
bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.getSens()));
|
bg.setText(c_bg + " ISF: " + DecimalFormatter.to1Decimal(wizard.getSens()));
|
||||||
bgInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBG()));
|
bgInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBG()));
|
||||||
|
@ -402,8 +399,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
carbs.setText(DecimalFormatter.to0Decimal(c_carbs) + "g IC: " + DecimalFormatter.to1Decimal(wizard.getIc()));
|
carbs.setText(DecimalFormatter.to0Decimal(c_carbs) + "g IC: " + DecimalFormatter.to1Decimal(wizard.getIc()));
|
||||||
carbsInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromCarbs()));
|
carbsInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromCarbs()));
|
||||||
|
|
||||||
bolusIobInsulin.setText(StringUtils.formatInsulin(wizard.getInsulingFromBolusIOB()));
|
bolusIobInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBolusIOB()));
|
||||||
basalIobInsulin.setText(StringUtils.formatInsulin(wizard.getInsulingFromBasalsIOB()));
|
basalIobInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromBasalsIOB()));
|
||||||
|
|
||||||
correctionInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromCorrection()));
|
correctionInsulin.setText(StringUtils.formatInsulin(wizard.getInsulinFromCorrection()));
|
||||||
|
|
||||||
|
|
|
@ -230,20 +230,13 @@ public class ActionStringHandler {
|
||||||
BolusWizard bolusWizard = new BolusWizard(profile, profileName, TreatmentsPlugin.getPlugin().getTempTargetFromHistory(),
|
BolusWizard bolusWizard = new BolusWizard(profile, profileName, TreatmentsPlugin.getPlugin().getTempTargetFromHistory(),
|
||||||
carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(profile.getUnits()),
|
carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(profile.getUnits()),
|
||||||
0d, percentage, useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend);
|
0d, percentage, useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend);
|
||||||
bolusWizard.doCalc();
|
|
||||||
|
|
||||||
Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolusWizard.getCalculatedTotalInsulin())).value();
|
if (Math.abs(bolusWizard.getInsulinAfterConstraints() - bolusWizard.getCalculatedTotalInsulin()) >= 0.01) {
|
||||||
if (Math.abs(insulinAfterConstraints - bolusWizard.getCalculatedTotalInsulin()) >= 0.01) {
|
|
||||||
sendError("Insulin constraint violation!" +
|
sendError("Insulin constraint violation!" +
|
||||||
"\nCannot deliver " + format.format(bolusWizard.getCalculatedTotalInsulin()) + "!");
|
"\nCannot deliver " + format.format(bolusWizard.getCalculatedTotalInsulin()) + "!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (bolusWizard.getCalculatedTotalInsulin() < 0) {
|
|
||||||
bolusWizard.setCalculatedTotalInsulin(0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bolusWizard.getCalculatedTotalInsulin() <= 0 && bolusWizard.getCarbs() <= 0) {
|
if (bolusWizard.getCalculatedTotalInsulin() <= 0 && bolusWizard.getCarbs() <= 0) {
|
||||||
rAction = "info";
|
rAction = "info";
|
||||||
rTitle = "INFO";
|
rTitle = "INFO";
|
||||||
|
@ -259,9 +252,9 @@ public class ActionStringHandler {
|
||||||
rMessage += "\nFrom" + formatInt.format(cobInfo.displayCob) + "g COB : " + format.format(bolusWizard.getInsulinFromCOB()) + "U";
|
rMessage += "\nFrom" + formatInt.format(cobInfo.displayCob) + "g COB : " + format.format(bolusWizard.getInsulinFromCOB()) + "U";
|
||||||
if (useBG) rMessage += "\nFrom BG: " + format.format(bolusWizard.getInsulinFromBG()) + "U";
|
if (useBG) rMessage += "\nFrom BG: " + format.format(bolusWizard.getInsulinFromBG()) + "U";
|
||||||
if (useBolusIOB)
|
if (useBolusIOB)
|
||||||
rMessage += "\nBolus IOB: " + format.format(bolusWizard.getInsulingFromBolusIOB()) + "U";
|
rMessage += "\nBolus IOB: " + format.format(bolusWizard.getInsulinFromBolusIOB()) + "U";
|
||||||
if (useBasalIOB)
|
if (useBasalIOB)
|
||||||
rMessage += "\nBasal IOB: " + format.format(bolusWizard.getInsulingFromBasalsIOB()) + "U";
|
rMessage += "\nBasal IOB: " + format.format(bolusWizard.getInsulinFromBasalsIOB()) + "U";
|
||||||
if (useTrend)
|
if (useTrend)
|
||||||
rMessage += "\nFrom 15' trend: " + format.format(bolusWizard.getInsulinFromTrend()) + "U";
|
rMessage += "\nFrom 15' trend: " + format.format(bolusWizard.getInsulinFromTrend()) + "U";
|
||||||
if (percentage != 100) {
|
if (percentage != 100) {
|
||||||
|
|
|
@ -29,57 +29,94 @@ import org.json.JSONObject
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class BolusWizard(val profile: Profile,
|
class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
val profileName: String,
|
val profileName: String,
|
||||||
val tempTarget: TempTarget?,
|
val tempTarget: TempTarget?,
|
||||||
val carbs: Int,
|
val carbs: Int,
|
||||||
val cob: Double,
|
val cob: Double,
|
||||||
val bg: Double,
|
val bg: Double,
|
||||||
val correction: Double,
|
val correction: Double,
|
||||||
val percentageCorrection: Double = 100.0,
|
private val percentageCorrection: Double = 100.0,
|
||||||
val useBg: Boolean,
|
private val useBg: Boolean,
|
||||||
val useCob: Boolean,
|
private val useCob: Boolean,
|
||||||
val includeBolusIOB: Boolean,
|
private val includeBolusIOB: Boolean,
|
||||||
val includeBasalIOB: Boolean,
|
private val includeBasalIOB: Boolean,
|
||||||
val useSuperBolus: Boolean,
|
private val useSuperBolus: Boolean,
|
||||||
val useTT: Boolean,
|
private val useTT: Boolean,
|
||||||
val useTrend: Boolean) {
|
private val useTrend: Boolean,
|
||||||
|
val notes: String = "",
|
||||||
|
private val carbTime: Int = 0
|
||||||
|
) {
|
||||||
|
|
||||||
private val log = LoggerFactory.getLogger(L.CORE)
|
private val log = LoggerFactory.getLogger(L.CORE)
|
||||||
|
|
||||||
// Intermediate
|
// Intermediate
|
||||||
var sens = 0.0
|
var sens = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var ic = 0.0
|
var ic = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var glucoseStatus: GlucoseStatus? = null
|
var glucoseStatus: GlucoseStatus? = null
|
||||||
|
private set
|
||||||
|
|
||||||
var targetBGLow = 0.0
|
var targetBGLow = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var targetBGHigh = 0.0
|
var targetBGHigh = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var bgDiff = 0.0
|
var bgDiff = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var insulinFromBG = 0.0
|
var insulinFromBG = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var insulinFromCarbs = 0.0
|
var insulinFromCarbs = 0.0
|
||||||
var insulingFromBolusIOB = 0.0
|
private set
|
||||||
var insulingFromBasalsIOB = 0.0
|
|
||||||
|
var insulinFromBolusIOB = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
|
var insulinFromBasalsIOB = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var insulinFromCorrection = 0.0
|
var insulinFromCorrection = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var insulinFromSuperBolus = 0.0
|
var insulinFromSuperBolus = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var insulinFromCOB = 0.0
|
var insulinFromCOB = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var insulinFromTrend = 0.0
|
var insulinFromTrend = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var trend = 0.0
|
var trend = 0.0
|
||||||
var carbTime = 0
|
private set
|
||||||
|
|
||||||
var notes = ""
|
|
||||||
var accepted = false
|
var accepted = false
|
||||||
|
private set
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
var calculatedTotalInsulin: Double = 0.0
|
var calculatedTotalInsulin: Double = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var totalBeforePercentageAdjustment: Double = 0.0
|
var totalBeforePercentageAdjustment: Double = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var carbsEquivalent: Double = 0.0
|
var carbsEquivalent: Double = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
var insulinAfterConstraints: Double = 0.0
|
var insulinAfterConstraints: Double = 0.0
|
||||||
|
private set
|
||||||
|
|
||||||
fun doCalc(): Double {
|
init {
|
||||||
|
doCalc()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doCalc() {
|
||||||
|
|
||||||
// Insulin from BG
|
// Insulin from BG
|
||||||
sens = profile.isf
|
sens = profile.isf
|
||||||
|
@ -102,11 +139,14 @@ class BolusWizard(val profile: Profile,
|
||||||
|
|
||||||
// Insulin from 15 min trend
|
// Insulin from 15 min trend
|
||||||
glucoseStatus = GlucoseStatus.getGlucoseStatusData()
|
glucoseStatus = GlucoseStatus.getGlucoseStatusData()
|
||||||
if (glucoseStatus != null && useTrend) {
|
glucoseStatus?.let {
|
||||||
trend = glucoseStatus!!.short_avgdelta
|
if (useTrend) {
|
||||||
insulinFromTrend = Profile.fromMgdlToUnits(trend, profile.units) * 3 / sens
|
trend = it.short_avgdelta
|
||||||
|
insulinFromTrend = Profile.fromMgdlToUnits(trend, profile.units) * 3 / sens
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Insuling from carbs
|
// Insuling from carbs
|
||||||
ic = profile.ic
|
ic = profile.ic
|
||||||
insulinFromCarbs = carbs / ic
|
insulinFromCarbs = carbs / ic
|
||||||
|
@ -120,8 +160,8 @@ class BolusWizard(val profile: Profile,
|
||||||
treatments.updateTotalIOBTempBasals()
|
treatments.updateTotalIOBTempBasals()
|
||||||
val basalIob = treatments.lastCalculationTempBasals.round()
|
val basalIob = treatments.lastCalculationTempBasals.round()
|
||||||
|
|
||||||
insulingFromBolusIOB = if (includeBolusIOB) -bolusIob.iob else 0.0
|
insulinFromBolusIOB = if (includeBolusIOB) -bolusIob.iob else 0.0
|
||||||
insulingFromBasalsIOB = if (includeBasalIOB) -basalIob.basaliob else 0.0
|
insulinFromBasalsIOB = if (includeBasalIOB) -basalIob.basaliob else 0.0
|
||||||
|
|
||||||
// Insulin from correction
|
// Insulin from correction
|
||||||
insulinFromCorrection = correction
|
insulinFromCorrection = correction
|
||||||
|
@ -135,7 +175,7 @@ class BolusWizard(val profile: Profile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Total
|
// Total
|
||||||
calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB
|
calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulinFromBolusIOB + insulinFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB
|
||||||
|
|
||||||
// Percentage adjustment
|
// Percentage adjustment
|
||||||
totalBeforePercentageAdjustment = calculatedTotalInsulin
|
totalBeforePercentageAdjustment = calculatedTotalInsulin
|
||||||
|
@ -154,8 +194,6 @@ class BolusWizard(val profile: Profile,
|
||||||
insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(calculatedTotalInsulin)).value()
|
insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(calculatedTotalInsulin)).value()
|
||||||
|
|
||||||
log.debug(this.toString())
|
log.debug(this.toString())
|
||||||
|
|
||||||
return calculatedTotalInsulin
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun nsJSON(): JSONObject {
|
fun nsJSON(): JSONObject {
|
||||||
|
@ -168,9 +206,9 @@ class BolusWizard(val profile: Profile,
|
||||||
boluscalcJSON.put("targetBGHigh", targetBGHigh)
|
boluscalcJSON.put("targetBGHigh", targetBGHigh)
|
||||||
boluscalcJSON.put("isf", sens)
|
boluscalcJSON.put("isf", sens)
|
||||||
boluscalcJSON.put("ic", ic)
|
boluscalcJSON.put("ic", ic)
|
||||||
boluscalcJSON.put("iob", -(insulingFromBolusIOB + insulingFromBasalsIOB))
|
boluscalcJSON.put("iob", -(insulinFromBolusIOB + insulinFromBasalsIOB))
|
||||||
boluscalcJSON.put("bolusiob", insulingFromBolusIOB)
|
boluscalcJSON.put("bolusiob", insulinFromBolusIOB)
|
||||||
boluscalcJSON.put("basaliob", insulingFromBasalsIOB)
|
boluscalcJSON.put("basaliob", insulinFromBasalsIOB)
|
||||||
boluscalcJSON.put("bolusiobused", includeBolusIOB)
|
boluscalcJSON.put("bolusiobused", includeBolusIOB)
|
||||||
boluscalcJSON.put("basaliobused", includeBasalIOB)
|
boluscalcJSON.put("basaliobused", includeBasalIOB)
|
||||||
boluscalcJSON.put("bg", bg)
|
boluscalcJSON.put("bg", bg)
|
||||||
|
@ -198,7 +236,7 @@ class BolusWizard(val profile: Profile,
|
||||||
return boluscalcJSON
|
return boluscalcJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
fun confirmMessageAfterConstraints(pump: PumpInterface): String {
|
private fun confirmMessageAfterConstraints(pump: PumpInterface): String {
|
||||||
|
|
||||||
var confirmMessage = MainApp.gs(R.string.entertreatmentquestion)
|
var confirmMessage = MainApp.gs(R.string.entertreatmentquestion)
|
||||||
if (insulinAfterConstraints > 0)
|
if (insulinAfterConstraints > 0)
|
||||||
|
|
|
@ -38,9 +38,9 @@ public class BolusWizardTest {
|
||||||
Profile profile = setupProfile(4d, 8d, 20d, 12d);
|
Profile profile = setupProfile(4d, 8d, 20d, 12d);
|
||||||
|
|
||||||
BolusWizard bw = new BolusWizard(profile, "", null, 20, 0.0, 4.2, 0d, 100d, true, true, true, true, false, false, false);
|
BolusWizard bw = new BolusWizard(profile, "", null, 20, 0.0, 4.2, 0d, 100d, true, true, true, true, false, false, false);
|
||||||
Double bolusForBg42 = bw.doCalc();
|
Double bolusForBg42 = bw.getCalculatedTotalInsulin();
|
||||||
bw = new BolusWizard(profile, "", null, 20, 0.0, 5.4, 0d, 100d, true, true, true, true, false, false, false);
|
bw = new BolusWizard(profile, "", null, 20, 0.0, 5.4, 0d, 100d, true, true, true, true, false, false, false);
|
||||||
Double bolusForBg54 = bw.doCalc();
|
Double bolusForBg54 = bw.getCalculatedTotalInsulin();
|
||||||
Assert.assertEquals(bolusForBg42, bolusForBg54);
|
Assert.assertEquals(bolusForBg42, bolusForBg54);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +49,9 @@ public class BolusWizardTest {
|
||||||
Profile profile = setupProfile(4d, 8d, 20d, 12d);
|
Profile profile = setupProfile(4d, 8d, 20d, 12d);
|
||||||
|
|
||||||
BolusWizard bw = new BolusWizard(profile, "", null, 20, 0.0, 9.8, 0d, 100d, true, true, true, true, false, false, false);
|
BolusWizard bw = new BolusWizard(profile, "", null, 20, 0.0, 9.8, 0d, 100d, true, true, true, true, false, false, false);
|
||||||
Double bolusForHighBg = bw.doCalc();
|
Double bolusForHighBg = bw.getCalculatedTotalInsulin();
|
||||||
bw = new BolusWizard(profile, "", null, 20, 0.0, 5.4, 0d, 100d, true, true, true, true, false, false, false);
|
bw = new BolusWizard(profile, "", null, 20, 0.0, 5.4, 0d, 100d, true, true, true, true, false, false, false);
|
||||||
Double bolusForBgInRange = bw.doCalc();
|
Double bolusForBgInRange = bw.getCalculatedTotalInsulin();
|
||||||
Assert.assertTrue(bolusForHighBg > bolusForBgInRange);
|
Assert.assertTrue(bolusForHighBg > bolusForBgInRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +60,9 @@ public class BolusWizardTest {
|
||||||
Profile profile = setupProfile(4d, 8d, 20d, 12d);
|
Profile profile = setupProfile(4d, 8d, 20d, 12d);
|
||||||
|
|
||||||
BolusWizard bw = new BolusWizard(profile, "", null, 20, 0.0, 3.6, 0d, 100d, true, true, true, true, false, false, false);
|
BolusWizard bw = new BolusWizard(profile, "", null, 20, 0.0, 3.6, 0d, 100d, true, true, true, true, false, false, false);
|
||||||
Double bolusForLowBg = bw.doCalc();
|
Double bolusForLowBg = bw.getCalculatedTotalInsulin();
|
||||||
bw = new BolusWizard(profile, "", null, 20, 0.0, 5.4, 0d, 100d, true, true, true, true, false, false, false);
|
bw = new BolusWizard(profile, "", null, 20, 0.0, 5.4, 0d, 100d, true, true, true, true, false, false, false);
|
||||||
Double bolusForBgInRange = bw.doCalc();
|
Double bolusForBgInRange = bw.getCalculatedTotalInsulin();
|
||||||
Assert.assertTrue(bolusForLowBg < bolusForBgInRange);
|
Assert.assertTrue(bolusForLowBg < bolusForBgInRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue