Merge pull request #1499 from jotomo/upstream-1482+1489
Combo: allow records created by the combo to be merged with existing records.
This commit is contained in:
commit
fee3b33d81
1 changed files with 4 additions and 16 deletions
|
@ -653,11 +653,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. */
|
||||||
* Updates a DetailedBolusInfo from a pump bolus and adds it as a Treatment to the DB.
|
|
||||||
* Handles edge cases when dates aren't unique which are extremely unlikely to occur,
|
|
||||||
* but if they do, the user should be warned since a bolus will be missing from calculations.
|
|
||||||
*/
|
|
||||||
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
|
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
|
||||||
DetailedBolusInfo dbi = detailedBolusInfo.copy();
|
DetailedBolusInfo dbi = detailedBolusInfo.copy();
|
||||||
dbi.date = calculateFakeBolusDate(lastPumpBolus);
|
dbi.date = calculateFakeBolusDate(lastPumpBolus);
|
||||||
|
@ -665,15 +661,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
dbi.source = Source.PUMP;
|
dbi.source = Source.PUMP;
|
||||||
dbi.insulin = lastPumpBolus.amount;
|
dbi.insulin = lastPumpBolus.amount;
|
||||||
try {
|
try {
|
||||||
boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false);
|
TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true);
|
||||||
if (!treatmentCreated) {
|
|
||||||
log.error("Adding treatment record overrode an existing record: " + dbi);
|
|
||||||
if (dbi.isSMB) {
|
|
||||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Adding treatment record failed", e);
|
log.error("Adding treatment record failed", e);
|
||||||
if (dbi.isSMB) {
|
if (dbi.isSMB) {
|
||||||
|
@ -1149,6 +1137,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
return historyResult.success;
|
return historyResult.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return value indicates whether a new record was created. */
|
||||||
private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) {
|
private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) {
|
||||||
boolean updated = false;
|
boolean updated = false;
|
||||||
for (Bolus pumpBolus : history.bolusHistory) {
|
for (Bolus pumpBolus : history.bolusHistory) {
|
||||||
|
@ -1158,8 +1147,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
dbi.source = Source.PUMP;
|
dbi.source = Source.PUMP;
|
||||||
dbi.insulin = pumpBolus.amount;
|
dbi.insulin = pumpBolus.amount;
|
||||||
dbi.eventType = CareportalEvent.CORRECTIONBOLUS;
|
dbi.eventType = CareportalEvent.CORRECTIONBOLUS;
|
||||||
if (TreatmentsPlugin.getPlugin().getService().getPumpRecordById(dbi.pumpId) == null) {
|
if (TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true)) {
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false);
|
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue