SafetyPlugin extends PluginBase implements ConstraintsInterface { @Override public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) { insulin.setIfGreater(0d, String.format(MainApp.gs(R.string.limitingbolus), 0d, MainApp.gs(R.string.itmustbepositivevalue)), this); Double maxBolus = SP.getDouble(R.string.key_treatmentssafety_maxbolus, 3d); insulin.setIfSmaller(maxBolus, String.format(MainApp.gs(R.string.limitingbolus), maxBolus, MainApp.gs(R.string.maxvalueinpreferences)), this); insulin.setIfSmaller(HardLimits.maxBolus(), String.format(MainApp.gs(R.string.limitingbolus), HardLimits.maxBolus(), MainApp.gs(R.string.hardlimit)), this); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); if (pump != null) { double rounded = pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulin.value()); insulin.setIfDifferent(rounded, MainApp.gs(R.string.pumplimit), this); } return insulin; } SafetyPlugin(); static SafetyPlugin getPlugin(); @Override Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value); @Override Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value); @Override Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value); @Override Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value); @Override Constraint<Boolean> isUAMEnabled(Constraint<Boolean> value); @Override Constraint<Boolean> isAdvancedFilteringEnabled(Constraint<Boolean> value); @Override Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile); @Override Constraint<Integer> applyBasalPercentConstraints(Constraint<Integer> percentRate, Profile profile); @Override Constraint<Double> applyBolusConstraints(Constraint<Double> insulin); @Override Constraint<Double> applyExtendedBolusConstraints(Constraint<Double> insulin); @Override Constraint<Integer> applyCarbsConstraints(Constraint<Integer> carbs); @Override Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob);  }
@Test public void bolusAmountShouldBeLimited() { when(SP.getDouble(R.string.key_treatmentssafety_maxbolus, 3d)).thenReturn(3d); when(SP.getString(R.string.key_age, "")).thenReturn("child"); Constraint<Double> d = new Constraint<>(Constants.REALLYHIGHBOLUS); d = safetyPlugin.applyBolusConstraints(d); Assert.assertEquals(3d, d.value(), 0.01d); Assert.assertEquals("Safety: Limiting bolus to 3.0 U because of max value in preferences\n" + "Safety: Limiting bolus to 5.0 U because of hard limit", d.getReasons()); Assert.assertEquals("Safety: Limiting bolus to 3.0 U because of max value in preferences", d.getMostLimitedReasons()); }
@Test public void doNotAllowNegativeBolusAmount() { when(SP.getDouble(R.string.key_treatmentssafety_maxbolus, 3d)).thenReturn(3d); when(SP.getString(R.string.key_age, "")).thenReturn("child"); Constraint<Double> d = new Constraint<>(-22d); d = safetyPlugin.applyBolusConstraints(d); Assert.assertEquals(0d, d.value(), 0.01d); Assert.assertEquals("Safety: Limiting bolus to 0.0 U because of it must be positive value", d.getReasons()); Assert.assertEquals("Safety: Limiting bolus to 0.0 U because of it must be positive value", d.getMostLimitedReasons()); }