Merge pull request #146 from p5nbTgip0r/mdt-insulin-change
Fix reservoir changes on MDT pumps being logged as cannula changes
This commit is contained in:
commit
60b71668ea
2 changed files with 46 additions and 0 deletions
|
@ -440,6 +440,20 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
}
|
||||
|
||||
// Rewind (for marking insulin change)
|
||||
List<PumpHistoryEntry> rewindRecords = getFilteredItems(PumpHistoryEntryType.Rewind);
|
||||
|
||||
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: Rewind [count={}, items={}]", rewindRecords.size(), gson().toJson(rewindRecords));
|
||||
|
||||
if (isCollectionNotEmpty(rewindRecords)) {
|
||||
try {
|
||||
processRewind(rewindRecords);
|
||||
} catch (Exception ex) {
|
||||
aapsLogger.error("ProcessHistoryData: Error processing Rewind entries: " + ex.getMessage(), ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
// TDD
|
||||
List<PumpHistoryEntry> tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType());
|
||||
|
||||
|
@ -515,6 +529,14 @@ public class MedtronicHistoryData {
|
|||
long lastPrimeRecord = 0L;
|
||||
|
||||
for (PumpHistoryEntry primeRecord : primeRecords) {
|
||||
Object fixedAmount = primeRecord.getDecodedDataEntry("FixedAmount");
|
||||
|
||||
if (fixedAmount != null && ((float) fixedAmount) == 0.0f) {
|
||||
// non-fixed primes are used to prime the tubing
|
||||
// fixed primes are used to prime the cannula
|
||||
// so skip the prime entry if it was not a fixed prime
|
||||
continue;
|
||||
}
|
||||
|
||||
if (primeRecord.atechDateTime > maxAllowedTimeInPast) {
|
||||
if (lastPrimeRecord < primeRecord.atechDateTime) {
|
||||
|
@ -534,6 +556,29 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
}
|
||||
|
||||
private void processRewind(List<PumpHistoryEntry> rewindRecords) {
|
||||
long maxAllowedTimeInPast = DateTimeUtil.getATDWithAddedMinutes(new GregorianCalendar(), -30);
|
||||
long lastRewindRecord = 0L;
|
||||
|
||||
for (PumpHistoryEntry rewindRecord : rewindRecords) {
|
||||
if (rewindRecord.atechDateTime > maxAllowedTimeInPast) {
|
||||
if (lastRewindRecord < rewindRecord.atechDateTime) {
|
||||
lastRewindRecord = rewindRecord.atechDateTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lastRewindRecord != 0L) {
|
||||
long lastRewindFromAAPS = sp.getLong(MedtronicConst.Statistics.LastRewind, 0L);
|
||||
|
||||
if (lastRewindRecord != lastRewindFromAAPS) {
|
||||
uploadCareportalEvent(DateTimeUtil.toMillisFromATD(lastRewindRecord), CareportalEvent.INSULINCHANGE);
|
||||
|
||||
sp.putLong(MedtronicConst.Statistics.LastRewind, lastRewindRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void uploadCareportalEvent(long date, String event) {
|
||||
if (databaseHelper.getCareportalEventFromTimestamp(date) != null)
|
||||
|
|
|
@ -33,6 +33,7 @@ public class MedtronicConst {
|
|||
public static final String SMBBoluses = StatsPrefix + "smb_boluses_delivered";
|
||||
public static final String LastPumpHistoryEntry = StatsPrefix + "pump_history_entry";
|
||||
public static final String LastPrime = StatsPrefix + "last_sent_prime";
|
||||
public static final String LastRewind = StatsPrefix + "last_sent_rewind";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue