diff --git a/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt b/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt index 2d08714..d5aae42 100644 --- a/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt +++ b/app/src/main/java/com/example/hpostesting/data/model/patient/DeviceData.kt @@ -3,6 +3,6 @@ package com.example.hpostesting.data.model.patient data class DeviceData ( val deviceId: String? = "", val deviceType: String? = "", - val coefficient: List? = null, + val coefficients: List? = null, val calibratedAt: String ) \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt b/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt index 497100e..eb692ed 100644 --- a/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt +++ b/app/src/main/java/com/example/hpostesting/data/repository/DatabaseRepository.kt @@ -116,7 +116,19 @@ class DatabaseRepository : Repository { } } - suspend fun getDeviceDataById(): List { + suspend fun getDeviceData(): List { 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 } + } + + + } \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt index f6d91c2..93d3852 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt @@ -71,6 +71,7 @@ class HemoCubeFragment : Fragment() { hemoCubeViewModel.getDeviceData() + hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) { deviceData = it } diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt index e30bd2f..77719a7 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt @@ -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>() + val deviceIdToRetrieve = deviceData.value?.firstOrNull()?.deviceId val networkStatusLiveData: LiveData get() = _networkStatusLiveData val fireBaseUpload = MutableLiveData() @@ -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() diff --git a/app/src/main/res/layout/fragment_hemo_cube_reference.xml b/app/src/main/res/layout/fragment_hemo_cube_reference.xml index 39015c6..3a612f7 100644 --- a/app/src/main/res/layout/fragment_hemo_cube_reference.xml +++ b/app/src/main/res/layout/fragment_hemo_cube_reference.xml @@ -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"