diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 2767f7611a..21ceea6950 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -680,6 +680,24 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } + @Nullable + public Treatment getTreatmentByDate(long mills) { + try { + Dao daoTreatments = getDaoTreatments(); + List treatments; + QueryBuilder queryBuilder = daoTreatments.queryBuilder(); + Where where = queryBuilder.where(); + where.eq("date", mills); + PreparedQuery preparedQuery = queryBuilder.prepare(); + treatments = daoTreatments.query(preparedQuery); + // date is unique + return treatments.isEmpty() ? null : treatments.get(0); + } catch (SQLException e) { + log.error("Unhandled exception", e); + return null; + } + } + public List getTreatmentDataFromTime(long mills, boolean ascending) { try { Dao daoTreatments = getDaoTreatments();