NSCv3: process BolusCalculatorResult
This commit is contained in:
parent
b3483aaecc
commit
b12c8909ca
5 changed files with 107 additions and 19 deletions
|
@ -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
|
||||
|
@ -325,15 +326,15 @@ class NSClientV3Plugin @Inject constructor(
|
|||
Operation.UPDATE -> nsAndroidClient?.let { return@let it::updateTreatment }
|
||||
}
|
||||
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.PairTemporaryTarget -> dataPair.value.toNSTemporaryTarget()
|
||||
is DataSyncSelector.PairBolus -> dataPair.value.toNSBolus()
|
||||
is DataSyncSelector.PairCarbs -> dataPair.value.toNSCarbs()
|
||||
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)
|
||||
is DataSyncSelector.PairTherapyEvent -> dataPair.value.toNSTherapyEvent()
|
||||
is DataSyncSelector.PairTherapyEvent -> dataPair.value.toNSTherapyEvent()
|
||||
|
||||
is DataSyncSelector.PairTemporaryBasal -> {
|
||||
is DataSyncSelector.PairTemporaryBasal -> {
|
||||
val profile = profileFunction.getProfile(dataPair.value.timestamp)
|
||||
if (profile == null) {
|
||||
dataSyncSelector.confirmLastTemporaryBasalIdIfGreater(dataPair.id)
|
||||
|
@ -365,7 +366,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
)
|
||||
call?.let { it(data) }?.let { result ->
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> {
|
||||
is DataSyncSelector.PairBolus -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdBoluses.add(dataPair.value)
|
||||
|
@ -374,7 +375,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
dataSyncSelector.confirmLastBolusIdIfGreater(dataPair.id)
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairCarbs -> {
|
||||
is DataSyncSelector.PairCarbs -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdCarbs.add(dataPair.value)
|
||||
|
@ -382,8 +383,17 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
dataSyncSelector.confirmLastCarbsIdIfGreater(dataPair.id)
|
||||
}
|
||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||
is DataSyncSelector.PairTemporaryTarget -> {
|
||||
|
||||
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
|
||||
storeDataForDb.nsIdTemporaryTargets.add(dataPair.value)
|
||||
|
@ -393,7 +403,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||
// is DataSyncSelector.PairGlucoseValue -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairTherapyEvent -> {
|
||||
is DataSyncSelector.PairTherapyEvent -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdTherapyEvents.add(dataPair.value)
|
||||
|
@ -402,7 +412,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
dataSyncSelector.confirmLastTherapyEventIdIfGreater(dataPair.id)
|
||||
}
|
||||
|
||||
is DataSyncSelector.PairTemporaryBasal -> {
|
||||
is DataSyncSelector.PairTemporaryBasal -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdTemporaryBasals.add(dataPair.value)
|
||||
|
|
|
@ -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