Fix reservoir changes on MDT pumps being logged as cannula changes

When the cannula tubing is primed on Medtronic pumps (manual prime), the history entry that gets logged is the same type as a fixed-prime (for priming the cannula after it has been inserted) so any time the reservoir was replaced AAPS would log a site change which reset autosens unnecessarily and also led to inaccurate reporting of insulin/cannula changes in Nightscout.

This commit aims to fix that by checking the `FixedAmount` data entry of `Prime` history entries to detect whether the prime was a manual-prime (priming tubing) or fixed-prime (priming cannula) and skip logging a site change event if it is the former. In order to automatically log insulin reservoir replacements, this commit also adds a monitor for `Rewind` history entries which logs an `InsulinChange` event for them (similar to the priming monitor).
This commit is contained in:
p5nbTgip0r 2020-12-26 21:31:42 -08:00
parent f9ec47010e
commit 549745017b
No known key found for this signature in database
GPG key ID: 48D5799EE24795C3
2 changed files with 46 additions and 0 deletions

View file

@ -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)

View file

@ -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";
}
}