NSCv3: process BolusCalculatorResult
This commit is contained in:
parent
b3483aaecc
commit
b12c8909ca
|
@ -4,14 +4,14 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
|
||||
data class NSBolusWizard(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val identifier: String?,
|
||||
override val device: String? = null,
|
||||
override val identifier: String? = null,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
override val srvModified: Long? = null,
|
||||
override val srvCreated: Long? = null,
|
||||
override val utcOffset: Long,
|
||||
override val subject: String?,
|
||||
override var isReadOnly: Boolean,
|
||||
override val subject: String? = null,
|
||||
override var isReadOnly: Boolean = false,
|
||||
override val isValid: Boolean,
|
||||
override val eventType: EventType,
|
||||
override val notes: String?,
|
||||
|
|
|
@ -66,7 +66,7 @@ data class BolusCalculatorResult(
|
|||
var note: String
|
||||
) : TraceableDBEntry, DBEntryWithTime {
|
||||
|
||||
private fun contentEqualsTo(other: BolusCalculatorResult): Boolean =
|
||||
fun contentEqualsTo(other: BolusCalculatorResult): Boolean =
|
||||
isValid == other.isValid &&
|
||||
timestamp == other.timestamp &&
|
||||
utcOffset == other.utcOffset &&
|
||||
|
|
|
@ -35,6 +35,7 @@ import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
|
|||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI
|
||||
import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolus
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolusWizard
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSCarbs
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSEffectiveProfileSwitch
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSProfileSwitch
|
||||
|
@ -327,7 +328,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> dataPair.value.toNSBolus()
|
||||
is DataSyncSelector.PairCarbs -> dataPair.value.toNSCarbs()
|
||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toNSBolusWizard()
|
||||
is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toNSTemporaryTarget()
|
||||
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||
// is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
||||
|
@ -382,7 +383,16 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
dataSyncSelector.confirmLastCarbsIdIfGreater(dataPair.id)
|
||||
}
|
||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||
|
||||
is DataSyncSelector.PairBolusCalculatorResult -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdBolusCalculatorResults.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(dataPair.id)
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairTemporaryTarget -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
|
|
|
@ -3,6 +3,8 @@ package info.nightscout.plugins.sync.nsclientV3.extensions
|
|||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonSyntaxException
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
import info.nightscout.sdk.localmodel.entry.NsUnits
|
||||
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||
import info.nightscout.sdk.localmodel.treatment.NSBolusWizard
|
||||
|
||||
fun NSBolusWizard.toBolusCalculatorResult(): BolusCalculatorResult? =
|
||||
|
@ -17,3 +19,20 @@ fun NSBolusWizard.toBolusCalculatorResult(): BolusCalculatorResult? =
|
|||
} catch (e: JsonSyntaxException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun BolusCalculatorResult.toNSBolusWizard(): NSBolusWizard =
|
||||
NSBolusWizard(
|
||||
eventType = EventType.BOLUS_WIZARD,
|
||||
isValid = isValid,
|
||||
date = timestamp,
|
||||
utcOffset = utcOffset,
|
||||
notes = note,
|
||||
bolusCalculatorResult = Gson().toJson(this).toString(),
|
||||
units = NsUnits.MG_DL,
|
||||
glucose = glucoseValue,
|
||||
identifier = interfaceIDs.nightscoutId,
|
||||
pumpId = interfaceIDs.pumpId,
|
||||
pumpType = interfaceIDs.pumpType?.name,
|
||||
pumpSerial = interfaceIDs.pumpSerial,
|
||||
endId = interfaceIDs.endId
|
||||
)
|
|
@ -0,0 +1,59 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.NSBolusWizard
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class BolusCalculatorResultExtensionKtTest {
|
||||
|
||||
@Test
|
||||
fun toBolusCalculatorResult() {
|
||||
val bolus = BolusCalculatorResult(
|
||||
timestamp = 10000,
|
||||
isValid = true,
|
||||
targetBGLow = 110.0,
|
||||
targetBGHigh = 120.0,
|
||||
isf = 30.0,
|
||||
ic = 2.0,
|
||||
bolusIOB = 1.1,
|
||||
wasBolusIOBUsed = true,
|
||||
basalIOB = 1.2,
|
||||
wasBasalIOBUsed = true,
|
||||
glucoseValue = 150.0,
|
||||
wasGlucoseUsed = true,
|
||||
glucoseDifference = 30.0,
|
||||
glucoseInsulin = 1.3,
|
||||
glucoseTrend = 15.0,
|
||||
wasTrendUsed = true,
|
||||
trendInsulin = 1.4,
|
||||
cob = 24.0,
|
||||
wasCOBUsed = true,
|
||||
cobInsulin = 1.5,
|
||||
carbs = 36.0,
|
||||
wereCarbsUsed = true,
|
||||
carbsInsulin = 1.6,
|
||||
otherCorrection = 1.7,
|
||||
wasSuperbolusUsed = true,
|
||||
superbolusInsulin = 0.3,
|
||||
wasTempTargetUsed = false,
|
||||
totalInsulin = 9.1,
|
||||
percentageCorrection = 70,
|
||||
profileName = " sss",
|
||||
note = "ddd",
|
||||
interfaceIDs_backing = InterfaceIDs(
|
||||
nightscoutId = "nightscoutId",
|
||||
pumpId = 11000,
|
||||
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||
pumpSerial = "bbbb"
|
||||
)
|
||||
)
|
||||
|
||||
val bolus2 = (bolus.toNSBolusWizard().convertToRemoteAndBack() as NSBolusWizard).toBolusCalculatorResult()!!
|
||||
Assertions.assertTrue(bolus.contentEqualsTo(bolus2))
|
||||
Assertions.assertTrue(bolus.interfaceIdsEqualsTo(bolus2))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue