RS insulin and canula change logging
This commit is contained in:
parent
1696092844
commit
f595560baa
|
@ -25,6 +25,7 @@ import info.nightscout.androidaps.utils.HtmlHelper
|
|||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.SafeParse
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import kotlinx.android.synthetic.main.dialog_fill.*
|
||||
import kotlinx.android.synthetic.main.notes.*
|
||||
import kotlinx.android.synthetic.main.okcancel.*
|
||||
|
@ -121,12 +122,12 @@ class FillDialog : DialogFragmentWithDate() {
|
|||
}
|
||||
if (siteChange) {
|
||||
aapsLogger.debug("USER ENTRY: SITE CHANGE")
|
||||
generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes)
|
||||
generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes, resourceHelper, sp)
|
||||
}
|
||||
if (insulinChange) {
|
||||
// add a second for case of both checked
|
||||
aapsLogger.debug("USER ENTRY: INSULIN CHANGE")
|
||||
generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes)
|
||||
generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes, resourceHelper, sp)
|
||||
}
|
||||
}, null)
|
||||
}
|
||||
|
@ -160,27 +161,28 @@ class FillDialog : DialogFragmentWithDate() {
|
|||
})
|
||||
}
|
||||
|
||||
private fun generateCareportalEvent(eventType: String, time: Long, notes: String) {
|
||||
val careportalEvent = CareportalEvent()
|
||||
careportalEvent.source = Source.USER
|
||||
careportalEvent.date = time
|
||||
careportalEvent.json = generateJson(eventType, time, notes).toString()
|
||||
careportalEvent.eventType = eventType
|
||||
MainApp.getDbHelper().createOrUpdate(careportalEvent)
|
||||
NSUpload.uploadEvent(eventType, time, notes)
|
||||
}
|
||||
|
||||
private fun generateJson(careportalEvent: String, time: Long, notes: String): JSONObject {
|
||||
val data = JSONObject()
|
||||
try {
|
||||
data.put("eventType", careportalEvent)
|
||||
data.put("created_at", DateUtil.toISOString(time))
|
||||
data.put("mills", time)
|
||||
data.put("enteredBy", sp.getString("careportal_enteredby", resourceHelper.gs(R.string.app_name)))
|
||||
if (notes.isNotEmpty()) data.put("notes", notes)
|
||||
} catch (ignored: JSONException) {
|
||||
companion object {
|
||||
fun generateCareportalEvent(eventType: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP) {
|
||||
val careportalEvent = CareportalEvent()
|
||||
careportalEvent.source = Source.USER
|
||||
careportalEvent.date = time
|
||||
careportalEvent.json = generateJson(eventType, time, notes, resourceHelper, sp).toString()
|
||||
careportalEvent.eventType = eventType
|
||||
MainApp.getDbHelper().createOrUpdate(careportalEvent)
|
||||
NSUpload.uploadEvent(eventType, time, notes)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
private fun generateJson(careportalEvent: String, time: Long, notes: String, resourceHelper: ResourceHelper, sp: SP): JSONObject {
|
||||
val data = JSONObject()
|
||||
try {
|
||||
data.put("eventType", careportalEvent)
|
||||
data.put("created_at", DateUtil.toISOString(time))
|
||||
data.put("mills", time)
|
||||
data.put("enteredBy", sp.getString("careportal_enteredby", resourceHelper.gs(R.string.app_name)))
|
||||
if (notes.isNotEmpty()) data.put("notes", notes)
|
||||
} catch (ignored: JSONException) {
|
||||
}
|
||||
return data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
||||
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -20,7 +20,8 @@ class DanaRSMessageHashTable @Inject constructor(
|
|||
danaRPump: DanaRPump,
|
||||
activePlugin: ActivePluginProvider,
|
||||
constraintChecker: ConstraintChecker,
|
||||
detailedBolusInfoStorage: DetailedBolusInfoStorage
|
||||
detailedBolusInfoStorage: DetailedBolusInfoStorage,
|
||||
sp: SP
|
||||
) {
|
||||
|
||||
var messages: HashMap<Int, DanaRS_Packet> = HashMap()
|
||||
|
@ -98,7 +99,7 @@ class DanaRSMessageHashTable @Inject constructor(
|
|||
put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus))
|
||||
// APS
|
||||
put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0))
|
||||
put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, 0))
|
||||
put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, 0))
|
||||
put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0))
|
||||
// v3
|
||||
put(DanaRS_Packet_General_Get_Shipping_Version(aapsLogger, danaRPump))
|
||||
|
|
|
@ -2,9 +2,11 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
|||
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||
import info.nightscout.androidaps.db.CareportalEvent
|
||||
import info.nightscout.androidaps.db.ExtendedBolus
|
||||
import info.nightscout.androidaps.db.Source
|
||||
import info.nightscout.androidaps.db.TemporaryBasal
|
||||
import info.nightscout.androidaps.dialogs.FillDialog
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -15,6 +17,7 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
|||
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import java.util.*
|
||||
|
||||
open class DanaRS_Packet_APS_History_Events(
|
||||
|
@ -24,6 +27,7 @@ open class DanaRS_Packet_APS_History_Events(
|
|||
private val activePlugin: ActivePluginProvider,
|
||||
private val danaRPump: DanaRPump,
|
||||
private val detailedBolusInfoStorage: DetailedBolusInfoStorage,
|
||||
private val sp: SP,
|
||||
private var from: Long
|
||||
) : DanaRS_Packet() {
|
||||
|
||||
|
@ -156,11 +160,15 @@ open class DanaRS_Packet_APS_History_Events(
|
|||
|
||||
DanaRPump.REFILL -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
|
||||
if (sp.getBoolean(R.string.key_rs_loginsulinchange, true))
|
||||
FillDialog.generateCareportalEvent(CareportalEvent.INSULINCHANGE, datetime, resourceHelper.gs(R.string.danarspump), resourceHelper, sp)
|
||||
status = "REFILL " + DateUtil.timeString(datetime)
|
||||
}
|
||||
|
||||
DanaRPump.PRIME -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
|
||||
if (sp.getBoolean(R.string.key_rs_logcanulachange, true))
|
||||
FillDialog.generateCareportalEvent(CareportalEvent.SITECHANGE, datetime, resourceHelper.gs(R.string.danarspump), resourceHelper, sp)
|
||||
status = "PRIME " + DateUtil.timeString(datetime)
|
||||
}
|
||||
|
||||
|
|
|
@ -211,10 +211,10 @@ class DanaRSService : DaggerService() {
|
|||
SystemClock.sleep(1000)
|
||||
val msg: DanaRS_Packet_APS_History_Events
|
||||
if (lastHistoryFetched == 0L) {
|
||||
msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, 0)
|
||||
msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, 0)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history")
|
||||
} else {
|
||||
msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, lastHistoryFetched)
|
||||
msg = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, lastHistoryFetched)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched))
|
||||
}
|
||||
sendMessage(msg)
|
||||
|
|
|
@ -288,7 +288,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
|
||||
/**
|
||||
* Returns all Treatments after specified timestamp. Also returns invalid entries (required to
|
||||
* map "Fill Canulla" entries to history (and not to add double bolus for it)
|
||||
* map "Fill Canula" entries to history (and not to add double bolus for it)
|
||||
*
|
||||
* @param fromTimestamp
|
||||
* @return
|
||||
|
|
|
@ -1815,4 +1815,10 @@
|
|||
<string name="overview_show_predictions">Predictions</string>
|
||||
<string name="overview_show_deviationslope">Deviation slope</string>
|
||||
<string name="key_graphconfig" translatable="false">graphconfig</string>
|
||||
<string name="key_rs_loginsulinchange" translatable="false">rs_loginsulinchange</string>
|
||||
<string name="rs_loginsulinchange_title">Log reservoir change</string>
|
||||
<string name="rs_loginsulinchange_summary">Add \"Insulin Change\" event to careportal when detected in history</string>
|
||||
<string name="key_rs_logcanulachange" translatable="false">rs_logcanulachange</string>
|
||||
<string name="rs_logcanulachange_title">Log canula change</string>
|
||||
<string name="rs_logcanulachange_summary">Add \"Site Change\" event to careportal when detected in history</string>
|
||||
</resources>
|
||||
|
|
|
@ -35,6 +35,18 @@
|
|||
android:key="@string/key_danars_bolusspeed"
|
||||
android:title="@string/bolusspeed" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_rs_loginsulinchange"
|
||||
android:summary="@string/rs_loginsulinchange_summary"
|
||||
android:title="@string/rs_loginsulinchange_title" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_rs_logcanulachange"
|
||||
android:summary="@string/rs_logcanulachange_summary"
|
||||
android:title="@string/rs_logcanulachange_title" />
|
||||
|
||||
<androidx.preference.PreferenceScreen
|
||||
android:key="absorption_danars_advanced"
|
||||
android:title="@string/advancedsettings_title">
|
||||
|
|
|
@ -27,7 +27,7 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() {
|
|||
fun runTest() {
|
||||
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
|
||||
|
||||
val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin, constraintChecker, detailedBolusInfoStorage)
|
||||
val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin, constraintChecker, detailedBolusInfoStorage, sp)
|
||||
val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0)
|
||||
val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command)
|
||||
Assert.assertEquals(BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong())
|
||||
|
|
|
@ -23,7 +23,7 @@ class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() {
|
|||
@Test fun runTest() {
|
||||
val now = DateUtil.now()
|
||||
|
||||
val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, now)
|
||||
val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRPump, detailedBolusInfoStorage, sp, now)
|
||||
// test getRequestedParams
|
||||
val returnedValues = testPacket.requestParams
|
||||
val expectedValues = getCalender(now)
|
||||
|
|
Loading…
Reference in a new issue