- 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
|
@ -28,5 +28,16 @@ data class PumpDbEntryBolus(var insulin: Double,
|
|||
var carbs: Double,
|
||||
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)
|
|
@ -7,8 +7,10 @@ import info.nightscout.androidaps.data.DetailedBolusInfo
|
|||
import info.nightscout.androidaps.db.TemporaryBasal
|
||||
import info.nightscout.androidaps.interfaces.PumpSync
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import java.lang.reflect.Type
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
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 {
|
||||
val temporaryId = creator.generateTempId(detailedBolusInfo.timestamp)
|
||||
val response = pumpSync.addBolusWithTempId(
|
||||
val result = pumpSync.addBolusWithTempId(
|
||||
detailedBolusInfo.timestamp,
|
||||
detailedBolusInfo.insulin,
|
||||
temporaryId,
|
||||
detailedBolusInfo.bolusType,
|
||||
creator.model(),
|
||||
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]!!
|
||||
|
||||
innerList.add(PumpDbEntry(temporaryId, detailedBolusInfo.timestamp, creator.model(), creator.serialNumber(), detailedBolusInfo))
|
||||
pumpSyncStorage[BOLUS] = innerList
|
||||
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
|
||||
|
@ -123,6 +145,8 @@ class PumpSyncStorage @Inject constructor(
|
|||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun removeBolusWithTemporaryId(temporaryId: Long) {
|
||||
val bolusList = removeTemporaryId(temporaryId, pumpSyncStorage[BOLUS]!!)
|
||||
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.defs.PumpDriverState
|
||||
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.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter.to0Decimal
|
||||
|
@ -57,12 +60,11 @@ abstract class PumpPluginAbstract protected constructor(
|
|||
var fabricPrivacy: FabricPrivacy,
|
||||
var dateUtil: DateUtil,
|
||||
var aapsSchedulers: AapsSchedulers,
|
||||
var pumpSync: PumpSync
|
||||
) : PumpPluginBase(pluginDescription!!, injector!!, aapsLogger, resourceHelper, commandQueue), Pump, Constraints {
|
||||
var pumpSync: PumpSync,
|
||||
var pumpSyncStorage: PumpSyncStorage
|
||||
) : PumpPluginBase(pluginDescription!!, injector!!, aapsLogger, resourceHelper, commandQueue), Pump, Constraints, PumpSyncEntriesCreator {
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
//protected override var injector: HasAndroidInjector? = null
|
||||
//protected var dateUtil: DateUtil
|
||||
|
||||
// Pump capabilities
|
||||
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()
|
||||
|
||||
abstract fun initPumpStatusData()
|
||||
|
@ -343,10 +343,11 @@ abstract class PumpPluginAbstract protected constructor(
|
|||
// bolus needed, ask pump to deliver it
|
||||
deliverBolus(detailedBolusInfo)
|
||||
} else {
|
||||
detailedBolusInfo.timestamp = System.currentTimeMillis()
|
||||
|
||||
// no bolus required, carb only treatment
|
||||
// TODO carb only bolus - DONE
|
||||
pumpSync.syncCarbsWithTimestamp(System.currentTimeMillis(), detailedBolusInfo.carbs, null, model(), serialNumber());
|
||||
// activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, true)
|
||||
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(detailedBolusInfo, this))
|
||||
|
||||
val bolusingEvent = EventOverviewBolusProgress
|
||||
bolusingEvent.t = EventOverviewBolusProgress.Treatment(0.0, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB)
|
||||
bolusingEvent.percent = 100
|
||||
|
|
|
@ -91,7 +91,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
dateUtil: DateUtil,
|
||||
aapsSchedulers: AapsSchedulers,
|
||||
pumpSync: PumpSync,
|
||||
val pumpSyncStorage: PumpSyncStorage
|
||||
pumpSyncStorage: PumpSyncStorage
|
||||
) : PumpPluginAbstract(PluginDescription() //
|
||||
.mainType(PluginType.PUMP) //
|
||||
.fragmentClass(MedtronicFragment::class.java.name) //
|
||||
|
@ -101,7 +101,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
.preferencesId(R.xml.pref_medtronic)
|
||||
.description(R.string.description_pump_medtronic), //
|
||||
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 {
|
||||
|
||||
private var rileyLinkMedtronicService: RileyLinkMedtronicService? = null
|
||||
|
@ -635,7 +635,6 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
|
||||
pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
||||
|
||||
|
||||
// // TODO fix
|
||||
// if (usePumpSync) {
|
||||
// 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.plugins.pump.common.defs.PumpType
|
||||
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.utils.DateTimeUtil
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
|
||||
|
@ -215,9 +216,9 @@ class MedtronicHistoryData @Inject constructor(
|
|||
|
||||
private fun isCollectionNotEmpty(col: List<*>?): Boolean {
|
||||
return col != null && !col.isEmpty()
|
||||
}////////
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
val isPumpSuspended: Boolean
|
||||
get() {
|
||||
val items = getDataForPumpSuspends()
|
||||
|
@ -304,7 +305,7 @@ class MedtronicHistoryData @Inject constructor(
|
|||
}
|
||||
|
||||
// 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)))
|
||||
if (tdds.isNotEmpty()) {
|
||||
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) {
|
||||
Bolus("Bolus"),
|
||||
TBR("TBR"),
|
||||
|
@ -533,7 +507,6 @@ class MedtronicHistoryData @Inject constructor(
|
|||
|
||||
|
||||
private fun addExtendedBolus(bolus: PumpHistoryEntry, bolusDTO: BolusDTO, isMultiwave: Boolean) {
|
||||
|
||||
val durationMs : Long = bolusDTO.duration!! * 60L * 1000L
|
||||
|
||||
val result = pumpSync.syncExtendedBolusWithPumpId(
|
||||
|
@ -555,61 +528,17 @@ class MedtronicHistoryData @Inject constructor(
|
|||
if (bolus.containsDecodedData("Estimate")) {
|
||||
val bolusWizard = bolus.decodedData!!["Estimate"] as BolusWizardDTO
|
||||
|
||||
val result = pumpSync.syncCarbsWithTimestamp(
|
||||
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(
|
||||
tryToGetByLocalTime(bolus.atechDateTime!!),
|
||||
bolusWizard.carbs.toDouble(),
|
||||
bolus.pumpId!!,
|
||||
medtronicPumpStatus.pumpType,
|
||||
medtronicPumpStatus.serialNumber!!)
|
||||
|
||||
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))
|
||||
medtronicPumpStatus.serialNumber!!,
|
||||
bolus.pumpId!!
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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>) {
|
||||
Collections.reverse(entryList)
|
||||
val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair?
|
||||
|
@ -831,82 +760,6 @@ class MedtronicHistoryData @Inject constructor(
|
|||
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?) {
|
||||
if (bolus!!.containsDecodedData("Estimate")) {
|
||||
|
@ -962,53 +815,41 @@ 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
|
||||
// no_delivery/prime & rewind/prime
|
||||
private fun getSuspendRecords(): MutableList<TempBasalProcessDTO> {
|
||||
val outList: MutableList<TempBasalProcessDTO> = ArrayList()
|
||||
val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
|
||||
|
||||
// suspend/resume
|
||||
outList.addAll(getSuspendResumeRecordsList())
|
||||
// no_delivery/prime & rewind/prime
|
||||
outList.addAll(getNoDeliveryRewindPrimeRecordsList())
|
||||
return outList
|
||||
}
|
||||
|
||||
// suspend/resume
|
||||
outList.addAll(getSuspendResumeRecordsList())
|
||||
// no_delivery/prime & rewind/prime
|
||||
outList.addAll(getNoDeliveryRewindPrimeRecordsList())
|
||||
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> {
|
||||
val filteredItems = getFilteredItems(newHistory, //
|
||||
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
|
||||
val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
|
||||
if (filteredItems.size > 0) {
|
||||
val filtered2Items: MutableList<PumpHistoryEntry> = mutableListOf()
|
||||
if (filteredItems.size % 2 == 0 && filteredItems[0].entryType === PumpHistoryEntryType.ResumePump) {
|
||||
// full resume suspends (S R S R)
|
||||
filtered2Items.addAll(filteredItems)
|
||||
} else if (filteredItems.size % 2 == 0 && filteredItems[0].entryType === PumpHistoryEntryType.SuspendPump) {
|
||||
// not full suspends, need to retrive one more record and discard first one (R S R S) -> ([S] R S R [xS])
|
||||
filteredItems.removeAt(0)
|
||||
val filteredItems = getFilteredItems(newHistory, //
|
||||
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
|
||||
val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
|
||||
if (filteredItems.size > 0) {
|
||||
val filtered2Items: MutableList<PumpHistoryEntry> = mutableListOf()
|
||||
if (filteredItems.size % 2 == 0 && filteredItems[0].entryType === PumpHistoryEntryType.ResumePump) {
|
||||
// full resume suspends (S R S R)
|
||||
filtered2Items.addAll(filteredItems)
|
||||
} else if (filteredItems.size % 2 == 0 && filteredItems[0].entryType === PumpHistoryEntryType.SuspendPump) {
|
||||
// not full suspends, need to retrive one more record and discard first one (R S R S) -> ([S] R S R [xS])
|
||||
filteredItems.removeAt(0)
|
||||
val oneMoreEntryFromHistory = getOneMoreEntryFromHistory(PumpHistoryEntryType.SuspendPump)
|
||||
if (oneMoreEntryFromHistory != null) {
|
||||
filteredItems.add(oneMoreEntryFromHistory)
|
||||
} else {
|
||||
filteredItems.removeAt(filteredItems.size - 1) // remove last (unpaired R)
|
||||
}
|
||||
filtered2Items.addAll(filteredItems)
|
||||
} else {
|
||||
if (filteredItems[0].entryType === PumpHistoryEntryType.ResumePump) {
|
||||
// get one more from history (R S R) -> ([S] R S R)
|
||||
val oneMoreEntryFromHistory = getOneMoreEntryFromHistory(PumpHistoryEntryType.SuspendPump)
|
||||
if (oneMoreEntryFromHistory != null) {
|
||||
filteredItems.add(oneMoreEntryFromHistory)
|
||||
|
@ -1017,39 +858,29 @@ class MedtronicHistoryData @Inject constructor(
|
|||
}
|
||||
filtered2Items.addAll(filteredItems)
|
||||
} else {
|
||||
if (filteredItems[0].entryType === PumpHistoryEntryType.ResumePump) {
|
||||
// get one more from history (R S R) -> ([S] R S R)
|
||||
val oneMoreEntryFromHistory = getOneMoreEntryFromHistory(PumpHistoryEntryType.SuspendPump)
|
||||
if (oneMoreEntryFromHistory != null) {
|
||||
filteredItems.add(oneMoreEntryFromHistory)
|
||||
} else {
|
||||
filteredItems.removeAt(filteredItems.size - 1) // remove last (unpaired R)
|
||||
}
|
||||
filtered2Items.addAll(filteredItems)
|
||||
} else {
|
||||
// remove last and have paired items
|
||||
filteredItems.removeAt(0)
|
||||
filtered2Items.addAll(filteredItems)
|
||||
}
|
||||
}
|
||||
if (filtered2Items.size > 0) {
|
||||
sort(filtered2Items)
|
||||
Collections.reverse(filtered2Items)
|
||||
var i = 0
|
||||
while (i < filtered2Items.size) {
|
||||
val dto = TempBasalProcessDTO()
|
||||
dto.itemOne = filtered2Items[i]
|
||||
dto.itemTwo = filtered2Items[i + 1]
|
||||
dto.processOperation = TempBasalProcessDTO.Operation.Add
|
||||
outList.add(dto)
|
||||
i += 2
|
||||
}
|
||||
// remove last and have paired items
|
||||
filteredItems.removeAt(0)
|
||||
filtered2Items.addAll(filteredItems)
|
||||
}
|
||||
}
|
||||
return outList
|
||||
}//////////
|
||||
if (filtered2Items.size > 0) {
|
||||
sort(filtered2Items)
|
||||
Collections.reverse(filtered2Items)
|
||||
var i = 0
|
||||
while (i < filtered2Items.size) {
|
||||
val dto = TempBasalProcessDTO()
|
||||
dto.itemOne = filtered2Items[i]
|
||||
dto.itemTwo = filtered2Items[i + 1]
|
||||
dto.processOperation = TempBasalProcessDTO.Operation.Add
|
||||
outList.add(dto)
|
||||
i += 2
|
||||
}
|
||||
}
|
||||
}
|
||||
return outList
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
|
||||
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
|
||||
setOf(PumpHistoryEntryType.Prime))
|
||||
|
@ -1134,15 +965,6 @@ class MedtronicHistoryData @Inject constructor(
|
|||
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 {
|
||||
return DateTimeUtil.toMillisFromATD(atechDateTime)
|
||||
}
|
||||
|
@ -1169,20 +991,22 @@ class MedtronicHistoryData @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private val tDDType: PumpHistoryEntryType
|
||||
get() = if (medtronicUtil.medtronicPumpModel == null) {
|
||||
private fun getTDDType(): PumpHistoryEntryType {
|
||||
return if (medtronicUtil.medtronicPumpModel == null) {
|
||||
PumpHistoryEntryType.EndResultTotals
|
||||
} else when (medtronicUtil.medtronicPumpModel) {
|
||||
MedtronicDeviceType.Medtronic_515, MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515
|
||||
MedtronicDeviceType.Medtronic_522, MedtronicDeviceType.Medtronic_722 -> PumpHistoryEntryType.DailyTotals522
|
||||
MedtronicDeviceType.Medtronic_515, MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515
|
||||
MedtronicDeviceType.Medtronic_522, MedtronicDeviceType.Medtronic_722 -> PumpHistoryEntryType.DailyTotals522
|
||||
MedtronicDeviceType.Medtronic_523_Revel,
|
||||
MedtronicDeviceType.Medtronic_723_Revel,
|
||||
MedtronicDeviceType.Medtronic_554_Veo,
|
||||
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
|
||||
else -> {
|
||||
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
|
||||
|
||||
else -> {
|
||||
PumpHistoryEntryType.EndResultTotals
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun hasBasalProfileChanged(): Boolean {
|
||||
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
|
||||
|
@ -1217,10 +1041,6 @@ class MedtronicHistoryData @Inject constructor(
|
|||
PumpHistoryEntryType.ChangeTime))
|
||||
}
|
||||
|
||||
// fun setLastHistoryRecordTime(lastHistoryRecordTime: Long?) {
|
||||
// // this.previousLastHistoryRecordTime = this.lastHistoryRecordTime;
|
||||
// }
|
||||
|
||||
fun setIsInInit(init: Boolean) {
|
||||
isInit = init
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue