create history records on pod activation. save basal profiles to history
This commit is contained in:
parent
75f51b1408
commit
a51c49f81c
|
@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmed
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord
|
||||
|
@ -372,7 +373,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
deliverySuspended = true
|
||||
}
|
||||
},
|
||||
historyEntry = history.createRecord(commandType = OmnipodCommandType.SET_BASAL_PROFILE),
|
||||
historyEntry = history.createRecord(
|
||||
commandType = OmnipodCommandType.SET_BASAL_PROFILE,
|
||||
basalProfileRecord = BasalValuesRecord(profile.getBasalValues().toList())
|
||||
),
|
||||
activeCommandEntry = { historyId ->
|
||||
podStateManager.createActiveCommand(historyId, basalProgram = basalProgram)
|
||||
},
|
||||
|
@ -1139,7 +1143,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
return profileFunction.getProfile()?.let {
|
||||
executeProgrammingCommand(
|
||||
pre = observeDeliverySuspended(),
|
||||
historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY),
|
||||
historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY, basalProfileRecord = BasalValuesRecord(it.getBasalValues().toList())),
|
||||
command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(it), hasBasalBeepEnabled())
|
||||
.ignoreElements()
|
||||
).doFinally {
|
||||
|
|
|
@ -7,11 +7,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.Omnipod
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType.SET_BOLUS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType.SET_TEMPORARY_BASAL
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.HistoryRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordDao
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.HistoryRecordEntity
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.mapper.HistoryMapper
|
||||
|
@ -53,6 +49,7 @@ class DashHistory @Inject constructor(
|
|||
initialResult: InitialResult = InitialResult.NOT_SENT,
|
||||
tempBasalRecord: TempBasalRecord? = null,
|
||||
bolusRecord: BolusRecord? = null,
|
||||
basalProfileRecord: BasalValuesRecord? = null,
|
||||
resolveResult: ResolvedResult? = null,
|
||||
resolvedAt: Long? = null
|
||||
): Single<String> = Single.defer {
|
||||
|
@ -72,6 +69,7 @@ class DashHistory @Inject constructor(
|
|||
commandType = commandType,
|
||||
tempBasalRecord = tempBasalRecord,
|
||||
bolusRecord = bolusRecord,
|
||||
basalProfileRecord = basalProfileRecord,
|
||||
initialResult = initialResult,
|
||||
resolvedResult = resolveResult,
|
||||
resolvedAt = resolvedAt
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data
|
||||
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
|
||||
sealed class Record
|
||||
|
||||
|
@ -8,6 +9,8 @@ data class BolusRecord(val amout: Double, val bolusType: BolusType) : Record()
|
|||
|
||||
data class TempBasalRecord(val duration: Int, val rate: Double) : Record()
|
||||
|
||||
data class BasalValuesRecord(val segments: List<Profile.ProfileValue>) : Record()
|
||||
|
||||
enum class BolusType {
|
||||
DEFAULT, SMB;
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.GsonBuilder
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
|
||||
|
@ -31,4 +33,17 @@ class Converters {
|
|||
|
||||
@TypeConverter
|
||||
fun fromOmnipodCommandType(omnipodCommandType: OmnipodCommandType) = omnipodCommandType.name
|
||||
|
||||
@TypeConverter
|
||||
fun toSegments(s: String?): List<Profile.ProfileValue> {
|
||||
s ?: return emptyList()
|
||||
val gson = GsonBuilder().create()
|
||||
return gson.fromJson(s, Array<Profile.ProfileValue>::class.java).toList()
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromBasalValues(segments: List<Profile.ProfileValue>): String {
|
||||
val gson = GsonBuilder().create()
|
||||
return gson.toJson(segments)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ abstract class DashHistoryDatabase : RoomDatabase() {
|
|||
|
||||
companion object {
|
||||
|
||||
const val VERSION = 1
|
||||
const val VERSION = 2
|
||||
|
||||
fun build(context: Context) =
|
||||
Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
DashHistoryDatabase::class.java,
|
||||
"omnipod_dash_history_database.db"
|
||||
"omnipod_dash_history_database.db",
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
|
|
|
@ -4,6 +4,7 @@ import androidx.room.Embedded
|
|||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.InitialResult
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult
|
||||
|
@ -18,6 +19,7 @@ data class HistoryRecordEntity(
|
|||
val initialResult: InitialResult,
|
||||
@Embedded(prefix = "tempBasalRecord_") val tempBasalRecord: TempBasalRecord?,
|
||||
@Embedded(prefix = "bolusRecord_") val bolusRecord: BolusRecord?,
|
||||
@Embedded(prefix = "basalprofile_") val basalProfileRecord: BasalValuesRecord?,
|
||||
val resolvedResult: ResolvedResult?,
|
||||
val resolvedAt: Long?
|
||||
) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.mapper
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BasalValuesRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.HistoryRecord
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord
|
||||
|
@ -17,7 +18,8 @@ class HistoryMapper {
|
|||
tempBasalRecord = historyRecord.record as? TempBasalRecord,
|
||||
bolusRecord = historyRecord.record as? BolusRecord,
|
||||
resolvedResult = historyRecord.resolvedResult,
|
||||
resolvedAt = historyRecord.resolvedAt
|
||||
resolvedAt = historyRecord.resolvedAt,
|
||||
basalProfileRecord = historyRecord.record as? BasalValuesRecord
|
||||
)
|
||||
|
||||
fun entityToDomain(entity: HistoryRecordEntity): HistoryRecord =
|
||||
|
@ -27,7 +29,7 @@ class HistoryMapper {
|
|||
date = entity.date,
|
||||
initialResult = entity.initialResult,
|
||||
commandType = entity.commandType,
|
||||
record = entity.bolusRecord ?: entity.tempBasalRecord,
|
||||
record = entity.bolusRecord ?: entity.tempBasalRecord ?: entity.basalProfileRecord,
|
||||
resolvedResult = entity.resolvedResult,
|
||||
resolvedAt = entity.resolvedAt
|
||||
)
|
||||
|
|
|
@ -5,11 +5,13 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InitializePodViewModel
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
|
@ -24,7 +26,9 @@ class DashInitializePodViewModel @Inject constructor(
|
|||
logger: AAPSLogger,
|
||||
private val sp: SP,
|
||||
private val podStateManager: OmnipodDashPodStateManager,
|
||||
private val resourceHelper: ResourceHelper
|
||||
private val resourceHelper: ResourceHelper,
|
||||
private val history: DashHistory,
|
||||
|
||||
) : InitializePodViewModel(injector, logger) {
|
||||
override fun isPodInAlarm(): Boolean = false // TODO
|
||||
|
||||
|
@ -41,27 +45,24 @@ class DashInitializePodViewModel @Inject constructor(
|
|||
} else
|
||||
null
|
||||
|
||||
super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
|
||||
onNext = { podEvent ->
|
||||
logger.debug(
|
||||
LTag.PUMP,
|
||||
"Received PodEvent in Pod activation part 1: $podEvent"
|
||||
)
|
||||
},
|
||||
onError = { throwable ->
|
||||
logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable)
|
||||
source.onSuccess(
|
||||
PumpEnactResult(injector)
|
||||
.success(false)
|
||||
.comment(I8n.textFromException(throwable, resourceHelper))
|
||||
)
|
||||
},
|
||||
onComplete = {
|
||||
logger.debug("Pod activation part 1 completed")
|
||||
podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits)
|
||||
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||
}
|
||||
)
|
||||
super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger)
|
||||
.ignoreElements()
|
||||
.andThen(podStateManager.updateLowReservoirAlertSettings(lowReservoirAlertEnabled, lowReservoirAlertUnits))
|
||||
.andThen(history.createRecord(OmnipodCommandType.INITIALIZE_POD).ignoreElement())
|
||||
.subscribeBy(
|
||||
onError = { throwable ->
|
||||
logger.error(LTag.PUMP, "Error in Pod activation part 1", throwable)
|
||||
source.onSuccess(
|
||||
PumpEnactResult(injector)
|
||||
.success(false)
|
||||
.comment(I8n.textFromException(throwable, resourceHelper))
|
||||
)
|
||||
},
|
||||
onComplete = {
|
||||
logger.debug("Pod activation part 1 completed")
|
||||
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@StringRes
|
||||
|
|
|
@ -12,10 +12,12 @@ import info.nightscout.androidaps.plugins.bus.RxBus
|
|||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activation.viewmodel.action.InsertCannulaViewModel
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Constants
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
|
||||
|
@ -34,6 +36,7 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
private val rxBus: RxBus,
|
||||
private val sp: SP,
|
||||
private val resourceHelper: ResourceHelper,
|
||||
private val history: DashHistory,
|
||||
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
|
@ -67,6 +70,7 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown)
|
||||
.ignoreElements()
|
||||
.andThen(podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationHours))
|
||||
.andThen(history.createRecord(OmnipodCommandType.INSERT_CANNULA).ignoreElement())
|
||||
.subscribeBy(
|
||||
onError = { throwable ->
|
||||
logger.error(LTag.PUMP, "Error in Pod activation part 2", throwable)
|
||||
|
@ -98,7 +102,6 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
pumpType = PumpType.OMNIPOD_DASH,
|
||||
pumpSerial = podStateManager.uniqueId?.toString() ?: "n/a"
|
||||
)
|
||||
|
||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED))
|
||||
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue