fix cutting TBR & EB
This commit is contained in:
parent
2a087c8d84
commit
1684b88270
|
@ -13,7 +13,7 @@ class SyncPumpCancelExtendedBolusIfAnyTransaction(
|
|||
val existing = database.extendedBolusDao.findByPumpEndIds(endPumpId, pumpType, pumpSerial)
|
||||
if (existing != null) // assume EB has been cut already
|
||||
return result
|
||||
val running = database.extendedBolusDao.getExtendedBolusActiveAt(timestamp, pumpType, pumpSerial).blockingGet()
|
||||
val running = database.extendedBolusDao.getExtendedBolusActiveAt(timestamp).blockingGet()
|
||||
if (running != null && running.interfaceIDs.endId == null) { // do not allow overwrite if cut by end event
|
||||
val pctRun = (timestamp - running.timestamp) / running.duration.toDouble()
|
||||
running.amount *= pctRun
|
||||
|
|
|
@ -13,13 +13,13 @@ class SyncPumpCancelTemporaryBasalIfAnyTransaction(
|
|||
val existing = database.temporaryBasalDao.findByPumpEndIds(endPumpId, pumpType, pumpSerial)
|
||||
if (existing != null) // assume TBR has been cut already
|
||||
return result
|
||||
val current = database.temporaryBasalDao.getTemporaryBasalActiveAt(timestamp, pumpType, pumpSerial).blockingGet()
|
||||
if (current != null && current.interfaceIDs.endId == null) { // do not allow overwrite if cut by end event
|
||||
if (current.timestamp != timestamp) current.end = timestamp // prevent zero duration
|
||||
else current.duration = 1
|
||||
current.interfaceIDs.endId = endPumpId
|
||||
database.temporaryBasalDao.updateExistingEntry(current)
|
||||
result.updated.add(current)
|
||||
val running = database.temporaryBasalDao.getTemporaryBasalActiveAt(timestamp).blockingGet()
|
||||
if (running != null && running.interfaceIDs.endId == null) { // do not allow overwrite if cut by end event
|
||||
if (running.timestamp != timestamp) running.end = timestamp // prevent zero duration
|
||||
else running.duration = 1
|
||||
running.interfaceIDs.endId = endPumpId
|
||||
database.temporaryBasalDao.updateExistingEntry(running)
|
||||
result.updated.add(running)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -13,21 +13,21 @@ class SyncPumpExtendedBolusTransaction(private val extendedBolus: ExtendedBolus)
|
|||
?: extendedBolus.interfaceIDs.pumpSerial
|
||||
?: throw IllegalStateException("Some pump ID is null")
|
||||
val result = TransactionResult()
|
||||
val current = database.extendedBolusDao.findByPumpIds(extendedBolus.interfaceIDs.pumpId!!, extendedBolus.interfaceIDs.pumpType!!, extendedBolus.interfaceIDs.pumpSerial!!)
|
||||
if (current != null) {
|
||||
if (current.interfaceIDs.endId == null &&
|
||||
(current.timestamp != extendedBolus.timestamp ||
|
||||
current.amount != extendedBolus.amount ||
|
||||
current.duration != extendedBolus.duration)
|
||||
val existing = database.extendedBolusDao.findByPumpIds(extendedBolus.interfaceIDs.pumpId!!, extendedBolus.interfaceIDs.pumpType!!, extendedBolus.interfaceIDs.pumpSerial!!)
|
||||
if (existing != null) {
|
||||
if (existing.interfaceIDs.endId == null &&
|
||||
(existing.timestamp != extendedBolus.timestamp ||
|
||||
existing.amount != extendedBolus.amount ||
|
||||
existing.duration != extendedBolus.duration)
|
||||
) {
|
||||
current.timestamp = extendedBolus.timestamp
|
||||
current.amount = extendedBolus.amount
|
||||
current.duration = extendedBolus.duration
|
||||
database.extendedBolusDao.updateExistingEntry(current)
|
||||
result.updated.add(current)
|
||||
existing.timestamp = extendedBolus.timestamp
|
||||
existing.amount = extendedBolus.amount
|
||||
existing.duration = extendedBolus.duration
|
||||
database.extendedBolusDao.updateExistingEntry(existing)
|
||||
result.updated.add(existing)
|
||||
}
|
||||
} else {
|
||||
val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp, extendedBolus.interfaceIDs.pumpType!!, extendedBolus.interfaceIDs.pumpSerial!!).blockingGet()
|
||||
val running = database.extendedBolusDao.getExtendedBolusActiveAt(extendedBolus.timestamp).blockingGet()
|
||||
if (running != null) {
|
||||
val pctRun = (extendedBolus.timestamp - running.timestamp) / running.duration.toDouble()
|
||||
running.amount *= pctRun
|
||||
|
|
|
@ -16,23 +16,23 @@ class SyncPumpTemporaryBasalTransaction(
|
|||
?: temporaryBasal.interfaceIDs.pumpSerial
|
||||
?: throw IllegalStateException("Some pump ID is null")
|
||||
val result = TransactionResult()
|
||||
val current = database.temporaryBasalDao.findByPumpIds(temporaryBasal.interfaceIDs.pumpId!!, temporaryBasal.interfaceIDs.pumpType!!, temporaryBasal.interfaceIDs.pumpSerial!!)
|
||||
if (current != null) {
|
||||
val existing = database.temporaryBasalDao.findByPumpIds(temporaryBasal.interfaceIDs.pumpId!!, temporaryBasal.interfaceIDs.pumpType!!, temporaryBasal.interfaceIDs.pumpSerial!!)
|
||||
if (existing != null) {
|
||||
if (
|
||||
current.timestamp != temporaryBasal.timestamp ||
|
||||
current.rate != temporaryBasal.rate ||
|
||||
current.duration != temporaryBasal.duration && current.interfaceIDs.endId == null ||
|
||||
current.type != type ?: current.type
|
||||
existing.timestamp != temporaryBasal.timestamp ||
|
||||
existing.rate != temporaryBasal.rate ||
|
||||
existing.duration != temporaryBasal.duration && existing.interfaceIDs.endId == null ||
|
||||
existing.type != type ?: existing.type
|
||||
) {
|
||||
current.timestamp = temporaryBasal.timestamp
|
||||
current.rate = temporaryBasal.rate
|
||||
current.duration = temporaryBasal.duration
|
||||
current.type = type ?: current.type
|
||||
database.temporaryBasalDao.updateExistingEntry(current)
|
||||
result.updated.add(current)
|
||||
existing.timestamp = temporaryBasal.timestamp
|
||||
existing.rate = temporaryBasal.rate
|
||||
existing.duration = temporaryBasal.duration
|
||||
existing.type = type ?: existing.type
|
||||
database.temporaryBasalDao.updateExistingEntry(existing)
|
||||
result.updated.add(existing)
|
||||
}
|
||||
} else {
|
||||
val running = database.temporaryBasalDao.getTemporaryBasalActiveAt(temporaryBasal.timestamp, temporaryBasal.interfaceIDs.pumpType!!, temporaryBasal.interfaceIDs.pumpSerial!!).blockingGet()
|
||||
val running = database.temporaryBasalDao.getTemporaryBasalActiveAt(temporaryBasal.timestamp).blockingGet()
|
||||
if (running != null) {
|
||||
running.end = temporaryBasal.timestamp
|
||||
running.interfaceIDs.endId = temporaryBasal.interfaceIDs.pumpId
|
||||
|
|
Loading…
Reference in a new issue