- removed unused (old) methods from MedtronicHistoryData
- PumpSyncStorage added method addCarbs, that is now used in PUmpPluginAbstract and in MetronicPumpPlugin and MedtronicHistoryData - extended PumpDbEntry with other data classes: for Bolus, TBR (incomplete) and Carbs
This commit is contained in:
parent
6504498cd2
commit
a3f0bf41cd
5 changed files with 117 additions and 262 deletions
|
@ -28,5 +28,16 @@ data class PumpDbEntryBolus(var insulin: Double,
|
||||||
var carbs: Double,
|
var carbs: Double,
|
||||||
var bolusType: DetailedBolusInfo.BolusType)
|
var bolusType: DetailedBolusInfo.BolusType)
|
||||||
|
|
||||||
|
data class PumpDbEntryCarbs(var date: Long,
|
||||||
|
var carbs: Double,
|
||||||
|
var pumpType: PumpType,
|
||||||
|
var serialNumber: String,
|
||||||
|
var pumpId: Long? = null) {
|
||||||
|
constructor(detailedBolusInfo: DetailedBolusInfo,
|
||||||
|
creator: PumpSyncEntriesCreator) : this(detailedBolusInfo.timestamp,
|
||||||
|
detailedBolusInfo.carbs,
|
||||||
|
creator.model(),
|
||||||
|
creator.serialNumber())
|
||||||
|
}
|
||||||
|
|
||||||
data class PumpDbEntryTBR(var temporaryId: Long)
|
data class PumpDbEntryTBR(var temporaryId: Long)
|
|
@ -7,8 +7,10 @@ import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal
|
import info.nightscout.androidaps.db.TemporaryBasal
|
||||||
import info.nightscout.androidaps.interfaces.PumpSync
|
import info.nightscout.androidaps.interfaces.PumpSync
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@ -86,25 +88,45 @@ class PumpSyncStorage @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//abstract fun generateTempId(timeMillis: Long): Long
|
|
||||||
|
|
||||||
fun addBolusWithTempId(detailedBolusInfo: DetailedBolusInfo, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean {
|
fun addBolusWithTempId(detailedBolusInfo: DetailedBolusInfo, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean {
|
||||||
val temporaryId = creator.generateTempId(detailedBolusInfo.timestamp)
|
val temporaryId = creator.generateTempId(detailedBolusInfo.timestamp)
|
||||||
val response = pumpSync.addBolusWithTempId(
|
val result = pumpSync.addBolusWithTempId(
|
||||||
detailedBolusInfo.timestamp,
|
detailedBolusInfo.timestamp,
|
||||||
detailedBolusInfo.insulin,
|
detailedBolusInfo.insulin,
|
||||||
temporaryId,
|
temporaryId,
|
||||||
detailedBolusInfo.bolusType,
|
detailedBolusInfo.bolusType,
|
||||||
creator.model(),
|
creator.model(),
|
||||||
creator.serialNumber())
|
creator.serialNumber())
|
||||||
if (response && writeToInternalHistory) {
|
|
||||||
|
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolusWithTempId [date=%d, temporaryId=%d, insulin=%.2f, type=%s, pumpSerial=%s] - Result: %b",
|
||||||
|
detailedBolusInfo.timestamp, temporaryId, detailedBolusInfo.insulin, detailedBolusInfo.bolusType,
|
||||||
|
creator.serialNumber(), result))
|
||||||
|
|
||||||
|
if (detailedBolusInfo.carbs>0.0) {
|
||||||
|
addCarbs(PumpDbEntryCarbs(detailedBolusInfo, creator))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result && writeToInternalHistory) {
|
||||||
var innerList: MutableList<PumpDbEntry> = pumpSyncStorage[BOLUS]!!
|
var innerList: MutableList<PumpDbEntry> = pumpSyncStorage[BOLUS]!!
|
||||||
|
|
||||||
innerList.add(PumpDbEntry(temporaryId, detailedBolusInfo.timestamp, creator.model(), creator.serialNumber(), detailedBolusInfo))
|
innerList.add(PumpDbEntry(temporaryId, detailedBolusInfo.timestamp, creator.model(), creator.serialNumber(), detailedBolusInfo))
|
||||||
pumpSyncStorage[BOLUS] = innerList
|
pumpSyncStorage[BOLUS] = innerList
|
||||||
saveStorage()
|
saveStorage()
|
||||||
}
|
}
|
||||||
return response
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun addCarbs(carbsDto: PumpDbEntryCarbs) {
|
||||||
|
val result = pumpSync.syncCarbsWithTimestamp(
|
||||||
|
carbsDto.date,
|
||||||
|
carbsDto.carbs,
|
||||||
|
null,
|
||||||
|
carbsDto.pumpType,
|
||||||
|
carbsDto.serialNumber)
|
||||||
|
|
||||||
|
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncCarbsWithTimestamp [date=%d, carbs=%.2f, pumpSerial=%s] - Result: %b",
|
||||||
|
carbsDto.date, carbsDto.carbs, carbsDto.serialNumber, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -123,6 +145,8 @@ class PumpSyncStorage @Inject constructor(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun removeBolusWithTemporaryId(temporaryId: Long) {
|
fun removeBolusWithTemporaryId(temporaryId: Long) {
|
||||||
val bolusList = removeTemporaryId(temporaryId, pumpSyncStorage[BOLUS]!!)
|
val bolusList = removeTemporaryId(temporaryId, pumpSyncStorage[BOLUS]!!)
|
||||||
pumpSyncStorage[BOLUS] = bolusList
|
pumpSyncStorage[BOLUS] = bolusList
|
||||||
|
|
|
@ -26,6 +26,9 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewB
|
||||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus
|
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryCarbs
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter.to0Decimal
|
import info.nightscout.androidaps.utils.DecimalFormatter.to0Decimal
|
||||||
|
@ -57,12 +60,11 @@ abstract class PumpPluginAbstract protected constructor(
|
||||||
var fabricPrivacy: FabricPrivacy,
|
var fabricPrivacy: FabricPrivacy,
|
||||||
var dateUtil: DateUtil,
|
var dateUtil: DateUtil,
|
||||||
var aapsSchedulers: AapsSchedulers,
|
var aapsSchedulers: AapsSchedulers,
|
||||||
var pumpSync: PumpSync
|
var pumpSync: PumpSync,
|
||||||
) : PumpPluginBase(pluginDescription!!, injector!!, aapsLogger, resourceHelper, commandQueue), Pump, Constraints {
|
var pumpSyncStorage: PumpSyncStorage
|
||||||
|
) : PumpPluginBase(pluginDescription!!, injector!!, aapsLogger, resourceHelper, commandQueue), Pump, Constraints, PumpSyncEntriesCreator {
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
//protected override var injector: HasAndroidInjector? = null
|
|
||||||
//protected var dateUtil: DateUtil
|
|
||||||
|
|
||||||
// Pump capabilities
|
// Pump capabilities
|
||||||
final override var pumpDescription = PumpDescription()
|
final override var pumpDescription = PumpDescription()
|
||||||
|
@ -81,8 +83,6 @@ abstract class PumpPluginAbstract protected constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//protected var aapsSchedulers: AapsSchedulers
|
|
||||||
//protected var pumpSync: PumpSync
|
|
||||||
protected var gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
protected var gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
||||||
|
|
||||||
abstract fun initPumpStatusData()
|
abstract fun initPumpStatusData()
|
||||||
|
@ -343,10 +343,11 @@ abstract class PumpPluginAbstract protected constructor(
|
||||||
// bolus needed, ask pump to deliver it
|
// bolus needed, ask pump to deliver it
|
||||||
deliverBolus(detailedBolusInfo)
|
deliverBolus(detailedBolusInfo)
|
||||||
} else {
|
} else {
|
||||||
|
detailedBolusInfo.timestamp = System.currentTimeMillis()
|
||||||
|
|
||||||
// no bolus required, carb only treatment
|
// no bolus required, carb only treatment
|
||||||
// TODO carb only bolus - DONE
|
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(detailedBolusInfo, this))
|
||||||
pumpSync.syncCarbsWithTimestamp(System.currentTimeMillis(), detailedBolusInfo.carbs, null, model(), serialNumber());
|
|
||||||
// activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, true)
|
|
||||||
val bolusingEvent = EventOverviewBolusProgress
|
val bolusingEvent = EventOverviewBolusProgress
|
||||||
bolusingEvent.t = EventOverviewBolusProgress.Treatment(0.0, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB)
|
bolusingEvent.t = EventOverviewBolusProgress.Treatment(0.0, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB)
|
||||||
bolusingEvent.percent = 100
|
bolusingEvent.percent = 100
|
||||||
|
|
|
@ -91,7 +91,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
dateUtil: DateUtil,
|
dateUtil: DateUtil,
|
||||||
aapsSchedulers: AapsSchedulers,
|
aapsSchedulers: AapsSchedulers,
|
||||||
pumpSync: PumpSync,
|
pumpSync: PumpSync,
|
||||||
val pumpSyncStorage: PumpSyncStorage
|
pumpSyncStorage: PumpSyncStorage
|
||||||
) : PumpPluginAbstract(PluginDescription() //
|
) : PumpPluginAbstract(PluginDescription() //
|
||||||
.mainType(PluginType.PUMP) //
|
.mainType(PluginType.PUMP) //
|
||||||
.fragmentClass(MedtronicFragment::class.java.name) //
|
.fragmentClass(MedtronicFragment::class.java.name) //
|
||||||
|
@ -101,7 +101,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
.preferencesId(R.xml.pref_medtronic)
|
.preferencesId(R.xml.pref_medtronic)
|
||||||
.description(R.string.description_pump_medtronic), //
|
.description(R.string.description_pump_medtronic), //
|
||||||
PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later
|
PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later
|
||||||
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil, aapsSchedulers, pumpSync
|
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil, aapsSchedulers, pumpSync, pumpSyncStorage
|
||||||
), Pump, RileyLinkPumpDevice, PumpSyncEntriesCreator {
|
), Pump, RileyLinkPumpDevice, PumpSyncEntriesCreator {
|
||||||
|
|
||||||
private var rileyLinkMedtronicService: RileyLinkMedtronicService? = null
|
private var rileyLinkMedtronicService: RileyLinkMedtronicService? = null
|
||||||
|
@ -635,7 +635,6 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
||||||
|
|
||||||
|
|
||||||
// // TODO fix
|
// // TODO fix
|
||||||
// if (usePumpSync) {
|
// if (usePumpSync) {
|
||||||
// pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
// pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryCarbs
|
||||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
|
||||||
|
@ -215,9 +216,9 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
private fun isCollectionNotEmpty(col: List<*>?): Boolean {
|
private fun isCollectionNotEmpty(col: List<*>?): Boolean {
|
||||||
return col != null && !col.isEmpty()
|
return col != null && !col.isEmpty()
|
||||||
}////////
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
val isPumpSuspended: Boolean
|
val isPumpSuspended: Boolean
|
||||||
get() {
|
get() {
|
||||||
val items = getDataForPumpSuspends()
|
val items = getDataForPumpSuspends()
|
||||||
|
@ -304,7 +305,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// TDD
|
// TDD
|
||||||
val tdds: MutableList<PumpHistoryEntry> = getFilteredItems(setOf(PumpHistoryEntryType.EndResultTotals, tDDType))
|
val tdds: MutableList<PumpHistoryEntry> = getFilteredItems(setOf(PumpHistoryEntryType.EndResultTotals, getTDDType()))
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: TDD [count=%d, items=%s]", tdds.size, gson.toJson(tdds)))
|
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: TDD [count=%d, items=%s]", tdds.size, gson.toJson(tdds)))
|
||||||
if (tdds.isNotEmpty()) {
|
if (tdds.isNotEmpty()) {
|
||||||
try {
|
try {
|
||||||
|
@ -432,33 +433,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private fun processTDDs_Old(tddsIn: MutableList<PumpHistoryEntry>) {
|
|
||||||
// val tdds = filterTDDs(tddsIn)
|
|
||||||
// aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, """
|
|
||||||
// ${logPrefix}TDDs found: %d.
|
|
||||||
// %s
|
|
||||||
// """.trimIndent(), tdds.size, gson.toJson(tdds)))
|
|
||||||
// //val tddsDb = databaseHelper.getTDDsForLastXDays(3)
|
|
||||||
// for (tdd in tdds) {
|
|
||||||
// //val tddDbEntry = findTDD(tdd.atechDateTime!!, tddsDb)
|
|
||||||
// val totalsDTO = tdd.decodedData!!["Object"] as DailyTotalsDTO
|
|
||||||
//
|
|
||||||
// aapsLogger.debug(LTag.PUMP, "DailyTotals: {}", totalsDTO);
|
|
||||||
// if (tddDbEntry == null) {
|
|
||||||
// val tddNew = TDD()
|
|
||||||
// totalsDTO!!.setTDD(tddNew)
|
|
||||||
// aapsLogger.debug(LTag.PUMP, "TDD Add: $tddNew")
|
|
||||||
// databaseHelper.createOrUpdateTDD(tddNew)
|
|
||||||
// } else {
|
|
||||||
// if (!totalsDTO!!.doesEqual(tddDbEntry)) {
|
|
||||||
// totalsDTO.setTDD(tddDbEntry)
|
|
||||||
// aapsLogger.debug(LTag.PUMP, "TDD Edit: $tddDbEntry")
|
|
||||||
// databaseHelper.createOrUpdateTDD(tddDbEntry)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private enum class ProcessHistoryRecord(val description: String) {
|
private enum class ProcessHistoryRecord(val description: String) {
|
||||||
Bolus("Bolus"),
|
Bolus("Bolus"),
|
||||||
TBR("TBR"),
|
TBR("TBR"),
|
||||||
|
@ -533,7 +507,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
|
|
||||||
private fun addExtendedBolus(bolus: PumpHistoryEntry, bolusDTO: BolusDTO, isMultiwave: Boolean) {
|
private fun addExtendedBolus(bolus: PumpHistoryEntry, bolusDTO: BolusDTO, isMultiwave: Boolean) {
|
||||||
|
|
||||||
val durationMs : Long = bolusDTO.duration!! * 60L * 1000L
|
val durationMs : Long = bolusDTO.duration!! * 60L * 1000L
|
||||||
|
|
||||||
val result = pumpSync.syncExtendedBolusWithPumpId(
|
val result = pumpSync.syncExtendedBolusWithPumpId(
|
||||||
|
@ -555,61 +528,17 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
if (bolus.containsDecodedData("Estimate")) {
|
if (bolus.containsDecodedData("Estimate")) {
|
||||||
val bolusWizard = bolus.decodedData!!["Estimate"] as BolusWizardDTO
|
val bolusWizard = bolus.decodedData!!["Estimate"] as BolusWizardDTO
|
||||||
|
|
||||||
val result = pumpSync.syncCarbsWithTimestamp(
|
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(
|
||||||
tryToGetByLocalTime(bolus.atechDateTime!!),
|
tryToGetByLocalTime(bolus.atechDateTime!!),
|
||||||
bolusWizard.carbs.toDouble(),
|
bolusWizard.carbs.toDouble(),
|
||||||
bolus.pumpId!!,
|
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber!!)
|
medtronicPumpStatus.serialNumber!!,
|
||||||
|
bolus.pumpId!!
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncCarbsWithTimestamp [date=%d, pumpId=%d, carbs=%.2f, pumpSerial=%s] - Result: %b",
|
))
|
||||||
bolus.atechDateTime!!, bolusWizard.carbs.toDouble(), bolus.pumpId,
|
|
||||||
medtronicPumpStatus.serialNumber!!, result))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun processBolusEntries_Old(entryList: MutableList<PumpHistoryEntry>) {
|
|
||||||
val oldestTimestamp = getOldestTimestamp(entryList)
|
|
||||||
val entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus)
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: List (before filter): %s, FromDb=%s", gson.toJson(entryList),
|
|
||||||
gsonCore.toJson(entriesFromHistory)))
|
|
||||||
filterOutAlreadyAddedEntries(entryList, entriesFromHistory)
|
|
||||||
if (entryList.isEmpty()) {
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: EntryList was filtered out.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
filterOutNonInsulinEntries(entriesFromHistory)
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: List (after filter): %s, FromDb=%s", gson.toJson(entryList),
|
|
||||||
gsonCore.toJson(entriesFromHistory)))
|
|
||||||
if (isCollectionEmpty(entriesFromHistory)) {
|
|
||||||
for (treatment in entryList) {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "Add Bolus (no db entry): $treatment")
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: Add Bolus: FromDb=null, Treatment=$treatment")
|
|
||||||
addBolus(treatment, null)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (treatment in entryList) {
|
|
||||||
val treatmentDb = findDbEntry_Old(treatment, entriesFromHistory)
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Add Bolus %s - (entryFromDb=%s) ", treatment, treatmentDb))
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: Add Bolus: FromDb=%s, Treatment=%s", treatmentDb, treatment))
|
|
||||||
addBolus(treatment, treatmentDb as Treatment?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun filterOutNonInsulinEntries(entriesFromHistory: MutableList<DbObjectBase>) {
|
|
||||||
// when we try to pair PumpHistory with AAPS treatments, we need to ignore all non-insulin entries
|
|
||||||
val removeList: MutableList<DbObjectBase> = mutableListOf()
|
|
||||||
for (dbObjectBase in entriesFromHistory) {
|
|
||||||
val treatment = dbObjectBase as Treatment
|
|
||||||
if (Round.isSame(treatment.insulin, 0.0)) {
|
|
||||||
removeList.add(dbObjectBase)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entriesFromHistory.removeAll(removeList)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun processTBREntries(entryList: MutableList<PumpHistoryEntry>) {
|
private fun processTBREntries(entryList: MutableList<PumpHistoryEntry>) {
|
||||||
Collections.reverse(entryList)
|
Collections.reverse(entryList)
|
||||||
val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair?
|
val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair?
|
||||||
|
@ -831,82 +760,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterOutAlreadyAddedEntries(entryList: MutableList<PumpHistoryEntry>, treatmentsFromHistory: MutableList<DbObjectBase>) {
|
|
||||||
if (isCollectionEmpty(treatmentsFromHistory))
|
|
||||||
return
|
|
||||||
|
|
||||||
val removeTreatmentsFromHistory: MutableList<DbObjectBase> = ArrayList()
|
|
||||||
val removeTreatmentsFromPH: MutableList<PumpHistoryEntry> = ArrayList()
|
|
||||||
|
|
||||||
for (treatment in treatmentsFromHistory) {
|
|
||||||
if (treatment.getPumpId() != 0L) {
|
|
||||||
var selectedBolus: PumpHistoryEntry? = null
|
|
||||||
for (bolus in entryList) {
|
|
||||||
if (bolus.pumpId == treatment.getPumpId()) {
|
|
||||||
selectedBolus = bolus
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (selectedBolus != null) {
|
|
||||||
entryList.remove(selectedBolus)
|
|
||||||
removeTreatmentsFromPH.add(selectedBolus)
|
|
||||||
removeTreatmentsFromHistory.add(treatment)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory=%s, Treatments=%s",
|
|
||||||
gson.toJson(removeTreatmentsFromPH),
|
|
||||||
gsonCore.toJson(removeTreatmentsFromHistory)))
|
|
||||||
treatmentsFromHistory.removeAll(removeTreatmentsFromHistory)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addBolus(bolus: PumpHistoryEntry?, treatment: Treatment?) {
|
|
||||||
val bolusDTO = bolus!!.decodedData!!["Object"] as BolusDTO?
|
|
||||||
if (treatment == null) {
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): Bolus=$bolusDTO")
|
|
||||||
when (bolusDTO!!.bolusType) {
|
|
||||||
PumpBolusType.Normal -> {
|
|
||||||
val detailedBolusInfo = DetailedBolusInfo()
|
|
||||||
detailedBolusInfo.bolusTimestamp = tryToGetByLocalTime(bolus.atechDateTime!!)
|
|
||||||
detailedBolusInfo.pumpType = medtronicPumpStatus.pumpType
|
|
||||||
detailedBolusInfo.pumpSerial = medtronicPumpStatus.serialNumber
|
|
||||||
detailedBolusInfo.bolusPumpId = bolus.pumpId
|
|
||||||
detailedBolusInfo.insulin = bolusDTO.deliveredAmount!!
|
|
||||||
addCarbsFromEstimate(detailedBolusInfo, bolus)
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo=$detailedBolusInfo")
|
|
||||||
val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false)
|
|
||||||
bolus.linkedObject = detailedBolusInfo
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolus - [date=%d,pumpId=%d, insulin=%.2f, newRecord=%b]", detailedBolusInfo.timestamp,
|
|
||||||
detailedBolusInfo.bolusPumpId, detailedBolusInfo.insulin, newRecord))
|
|
||||||
}
|
|
||||||
|
|
||||||
PumpBolusType.Audio, PumpBolusType.Extended -> {
|
|
||||||
val extendedBolus = ExtendedBolus(injector)
|
|
||||||
extendedBolus.date = tryToGetByLocalTime(bolus.atechDateTime!!)
|
|
||||||
extendedBolus.source = Source.PUMP
|
|
||||||
extendedBolus.insulin = bolusDTO.deliveredAmount!!
|
|
||||||
extendedBolus.pumpId = bolus.pumpId!!
|
|
||||||
extendedBolus.isValid = true
|
|
||||||
extendedBolus.durationInMinutes = bolusDTO.duration!!
|
|
||||||
bolus.linkedObject = extendedBolus
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus=$extendedBolus")
|
|
||||||
activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus)
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolus - Extended [date=%d,pumpId=%d, insulin=%.3f, duration=%d]", extendedBolus.date,
|
|
||||||
extendedBolus.pumpId, extendedBolus.insulin, extendedBolus.durationInMinutes))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: addBolus(OldTreatment=%s): Bolus=%s", treatment, bolusDTO))
|
|
||||||
treatment.source = Source.PUMP
|
|
||||||
treatment.pumpId = bolus.pumpId!!
|
|
||||||
treatment.insulin = bolusDTO!!.deliveredAmount!!
|
|
||||||
val updateReturn = activePlugin.activeTreatments.createOrUpdateMedtronic(treatment, false)
|
|
||||||
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: addBolus(tretament!=null): NewTreatment=%s, UpdateReturn=%s", treatment, updateReturn))
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "editBolus - [date=%d,pumpId=%d, insulin=%.3f, newRecord=%s]", treatment.date,
|
|
||||||
treatment.pumpId, treatment.insulin, updateReturn.toString()))
|
|
||||||
bolus.linkedObject = treatment
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addCarbsFromEstimate(detailedBolusInfo: DetailedBolusInfo, bolus: PumpHistoryEntry?) {
|
private fun addCarbsFromEstimate(detailedBolusInfo: DetailedBolusInfo, bolus: PumpHistoryEntry?) {
|
||||||
if (bolus!!.containsDecodedData("Estimate")) {
|
if (bolus!!.containsDecodedData("Estimate")) {
|
||||||
|
@ -962,41 +815,19 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun processSuspends_Old(tempBasalProcessList: List<TempBasalProcessDTO>) {
|
|
||||||
for (tempBasalProcess in tempBasalProcessList) {
|
|
||||||
// TODO pumpSync - databaseHelper.findTempBasalByPumpId
|
|
||||||
var tempBasal = databaseHelper.findTempBasalByPumpId(tempBasalProcess.itemOne!!.pumpId!!)
|
|
||||||
if (tempBasal == null) {
|
|
||||||
// add
|
|
||||||
tempBasal = TemporaryBasal(injector)
|
|
||||||
tempBasal.date = tryToGetByLocalTime(tempBasalProcess.itemOne!!.atechDateTime!!)
|
|
||||||
tempBasal.source = Source.PUMP
|
|
||||||
tempBasal.pumpId = tempBasalProcess.itemOne!!.pumpId!!
|
|
||||||
tempBasal.durationInMinutes = tempBasalProcess.duration
|
|
||||||
tempBasal.absoluteRate = 0.0
|
|
||||||
tempBasal.isAbsolute = true
|
|
||||||
tempBasalProcess.itemOne!!.linkedObject = tempBasal
|
|
||||||
tempBasalProcess.itemTwo!!.linkedObject = tempBasal
|
|
||||||
// TODO pumpSync -databaseHelper.createOrUpdate(tbr-suspebd(
|
|
||||||
databaseHelper.createOrUpdate(tempBasal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// suspend/resume
|
// suspend/resume
|
||||||
// no_delivery/prime & rewind/prime
|
// no_delivery/prime & rewind/prime
|
||||||
private fun getSuspendRecords(): MutableList<TempBasalProcessDTO> {
|
private fun getSuspendRecords(): MutableList<TempBasalProcessDTO> {
|
||||||
val outList: MutableList<TempBasalProcessDTO> = ArrayList()
|
val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
|
||||||
|
|
||||||
// suspend/resume
|
// suspend/resume
|
||||||
outList.addAll(getSuspendResumeRecordsList())
|
outList.addAll(getSuspendResumeRecordsList())
|
||||||
// no_delivery/prime & rewind/prime
|
// no_delivery/prime & rewind/prime
|
||||||
outList.addAll(getNoDeliveryRewindPrimeRecordsList())
|
outList.addAll(getNoDeliveryRewindPrimeRecordsList())
|
||||||
return outList
|
return outList
|
||||||
}// remove last and have paired items// remove last (unpaired R)// get one more from history (R S R) -> ([S] R S R)// remove last (unpaired R)// not full suspends, need to retrive one more record and discard first one (R S R S) -> ([S] R S R [xS])// full resume suspends (S R S R)
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> {
|
private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> {
|
||||||
val filteredItems = getFilteredItems(newHistory, //
|
val filteredItems = getFilteredItems(newHistory, //
|
||||||
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
|
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
|
||||||
|
@ -1047,9 +878,9 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outList
|
return outList
|
||||||
}//////////
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
|
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
|
||||||
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
|
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
|
||||||
setOf(PumpHistoryEntryType.Prime))
|
setOf(PumpHistoryEntryType.Prime))
|
||||||
|
@ -1134,15 +965,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return if (tddsOut.size == 0) tdds else tddsOut
|
return if (tddsOut.size == 0) tdds else tddsOut
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun findTDD(atechDateTime: Long, tddsDb: List<TDD>): TDD? {
|
|
||||||
// for (tdd in tddsDb) {
|
|
||||||
// if (DateTimeUtil.isSameDayATDAndMillis(atechDateTime, tdd.date)) {
|
|
||||||
// return tdd
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null
|
|
||||||
// }
|
|
||||||
|
|
||||||
private fun tryToGetByLocalTime(atechDateTime: Long): Long {
|
private fun tryToGetByLocalTime(atechDateTime: Long): Long {
|
||||||
return DateTimeUtil.toMillisFromATD(atechDateTime)
|
return DateTimeUtil.toMillisFromATD(atechDateTime)
|
||||||
}
|
}
|
||||||
|
@ -1169,8 +991,8 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val tDDType: PumpHistoryEntryType
|
private fun getTDDType(): PumpHistoryEntryType {
|
||||||
get() = if (medtronicUtil.medtronicPumpModel == null) {
|
return if (medtronicUtil.medtronicPumpModel == null) {
|
||||||
PumpHistoryEntryType.EndResultTotals
|
PumpHistoryEntryType.EndResultTotals
|
||||||
} else when (medtronicUtil.medtronicPumpModel) {
|
} else when (medtronicUtil.medtronicPumpModel) {
|
||||||
MedtronicDeviceType.Medtronic_515, MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515
|
MedtronicDeviceType.Medtronic_515, MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515
|
||||||
|
@ -1179,10 +1001,12 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
MedtronicDeviceType.Medtronic_723_Revel,
|
MedtronicDeviceType.Medtronic_723_Revel,
|
||||||
MedtronicDeviceType.Medtronic_554_Veo,
|
MedtronicDeviceType.Medtronic_554_Veo,
|
||||||
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
|
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
PumpHistoryEntryType.EndResultTotals
|
PumpHistoryEntryType.EndResultTotals
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun hasBasalProfileChanged(): Boolean {
|
fun hasBasalProfileChanged(): Boolean {
|
||||||
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
|
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
|
||||||
|
@ -1217,10 +1041,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
PumpHistoryEntryType.ChangeTime))
|
PumpHistoryEntryType.ChangeTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
// fun setLastHistoryRecordTime(lastHistoryRecordTime: Long?) {
|
|
||||||
// // this.previousLastHistoryRecordTime = this.lastHistoryRecordTime;
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun setIsInInit(init: Boolean) {
|
fun setIsInInit(init: Boolean) {
|
||||||
isInit = init
|
isInit = init
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue