NS: Sync BolusCalculatorResult
This commit is contained in:
parent
b16318da2c
commit
60c14cda21
|
@ -214,6 +214,34 @@ class NSClientAddUpdateWorker(
|
||||||
}
|
}
|
||||||
} ?: aapsLogger.error("Error parsing EffectiveProfileSwitch json $json")
|
} ?: aapsLogger.error("Error parsing EffectiveProfileSwitch json $json")
|
||||||
}
|
}
|
||||||
|
eventType == TherapyEvent.Type.BOLUS_WIZARD.text ->
|
||||||
|
if (config.NSCLIENT) {
|
||||||
|
bolusCalculatorResultFromJson(json)?.let { bolusCalculatorResult ->
|
||||||
|
repository.runTransactionForResult(SyncNsBolusCalculatorResultTransaction(bolusCalculatorResult))
|
||||||
|
.doOnError {
|
||||||
|
aapsLogger.error(LTag.DATABASE, "Error while saving BolusCalculatorResult", it)
|
||||||
|
ret = Result.failure(workDataOf("Error" to it.toString()))
|
||||||
|
}
|
||||||
|
.blockingGet()
|
||||||
|
.also { result ->
|
||||||
|
result.inserted.forEach {
|
||||||
|
uel.log(Action.BOLUS_CALCULATOR_RESULT, Sources.NSClient,
|
||||||
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
|
)
|
||||||
|
aapsLogger.debug(LTag.DATABASE, "Inserted BolusCalculatorResult $it")
|
||||||
|
}
|
||||||
|
result.invalidated.forEach {
|
||||||
|
uel.log(Action.BOLUS_CALCULATOR_RESULT_REMOVED, Sources.NSClient,
|
||||||
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
|
)
|
||||||
|
aapsLogger.debug(LTag.DATABASE, "Invalidated BolusCalculatorResult $it")
|
||||||
|
}
|
||||||
|
result.updatedNsId.forEach {
|
||||||
|
aapsLogger.debug(LTag.DATABASE, "Updated nsId BolusCalculatorResult $it")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: aapsLogger.error("Error parsing BolusCalculatorResult json $json")
|
||||||
|
}
|
||||||
eventType == TherapyEvent.Type.CANNULA_CHANGE.text ||
|
eventType == TherapyEvent.Type.CANNULA_CHANGE.text ||
|
||||||
eventType == TherapyEvent.Type.INSULIN_CHANGE.text ||
|
eventType == TherapyEvent.Type.INSULIN_CHANGE.text ||
|
||||||
eventType == TherapyEvent.Type.SENSOR_CHANGE.text ||
|
eventType == TherapyEvent.Type.SENSOR_CHANGE.text ||
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package info.nightscout.androidaps.extensions
|
package info.nightscout.androidaps.extensions
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonSyntaxException
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.JsonHelper
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
fun BolusCalculatorResult.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
|
fun BolusCalculatorResult.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
|
||||||
|
@ -18,3 +20,23 @@ fun BolusCalculatorResult.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject
|
||||||
.put("units", Constants.MGDL)
|
.put("units", Constants.MGDL)
|
||||||
.put("notes", note)
|
.put("notes", note)
|
||||||
.also { if (isAdd && interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId) }
|
.also { if (isAdd && interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId) }
|
||||||
|
|
||||||
|
fun bolusCalculatorResultFromJson(jsonObject: JSONObject): BolusCalculatorResult? {
|
||||||
|
val timestamp = JsonHelper.safeGetLongAllowNull(jsonObject, "mills", null) ?: return null
|
||||||
|
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
|
||||||
|
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
|
||||||
|
val bcrString = JsonHelper.safeGetStringAllowNull(jsonObject, "bolusCalculatorResult", null) ?: return null
|
||||||
|
|
||||||
|
if (timestamp == 0L) return null
|
||||||
|
|
||||||
|
return try {
|
||||||
|
Gson().fromJson(bcrString, BolusCalculatorResult::class.java)
|
||||||
|
.also {
|
||||||
|
it.id = 0
|
||||||
|
it.isValid = isValid
|
||||||
|
it.interfaceIDs.nightscoutId = id
|
||||||
|
}
|
||||||
|
} catch (e: JsonSyntaxException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,89 +17,91 @@ class Translator @Inject internal constructor(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun translate(action: Action): String = when (action) {
|
fun translate(action: Action): String = when (action) {
|
||||||
Action.BOLUS -> resourceHelper.gs(R.string.uel_bolus)
|
Action.BOLUS -> resourceHelper.gs(R.string.uel_bolus)
|
||||||
Action.SMB -> resourceHelper.gs(R.string.smb_shortname)
|
Action.BOLUS_CALCULATOR_RESULT -> resourceHelper.gs(R.string.uel_bolus_calculator)
|
||||||
Action.BOLUS_ADVISOR -> resourceHelper.gs(R.string.uel_bolus_advisor)
|
Action.BOLUS_CALCULATOR_RESULT_REMOVED -> resourceHelper.gs(R.string.uel_bolus_calculator)
|
||||||
Action.EXTENDED_BOLUS -> resourceHelper.gs(R.string.uel_extended_bolus)
|
Action.SMB -> resourceHelper.gs(R.string.smb_shortname)
|
||||||
Action.SUPERBOLUS_TBR -> resourceHelper.gs(R.string.uel_superbolus_tbr)
|
Action.BOLUS_ADVISOR -> resourceHelper.gs(R.string.uel_bolus_advisor)
|
||||||
Action.CARBS -> resourceHelper.gs(R.string.uel_carbs)
|
Action.EXTENDED_BOLUS -> resourceHelper.gs(R.string.uel_extended_bolus)
|
||||||
Action.EXTENDED_CARBS -> resourceHelper.gs(R.string.uel_extended_carbs)
|
Action.SUPERBOLUS_TBR -> resourceHelper.gs(R.string.uel_superbolus_tbr)
|
||||||
Action.TEMP_BASAL -> resourceHelper.gs(R.string.uel_temp_basal)
|
Action.CARBS -> resourceHelper.gs(R.string.uel_carbs)
|
||||||
Action.TT -> resourceHelper.gs(R.string.uel_tt)
|
Action.EXTENDED_CARBS -> resourceHelper.gs(R.string.uel_extended_carbs)
|
||||||
Action.NEW_PROFILE -> resourceHelper.gs(R.string.uel_new_profile)
|
Action.TEMP_BASAL -> resourceHelper.gs(R.string.uel_temp_basal)
|
||||||
Action.CLONE_PROFILE -> resourceHelper.gs(R.string.uel_clone_profile)
|
Action.TT -> resourceHelper.gs(R.string.uel_tt)
|
||||||
Action.STORE_PROFILE -> resourceHelper.gs(R.string.uel_store_profile)
|
Action.NEW_PROFILE -> resourceHelper.gs(R.string.uel_new_profile)
|
||||||
Action.PROFILE_SWITCH -> resourceHelper.gs(R.string.uel_profile_switch)
|
Action.CLONE_PROFILE -> resourceHelper.gs(R.string.uel_clone_profile)
|
||||||
Action.PROFILE_SWITCH_CLONED -> resourceHelper.gs(R.string.uel_profile_switch_cloned)
|
Action.STORE_PROFILE -> resourceHelper.gs(R.string.uel_store_profile)
|
||||||
Action.CLOSED_LOOP_MODE -> resourceHelper.gs(R.string.uel_closed_loop_mode)
|
Action.PROFILE_SWITCH -> resourceHelper.gs(R.string.uel_profile_switch)
|
||||||
Action.LGS_LOOP_MODE -> resourceHelper.gs(R.string.uel_lgs_loop_mode)
|
Action.PROFILE_SWITCH_CLONED -> resourceHelper.gs(R.string.uel_profile_switch_cloned)
|
||||||
Action.OPEN_LOOP_MODE -> resourceHelper.gs(R.string.uel_open_loop_mode)
|
Action.CLOSED_LOOP_MODE -> resourceHelper.gs(R.string.uel_closed_loop_mode)
|
||||||
Action.LOOP_DISABLED -> resourceHelper.gs(R.string.uel_loop_disabled)
|
Action.LGS_LOOP_MODE -> resourceHelper.gs(R.string.uel_lgs_loop_mode)
|
||||||
Action.LOOP_ENABLED -> resourceHelper.gs(R.string.uel_loop_enabled)
|
Action.OPEN_LOOP_MODE -> resourceHelper.gs(R.string.uel_open_loop_mode)
|
||||||
Action.RECONNECT -> resourceHelper.gs(R.string.uel_reconnect)
|
Action.LOOP_DISABLED -> resourceHelper.gs(R.string.uel_loop_disabled)
|
||||||
Action.DISCONNECT -> resourceHelper.gs(R.string.uel_disconnect)
|
Action.LOOP_ENABLED -> resourceHelper.gs(R.string.uel_loop_enabled)
|
||||||
Action.RESUME -> resourceHelper.gs(R.string.uel_resume)
|
Action.RECONNECT -> resourceHelper.gs(R.string.uel_reconnect)
|
||||||
Action.SUSPEND -> resourceHelper.gs(R.string.uel_suspend)
|
Action.DISCONNECT -> resourceHelper.gs(R.string.uel_disconnect)
|
||||||
Action.HW_PUMP_ALLOWED -> resourceHelper.gs(R.string.uel_hw_pump_allowed)
|
Action.RESUME -> resourceHelper.gs(R.string.uel_resume)
|
||||||
Action.CLEAR_PAIRING_KEYS -> resourceHelper.gs(R.string.uel_clear_pairing_keys)
|
Action.SUSPEND -> resourceHelper.gs(R.string.uel_suspend)
|
||||||
Action.ACCEPTS_TEMP_BASAL -> resourceHelper.gs(R.string.uel_accepts_temp_basal)
|
Action.HW_PUMP_ALLOWED -> resourceHelper.gs(R.string.uel_hw_pump_allowed)
|
||||||
Action.CANCEL_TEMP_BASAL -> resourceHelper.gs(R.string.uel_cancel_temp_basal)
|
Action.CLEAR_PAIRING_KEYS -> resourceHelper.gs(R.string.uel_clear_pairing_keys)
|
||||||
Action.CANCEL_BOLUS -> resourceHelper.gs(R.string.uel_cancel_bolus)
|
Action.ACCEPTS_TEMP_BASAL -> resourceHelper.gs(R.string.uel_accepts_temp_basal)
|
||||||
Action.CANCEL_EXTENDED_BOLUS -> resourceHelper.gs(R.string.uel_cancel_extended_bolus)
|
Action.CANCEL_TEMP_BASAL -> resourceHelper.gs(R.string.uel_cancel_temp_basal)
|
||||||
Action.CANCEL_TT -> resourceHelper.gs(R.string.uel_cancel_tt)
|
Action.CANCEL_BOLUS -> resourceHelper.gs(R.string.uel_cancel_bolus)
|
||||||
Action.CAREPORTAL -> resourceHelper.gs(R.string.uel_careportal)
|
Action.CANCEL_EXTENDED_BOLUS -> resourceHelper.gs(R.string.uel_cancel_extended_bolus)
|
||||||
Action.SITE_CHANGE -> resourceHelper.gs(R.string.uel_site_change)
|
Action.CANCEL_TT -> resourceHelper.gs(R.string.uel_cancel_tt)
|
||||||
Action.RESERVOIR_CHANGE -> resourceHelper.gs(R.string.uel_reservoir_change)
|
Action.CAREPORTAL -> resourceHelper.gs(R.string.uel_careportal)
|
||||||
Action.CALIBRATION -> resourceHelper.gs(R.string.uel_calibration)
|
Action.SITE_CHANGE -> resourceHelper.gs(R.string.uel_site_change)
|
||||||
Action.PRIME_BOLUS -> resourceHelper.gs(R.string.uel_prime_bolus)
|
Action.RESERVOIR_CHANGE -> resourceHelper.gs(R.string.uel_reservoir_change)
|
||||||
Action.TREATMENT -> resourceHelper.gs(R.string.uel_treatment)
|
Action.CALIBRATION -> resourceHelper.gs(R.string.uel_calibration)
|
||||||
Action.CAREPORTAL_NS_REFRESH -> resourceHelper.gs(R.string.uel_careportal_ns_refresh)
|
Action.PRIME_BOLUS -> resourceHelper.gs(R.string.uel_prime_bolus)
|
||||||
Action.PROFILE_SWITCH_NS_REFRESH -> resourceHelper.gs(R.string.uel_profile_switch_ns_refresh)
|
Action.TREATMENT -> resourceHelper.gs(R.string.uel_treatment)
|
||||||
Action.TREATMENTS_NS_REFRESH -> resourceHelper.gs(R.string.uel_treatments_ns_refresh)
|
Action.CAREPORTAL_NS_REFRESH -> resourceHelper.gs(R.string.uel_careportal_ns_refresh)
|
||||||
Action.TT_NS_REFRESH -> resourceHelper.gs(R.string.uel_tt_ns_refresh)
|
Action.PROFILE_SWITCH_NS_REFRESH -> resourceHelper.gs(R.string.uel_profile_switch_ns_refresh)
|
||||||
Action.AUTOMATION_REMOVED -> resourceHelper.gs(R.string.uel_automation_removed)
|
Action.TREATMENTS_NS_REFRESH -> resourceHelper.gs(R.string.uel_treatments_ns_refresh)
|
||||||
Action.BG_REMOVED -> resourceHelper.gs(R.string.uel_bg_removed)
|
Action.TT_NS_REFRESH -> resourceHelper.gs(R.string.uel_tt_ns_refresh)
|
||||||
Action.CAREPORTAL_REMOVED -> resourceHelper.gs(R.string.uel_careportal_removed)
|
Action.AUTOMATION_REMOVED -> resourceHelper.gs(R.string.uel_automation_removed)
|
||||||
Action.BOLUS_REMOVED -> resourceHelper.gs(R.string.uel_bolus_removed)
|
Action.BG_REMOVED -> resourceHelper.gs(R.string.uel_bg_removed)
|
||||||
Action.CARBS_REMOVED -> resourceHelper.gs(R.string.uel_carbs_removed)
|
Action.CAREPORTAL_REMOVED -> resourceHelper.gs(R.string.uel_careportal_removed)
|
||||||
Action.TEMP_BASAL_REMOVED -> resourceHelper.gs(R.string.uel_temp_basal_removed)
|
Action.BOLUS_REMOVED -> resourceHelper.gs(R.string.uel_bolus_removed)
|
||||||
Action.EXTENDED_BOLUS_REMOVED -> resourceHelper.gs(R.string.uel_extended_bolus_removed)
|
Action.CARBS_REMOVED -> resourceHelper.gs(R.string.uel_carbs_removed)
|
||||||
Action.FOOD -> resourceHelper.gs(R.string.uel_food)
|
Action.TEMP_BASAL_REMOVED -> resourceHelper.gs(R.string.uel_temp_basal_removed)
|
||||||
Action.FOOD_REMOVED -> resourceHelper.gs(R.string.uel_food_removed)
|
Action.EXTENDED_BOLUS_REMOVED -> resourceHelper.gs(R.string.uel_extended_bolus_removed)
|
||||||
Action.PROFILE_REMOVED -> resourceHelper.gs(R.string.uel_profile_removed)
|
Action.FOOD -> resourceHelper.gs(R.string.uel_food)
|
||||||
Action.PROFILE_SWITCH_REMOVED -> resourceHelper.gs(R.string.uel_profile_switch_removed)
|
Action.FOOD_REMOVED -> resourceHelper.gs(R.string.uel_food_removed)
|
||||||
Action.RESTART_EVENTS_REMOVED -> resourceHelper.gs(R.string.uel_restart_events_removed)
|
Action.PROFILE_REMOVED -> resourceHelper.gs(R.string.uel_profile_removed)
|
||||||
Action.TREATMENT_REMOVED -> resourceHelper.gs(R.string.uel_treatment_removed)
|
Action.PROFILE_SWITCH_REMOVED -> resourceHelper.gs(R.string.uel_profile_switch_removed)
|
||||||
Action.TT_REMOVED -> resourceHelper.gs(R.string.uel_tt_removed)
|
Action.RESTART_EVENTS_REMOVED -> resourceHelper.gs(R.string.uel_restart_events_removed)
|
||||||
Action.NS_PAUSED -> resourceHelper.gs(R.string.uel_ns_paused)
|
Action.TREATMENT_REMOVED -> resourceHelper.gs(R.string.uel_treatment_removed)
|
||||||
Action.NS_RESUME -> resourceHelper.gs(R.string.uel_ns_resume)
|
Action.TT_REMOVED -> resourceHelper.gs(R.string.uel_tt_removed)
|
||||||
Action.NS_QUEUE_CLEARED -> resourceHelper.gs(R.string.uel_ns_queue_cleared)
|
Action.NS_PAUSED -> resourceHelper.gs(R.string.uel_ns_paused)
|
||||||
Action.NS_SETTINGS_COPIED -> resourceHelper.gs(R.string.uel_ns_settings_copied)
|
Action.NS_RESUME -> resourceHelper.gs(R.string.uel_ns_resume)
|
||||||
Action.ERROR_DIALOG_OK -> resourceHelper.gs(R.string.uel_error_dialog_ok)
|
Action.NS_QUEUE_CLEARED -> resourceHelper.gs(R.string.uel_ns_queue_cleared)
|
||||||
Action.ERROR_DIALOG_MUTE -> resourceHelper.gs(R.string.uel_error_dialog_mute)
|
Action.NS_SETTINGS_COPIED -> resourceHelper.gs(R.string.uel_ns_settings_copied)
|
||||||
Action.ERROR_DIALOG_MUTE_5MIN -> resourceHelper.gs(R.string.uel_error_dialog_mute_5min)
|
Action.ERROR_DIALOG_OK -> resourceHelper.gs(R.string.uel_error_dialog_ok)
|
||||||
Action.OBJECTIVE_STARTED -> resourceHelper.gs(R.string.uel_objective_started)
|
Action.ERROR_DIALOG_MUTE -> resourceHelper.gs(R.string.uel_error_dialog_mute)
|
||||||
Action.OBJECTIVE_UNSTARTED -> resourceHelper.gs(R.string.uel_objective_unstarted)
|
Action.ERROR_DIALOG_MUTE_5MIN -> resourceHelper.gs(R.string.uel_error_dialog_mute_5min)
|
||||||
Action.OBJECTIVES_SKIPPED -> resourceHelper.gs(R.string.uel_objectives_skipped)
|
Action.OBJECTIVE_STARTED -> resourceHelper.gs(R.string.uel_objective_started)
|
||||||
Action.STAT_RESET -> resourceHelper.gs(R.string.uel_stat_reset)
|
Action.OBJECTIVE_UNSTARTED -> resourceHelper.gs(R.string.uel_objective_unstarted)
|
||||||
Action.DELETE_LOGS -> resourceHelper.gs(R.string.uel_delete_logs)
|
Action.OBJECTIVES_SKIPPED -> resourceHelper.gs(R.string.uel_objectives_skipped)
|
||||||
Action.DELETE_FUTURE_TREATMENTS -> resourceHelper.gs(R.string.uel_delete_future_treatments)
|
Action.STAT_RESET -> resourceHelper.gs(R.string.uel_stat_reset)
|
||||||
Action.EXPORT_SETTINGS -> resourceHelper.gs(R.string.uel_export_settings)
|
Action.DELETE_LOGS -> resourceHelper.gs(R.string.uel_delete_logs)
|
||||||
Action.IMPORT_SETTINGS -> resourceHelper.gs(R.string.uel_import_settings)
|
Action.DELETE_FUTURE_TREATMENTS -> resourceHelper.gs(R.string.uel_delete_future_treatments)
|
||||||
Action.RESET_DATABASES -> resourceHelper.gs(R.string.uel_reset_databases)
|
Action.EXPORT_SETTINGS -> resourceHelper.gs(R.string.uel_export_settings)
|
||||||
Action.EXPORT_DATABASES -> resourceHelper.gs(R.string.uel_export_databases)
|
Action.IMPORT_SETTINGS -> resourceHelper.gs(R.string.uel_import_settings)
|
||||||
Action.IMPORT_DATABASES -> resourceHelper.gs(R.string.uel_import_databases)
|
Action.RESET_DATABASES -> resourceHelper.gs(R.string.uel_reset_databases)
|
||||||
Action.OTP_EXPORT -> resourceHelper.gs(R.string.uel_otp_export)
|
Action.EXPORT_DATABASES -> resourceHelper.gs(R.string.uel_export_databases)
|
||||||
Action.OTP_RESET -> resourceHelper.gs(R.string.uel_otp_reset)
|
Action.IMPORT_DATABASES -> resourceHelper.gs(R.string.uel_import_databases)
|
||||||
Action.EXPORT_CSV -> resourceHelper.gs(R.string.uel_export_csv)
|
Action.OTP_EXPORT -> resourceHelper.gs(R.string.uel_otp_export)
|
||||||
Action.STOP_SMS -> resourceHelper.gs(R.string.uel_stop_sms)
|
Action.OTP_RESET -> resourceHelper.gs(R.string.uel_otp_reset)
|
||||||
Action.START_AAPS -> resourceHelper.gs(R.string.uel_start_aaps)
|
Action.EXPORT_CSV -> resourceHelper.gs(R.string.uel_export_csv)
|
||||||
Action.EXIT_AAPS -> resourceHelper.gs(R.string.uel_exit_aaps)
|
Action.STOP_SMS -> resourceHelper.gs(R.string.uel_stop_sms)
|
||||||
Action.PLUGIN_ENABLED -> resourceHelper.gs(R.string.uel_plugin_enabled)
|
Action.START_AAPS -> resourceHelper.gs(R.string.uel_start_aaps)
|
||||||
Action.PLUGIN_DISABLED -> resourceHelper.gs(R.string.uel_plugin_disabled)
|
Action.EXIT_AAPS -> resourceHelper.gs(R.string.uel_exit_aaps)
|
||||||
Action.LOOP_CHANGE -> resourceHelper.gs(R.string.uel_loop_change)
|
Action.PLUGIN_ENABLED -> resourceHelper.gs(R.string.uel_plugin_enabled)
|
||||||
Action.LOOP_REMOVED -> resourceHelper.gs(R.string.uel_loop_removed)
|
Action.PLUGIN_DISABLED -> resourceHelper.gs(R.string.uel_plugin_disabled)
|
||||||
Action.UNKNOWN -> resourceHelper.gs(R.string.unknown)
|
Action.LOOP_CHANGE -> resourceHelper.gs(R.string.uel_loop_change)
|
||||||
|
Action.LOOP_REMOVED -> resourceHelper.gs(R.string.uel_loop_removed)
|
||||||
|
Action.UNKNOWN -> resourceHelper.gs(R.string.unknown)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun translate(units: ValueWithUnit?): String = when (units) {
|
fun translate(units: ValueWithUnit?): String = when (units) {
|
||||||
|
|
|
@ -397,6 +397,7 @@
|
||||||
|
|
||||||
<!-- User Entry -->
|
<!-- User Entry -->
|
||||||
<string name="uel_bolus">BOLUS</string>
|
<string name="uel_bolus">BOLUS</string>
|
||||||
|
<string name="uel_bolus_calculator">BOLUS CALCULATOR</string>
|
||||||
<string name="uel_bolus_advisor">BOLUS ADVISOR</string>
|
<string name="uel_bolus_advisor">BOLUS ADVISOR</string>
|
||||||
<string name="uel_extended_bolus">EXTENDED BOLUS</string>
|
<string name="uel_extended_bolus">EXTENDED BOLUS</string>
|
||||||
<string name="uel_superbolus_tbr">SUPERBOLUS TBR</string>
|
<string name="uel_superbolus_tbr">SUPERBOLUS TBR</string>
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.database.daos
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.Dao
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import info.nightscout.androidaps.database.TABLE_APS_RESULTS
|
|
||||||
import info.nightscout.androidaps.database.TABLE_BOLUS_CALCULATOR_RESULTS
|
import info.nightscout.androidaps.database.TABLE_BOLUS_CALCULATOR_RESULTS
|
||||||
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
|
@ -22,6 +21,12 @@ internal interface BolusCalculatorResultDao : TraceableDao<BolusCalculatorResult
|
||||||
@Query("SELECT id FROM $TABLE_BOLUS_CALCULATOR_RESULTS ORDER BY id DESC limit 1")
|
@Query("SELECT id FROM $TABLE_BOLUS_CALCULATOR_RESULTS ORDER BY id DESC limit 1")
|
||||||
fun getLastId(): Maybe<Long>
|
fun getLastId(): Maybe<Long>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||||
|
fun findByTimestamp(timestamp: Long): BolusCalculatorResult?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||||
|
fun findByNSId(nsId: String): BolusCalculatorResult?
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||||
fun getBolusCalculatorResultsFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
fun getBolusCalculatorResultsFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ data class UserEntry(
|
||||||
) : DBEntry, DBEntryWithTime {
|
) : DBEntry, DBEntryWithTime {
|
||||||
enum class Action (val colorGroup: ColorGroup) {
|
enum class Action (val colorGroup: ColorGroup) {
|
||||||
BOLUS (ColorGroup.InsulinTreatment),
|
BOLUS (ColorGroup.InsulinTreatment),
|
||||||
|
BOLUS_CALCULATOR_RESULT (ColorGroup.InsulinTreatment),
|
||||||
|
BOLUS_CALCULATOR_RESULT_REMOVED (ColorGroup.Aaps),
|
||||||
SMB (ColorGroup.InsulinTreatment),
|
SMB (ColorGroup.InsulinTreatment),
|
||||||
BOLUS_ADVISOR (ColorGroup.InsulinTreatment),
|
BOLUS_ADVISOR (ColorGroup.InsulinTreatment),
|
||||||
EXTENDED_BOLUS (ColorGroup.InsulinTreatment),
|
EXTENDED_BOLUS (ColorGroup.InsulinTreatment),
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sync the BolusCalculatorResult from NS
|
||||||
|
*/
|
||||||
|
class SyncNsBolusCalculatorResultTransaction(private val bolusCalculatorResult: BolusCalculatorResult) :
|
||||||
|
Transaction<SyncNsBolusCalculatorResultTransaction.TransactionResult>() {
|
||||||
|
|
||||||
|
override fun run(): TransactionResult {
|
||||||
|
val result = TransactionResult()
|
||||||
|
|
||||||
|
val current: BolusCalculatorResult? =
|
||||||
|
bolusCalculatorResult.interfaceIDs.nightscoutId?.let {
|
||||||
|
database.bolusCalculatorResultDao.findByNSId(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current != null) {
|
||||||
|
// nsId exists, allow only invalidation
|
||||||
|
if (current.isValid && !bolusCalculatorResult.isValid) {
|
||||||
|
current.isValid = false
|
||||||
|
database.bolusCalculatorResultDao.updateExistingEntry(current)
|
||||||
|
result.invalidated.add(current)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// not known nsId
|
||||||
|
val existing = database.bolusCalculatorResultDao.findByTimestamp(bolusCalculatorResult.timestamp)
|
||||||
|
if (existing != null && existing.interfaceIDs.nightscoutId == null) {
|
||||||
|
// the same record, update nsId only
|
||||||
|
existing.interfaceIDs.nightscoutId = bolusCalculatorResult.interfaceIDs.nightscoutId
|
||||||
|
existing.isValid = bolusCalculatorResult.isValid
|
||||||
|
database.bolusCalculatorResultDao.updateExistingEntry(existing)
|
||||||
|
result.updatedNsId.add(existing)
|
||||||
|
} else {
|
||||||
|
database.bolusCalculatorResultDao.insertNewEntry(bolusCalculatorResult)
|
||||||
|
result.inserted.add(bolusCalculatorResult)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TransactionResult {
|
||||||
|
|
||||||
|
val updatedNsId = mutableListOf<BolusCalculatorResult>()
|
||||||
|
val inserted = mutableListOf<BolusCalculatorResult>()
|
||||||
|
val invalidated = mutableListOf<BolusCalculatorResult>()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue