OH uploader enqueue Treatments and don_t load historical values
This commit is contained in:
parent
e69966ad47
commit
8a6a3d2283
4 changed files with 69 additions and 9 deletions
|
@ -9,7 +9,6 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
|
||||
//TODO OH: make injectable
|
||||
class OHUploadWorker(context: Context, workerParameters: WorkerParameters)
|
||||
: RxWorker(context, workerParameters) {
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO OH: make injectable
|
||||
class ExchangeAuthTokenDialog : DaggerDialogFragment() {
|
||||
|
||||
@Inject
|
||||
|
|
|
@ -162,6 +162,23 @@ class OpenHumansUploader @Inject constructor(
|
|||
put("nsId", bgReading._id)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun enqueueTreatment(treatment: Treatment, deleted: Boolean = false) = insertQueueItem("Treatments") {
|
||||
put("date", treatment.date)
|
||||
put("isValid", treatment.isValid)
|
||||
put("source", treatment.source)
|
||||
put("nsId", treatment._id)
|
||||
put("boluscalc", treatment.boluscalc)
|
||||
put("carbs", treatment.carbs)
|
||||
put("dia", treatment.dia)
|
||||
put("insulin", treatment.insulin)
|
||||
put("insulinInterfaceID", treatment.insulinInterfaceID)
|
||||
put("isSMB", treatment.isSMB)
|
||||
put("mealBolus", treatment.mealBolus)
|
||||
put("bolusCalcJson", treatment.getBoluscalc())
|
||||
put("isDeletion", deleted)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun enqueueCareportalEvent(careportalEvent: CareportalEvent, deleted: Boolean = false) = insertQueueItem("CareportalEvents") {
|
||||
put("date", careportalEvent.date)
|
||||
|
@ -306,7 +323,7 @@ class OpenHumansUploader @Inject constructor(
|
|||
.flatMap { openHumansAPI.getProjectMemberId(it.accessToken) }
|
||||
.doOnSuccess {
|
||||
projectMemberId = it
|
||||
copyExistingDataToQueue()
|
||||
// TODO: halted for now. Might create too much upload data. copyExistingDataToQueue()
|
||||
rxBus.send(OpenHumansFragment.UpdateViewEvent)
|
||||
}
|
||||
.doOnError {
|
||||
|
|
|
@ -42,6 +42,7 @@ import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
|||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||
|
@ -63,6 +64,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
@Inject RxBusWrapper rxBus;
|
||||
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||
@Inject DatabaseHelperInterface databaseHelper;
|
||||
@Inject OpenHumansUploader openHumansUploader;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
|
@ -107,9 +109,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
}
|
||||
}
|
||||
|
||||
public Dao<Treatment, Long> getDao() {
|
||||
public TreatmentDaoWrapper getDao() {
|
||||
try {
|
||||
return DaoManager.createDao(this.getConnectionSource(), Treatment.class);
|
||||
return new TreatmentDaoWrapper(DaoManager.createDao(this.getConnectionSource(), Treatment.class));
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Cannot create Dao for Treatment.class");
|
||||
}
|
||||
|
@ -117,6 +119,49 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
return null;
|
||||
}
|
||||
|
||||
class TreatmentDaoWrapper {
|
||||
private final Dao<Treatment, Long> wrapped;
|
||||
|
||||
TreatmentDaoWrapper(Dao<Treatment, Long> wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
}
|
||||
|
||||
public void executeRaw(String statement, String... arguments) throws SQLException {
|
||||
wrapped.executeRaw(statement, arguments);
|
||||
}
|
||||
|
||||
public List<Treatment> queryForAll() throws SQLException {
|
||||
return wrapped.queryForAll();
|
||||
}
|
||||
|
||||
public void delete(Treatment data) throws SQLException {
|
||||
wrapped.delete(data);
|
||||
openHumansUploader.enqueueTreatment(data, true);
|
||||
}
|
||||
|
||||
public void create(Treatment data) throws SQLException {
|
||||
wrapped.create(data);
|
||||
openHumansUploader.enqueueTreatment(data);
|
||||
}
|
||||
|
||||
public Treatment queryForId(long id) throws SQLException {
|
||||
return wrapped.queryForId(id);
|
||||
}
|
||||
|
||||
public void update(Treatment data) throws SQLException {
|
||||
wrapped.update(data);
|
||||
openHumansUploader.enqueueTreatment(data);
|
||||
}
|
||||
|
||||
public QueryBuilder<Treatment, Long> queryBuilder() {
|
||||
return wrapped.queryBuilder();
|
||||
}
|
||||
|
||||
public List<Treatment> query(PreparedQuery<Treatment> data) throws SQLException {
|
||||
return wrapped.query(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -702,7 +747,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
@Nullable
|
||||
public Treatment findByNSId(String _id) {
|
||||
try {
|
||||
Dao<Treatment, Long> daoTreatments = getDao();
|
||||
TreatmentDaoWrapper daoTreatments = getDao();
|
||||
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", _id);
|
||||
|
@ -724,7 +769,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
|
||||
public List<Treatment> getTreatmentDataFromTime(long mills, boolean ascending) {
|
||||
try {
|
||||
Dao<Treatment, Long> daoTreatments = getDao();
|
||||
TreatmentDaoWrapper daoTreatments = getDao();
|
||||
List<Treatment> treatments;
|
||||
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
|
||||
queryBuilder.orderBy("date", ascending);
|
||||
|
@ -741,7 +786,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
|
||||
public List<Treatment> getTreatmentDataFromTime(long from, long to, boolean ascending) {
|
||||
try {
|
||||
Dao<Treatment, Long> daoTreatments = getDao();
|
||||
TreatmentDaoWrapper daoTreatments = getDao();
|
||||
List<Treatment> treatments;
|
||||
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
|
||||
queryBuilder.orderBy("date", ascending);
|
||||
|
|
Loading…
Reference in a new issue