- added almost all history writing

This commit is contained in:
Andy Rozman 2019-12-18 23:24:20 +00:00
parent be8a2fab75
commit 5143a2f814
2 changed files with 52 additions and 6 deletions

View file

@ -151,24 +151,27 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) { public PumpEnactResult initPod(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, Profile profile) {
long time = System.currentTimeMillis();
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) { if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
try { try {
Disposable disposable = delegate.pairAndPrime().subscribe(res -> // Disposable disposable = delegate.pairAndPrime().subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res)); handleSetupActionResult(podInitActionType, podInitReceiver, res, time));
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment); podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment);
addFailureToHistory(time, PodHistoryEntryType.PairAndPrime, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
} else if (PodInitActionType.FillCannulaSetBasalProfileWizardStep.equals(podInitActionType)) { } else if (PodInitActionType.FillCannulaSetBasalProfileWizardStep.equals(podInitActionType)) {
try { try {
Disposable disposable = delegate.insertCannula(mapProfileToBasalSchedule(profile)).subscribe(res -> // Disposable disposable = delegate.insertCannula(mapProfileToBasalSchedule(profile)).subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res)); handleSetupActionResult(podInitActionType, podInitReceiver, res, time));
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment); podInitReceiver.returnInitTaskStatus(podInitActionType, false, comment);
addFailureToHistory(time, PodHistoryEntryType.FillCannulaSetBasalProfile, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
} }
@ -178,22 +181,28 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult getPodStatus() { public PumpEnactResult getPodStatus() {
long time = System.currentTimeMillis();
try { try {
StatusResponse statusResponse = delegate.getPodStatus(); StatusResponse statusResponse = delegate.getPodStatus();
addSuccessToHistory(time, PodHistoryEntryType.GetPodStatus, statusResponse);
return new PumpEnactResult().success(true).enacted(false); return new PumpEnactResult().success(true).enacted(false);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.GetPodStatus, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
} }
@Override @Override
public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) {
long time = System.currentTimeMillis();
try { try {
delegate.deactivatePod(); delegate.deactivatePod();
addSuccessToHistory(time, PodHistoryEntryType.DeactivatePod, null);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, comment); podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, comment);
addFailureToHistory(time, PodHistoryEntryType.DeactivatePod, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
@ -206,13 +215,17 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult setBasalProfile(Profile basalProfile) { public PumpEnactResult setBasalProfile(Profile basalProfile) {
long time = System.currentTimeMillis();
try { try {
delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile), isBasalBeepsEnabled()); delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile), isBasalBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.SetBasalSchedule, basalProfile);
} catch (Exception ex) { } catch (Exception ex) {
if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) { if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) {
addToHistory(time, PodHistoryEntryType.SetBasalSchedule, "Uncertain failure", false);
return new PumpEnactResult().success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_set_basal_failed_uncertain)); return new PumpEnactResult().success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_set_basal_failed_uncertain));
} }
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.SetBasalSchedule, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
@ -226,10 +239,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
public PumpEnactResult resetPodStatus() { public PumpEnactResult resetPodStatus() {
delegate.resetPodState(); delegate.resetPodState();
//addToHistory(System.currentTimeMillis(), PodDbEntryType.ResetPodState, null, null, null, null);
OmnipodUtil.setPodSessionState(null); OmnipodUtil.setPodSessionState(null);
addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.ResetPodState, null);
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} }
@ -276,10 +289,13 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult cancelBolus() { public PumpEnactResult cancelBolus() {
long time = System.currentTimeMillis();
try { try {
delegate.cancelBolus(isBolusBeepsEnabled()); delegate.cancelBolus(isBolusBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
@ -289,10 +305,13 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) { public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
boolean beepsEnabled = isBasalBeepsEnabled(); boolean beepsEnabled = isBasalBeepsEnabled();
long time = System.currentTimeMillis();
try { try {
delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled); delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled);
addSuccessToHistory(time, PodHistoryEntryType.SetTemporaryBasal, tempBasalPair);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.SetTemporaryBasal, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
@ -301,10 +320,13 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult cancelTemporaryBasal() { public PumpEnactResult cancelTemporaryBasal() {
long time = System.currentTimeMillis();
try { try {
delegate.cancelTemporaryBasal(isBasalBeepsEnabled()); delegate.cancelTemporaryBasal(isBasalBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.CancelTemporaryBasal, null);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.CancelTemporaryBasal, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
@ -313,10 +335,13 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult acknowledgeAlerts() { public PumpEnactResult acknowledgeAlerts() {
long time = System.currentTimeMillis();
try { try {
delegate.acknowledgeAlerts(); delegate.acknowledgeAlerts();
addSuccessToHistory(time, PodHistoryEntryType.AcknowledgeAlerts, null);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.AcknowledgeAlerts, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
@ -331,15 +356,18 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
// TODO should we add this to the OmnipodCommunicationManager interface? // TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult getPodInfo(PodInfoType podInfoType) { public PumpEnactResult getPodInfo(PodInfoType podInfoType) {
long time = System.currentTimeMillis();
try { try {
// TODO how can we return the PodInfo response? // TODO how can we return the PodInfo response?
// This method is useless unless we return the PodInfoResponse, // This method is useless unless we return the PodInfoResponse,
// because the pod state we keep, doesn't get updated from a PodInfoResponse. // because the pod state we keep, doesn't get updated from a PodInfoResponse.
// We use StatusResponses for that, which can be obtained from the getPodStatus method // We use StatusResponses for that, which can be obtained from the getPodStatus method
PodInfoResponse podInfo = delegate.getPodInfo(podInfoType); PodInfoResponse podInfo = delegate.getPodInfo(podInfoType);
addSuccessToHistory(time, PodHistoryEntryType.GetPodInfo, null);
return new PumpEnactResult().success(true).enacted(true); return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.GetPodInfo, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
} }
@ -369,13 +397,17 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
// TODO should we add this to the OmnipodCommunicationManager interface? // TODO should we add this to the OmnipodCommunicationManager interface?
// Updates the pods current time based on the device timezone and the pod's time zone // Updates the pods current time based on the device timezone and the pod's time zone
public PumpEnactResult setTime() { public PumpEnactResult setTime() {
long time = System.currentTimeMillis();
try { try {
delegate.setTime(isBasalBeepsEnabled()); delegate.setTime(isBasalBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.SetTime, null);
} catch (Exception ex) { } catch (Exception ex) {
if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) { if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) {
addFailureToHistory(time, PodHistoryEntryType.SetTime, "Uncertain failure");
return new PumpEnactResult().success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_set_time_failed_uncertain)); return new PumpEnactResult().success(false).enacted(false).comment(getStringResource(R.string.omnipod_error_set_time_failed_uncertain));
} }
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.SetTime, comment);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
@ -418,6 +450,16 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} }
} }
public void addSuccessToHistory(long requestTime, PodHistoryEntryType entryType, Object data) {
addToHistory(requestTime, entryType, data, true);
}
public void addFailureToHistory(long requestTime, PodHistoryEntryType entryType, Object data) {
addToHistory(requestTime, entryType, data, false);
}
public void addToHistory(long requestTime, PodHistoryEntryType entryType, Object data, boolean success) { public void addToHistory(long requestTime, PodHistoryEntryType entryType, Object data, boolean success) {
PodHistory podHistory = new PodHistory(requestTime, entryType); PodHistory podHistory = new PodHistory(requestTime, entryType);
@ -437,7 +479,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} }
private void handleSetupActionResult(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, SetupActionResult res) { private void handleSetupActionResult(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, SetupActionResult res, long time) {
String comment = null; String comment = null;
switch (res.getResultType()) { switch (res.getResultType()) {
case FAILURE: case FAILURE:
@ -454,6 +496,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
break; break;
} }
addToHistory(time, podInitActionType == PodInitActionType.PairAndPrimeWizardStep ?
PodHistoryEntryType.PairAndPrime : PodHistoryEntryType.FillCannulaSetBasalProfile, comment, res.getResultType().isSuccess());
podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), comment); podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), comment);
} }

View file

@ -9,7 +9,7 @@ import java.util.Map;
public enum PodHistoryEntryType { public enum PodHistoryEntryType {
PairAndPrime(1), PairAndPrime(1),
InsertCannula(2), FillCannulaSetBasalProfile(2),
DeactivatePod(3), DeactivatePod(3),
ResetPodState(4), ResetPodState(4),
@ -20,6 +20,7 @@ public enum PodHistoryEntryType {
GetPodStatus(30), GetPodStatus(30),
GetPodInfo(31), GetPodInfo(31),
SetTime(32),
SetBolus(40), SetBolus(40),
CancelBolus(41), CancelBolus(41),