Merge pull request #562 from avereha/avereha/invalidateTemporaryBasalWithPumpId
add invalidateTemporaryBasalWithPumpId
This commit is contained in:
commit
005c607639
|
@ -344,6 +344,21 @@ interface PumpSync {
|
||||||
**/
|
**/
|
||||||
fun invalidateTemporaryBasal(id: Long): Boolean
|
fun invalidateTemporaryBasal(id: Long): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate of temporary basals that failed to start
|
||||||
|
*
|
||||||
|
* If exists, isValid is set false
|
||||||
|
* If db record doesn't exist data is ignored and false returned
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param pumpId pumpId of temporary basal
|
||||||
|
* @param pumpType pump type like PumpType.ACCU_CHEK_COMBO
|
||||||
|
* @param pumpSerial pump serial number
|
||||||
|
* @return true if running record is found and invalidated
|
||||||
|
**/
|
||||||
|
|
||||||
|
fun invalidateTemporaryBasalWithPumpId(pumpId: Long, pumpType: PumpType, pumpSerial: String): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidate of temporary basals that failed to start
|
* Invalidate of temporary basals that failed to start
|
||||||
* MDT specific
|
* MDT specific
|
||||||
|
|
|
@ -330,6 +330,19 @@ class PumpSyncImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun invalidateTemporaryBasalWithPumpId(pumpId: Long, pumpType: PumpType, pumpSerial: String): Boolean {
|
||||||
|
repository.runTransactionForResult(InvalidateTemporaryBasalTransactionWithPumpId(pumpId, pumpType.toDbPumpType(),
|
||||||
|
pumpSerial))
|
||||||
|
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TemporaryBasal", it) }
|
||||||
|
.blockingGet()
|
||||||
|
.also { result ->
|
||||||
|
result.invalidated.forEach {
|
||||||
|
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it")
|
||||||
|
}
|
||||||
|
return result.invalidated.size > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun invalidateTemporaryBasalWithTempId(temporaryId: Long): Boolean {
|
override fun invalidateTemporaryBasalWithTempId(temporaryId: Long): Boolean {
|
||||||
repository.runTransactionForResult(InvalidateTemporaryBasalWithTempIdTransaction(temporaryId))
|
repository.runTransactionForResult(InvalidateTemporaryBasalWithTempIdTransaction(temporaryId))
|
||||||
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TemporaryBasal", it) }
|
.doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating TemporaryBasal", it) }
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.embedments.InterfaceIDs
|
||||||
|
import info.nightscout.androidaps.database.entities.TemporaryBasal
|
||||||
|
|
||||||
|
class InvalidateTemporaryBasalTransactionWithPumpId(val pumpId: Long, val pumpType: InterfaceIDs.PumpType, val
|
||||||
|
pumpSerial:
|
||||||
|
String) :
|
||||||
|
Transaction<InvalidateTemporaryBasalTransactionWithPumpId.TransactionResult>() {
|
||||||
|
|
||||||
|
override fun run(): TransactionResult {
|
||||||
|
val result = TransactionResult()
|
||||||
|
val temporaryBasal = database.temporaryBasalDao.findByPumpIds(pumpId, pumpType, pumpSerial)
|
||||||
|
?: throw IllegalArgumentException("There is no such Temporary Basal with the specified temp ID.")
|
||||||
|
temporaryBasal.isValid = false
|
||||||
|
database.temporaryBasalDao.updateExistingEntry(temporaryBasal)
|
||||||
|
result.invalidated.add(temporaryBasal)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
class TransactionResult {
|
||||||
|
|
||||||
|
val invalidated = mutableListOf<TemporaryBasal>()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue