-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VIT-6645: Device SDK auto-posting samples (#128)
Move timeseries POST methods to VitalPrivateService. Mark `createConnectedSourceIfNotExist` as VitalPrivateApi. Devices SDK would now try to auto-post glucose and blood pressure samples after reading them, if the Core SDK has signed-in with a user.
- Loading branch information
Showing
13 changed files
with
151 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
VitalDevices/src/main/java/io/tryvital/vitaldevices/Brand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package io.tryvital.vitaldevices | ||
|
||
import io.tryvital.client.services.data.ManualProviderSlug | ||
|
||
sealed class Brand(val name: String) { | ||
object Omron : Brand("Omron") | ||
object AccuChek : Brand("Accu-Chek") | ||
object Contour : Brand("Contour") | ||
object Beurer : Brand("Beurer") | ||
object Libre : Brand("FreeStyle Libre") | ||
|
||
fun toManualProviderSlug(): ManualProviderSlug = when (this) { | ||
is Omron -> ManualProviderSlug.OmronBLE | ||
is AccuChek -> ManualProviderSlug.AccuchekBLE | ||
is Contour -> ManualProviderSlug.ContourBLE | ||
is Beurer -> ManualProviderSlug.BeurerBLE | ||
is Libre -> ManualProviderSlug.LibreBLE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
VitalDevices/src/main/java/io/tryvital/vitaldevices/devices/BloodPressureSample.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
VitalDevices/src/main/java/io/tryvital/vitaldevices/devices/postSamples.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
@file:OptIn(VitalPrivateApi::class, DelicateCoroutinesApi::class) | ||
|
||
package io.tryvital.vitaldevices.devices | ||
|
||
import android.content.Context | ||
import io.tryvital.client.VitalClient | ||
import io.tryvital.client.createConnectedSourceIfNotExist | ||
import io.tryvital.client.services.VitalPrivateApi | ||
import io.tryvital.client.services.data.BloodPressureSamplePayload | ||
import io.tryvital.client.services.data.DataStage | ||
import io.tryvital.client.services.data.ManualProviderSlug | ||
import io.tryvital.client.services.data.QuantitySamplePayload | ||
import io.tryvital.client.services.data.TimeseriesPayload | ||
import io.tryvital.client.utils.VitalLogger | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import java.util.TimeZone | ||
|
||
internal fun postGlucoseSamples(context: Context, provider: ManualProviderSlug, samples: List<QuantitySamplePayload>) { | ||
if (samples.isEmpty()) { | ||
return | ||
} | ||
|
||
GlobalScope.launch { | ||
try { | ||
postGlucoseSamplesImpl(context, provider, samples) | ||
VitalLogger.getOrCreate().logI("[Device] posted ${samples.count()} glucose for $provider") | ||
|
||
} catch (e: Throwable) { | ||
VitalLogger.getOrCreate().logE("[Device] failed to post ${samples.count()} glucose for $provider", e) | ||
} | ||
} | ||
} | ||
|
||
internal fun postBloodPressureSamples(context: Context, provider: ManualProviderSlug, samples: List<BloodPressureSamplePayload>) { | ||
if (samples.isEmpty()) { | ||
return | ||
} | ||
|
||
GlobalScope.launch { | ||
try { | ||
postBloodPressureSamplesImpl(context, provider, samples) | ||
VitalLogger.getOrCreate().logI("[Device] posted ${samples.count()} BP for $provider") | ||
|
||
} catch (e: Throwable) { | ||
VitalLogger.getOrCreate().logE("[Device] failed to post ${samples.count()} BP for $provider", e) | ||
} | ||
} | ||
} | ||
|
||
private suspend fun postGlucoseSamplesImpl(context: Context, provider: ManualProviderSlug, samples: List<QuantitySamplePayload>) { | ||
val client = VitalClient.getOrCreate(context) | ||
if (VitalClient.Status.SignedIn !in VitalClient.status) { | ||
return | ||
} | ||
|
||
client.createConnectedSourceIfNotExist(provider) | ||
client.vitalPrivateService.timeseriesPost( | ||
userId = VitalClient.checkUserId(), | ||
resource = "glucose", | ||
payload = TimeseriesPayload( | ||
stage = DataStage.Daily, | ||
data = samples, | ||
startDate = null, | ||
endDate = null, | ||
timeZoneId = TimeZone.getDefault().id, | ||
provider = provider, | ||
) | ||
) | ||
} | ||
|
||
private suspend fun postBloodPressureSamplesImpl(context: Context, provider: ManualProviderSlug, samples: List<BloodPressureSamplePayload>) { | ||
val client = VitalClient.getOrCreate(context) | ||
if (VitalClient.Status.SignedIn !in VitalClient.status) { | ||
return | ||
} | ||
|
||
client.createConnectedSourceIfNotExist(provider) | ||
client.vitalPrivateService.bloodPressureTimeseriesPost( | ||
userId = VitalClient.checkUserId(), | ||
payload = TimeseriesPayload( | ||
stage = DataStage.Daily, | ||
data = samples, | ||
startDate = null, | ||
endDate = null, | ||
timeZoneId = TimeZone.getDefault().id, | ||
provider = provider, | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.