package info.nightscout.androidaps.data; import androidx.annotation.NonNull; import java.util.ArrayList; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; /** * Created by mike on 19.03.2018. */ public class ConstraintChecker implements ConstraintsInterface { public Constraint isLoopInvokationAllowed() { return isLoopInvocationAllowed(new Constraint<>(true)); } public Constraint isClosedLoopAllowed() { return isClosedLoopAllowed(new Constraint<>(true)); } public Constraint isAutosensModeEnabled() { return isAutosensModeEnabled(new Constraint<>(true)); } public Constraint isAMAModeEnabled() { return isAMAModeEnabled(new Constraint<>(true)); } public Constraint isSMBModeEnabled() { return isSMBModeEnabled(new Constraint<>(true)); } public Constraint isUAMEnabled() { return isUAMEnabled(new Constraint<>(true)); } public Constraint isAdvancedFilteringEnabled() { return isAdvancedFilteringEnabled(new Constraint<>(true)); } public Constraint isSuperBolusEnabled() { return isSuperBolusEnabled(new Constraint<>(true)); } public Constraint getMaxBasalAllowed(Profile profile) { return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile); } public Constraint getMaxBasalPercentAllowed(Profile profile) { return applyBasalPercentConstraints(new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE), profile); } public Constraint getMaxBolusAllowed() { return applyBolusConstraints(new Constraint<>(Constants.REALLYHIGHBOLUS)); } public Constraint getMaxExtendedBolusAllowed() { return applyExtendedBolusConstraints(new Constraint<>(Constants.REALLYHIGHBOLUS)); } public Constraint getMaxCarbsAllowed() { return applyCarbsConstraints(new Constraint<>(Constants.REALLYHIGHCARBS)); } public Constraint getMaxIOBAllowed() { return applyMaxIOBConstraints(new Constraint<>(Constants.REALLYHIGHIOB)); } @Override public Constraint isLoopInvocationAllowed(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isLoopInvocationAllowed(value); } return value; } @Override public Constraint isClosedLoopAllowed(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isClosedLoopAllowed(value); } return value; } @Override public Constraint isAutosensModeEnabled(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isAutosensModeEnabled(value); } return value; } @Override public Constraint isAMAModeEnabled(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.isAMAModeEnabled(value); } return value; } @Override public Constraint isSMBModeEnabled(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isSMBModeEnabled(value); } return value; } @Override public Constraint isUAMEnabled(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isUAMEnabled(value); } return value; } @Override public Constraint isAdvancedFilteringEnabled(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isAdvancedFilteringEnabled(value); } return value; } @Override public Constraint isSuperBolusEnabled(@NonNull Constraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isSuperBolusEnabled(value); } return value; } @Override public Constraint applyBasalConstraints(@NonNull Constraint absoluteRate, Profile profile) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.applyBasalConstraints(absoluteRate, profile); } return absoluteRate; } @Override public Constraint applyBasalPercentConstraints(@NonNull Constraint percentRate, Profile profile) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyBasalPercentConstraints(percentRate, profile); } return percentRate; } @Override public Constraint applyBolusConstraints(@NonNull Constraint insulin) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyBolusConstraints(insulin); } return insulin; } @Override public Constraint applyExtendedBolusConstraints(@NonNull Constraint insulin) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyExtendedBolusConstraints(insulin); } return insulin; } @Override public Constraint applyCarbsConstraints(@NonNull Constraint carbs) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyCarbsConstraints(carbs); } return carbs; } @Override public Constraint applyMaxIOBConstraints(@NonNull Constraint maxIob) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyMaxIOBConstraints(maxIob); } return maxIob; } }