- added methods to return correct Extended bolus size
- using exetended bolus size
This commit is contained in:
parent
c167728935
commit
679b4b2668
3 changed files with 47 additions and 39 deletions
|
@ -23,7 +23,7 @@ public class DoseSettings {
|
||||||
|
|
||||||
public DoseSettings(float step, int durationStep, int maxDuration, float minDose)
|
public DoseSettings(float step, int durationStep, int maxDuration, float minDose)
|
||||||
{
|
{
|
||||||
this(step, durationStep, maxDuration, minDose, null);
|
this(step, durationStep, maxDuration, minDose, Float.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCommon.utils;
|
package info.nightscout.androidaps.plugins.PumpCommon.utils;
|
||||||
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings;
|
||||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.DoseStepSize;
|
import info.nightscout.androidaps.plugins.PumpCommon.defs.DoseStepSize;
|
||||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
|
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
|
||||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
|
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
|
||||||
|
@ -12,64 +13,73 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
|
||||||
|
|
||||||
public class PumpUtil {
|
public class PumpUtil {
|
||||||
|
|
||||||
|
public static double determineCorrectBolusSize(double bolusAmount, PumpType pumpType) {
|
||||||
public static double determineCorrectBolusSize(double bolusAmount, PumpType pumpType)
|
if (bolusAmount == 0.0d || pumpType == null) {
|
||||||
{
|
|
||||||
if (bolusAmount == 0.0d || pumpType==null)
|
|
||||||
{
|
|
||||||
return bolusAmount;
|
return bolusAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bolusStepSize;
|
double bolusStepSize;
|
||||||
|
|
||||||
if (pumpType.getSpecialBolusSize()==null)
|
if (pumpType.getSpecialBolusSize() == null) {
|
||||||
{
|
|
||||||
bolusStepSize = pumpType.getBolusSize();
|
bolusStepSize = pumpType.getBolusSize();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
DoseStepSize specialBolusSize = pumpType.getSpecialBolusSize();
|
DoseStepSize specialBolusSize = pumpType.getSpecialBolusSize();
|
||||||
|
|
||||||
bolusStepSize = specialBolusSize.getStepSizeForAmount((float)bolusAmount);
|
bolusStepSize = specialBolusSize.getStepSizeForAmount((float)bolusAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.round(bolusAmount/bolusStepSize) * bolusStepSize;
|
return Math.round(bolusAmount / bolusStepSize) * bolusStepSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static double determineCorrectBasalSize(Double basalAmount, PumpType pumpType)
|
public static double determineCorrectExtendedBolusSize(double bolusAmount, PumpType pumpType) {
|
||||||
{
|
if (bolusAmount == 0.0d || pumpType == null) {
|
||||||
if ( basalAmount == null || basalAmount == 0.0d || pumpType==null)
|
return bolusAmount;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
double bolusStepSize;
|
||||||
|
|
||||||
|
if (pumpType.getExtendedBolusSettings() == null) { // this should be never null
|
||||||
|
return 0.0d;
|
||||||
|
}
|
||||||
|
|
||||||
|
DoseSettings extendedBolusSettings = pumpType.getExtendedBolusSettings();
|
||||||
|
|
||||||
|
bolusStepSize = extendedBolusSettings.getStep();
|
||||||
|
|
||||||
|
if (bolusAmount > extendedBolusSettings.getMaxDose()) {
|
||||||
|
bolusAmount = extendedBolusSettings.getMaxDose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.round(bolusAmount / bolusStepSize) * bolusStepSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static double determineCorrectBasalSize(Double basalAmount, PumpType pumpType) {
|
||||||
|
if (basalAmount == null || basalAmount == 0.0d || pumpType == null) {
|
||||||
return basalAmount;
|
return basalAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
double basalStepSize;
|
double basalStepSize;
|
||||||
|
|
||||||
if (pumpType.getBaseBasalSpecialSteps()==null)
|
if (pumpType.getBaseBasalSpecialSteps() == null) {
|
||||||
{
|
|
||||||
basalStepSize = pumpType.getBaseBasalStep();
|
basalStepSize = pumpType.getBaseBasalStep();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
DoseStepSize specialBolusSize = pumpType.getBaseBasalSpecialSteps();
|
DoseStepSize specialBolusSize = pumpType.getBaseBasalSpecialSteps();
|
||||||
|
|
||||||
basalStepSize = specialBolusSize.getStepSizeForAmount(basalAmount.floatValue());
|
basalStepSize = specialBolusSize.getStepSizeForAmount(basalAmount.floatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (basalAmount> pumpType.getTbrSettings().getMaxDose())
|
if (basalAmount > pumpType.getTbrSettings().getMaxDose())
|
||||||
basalAmount = pumpType.getTbrSettings().getMaxDose().doubleValue();
|
basalAmount = pumpType.getTbrSettings().getMaxDose().doubleValue();
|
||||||
|
|
||||||
|
return Math.round(basalAmount / basalStepSize) * basalStepSize;
|
||||||
return Math.round(basalAmount/basalStepSize) * basalStepSize;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType) {
|
||||||
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
|
|
||||||
{
|
|
||||||
// reset
|
// reset
|
||||||
pumpDescription.resetSettings();
|
pumpDescription.resetSettings();
|
||||||
|
|
||||||
|
@ -85,14 +95,11 @@ public class PumpUtil {
|
||||||
|
|
||||||
pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TempBasal);
|
pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TempBasal);
|
||||||
|
|
||||||
if (pumpType.getPumpTempBasalType()==PumpTempBasalType.Percent)
|
if (pumpType.getPumpTempBasalType() == PumpTempBasalType.Percent) {
|
||||||
{
|
|
||||||
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
|
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
|
||||||
pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
|
pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
|
||||||
pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep();
|
pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
|
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
|
||||||
pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
|
pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
|
||||||
pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep();
|
pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep();
|
||||||
|
@ -101,8 +108,10 @@ public class PumpUtil {
|
||||||
pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep();
|
pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep();
|
||||||
pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
|
pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
|
||||||
|
|
||||||
pumpDescription.tempDurationStep15mAllowed = pumpType.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration15minAllowed);
|
pumpDescription.tempDurationStep15mAllowed = pumpType.getSpecialBasalDurations()
|
||||||
pumpDescription.tempDurationStep30mAllowed = pumpType.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration30minAllowed);
|
.hasCapability(PumpCapability.BasalRate_Duration15minAllowed);
|
||||||
|
pumpDescription.tempDurationStep30mAllowed = pumpType.getSpecialBasalDurations()
|
||||||
|
.hasCapability(PumpCapability.BasalRate_Duration30minAllowed);
|
||||||
|
|
||||||
pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
|
pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
|
||||||
pumpDescription.basalStep = pumpType.getBaseBasalStep();
|
pumpDescription.basalStep = pumpType.getBaseBasalStep();
|
||||||
|
@ -118,5 +127,4 @@ public class PumpUtil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,10 +263,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
|
|
||||||
if (this.pumpType!=null)
|
detailedBolusInfo.insulin = PumpUtil.determineCorrectBolusSize(detailedBolusInfo.insulin, this.pumpType);
|
||||||
{
|
|
||||||
detailedBolusInfo.insulin = PumpUtil.determineCorrectBolusSize(detailedBolusInfo.insulin, this.pumpType);
|
|
||||||
}
|
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
@ -362,6 +359,9 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
PumpEnactResult result = cancelExtendedBolus();
|
PumpEnactResult result = cancelExtendedBolus();
|
||||||
if (!result.success)
|
if (!result.success)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
insulin = PumpUtil.determineCorrectExtendedBolusSize(insulin, this.pumpType);
|
||||||
|
|
||||||
ExtendedBolus extendedBolus = new ExtendedBolus();
|
ExtendedBolus extendedBolus = new ExtendedBolus();
|
||||||
extendedBolus.date = System.currentTimeMillis();
|
extendedBolus.date = System.currentTimeMillis();
|
||||||
extendedBolus.insulin = insulin;
|
extendedBolus.insulin = insulin;
|
||||||
|
|
Loading…
Reference in a new issue