Use bolus id for history entry

This commit is contained in:
Jamorham 2018-02-01 14:37:16 +00:00
parent 73ea3628b2
commit 6a12b0a931
No known key found for this signature in database
GPG key ID: 0BC5C3E0AAD64DF9
5 changed files with 60 additions and 3 deletions

View file

@ -95,4 +95,12 @@ public class InsightPumpAsyncAdapter {
}
}
int getResponseID(UUID uuid) {
if (checkCommandResult(uuid) == Cstatus.SUCCESS) {
return commandResults.get(uuid).response_id;
} else {
return -2; // invalid
}
}
}

View file

@ -45,6 +45,7 @@ import sugar.free.sightparser.applayer.descriptors.ActiveBolus;
import sugar.free.sightparser.applayer.descriptors.ActiveBolusType;
import sugar.free.sightparser.applayer.descriptors.PumpStatus;
import sugar.free.sightparser.applayer.messages.AppLayerMessage;
import sugar.free.sightparser.applayer.messages.remote_control.BolusMessage;
import sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage;
import sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMessage;
import sugar.free.sightparser.applayer.messages.remote_control.StandardBolusMessage;
@ -53,6 +54,7 @@ import sugar.free.sightparser.handling.TaskRunner;
import sugar.free.sightparser.handling.taskrunners.SetTBRTaskRunner;
import sugar.free.sightparser.handling.taskrunners.StatusTaskRunner;
import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.getRecordUniqueID;
import static info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers.roundDouble;
@ -140,6 +142,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
pumpDescription.basalMinimumRate = 0.02d;
pumpDescription.isRefillingCapable = false;
//pumpDescription.storesCarbInfo = false; // uncomment when PumpDescription updated to include this
this.connector = Connector.get();
this.connector.init();
@ -399,6 +402,9 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
}
final Cstatus cs = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME);
result.success = cs.success();
if (cs.success()) {
detailedBolusInfo.pumpId = getRecordUniqueID(async.getResponseID(cmd));
}
} else {
result.success = true; // always true with carb only treatments
}
@ -596,6 +602,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
extendedBolus.insulin = insulin;
extendedBolus.durationInMinutes = durationInMinutes;
extendedBolus.source = Source.USER;
extendedBolus.pumpId = getRecordUniqueID(async.getResponseID(cmd));
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
}
@ -867,6 +874,9 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface {
@Override
public void onResult(Object o) {
log(name + " success");
if (o instanceof BolusMessage) {
event.response_id = ((BolusMessage)o).getBolusId();
}
event.success = true;
pushCallbackEvent(event);
}

View file

@ -12,6 +12,7 @@ public class EventInsightPumpCallback extends Event {
public UUID request_uuid;
public boolean success = false;
public String message = null;
public int response_id = -1;
public EventInsightPumpCallback() {
request_uuid = UUID.randomUUID();

View file

@ -4,8 +4,11 @@ import android.content.Intent;
import java.util.Date;
import info.nightscout.utils.SP;
import sugar.free.sightparser.handling.HistoryBroadcast;
import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.updatePumpSerialNumber;
/**
* Created by jamorham on 27/01/2018.
*
@ -13,7 +16,7 @@ import sugar.free.sightparser.handling.HistoryBroadcast;
*
*/
public class HistoryIntentAdapter {
class HistoryIntentAdapter {
private HistoryLogAdapter logAdapter = new HistoryLogAdapter();
@ -25,7 +28,8 @@ public class HistoryIntentAdapter {
android.util.Log.e("HistoryIntentAdapter", msg);
}
private static long getRecordUniqueID(long pump_serial_number, long pump_record_id) {
static long getRecordUniqueID(long pump_serial_number, long pump_record_id) {
updatePumpSerialNumber(pump_serial_number);
return (pump_serial_number * 10000000) + pump_record_id;
}
@ -54,6 +58,7 @@ public class HistoryIntentAdapter {
void processDeliveredBolusIntent(Intent intent) {
final String bolus_type = intent.getStringExtra(HistoryBroadcast.EXTRA_BOLUS_TYPE);
final int bolus_id = intent.getIntExtra(HistoryBroadcast.EXTRA_BOLUS_ID,-1);
final int pump_record_id = intent.getIntExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
final long pump_serial_number = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
final Date event_time = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
@ -62,7 +67,7 @@ public class HistoryIntentAdapter {
final float extended_insulin = intent.getFloatExtra(HistoryBroadcast.EXTRA_EXTENDED_AMOUNT, -1);
final int extended_minutes = intent.getIntExtra(HistoryBroadcast.EXTRA_DURATION, -1);
final long record_unique_id = getRecordUniqueID(pump_serial_number, pump_record_id);
final long record_unique_id = getRecordUniqueID(pump_serial_number, bolus_id > -1 ? bolus_id : pump_record_id);
switch (bolus_type) {
case "STANDARD":

View file

@ -0,0 +1,33 @@
package info.nightscout.androidaps.plugins.PumpInsight.history;
import info.nightscout.utils.SP;
/**
* Created by jamorham on 01/02/2018.
*/
public class PumpIdCache {
private static final String INSIGHT_PUMP_ID_PREF = "insight-pump-id";
private static long cachedPumpSerialNumber = -1;
private static void log(String msg) {
android.util.Log.e("PumpIdCache", msg);
}
static void updatePumpSerialNumber(long pump_serial_number) {
if (pump_serial_number != cachedPumpSerialNumber) {
cachedPumpSerialNumber = pump_serial_number;
log("Updating pump serial number: " + pump_serial_number);
SP.putLong(INSIGHT_PUMP_ID_PREF, cachedPumpSerialNumber);
}
}
public static long getRecordUniqueID(long record_id) {
if (cachedPumpSerialNumber == -1) {
cachedPumpSerialNumber = SP.getLong(INSIGHT_PUMP_ID_PREF, 0L);
}
return HistoryIntentAdapter.getRecordUniqueID(cachedPumpSerialNumber, record_id);
}
}