Add total delivered to dash history
This commit is contained in:
parent
7faa34aa50
commit
2826854b7c
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.history
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType
|
||||
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.definition.PodConstants.Companion.POD_PULSE_BOLUS_UNITS
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmationDenied
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmationSuccess
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandSendingFailure
|
||||
|
@ -57,6 +58,7 @@ class DashHistory @Inject constructor(
|
|||
tempBasalRecord: TempBasalRecord? = null,
|
||||
bolusRecord: BolusRecord? = null,
|
||||
basalProfileRecord: BasalValuesRecord? = null,
|
||||
totalAmountDeliveredRecord: Double? = null,
|
||||
resolveResult: ResolvedResult? = null,
|
||||
resolvedAt: Long? = null
|
||||
): Single<Long> = Single.defer {
|
||||
|
@ -79,6 +81,7 @@ class DashHistory @Inject constructor(
|
|||
tempBasalRecord = tempBasalRecord,
|
||||
bolusRecord = bolusRecord,
|
||||
basalProfileRecord = basalProfileRecord,
|
||||
totalAmountDelivered = totalAmountDeliveredRecord,
|
||||
initialResult = initialResult,
|
||||
resolvedResult = resolveResult,
|
||||
resolvedAt = resolvedAt
|
||||
|
@ -99,18 +102,23 @@ class DashHistory @Inject constructor(
|
|||
logger.error(LTag.PUMP, "HistoryId not found to for updating from state")
|
||||
return@defer Completable.complete()
|
||||
}
|
||||
when (podState.getCommandConfirmationFromState()) {
|
||||
CommandSendingFailure ->
|
||||
|
||||
val setTotalAmountDelivered = dao.setTotalAmountDelivered(historyId, podState.pulsesDelivered?.times(POD_PULSE_BOLUS_UNITS))
|
||||
|
||||
val commandConfirmation = when (podState.getCommandConfirmationFromState()) {
|
||||
CommandSendingFailure ->
|
||||
dao.setInitialResult(historyId, InitialResult.FAILURE_SENDING)
|
||||
CommandSendingNotConfirmed ->
|
||||
dao.setInitialResult(historyId, InitialResult.SENT)
|
||||
CommandConfirmationDenied ->
|
||||
CommandConfirmationDenied ->
|
||||
markFailure(historyId)
|
||||
CommandConfirmationSuccess ->
|
||||
dao.setInitialResult(historyId, InitialResult.SENT)
|
||||
.andThen(markSuccess(historyId))
|
||||
NoActiveCommand ->
|
||||
NoActiveCommand ->
|
||||
Completable.complete()
|
||||
}
|
||||
|
||||
Completable.concat(listOf(setTotalAmountDelivered, commandConfirmation))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ data class HistoryRecord(
|
|||
val commandType: OmnipodCommandType,
|
||||
val initialResult: InitialResult,
|
||||
val record: Record?,
|
||||
val totalAmountDelivered: Double?,
|
||||
val resolvedResult: ResolvedResult?,
|
||||
val resolvedAt: Long?
|
||||
) {
|
||||
|
|
|
@ -18,7 +18,7 @@ abstract class DashHistoryDatabase : RoomDatabase() {
|
|||
|
||||
companion object {
|
||||
|
||||
const val VERSION = 3
|
||||
const val VERSION = 4
|
||||
|
||||
fun build(context: Context) =
|
||||
Room.databaseBuilder(
|
||||
|
|
|
@ -36,4 +36,7 @@ abstract class HistoryRecordDao {
|
|||
|
||||
@Query("UPDATE historyrecords SET initialResult = :initialResult WHERE id = :id ")
|
||||
abstract fun setInitialResult(id: Long, initialResult: InitialResult): Completable
|
||||
|
||||
@Query("UPDATE historyrecords SET totalAmountDelivered = :totalAmountDelivered WHERE id = :id ")
|
||||
abstract fun setTotalAmountDelivered(id: Long, totalAmountDelivered: Double?): Completable
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ data class HistoryRecordEntity(
|
|||
@Embedded(prefix = "tempBasalRecord_") val tempBasalRecord: TempBasalRecord?,
|
||||
@Embedded(prefix = "bolusRecord_") val bolusRecord: BolusRecord?,
|
||||
@Embedded(prefix = "basalprofile_") val basalProfileRecord: BasalValuesRecord?,
|
||||
val totalAmountDelivered: Double?,
|
||||
val resolvedResult: ResolvedResult?,
|
||||
val resolvedAt: Long?
|
||||
)
|
||||
|
|
|
@ -13,6 +13,7 @@ class HistoryMapper {
|
|||
initialResult = entity.initialResult,
|
||||
commandType = entity.commandType,
|
||||
record = entity.bolusRecord ?: entity.tempBasalRecord ?: entity.basalProfileRecord,
|
||||
totalAmountDelivered = entity.totalAmountDelivered,
|
||||
resolvedResult = entity.resolvedResult,
|
||||
resolvedAt = entity.resolvedAt
|
||||
)
|
||||
|
|
|
@ -213,6 +213,7 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() {
|
|||
holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(it.displayTimestamp())
|
||||
setValue(it, holder.valueView)
|
||||
setType(it, holder.typeView)
|
||||
setAmount(it, holder.amountView)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,6 +298,12 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() {
|
|||
setTextViewColor(check_result = false, valueView, historyEntry)
|
||||
}
|
||||
|
||||
private fun setAmount(historyEntry: HistoryRecord, amountView: TextView) {
|
||||
amountView.text = historyEntry.totalAmountDelivered?.let { rh.gs(R.string.omnipod_common_history_total_delivered, it) ?: "" }
|
||||
// Set some color
|
||||
setTextViewColor(check_result = false, amountView, historyEntry)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return historyList.size
|
||||
}
|
||||
|
@ -306,6 +313,7 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() {
|
|||
val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time)
|
||||
val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source)
|
||||
val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description)
|
||||
val amountView: TextView = itemView.findViewById(R.id.omnipod_history_amount)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,18 +14,36 @@
|
|||
android:text="@string/omnipod_dash_history_item_date"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/omnipod_history_source"
|
||||
android:layout_width="132dp"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/omnipod_dash_history_item_source"
|
||||
android:textSize="12sp" />
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/omnipod_history_description"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/omnipod_dash_history_item_description"
|
||||
android:textSize="12sp" />
|
||||
<TextView
|
||||
android:id="@+id/omnipod_history_source"
|
||||
android:layout_width="132dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/omnipod_dash_history_item_source"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/omnipod_history_description"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/omnipod_dash_history_item_description"
|
||||
android:layout_toEndOf="@id/omnipod_history_source"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/omnipod_history_amount"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/omnipod_dash_history_item_amount"
|
||||
android:layout_below="@+id/omnipod_history_description"
|
||||
android:layout_toEndOf="@id/omnipod_history_source"
|
||||
android:textSize="12sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -11,6 +11,7 @@
|
|||
<!-- Omnipod Dash - History -->
|
||||
<string name="omnipod_dash_history_title">Pod History</string>
|
||||
<string name="omnipod_dash_history_item_description">Description</string>
|
||||
<string name="omnipod_dash_history_item_amount">Amount</string>
|
||||
<string name="omnipod_dash_history_item_source">Source</string>
|
||||
<string name="omnipod_dash_history_item_date">Date</string>
|
||||
<string name="omnipod_dash_history_type">Type:</string>
|
||||
|
@ -47,6 +48,7 @@
|
|||
<string name="omnipod_common_history_tbr_value">Rate: %1$.2f U, duration: %2$d minutes</string>
|
||||
<string name="omnipod_common_history_bolus_value">%1$.2f U</string>
|
||||
<string name="omnipod_common_alert_delivery_suspended">Insulin delivery is suspended</string>
|
||||
<string name="omnipod_common_history_total_delivered">Total delivered: %1$.2f U</string>
|
||||
<string name="omnipod_dash_connection_lost">Lost connection to pod</string>
|
||||
<string name="omnipod_dash_bolus_already_in_progress">Another bolus is being delivered</string>
|
||||
<string name="omnipod_dash_not_enough_insulin">Not enough insulin left in the reservoir</string>
|
||||
|
@ -60,6 +62,7 @@
|
|||
<string name="failed_to_set_the_new_basal_profile">Failed to set the new basal profile. Delivery suspended</string>
|
||||
<string name="setting_basal_profile_might_have_failed">Setting basal profile might have failed. Delivery might be suspended! Please manually refresh the Pod status from the Omnipod tab and resume delivery if needed.</string>
|
||||
<string name="bolus_delivery_status_uncertain">Bolus delivery status uncertain. Refresh pod status to confirm or deny.</string>
|
||||
<string name="temp_basal_out_of_sync">Temp basal status not as expected! If a temp basal was previously running, it has been cancelled. Please check delivered insulin and pod history</string>
|
||||
<string name="checking_delivery_status">Checking delivery status</string>
|
||||
<string name="setting_temp_basal_might_have_basal_failed">Setting temp basal might have basal failed. If a temp basal was previously running, it has been cancelled. Please manually refresh the Pod status from the Omnipod tab.</string>
|
||||
<string name="cancel_temp_basal_result_is_uncertain">Cancel temp basal result is uncertain</string>
|
||||
|
|
Loading…
Reference in a new issue