From 4e00389622c0da29378e776a91b668cbe373caf8 Mon Sep 17 00:00:00 2001 From: Philoul Date: Thu, 15 Jul 2021 00:30:57 +0200 Subject: [PATCH] Add DanaI and add UserEntry.Sources in Pumptype to simplify code --- .../plugins/pump/PumpSyncImplementation.kt | 5 ++- .../plugins/pump/common/defs/PumpType.kt | 43 +++++++++++++------ .../nightscout/androidaps/utils/Translator.kt | 1 + .../utils/userEntry/UserEntryMapper.kt | 1 + .../userEntry/UserEntryPresentationHelper.kt | 1 + .../androidaps/database/entities/UserEntry.kt | 23 +++++----- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt index ba1609c579..9bef19b5c2 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/PumpSyncImplementation.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification @@ -30,7 +31,8 @@ class PumpSyncImplementation @Inject constructor( private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, private val profileFunction: ProfileFunction, - private val repository: AppRepository + private val repository: AppRepository, + private val uel: UserEntryLogger ) : PumpSync { private val disposable = CompositeDisposable() @@ -213,6 +215,7 @@ class PumpSyncImplementation @Inject constructor( pumpType = pumpType.toDbPumpType(), pumpSerial = pumpSerial) ) + uel.log(UserEntry.Action.CAREPORTAL, pumpType.source, note, ValueWithUnit.Timestamp(timestamp), ValueWithUnit.TherapyEventType(type.toDBbEventType())) repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(therapyEvent)) .doOnError { aapsLogger.error(LTag.DATABASE, "Error while saving TherapyEvent", it) diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt index 88d268b6f1..daadd2dc78 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.common.defs import info.nightscout.androidaps.core.R import info.nightscout.androidaps.database.embedments.InterfaceIDs +import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.plugins.common.ManufacturerType import info.nightscout.androidaps.utils.Round import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -50,7 +51,8 @@ enum class PumpType { baseBasalMinValue = 0.01, baseBasalStep = 0.01, baseBasalSpecialSteps = DoseStepSize.ComboBasal, - pumpCapability = PumpCapability.ComboCapabilities), + pumpCapability = PumpCapability.ComboCapabilities, + source = Sources.Combo), ACCU_CHEK_SPIRIT(description = "Accu-Chek Spirit", manufacturer = ManufacturerType.Roche, model = "Spirit", @@ -90,7 +92,8 @@ enum class PumpType { baseBasalMaxValue = null, baseBasalStep = 0.01, baseBasalSpecialSteps = DoseStepSize.InsightBasal, - pumpCapability = PumpCapability.InsightCapabilities), + pumpCapability = PumpCapability.InsightCapabilities, + source = Sources.Insight), ACCU_CHEK_SOLO(description = "Accu-Chek Solo", manufacturer = ManufacturerType.Roche, model = "Solo", @@ -133,7 +136,8 @@ enum class PumpType { baseBasalMinValue = 0.04, baseBasalStep = 0.01, baseBasalSpecialSteps = null, - pumpCapability = PumpCapability.DanaCapabilities), + pumpCapability = PumpCapability.DanaCapabilities, + source = Sources.DanaR), DANA_R_KOREAN(description = "DanaR Korean", manufacturer = ManufacturerType.Sooil, model = "DanaRKorean", @@ -146,7 +150,8 @@ enum class PumpType { baseBasalMinValue = 0.1, baseBasalStep = 0.01, baseBasalSpecialSteps = null, - pumpCapability = PumpCapability.DanaCapabilities), + pumpCapability = PumpCapability.DanaCapabilities, + source = Sources.DanaRC), DANA_RS(description = "DanaRS", manufacturer = ManufacturerType.Sooil, model = "DanaRS", @@ -159,10 +164,11 @@ enum class PumpType { baseBasalMinValue = 0.04, baseBasalStep = 0.01, baseBasalSpecialSteps = null, - pumpCapability = PumpCapability.DanaWithHistoryCapabilities), + pumpCapability = PumpCapability.DanaWithHistoryCapabilities, + source = Sources.DanaRS), DANA_RS_KOREAN(description = "DanaRSKorean", model = "DanaRSKorean", parent = DANA_RS), - DANA_I(description = "DanaI", model = "DanaI", parent = DANA_RS), - DANA_RV2(description = "DanaRv2", model = "DanaRv2", parent = DANA_RS), + DANA_I(description = "DanaI", model = "DanaI", parent = DANA_RS, source = Sources.DanaI), + DANA_RV2(description = "DanaRv2", model = "DanaRv2", parent = DANA_RS, source = Sources.DanaRv2), OMNIPOD_EROS(description = "Omnipod Eros", manufacturer = ManufacturerType.Insulet, model = "Eros", @@ -177,7 +183,8 @@ enum class PumpType { baseBasalStep = 0.05, baseBasalSpecialSteps = null, pumpCapability = PumpCapability.OmnipodCapabilities, - hasCustomUnreachableAlertCheck = true), + hasCustomUnreachableAlertCheck = true, + source = Sources.OmnipodEros), OMNIPOD_DASH(description = "Omnipod Dash", manufacturer = ManufacturerType.Insulet, model = "Dash", @@ -205,7 +212,8 @@ enum class PumpType { baseBasalMinValue = 0.05, baseBasalStep = 0.05, baseBasalSpecialSteps = null, - pumpCapability = PumpCapability.MedtronicCapabilities), + pumpCapability = PumpCapability.MedtronicCapabilities, + source = Sources.Medtronic), MEDTRONIC_515_715(description = "Medtronic 515/715", model = "515/715", parent = MEDTRONIC_512_712), @@ -224,7 +232,8 @@ enum class PumpType { baseBasalMinValue = 0.025, baseBasalStep = 0.025, baseBasalSpecialSteps = DoseStepSize.MedtronicVeoBasal, - pumpCapability = PumpCapability.MedtronicCapabilities), + pumpCapability = PumpCapability.MedtronicCapabilities, + source = Sources.Medtronic), MEDTRONIC_554_754_VEO(description = "Medtronic 554/754 (Veo)", model = "554/754 (Veo)", parent = MEDTRONIC_523_723_REVEL), MEDTRONIC_640G(description = "Medtronic 640G", manufacturer = ManufacturerType.Medtronic, @@ -284,7 +293,8 @@ enum class PumpType { model = "USER", tbrSettings = DoseSettings(1.0, 15, 24 * 60, 0.0, 500.0), extendedBolusSettings = DoseSettings(0.1, 15, 12 * 60, 0.1), - pumpCapability = PumpCapability.MDI), + pumpCapability = PumpCapability.MDI, + source = Sources.MDI), //Diaconn Pump DIACONN_G8(description = "DiaconnG8", @@ -300,7 +310,8 @@ enum class PumpType { baseBasalMaxValue = 3.0, baseBasalStep = 0.01, baseBasalSpecialSteps = null, - pumpCapability = PumpCapability.DanaWithHistoryCapabilities); + pumpCapability = PumpCapability.DanaWithHistoryCapabilities, + source = Sources.DiaconnG8); val description: String var manufacturer: ManufacturerType? = null @@ -342,6 +353,7 @@ enum class PumpType { var hasCustomUnreachableAlertCheck = false private set private var parent: PumpType? = null + val source: Sources companion object { @@ -349,9 +361,10 @@ enum class PumpType { values().firstOrNull { it.description == desc } ?: GENERIC_AAPS } - constructor(description: String, model: String, parent: PumpType, pumpCapability: PumpCapability? = null) { + constructor(description: String, model: String, parent: PumpType, pumpCapability: PumpCapability? = null, source: Sources? = null) { this.description = description this.parent = parent + this.source = source ?: parent.source this.pumpCapability = pumpCapability parent.model = model } @@ -370,7 +383,8 @@ enum class PumpType { baseBasalStep: Double = 1.0, baseBasalSpecialSteps: DoseStepSize? = null, pumpCapability: PumpCapability, - hasCustomUnreachableAlertCheck: Boolean = false) { + hasCustomUnreachableAlertCheck: Boolean = false, + source: Sources = Sources.VirtualPump) { this.description = description this.manufacturer = manufacturer this.model = model @@ -386,6 +400,7 @@ enum class PumpType { this.baseBasalSpecialSteps = baseBasalSpecialSteps this.pumpCapability = pumpCapability this.hasCustomUnreachableAlertCheck = hasCustomUnreachableAlertCheck + this.source = source } fun getFullDescription(i18nTemplate: String, hasExtendedBasals: Boolean, resourceHelper: ResourceHelper): String { diff --git a/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt b/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt index ec1c2a85ec..fa71db66b4 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt @@ -264,6 +264,7 @@ class Translator @Inject internal constructor( Sources.DanaRC -> TODO() Sources.DanaRv2 -> TODO() Sources.DanaRS -> TODO() + Sources.DanaI -> TODO() Sources.DiaconnG8 -> TODO() Sources.Insight -> TODO() Sources.Combo -> TODO() diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt index 7344def62d..fb667823e4 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt @@ -129,6 +129,7 @@ class UserEntryMapper { DanaRC (UserEntry.Sources.DanaRC), DanaRv2 (UserEntry.Sources.DanaRv2), DanaRS (UserEntry.Sources.DanaRS), + DanaI (UserEntry.Sources.DanaI), DiaconnG8 (UserEntry.Sources.DiaconnG8), Insight (UserEntry.Sources.Insight), Combo (UserEntry.Sources.Combo), diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt index 64ca22d779..f2627a3d55 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt @@ -83,6 +83,7 @@ class UserEntryPresentationHelper @Inject constructor( Sources.DanaRC -> R.drawable.ic_danars_128 Sources.DanaRv2 -> R.drawable.ic_danars_128 Sources.DanaRS -> R.drawable.ic_danars_128 + Sources.DanaI -> R.drawable.ic_danai_128 Sources.DiaconnG8 -> R.drawable.ic_diaconn_g8 Sources.Insight -> R.drawable.ic_insight_128 Sources.Combo -> R.drawable.ic_combo_128 diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt index d1c870ff45..4b2b56d019 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt @@ -153,19 +153,20 @@ data class UserEntry( Objectives, //From Objectives plugin Pump, //To update with one Source per pump Dana, //Only one UserEntry in Common module Dana - DanaR, //No entry currently - DanaRC, //No entry currently - DanaRv2, //No entry currently - DanaRS, //No entry currently - DiaconnG8, //No entry currently - Insight, //No entry currently - Combo, //No entry currently - Medtronic, //No entry currently + DanaR, + DanaRC, + DanaRv2, + DanaRS, + DanaI, + DiaconnG8, + Insight, + Combo, + Medtronic, Omnipod, //No entry currently - OmnipodEros, //No entry currently + OmnipodEros, OmnipodDash, //No entry currently - MDI, //No entry currently - VirtualPump, //No entry currently + MDI, + VirtualPump, SMS, //From SMS plugin Treatments, //From Treatments plugin Wear, //From Wear plugin