Fetching caliberation value done

This commit is contained in:
smileomi18@gmail.com
2023-08-03 13:40:35 +05:30
parent 1ba919c956
commit 47633267f7
5 changed files with 31 additions and 5 deletions

View File

@@ -3,6 +3,6 @@ package com.example.hpostesting.data.model.patient
data class DeviceData (
val deviceId: String? = "",
val deviceType: String? = "",
val coefficient: List<Double>? = null,
val coefficients: List<Double>? = null,
val calibratedAt: String
)

View File

@@ -116,7 +116,19 @@ class DatabaseRepository : Repository {
}
}
suspend fun getDeviceDataById(): List<DeviceData> {
suspend fun getDeviceData(): List<DeviceData> {
return db.collection("devices").get().await().toObjects(DeviceData::class.java)
}
suspend fun getDeviceDataById(deviceId: String): DeviceData? {
val querySnapshot = db.collection("devices").get().await()
val allDeviceDataList = querySnapshot.toObjects(DeviceData::class.java)
// Find the DeviceData object with the specified deviceId
return allDeviceDataList.find { it.deviceId == deviceId }
}
}

View File

@@ -71,6 +71,7 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.getDeviceData()
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
deviceData = it
}

View File

@@ -29,8 +29,13 @@ class HemoCubeViewModel @Inject constructor(
var isServiceConnected = false
val progressBar = MutableLiveData(false)
val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
// Get the device ID of the device you want to retrieve data for (e.g., the first device in the list)
private val _networkStatusLiveData = NetworkStatusLiveData(context)
val deviceData = MutableLiveData<List<DeviceData>>()
val deviceIdToRetrieve = deviceData.value?.firstOrNull()?.deviceId
val networkStatusLiveData: LiveData<Boolean>
get() = _networkStatusLiveData
val fireBaseUpload = MutableLiveData<String>()
@@ -63,12 +68,20 @@ class HemoCubeViewModel @Inject constructor(
}
}
fun getDeviceData() = viewModelScope.launch {
repository.getDeviceDataById().let {
deviceData.postValue(it)
deviceIdToRetrieve?.let { deviceId ->
val deviceIdinfo = repository.getDeviceDataById(deviceId)
deviceData.postValue(listOf(deviceIdinfo!!))
}
}
private fun addResultTestToDb() {
testDetails?.deviceRatio = DataHolder.hemocubeResult
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()

View File

@@ -51,7 +51,7 @@
android:id="@+id/tv_subtitle4"
style="@style/title2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="80dp"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="16dp"
android:hint="Result"