Unify check in deliverTreatment, fix DanaRKorean
This commit is contained in:
parent
32ec95d474
commit
113f511269
12 changed files with 254 additions and 328 deletions
|
@ -1012,6 +1012,10 @@ class ComboV2Plugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
val oldInsulinAmount = detailedBolusInfo.insulin
|
||||
detailedBolusInfo.insulin = constraintChecker
|
||||
.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger))
|
||||
|
@ -1021,14 +1025,6 @@ class ComboV2Plugin @Inject constructor(
|
|||
"Applied bolus constraints: old insulin amount: $oldInsulinAmount new: ${detailedBolusInfo.insulin}"
|
||||
)
|
||||
|
||||
// Carbs are not allowed because the Combo does not record carbs.
|
||||
// This is defined in the ACCU_CHEK_COMBO PumpType enum's
|
||||
// pumpCapability field, so AndroidAPS is informed about this
|
||||
// lack of carb storage capability. We therefore do not expect
|
||||
// nonzero carbs here.
|
||||
// (Also, a zero insulin value makes no sense when bolusing.)
|
||||
require((detailedBolusInfo.insulin > 0) && (detailedBolusInfo.carbs <= 0.0)) { detailedBolusInfo.toString() }
|
||||
|
||||
val acquiredPump = getAcquiredPump()
|
||||
|
||||
val requestedBolusAmount = detailedBolusInfo.insulin.iuToCctlBolus()
|
||||
|
|
|
@ -147,9 +147,11 @@ class DanaRKoreanPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
|
||||
require(detailedBolusInfo.carbs > 0)
|
||||
return if (detailedBolusInfo.insulin > 0) {
|
||||
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
|
||||
var connectionOK = false
|
||||
if (detailedBolusInfo.insulin > 0)
|
||||
|
@ -179,13 +181,7 @@ class DanaRKoreanPlugin @Inject constructor(
|
|||
PumpType.DANA_R_KOREAN,
|
||||
serialNumber()
|
||||
)
|
||||
result
|
||||
} else {
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success(false).bolusDelivered(0.0).comment(app.aaps.core.ui.R.string.invalid_input)
|
||||
aapsLogger.error("deliverTreatment: Invalid input")
|
||||
result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// This is called from APS
|
||||
|
|
|
@ -159,8 +159,10 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
// Pump interface
|
||||
@NonNull @Override
|
||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
if (detailedBolusInfo.insulin == 0 || detailedBolusInfo.carbs > 0) {
|
||||
throw new IllegalArgumentException(detailedBolusInfo.toString(), new Exception());
|
||||
}
|
||||
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new ConstraintObject<>(detailedBolusInfo.insulin, getAapsLogger())).value();
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||
// v2 stores end time for bolus, we need to adjust time
|
||||
// default delivery speed is 12 sec/U
|
||||
int preferencesSpeed = sp.getInt(info.nightscout.pump.dana.R.string.key_danars_bolusspeed, 0);
|
||||
|
@ -201,12 +203,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered());
|
||||
// remove carbs because it's get from history separately
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success(false).bolusDelivered(0d).comment(app.aaps.core.ui.R.string.invalid_input);
|
||||
aapsLogger.error("deliverTreatment: Invalid input");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -160,11 +160,13 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
if (detailedBolusInfo.insulin == 0 || detailedBolusInfo.carbs > 0) {
|
||||
throw new IllegalArgumentException(detailedBolusInfo.toString(), new Exception());
|
||||
}
|
||||
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(new ConstraintObject<>(detailedBolusInfo.insulin, getAapsLogger())).value();
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||
EventOverviewBolusProgress.Treatment t = new EventOverviewBolusProgress.Treatment(0, 0, detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.getId());
|
||||
boolean connectionOK = false;
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
|
||||
if (detailedBolusInfo.insulin > 0)
|
||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp, t);
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.getInsulin()) < pumpDescription.getBolusStep())
|
||||
|
@ -192,12 +194,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
PumpType.DANA_R,
|
||||
serialNumber());
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success(false).bolusDelivered(0d).comment(app.aaps.core.ui.R.string.invalid_input);
|
||||
aapsLogger.error("deliverTreatment: Invalid input");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// This is called from APS
|
||||
|
|
|
@ -288,8 +288,11 @@ class DanaRSPlugin @Inject constructor(
|
|||
|
||||
@Synchronized
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
|
||||
return if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||
val preferencesSpeed = sp.getInt(info.nightscout.pump.dana.R.string.key_danars_bolusspeed, 0)
|
||||
var speed = 12
|
||||
when (preferencesSpeed) {
|
||||
|
@ -325,15 +328,7 @@ class DanaRSPlugin @Inject constructor(
|
|||
result.comment = rh.gs(info.nightscout.pump.dana.R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, error)
|
||||
} else result.comment = rh.gs(app.aaps.core.ui.R.string.ok)
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered)
|
||||
result
|
||||
} else {
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = false
|
||||
result.bolusDelivered = 0.0
|
||||
result.comment = rh.gs(app.aaps.core.ui.R.string.invalid_input)
|
||||
aapsLogger.error("deliverTreatment: Invalid input")
|
||||
result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun stopBolusDelivering() {
|
||||
|
|
|
@ -271,8 +271,11 @@ class DiaconnG8Plugin @Inject constructor(
|
|||
|
||||
@Synchronized
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
|
||||
return if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||
val carbs = detailedBolusInfo.carbs
|
||||
detailedBolusInfo.carbs = 0.0
|
||||
var carbTimeStamp = detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp
|
||||
|
@ -291,15 +294,7 @@ class DiaconnG8Plugin @Inject constructor(
|
|||
setErrorMsg(diaconnG8Pump.resultErrorCode, result)
|
||||
} else result.comment = rh.gs(app.aaps.core.ui.R.string.ok)
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered)
|
||||
result
|
||||
} else {
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = false
|
||||
result.bolusDelivered = 0.0
|
||||
result.comment = rh.gs(app.aaps.core.ui.R.string.invalid_input)
|
||||
aapsLogger.error("deliverTreatment: Invalid input")
|
||||
result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun stopBolusDelivering() {
|
||||
|
|
|
@ -270,9 +270,11 @@ class EopatchPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
val askedInsulin = detailedBolusInfo.insulin
|
||||
if (detailedBolusInfo.insulin > 0.0) {
|
||||
var isSuccess = true
|
||||
val result = BehaviorSubject.createDefault(true)
|
||||
val disposable = result.hide()
|
||||
|
@ -320,11 +322,6 @@ class EopatchPumpPlugin @Inject constructor(
|
|||
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(askedInsulin)
|
||||
else
|
||||
PumpEnactResult(injector).success(false)/*.enacted(false)*/.bolusDelivered(Round.roundTo(detailedBolusInfo.insulin, 0.01))
|
||||
|
||||
} else {
|
||||
// no bolus required
|
||||
return PumpEnactResult(injector).success(false).enacted(false).bolusDelivered(0.0).comment(rh.gs(app.aaps.core.ui.R.string.error))
|
||||
}
|
||||
}
|
||||
|
||||
override fun stopBolusDelivering() {
|
||||
|
|
|
@ -377,10 +377,13 @@ import kotlin.math.abs
|
|||
|
||||
@Synchronized
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: " + detailedBolusInfo.insulin + "U")
|
||||
if (!isInitialized()) return PumpEnactResult(injector).success(false).enacted(false)
|
||||
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(ConstraintObject(detailedBolusInfo.insulin, aapsLogger)).value()
|
||||
return if (detailedBolusInfo.insulin > 0 && detailedBolusInfo.carbs == 0.0) {
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Delivering bolus: " + detailedBolusInfo.insulin + "U")
|
||||
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
|
||||
val connectionOK = medtrumService?.setBolus(detailedBolusInfo, t) ?: false
|
||||
|
@ -394,16 +397,7 @@ import kotlin.math.abs
|
|||
result.comment = "ok"
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Success: ${result.success} Asked: ${detailedBolusInfo.insulin} Delivered: ${result.bolusDelivered}")
|
||||
result
|
||||
} else {
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Invalid input")
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = false
|
||||
result.bolusDelivered = 0.0
|
||||
result.comment = rh.gs(app.aaps.core.ui.R.string.invalid_input)
|
||||
aapsLogger.error("deliverTreatment: Invalid input")
|
||||
result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun stopBolusDelivering() {
|
||||
|
|
|
@ -554,19 +554,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
get() = 0
|
||||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
try {
|
||||
bolusDeliveryInProgress = true
|
||||
aapsLogger.info(LTag.PUMP, "Delivering treatment: $detailedBolusInfo $bolusCanceled")
|
||||
if (detailedBolusInfo.carbs > 0 ||
|
||||
detailedBolusInfo.insulin == 0.0
|
||||
) {
|
||||
// Accept only valid insulin requests
|
||||
return PumpEnactResult(injector)
|
||||
.success(false)
|
||||
.enacted(false)
|
||||
.bolusDelivered(0.0)
|
||||
.comment("Invalid input")
|
||||
}
|
||||
val requestedBolusAmount = detailedBolusInfo.insulin
|
||||
if (requestedBolusAmount > reservoirLevel) {
|
||||
return PumpEnactResult(injector)
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -661,29 +660,10 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
|
||||
// neither carbs nor bolus requested
|
||||
aapsLogger.error("deliverTreatment: Invalid input: neither carbs nor insulin are set in treatment");
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d)
|
||||
.comment(app.aaps.core.ui.R.string.invalid_input);
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
return deliverBolus(detailedBolusInfo);
|
||||
} else {
|
||||
// no bolus required, carb only treatment
|
||||
boolean result = pumpSync.syncCarbsWithTimestamp(
|
||||
detailedBolusInfo.timestamp,
|
||||
detailedBolusInfo.carbs,
|
||||
null,
|
||||
model(),
|
||||
serialNumber());
|
||||
|
||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncCarbsWithTimestamp " +
|
||||
"[date=%d, carbs=%.2f, pumpSerial=%s] - Result: %b",
|
||||
detailedBolusInfo.timestamp, detailedBolusInfo.carbs, serialNumber(), result));
|
||||
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d);
|
||||
if (detailedBolusInfo.insulin == 0 || detailedBolusInfo.carbs > 0) {
|
||||
throw new IllegalArgumentException(detailedBolusInfo.toString(), new Exception());
|
||||
}
|
||||
return deliverBolus(detailedBolusInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,6 @@ import app.aaps.core.interfaces.rx.AapsSchedulers
|
|||
import app.aaps.core.interfaces.rx.bus.RxBus
|
||||
import app.aaps.core.interfaces.rx.events.EventAppExit
|
||||
import app.aaps.core.interfaces.rx.events.EventCustomActionsChanged
|
||||
import app.aaps.core.interfaces.rx.events.EventOverviewBolusProgress
|
||||
import app.aaps.core.interfaces.sharedPreferences.SP
|
||||
import app.aaps.core.interfaces.utils.DateUtil
|
||||
import app.aaps.core.interfaces.utils.DecimalFormatter
|
||||
|
@ -35,7 +34,6 @@ import com.google.gson.GsonBuilder
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.pump.common.data.PumpStatus
|
||||
import info.nightscout.pump.common.defs.PumpDriverState
|
||||
import info.nightscout.pump.common.sync.PumpDbEntryCarbs
|
||||
import info.nightscout.pump.common.sync.PumpSyncEntriesCreator
|
||||
import info.nightscout.pump.common.sync.PumpSyncStorage
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
|
@ -303,27 +301,12 @@ abstract class PumpPluginAbstract protected constructor(
|
|||
|
||||
@Synchronized
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
return try {
|
||||
if (detailedBolusInfo.insulin == 0.0 && detailedBolusInfo.carbs == 0.0) {
|
||||
// neither carbs nor bolus requested
|
||||
aapsLogger.error("deliverTreatment: Invalid input")
|
||||
PumpEnactResult(injector).success(false).enacted(false).bolusDelivered(0.0).comment(app.aaps.core.ui.R.string.invalid_input)
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
deliverBolus(detailedBolusInfo)
|
||||
} else {
|
||||
detailedBolusInfo.timestamp = System.currentTimeMillis()
|
||||
|
||||
// no bolus required, carb only treatment
|
||||
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(detailedBolusInfo, this))
|
||||
|
||||
val bolusingEvent = EventOverviewBolusProgress
|
||||
bolusingEvent.t = EventOverviewBolusProgress.Treatment(0.0, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
|
||||
bolusingEvent.percent = 100
|
||||
rxBus.send(bolusingEvent)
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Carb only treatment.")
|
||||
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(0.0).comment(R.string.common_resultok)
|
||||
}
|
||||
} finally {
|
||||
triggerUIChange()
|
||||
}
|
||||
|
|
|
@ -181,6 +181,10 @@ open class VirtualPumpPlugin @Inject constructor(
|
|||
get() = batteryPercent
|
||||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
// Insulin value must be greater than 0
|
||||
require(detailedBolusInfo.carbs == 0.0) { detailedBolusInfo.toString() }
|
||||
require(detailedBolusInfo.insulin > 0) { detailedBolusInfo.toString() }
|
||||
|
||||
val result = PumpEnactResult(injector)
|
||||
.success(true)
|
||||
.bolusDelivered(detailedBolusInfo.insulin)
|
||||
|
|
Loading…
Add table
Reference in a new issue