Add total delivered to dash history

This commit is contained in:
jbr7rr 2023-05-14 15:25:35 +02:00
parent 7faa34aa50
commit 2826854b7c
9 changed files with 61 additions and 18 deletions

View file

@ -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
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType.SET_BOLUS 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.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.CommandConfirmationDenied
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmationSuccess import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmationSuccess
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandSendingFailure import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandSendingFailure
@ -57,6 +58,7 @@ class DashHistory @Inject constructor(
tempBasalRecord: TempBasalRecord? = null, tempBasalRecord: TempBasalRecord? = null,
bolusRecord: BolusRecord? = null, bolusRecord: BolusRecord? = null,
basalProfileRecord: BasalValuesRecord? = null, basalProfileRecord: BasalValuesRecord? = null,
totalAmountDeliveredRecord: Double? = null,
resolveResult: ResolvedResult? = null, resolveResult: ResolvedResult? = null,
resolvedAt: Long? = null resolvedAt: Long? = null
): Single<Long> = Single.defer { ): Single<Long> = Single.defer {
@ -79,6 +81,7 @@ class DashHistory @Inject constructor(
tempBasalRecord = tempBasalRecord, tempBasalRecord = tempBasalRecord,
bolusRecord = bolusRecord, bolusRecord = bolusRecord,
basalProfileRecord = basalProfileRecord, basalProfileRecord = basalProfileRecord,
totalAmountDelivered = totalAmountDeliveredRecord,
initialResult = initialResult, initialResult = initialResult,
resolvedResult = resolveResult, resolvedResult = resolveResult,
resolvedAt = resolvedAt resolvedAt = resolvedAt
@ -99,7 +102,10 @@ class DashHistory @Inject constructor(
logger.error(LTag.PUMP, "HistoryId not found to for updating from state") logger.error(LTag.PUMP, "HistoryId not found to for updating from state")
return@defer Completable.complete() return@defer Completable.complete()
} }
when (podState.getCommandConfirmationFromState()) {
val setTotalAmountDelivered = dao.setTotalAmountDelivered(historyId, podState.pulsesDelivered?.times(POD_PULSE_BOLUS_UNITS))
val commandConfirmation = when (podState.getCommandConfirmationFromState()) {
CommandSendingFailure -> CommandSendingFailure ->
dao.setInitialResult(historyId, InitialResult.FAILURE_SENDING) dao.setInitialResult(historyId, InitialResult.FAILURE_SENDING)
CommandSendingNotConfirmed -> CommandSendingNotConfirmed ->
@ -112,5 +118,7 @@ class DashHistory @Inject constructor(
NoActiveCommand -> NoActiveCommand ->
Completable.complete() Completable.complete()
} }
Completable.concat(listOf(setTotalAmountDelivered, commandConfirmation))
} }
} }

View file

@ -9,6 +9,7 @@ data class HistoryRecord(
val commandType: OmnipodCommandType, val commandType: OmnipodCommandType,
val initialResult: InitialResult, val initialResult: InitialResult,
val record: Record?, val record: Record?,
val totalAmountDelivered: Double?,
val resolvedResult: ResolvedResult?, val resolvedResult: ResolvedResult?,
val resolvedAt: Long? val resolvedAt: Long?
) { ) {

View file

@ -18,7 +18,7 @@ abstract class DashHistoryDatabase : RoomDatabase() {
companion object { companion object {
const val VERSION = 3 const val VERSION = 4
fun build(context: Context) = fun build(context: Context) =
Room.databaseBuilder( Room.databaseBuilder(

View file

@ -36,4 +36,7 @@ abstract class HistoryRecordDao {
@Query("UPDATE historyrecords SET initialResult = :initialResult WHERE id = :id ") @Query("UPDATE historyrecords SET initialResult = :initialResult WHERE id = :id ")
abstract fun setInitialResult(id: Long, initialResult: InitialResult): Completable 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
} }

View file

@ -27,6 +27,7 @@ data class HistoryRecordEntity(
@Embedded(prefix = "tempBasalRecord_") val tempBasalRecord: TempBasalRecord?, @Embedded(prefix = "tempBasalRecord_") val tempBasalRecord: TempBasalRecord?,
@Embedded(prefix = "bolusRecord_") val bolusRecord: BolusRecord?, @Embedded(prefix = "bolusRecord_") val bolusRecord: BolusRecord?,
@Embedded(prefix = "basalprofile_") val basalProfileRecord: BasalValuesRecord?, @Embedded(prefix = "basalprofile_") val basalProfileRecord: BasalValuesRecord?,
val totalAmountDelivered: Double?,
val resolvedResult: ResolvedResult?, val resolvedResult: ResolvedResult?,
val resolvedAt: Long? val resolvedAt: Long?
) )

View file

@ -13,6 +13,7 @@ class HistoryMapper {
initialResult = entity.initialResult, initialResult = entity.initialResult,
commandType = entity.commandType, commandType = entity.commandType,
record = entity.bolusRecord ?: entity.tempBasalRecord ?: entity.basalProfileRecord, record = entity.bolusRecord ?: entity.tempBasalRecord ?: entity.basalProfileRecord,
totalAmountDelivered = entity.totalAmountDelivered,
resolvedResult = entity.resolvedResult, resolvedResult = entity.resolvedResult,
resolvedAt = entity.resolvedAt resolvedAt = entity.resolvedAt
) )

View file

@ -213,6 +213,7 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() {
holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(it.displayTimestamp()) holder.timeView.text = DateTimeUtil.toStringFromTimeInMillis(it.displayTimestamp())
setValue(it, holder.valueView) setValue(it, holder.valueView)
setType(it, holder.typeView) setType(it, holder.typeView)
setAmount(it, holder.amountView)
} }
} }
@ -297,6 +298,12 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() {
setTextViewColor(check_result = false, valueView, historyEntry) 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 { override fun getItemCount(): Int {
return historyList.size return historyList.size
} }
@ -306,6 +313,7 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() {
val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time) val timeView: TextView = itemView.findViewById(R.id.omnipod_history_time)
val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source) val typeView: TextView = itemView.findViewById(R.id.omnipod_history_source)
val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description) val valueView: TextView = itemView.findViewById(R.id.omnipod_history_description)
val amountView: TextView = itemView.findViewById(R.id.omnipod_history_amount)
} }
} }

View file

@ -14,18 +14,36 @@
android:text="@string/omnipod_dash_history_item_date" android:text="@string/omnipod_dash_history_item_date"
android:textSize="12sp" /> android:textSize="12sp" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView <TextView
android:id="@+id/omnipod_history_source" android:id="@+id/omnipod_history_source"
android:layout_width="132dp" android:layout_width="132dp"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:text="@string/omnipod_dash_history_item_source" android:text="@string/omnipod_dash_history_item_source"
android:layout_alignParentTop="true"
android:textSize="12sp" /> android:textSize="12sp" />
<TextView <TextView
android:id="@+id/omnipod_history_description" android:id="@+id/omnipod_history_description"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:text="@string/omnipod_dash_history_item_description" android:text="@string/omnipod_dash_history_item_description"
android:layout_toEndOf="@id/omnipod_history_source"
android:textSize="12sp" /> 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> </LinearLayout>

View file

@ -11,6 +11,7 @@
<!-- Omnipod Dash - History --> <!-- Omnipod Dash - History -->
<string name="omnipod_dash_history_title">Pod History</string> <string name="omnipod_dash_history_title">Pod History</string>
<string name="omnipod_dash_history_item_description">Description</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_source">Source</string>
<string name="omnipod_dash_history_item_date">Date</string> <string name="omnipod_dash_history_item_date">Date</string>
<string name="omnipod_dash_history_type">Type:</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_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_history_bolus_value">%1$.2f U</string>
<string name="omnipod_common_alert_delivery_suspended">Insulin delivery is suspended</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_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_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> <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="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="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="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="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="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> <string name="cancel_temp_basal_result_is_uncertain">Cancel temp basal result is uncertain</string>