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