convert BolusCalculatorResult units on upload
This commit is contained in:
parent
4a854616ae
commit
0273ba7bf0
3 changed files with 8 additions and 7 deletions
|
@ -60,7 +60,7 @@ class WizardInfoDialog : DaggerDialogFragment() {
|
|||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putString("data", data.toJson(true, dateUtil).toString())
|
||||
outState.putString("data", data.toJson(true, dateUtil, profileFunction).toString())
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -286,14 +286,14 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
|
||||
nsClientPlugin.nsClientService?.dbAdd(
|
||||
"treatments",
|
||||
bolusCalculatorResult.first.toJson(true, dateUtil),
|
||||
bolusCalculatorResult.first.toJson(true, dateUtil, profileFunction),
|
||||
DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id),
|
||||
"$startId/$lastDbId"
|
||||
)
|
||||
// with nsId = update
|
||||
bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
||||
nsClientPlugin.nsClientService?.dbUpdate(
|
||||
"treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(false, dateUtil),
|
||||
"treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(false, dateUtil, profileFunction),
|
||||
DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id), "$startId/$lastDbId"
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,22 +2,23 @@ package info.nightscout.androidaps.extensions
|
|||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonSyntaxException
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
import org.json.JSONObject
|
||||
|
||||
fun BolusCalculatorResult.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
|
||||
fun BolusCalculatorResult.toJson(isAdd: Boolean, dateUtil: DateUtil, profileFunction: ProfileFunction): JSONObject =
|
||||
JSONObject()
|
||||
.put("eventType", TherapyEvent.Type.BOLUS_WIZARD.text)
|
||||
.put("created_at", dateUtil.toISOString(timestamp))
|
||||
.put("isValid", isValid)
|
||||
.put("bolusCalculatorResult", Gson().toJson(this))
|
||||
.put("date", timestamp)
|
||||
.put("glucose", glucoseValue)
|
||||
.put("units", Constants.MGDL)
|
||||
.put("glucose", Profile.fromMgdlToUnits(glucoseValue, profileFunction.getUnits()))
|
||||
.put("units", profileFunction.getUnits().asText)
|
||||
.put("notes", note)
|
||||
.also { if (isAdd && interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue