boluswizard: do not check for correction constraints
This commit is contained in:
parent
d0b6b4e9fd
commit
14dd29befd
2 changed files with 17 additions and 30 deletions
|
@ -271,15 +271,7 @@ class WizardDialog : DialogFragment() {
|
||||||
// Entered values
|
// Entered values
|
||||||
var c_bg = SafeParse.stringToDouble(treatments_wizard_bginput.text)
|
var c_bg = SafeParse.stringToDouble(treatments_wizard_bginput.text)
|
||||||
val c_carbs = SafeParse.stringToInt(treatments_wizard_carbsinput.text)
|
val c_carbs = SafeParse.stringToInt(treatments_wizard_carbsinput.text)
|
||||||
var c_correction = SafeParse.stringToDouble(treatments_wizard_correctioninput.text)
|
val c_correction = SafeParse.stringToDouble(treatments_wizard_correctioninput.text)
|
||||||
val corrAfterConstraint = c_correction
|
|
||||||
if (c_correction > 0)
|
|
||||||
c_correction = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(c_correction)).value()
|
|
||||||
if (Math.abs(c_correction - corrAfterConstraint) > 0.01) { // c_correction != corrAfterConstraint doesn't work
|
|
||||||
treatments_wizard_correctioninput.value = 0.0
|
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.bolusconstraintapplied))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val carbsAfterConstraint = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(c_carbs)).value()
|
val carbsAfterConstraint = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(c_carbs)).value()
|
||||||
if (Math.abs(c_carbs - carbsAfterConstraint) > 0.01) {
|
if (Math.abs(c_carbs - carbsAfterConstraint) > 0.01) {
|
||||||
treatments_wizard_carbsinput.value = 0.0
|
treatments_wizard_carbsinput.value = 0.0
|
||||||
|
@ -299,7 +291,7 @@ class WizardDialog : DialogFragment() {
|
||||||
|
|
||||||
val carbTime = SafeParse.stringToInt(treatments_wizard_carbtimeinput.text)
|
val carbTime = SafeParse.stringToInt(treatments_wizard_carbtimeinput.text)
|
||||||
|
|
||||||
wizard = BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, corrAfterConstraint,
|
wizard = BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, c_cob, c_bg, c_correction,
|
||||||
SP.getInt(R.string.key_boluswizard_percentage, 100).toDouble(),
|
SP.getInt(R.string.key_boluswizard_percentage, 100).toDouble(),
|
||||||
treatments_wizard_bgcheckbox.isChecked,
|
treatments_wizard_bgcheckbox.isChecked,
|
||||||
treatments_wizard_cobcheckbox.isChecked,
|
treatments_wizard_cobcheckbox.isChecked,
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
val profileName: String,
|
val profileName: String,
|
||||||
|
@ -60,14 +61,11 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
var glucoseStatus: GlucoseStatus? = null
|
var glucoseStatus: GlucoseStatus? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var targetBGLow = 0.0
|
private var targetBGLow = 0.0
|
||||||
private set
|
|
||||||
|
|
||||||
var targetBGHigh = 0.0
|
private var targetBGHigh = 0.0
|
||||||
private set
|
|
||||||
|
|
||||||
var bgDiff = 0.0
|
private var bgDiff = 0.0
|
||||||
private set
|
|
||||||
|
|
||||||
var insulinFromBG = 0.0
|
var insulinFromBG = 0.0
|
||||||
private set
|
private set
|
||||||
|
@ -96,8 +94,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
var trend = 0.0
|
var trend = 0.0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var accepted = false
|
private var accepted = false
|
||||||
private set
|
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
var calculatedTotalInsulin: Double = 0.0
|
var calculatedTotalInsulin: Double = 0.0
|
||||||
|
@ -127,12 +124,10 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, profile.units)
|
targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, profile.units)
|
||||||
}
|
}
|
||||||
if (useBg && bg > 0) {
|
if (useBg && bg > 0) {
|
||||||
if (bg >= targetBGLow && bg <= targetBGHigh) {
|
bgDiff = when {
|
||||||
bgDiff = 0.0
|
bg in targetBGLow..targetBGHigh -> 0.0
|
||||||
} else if (bg <= targetBGLow) {
|
bg <= targetBGLow -> bg - targetBGLow
|
||||||
bgDiff = bg - targetBGLow
|
else -> bg - targetBGHigh
|
||||||
} else {
|
|
||||||
bgDiff = bg - targetBGHigh
|
|
||||||
}
|
}
|
||||||
insulinFromBG = bgDiff / sens
|
insulinFromBG = bgDiff / sens
|
||||||
}
|
}
|
||||||
|
@ -147,7 +142,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Insuling from carbs
|
// Insulin from carbs
|
||||||
ic = profile.ic
|
ic = profile.ic
|
||||||
insulinFromCarbs = carbs / ic
|
insulinFromCarbs = carbs / ic
|
||||||
insulinFromCOB = if (useCob) (cob / ic) else 0.0
|
insulinFromCOB = if (useCob) (cob / ic) else 0.0
|
||||||
|
@ -197,7 +192,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
log.debug(this.toString())
|
log.debug(this.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun nsJSON(): JSONObject {
|
private fun nsJSON(): JSONObject {
|
||||||
val boluscalcJSON = JSONObject()
|
val boluscalcJSON = JSONObject()
|
||||||
try {
|
try {
|
||||||
boluscalcJSON.put("profile", profileName)
|
boluscalcJSON.put("profile", profileName)
|
||||||
|
@ -260,7 +255,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
if (absorptionRate > .25)
|
if (absorptionRate > .25)
|
||||||
confirmMessage += "<br/>" + MainApp.gs(R.string.slowabsorptiondetected, MainApp.gc(R.color.cobAlert), (absorptionRate * 100).toInt())
|
confirmMessage += "<br/>" + MainApp.gs(R.string.slowabsorptiondetected, MainApp.gc(R.color.cobAlert), (absorptionRate * 100).toInt())
|
||||||
}
|
}
|
||||||
if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) {
|
if (abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) {
|
||||||
confirmMessage += "<br/>" + MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), calculatedTotalInsulin, insulinAfterConstraints)
|
confirmMessage += "<br/>" + MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), calculatedTotalInsulin, insulinAfterConstraints)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,10 +263,10 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
}
|
}
|
||||||
|
|
||||||
fun confirmAndExecute(context: Context) {
|
fun confirmAndExecute(context: Context) {
|
||||||
val profile = ProfileFunctions.getInstance().profile
|
val profile = ProfileFunctions.getInstance().profile ?: return
|
||||||
val pump = ConfigBuilderPlugin.getPlugin().activePump
|
val pump = ConfigBuilderPlugin.getPlugin().activePump ?: return
|
||||||
|
|
||||||
if (pump != null && profile != null && (calculatedTotalInsulin > 0.0 || carbs > 0.0)) {
|
if (calculatedTotalInsulin > 0.0 || carbs > 0.0) {
|
||||||
val confirmMessage = confirmMessageAfterConstraints(pump)
|
val confirmMessage = confirmMessageAfterConstraints(pump)
|
||||||
|
|
||||||
val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
|
|
Loading…
Add table
Reference in a new issue