Device Diagnostics Api structure done successfully
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.example.hpostesting.data.api
|
||||
|
||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsResponse
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
||||
import com.example.hpostesting.data.model.login.LoginRequest
|
||||
@@ -18,4 +20,5 @@ interface MolbioAuthApi {
|
||||
suspend fun login(
|
||||
@Body loginRequest: LoginRequest
|
||||
): LoginResponse
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ interface MolbioResultApi {
|
||||
): UploadLogsResponse
|
||||
|
||||
|
||||
@POST("deviceService/device/uploadDeviceDiagnostics")
|
||||
@PUT("deviceService/device/uploadDeviceDiagnostics")
|
||||
suspend fun deviceDiagnostics(
|
||||
@Body deviceDiagnosticsRequest: DeviceDiagnosticsRequest
|
||||
): DeviceDiagnosticsResponse
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.example.hpostesting.data.model.devicediagnostics
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class AdditionalDetails(
|
||||
@SerializedName("Data")
|
||||
val data: DeviceDiagnosticsData?,
|
||||
@SerializedName("Message")
|
||||
val message: String? = "",
|
||||
@SerializedName("Result")
|
||||
val result: String? = ""
|
||||
)
|
||||
data class DeviceDiagnosticsRequest(
|
||||
@SerializedName("additionalDetails") val additionalDetails: AdditionalDetails1
|
||||
val batteryLevel: String? = "",
|
||||
val batteryCapacity: String? = "",
|
||||
val batteryMaxCapacity: String? = "",
|
||||
val batteryTemperature: String? = "",
|
||||
val batteryVoltage: String? = "",
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example.hpostesting.data.model.devicediagnostics
|
||||
|
||||
data class DeviceDiagnosticsData(
|
||||
val id: String? = "",
|
||||
val deviceId: String? = "",
|
||||
val additionalDetails: AdditionalDetails?= AdditionalDetails(),
|
||||
val createdBy: String? = "",
|
||||
val updatedBy: String? = "",
|
||||
val updatedAt: String? = "",
|
||||
val createdAt: String? = "",
|
||||
)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.hpostesting.data.model.devicediagnostics
|
||||
|
||||
data class DeviceDiagnosticsRequest(
|
||||
val additionalDetails: AdditionalDetails?= AdditionalDetails()
|
||||
)
|
||||
@@ -2,11 +2,10 @@ package com.example.hpostesting.data.model.devicediagnostics
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
|
||||
data class DeviceDiagnosticsResponse(
|
||||
@SerializedName("Data")
|
||||
val data: DeviceDiagnosticsData?,
|
||||
@SerializedName("Message")
|
||||
val data: DeviceDiagnosticsData? = DeviceDiagnosticsData(),
|
||||
val message: String? = "",
|
||||
@SerializedName("Result")
|
||||
val result: String? = ""
|
||||
)
|
||||
|
||||
@@ -80,7 +80,7 @@ class DatabaseRepository @Inject constructor(
|
||||
}
|
||||
|
||||
override suspend fun deviceDiagnostics(deviceDiagnosticsRequest: DeviceDiagnosticsRequest): Result<DeviceDiagnosticsResponse> {
|
||||
return safeApiCall { molbioResultApi.deviceDiagnostics(deviceDiagnosticsRequest) }
|
||||
return safeApiCall { molbioResultApi.deviceDiagnostics(deviceDiagnosticsRequest) }
|
||||
}
|
||||
|
||||
override suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse> {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.hpostesting.presentation.diagnostics
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
@@ -12,9 +14,10 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.Result.Success
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.devicediagnostics.AdditionalDetails1
|
||||
import com.example.hpostesting.data.model.devicediagnostics.AdditionalDetails
|
||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
@@ -35,7 +38,10 @@ class DiagnosticsFragment : Fragment() {
|
||||
private var resultData: String = ""
|
||||
private val messages = MutableLiveData<String>()
|
||||
private var startListening = MutableLiveData(false)
|
||||
|
||||
private val batteryStatus: Intent? =
|
||||
IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { ifilter ->
|
||||
context?.registerReceiver(null, ifilter)
|
||||
}
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
): View {
|
||||
@@ -65,7 +71,7 @@ class DiagnosticsFragment : Fragment() {
|
||||
val batteryTemperature = diagnosticsViewModel.getBatteryTemperature().toString()
|
||||
val batteryVoltage = context?.let { diagnosticsViewModel.getBatteryVoltage(it).toString() }
|
||||
|
||||
val additionalDetails = AdditionalDetails1(
|
||||
val additionalDetails = AdditionalDetails(
|
||||
batteryLevel = batteryLevel,
|
||||
batteryCapacity = batteryCapacity!!,
|
||||
batteryMaxCapacity = batteryMaxCapacity!!,
|
||||
@@ -76,6 +82,8 @@ class DiagnosticsFragment : Fragment() {
|
||||
DeviceDiagnosticsRequest(additionalDetails = additionalDetails)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -99,49 +107,45 @@ class DiagnosticsFragment : Fragment() {
|
||||
}
|
||||
|
||||
binding.progressBar.visibility = View.GONE
|
||||
|
||||
}
|
||||
|
||||
// diagnosticsViewModel.deviceDiagnosticsResponse.observe(viewLifecycleOwner) { response ->
|
||||
// when (response) {
|
||||
// is Result.Success-> {
|
||||
//
|
||||
// val result = response.data?.result
|
||||
// if (result == "Success") {
|
||||
// Toast.makeText(
|
||||
// activity, response.data?.message ?: "Device diagnostics uploaded successfully", Toast.LENGTH_LONG
|
||||
// ).show()
|
||||
//
|
||||
// response.data?.data?.let { diagnosticsData ->
|
||||
//
|
||||
// val batteryLevel = diagnosticsData.additionalDetails.batteryLevel
|
||||
//
|
||||
// }
|
||||
// } else {
|
||||
// Toast.makeText(
|
||||
// activity,
|
||||
// "Received success response but the result is not successful: ${response.data?.message}",
|
||||
// Toast.LENGTH_LONG
|
||||
// ).show()
|
||||
// }
|
||||
// }
|
||||
// is Result.Error -> {
|
||||
// // Handle the error scenario
|
||||
// Toast.makeText(
|
||||
// activity,
|
||||
// "An error occurred: ${response.exception.message}",
|
||||
// Toast.LENGTH_LONG
|
||||
// ).show()
|
||||
// }
|
||||
// is Result.Loading -> {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
diagnosticsViewModel.deviceDiagnosticsResponse.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Success -> {
|
||||
if (response.data.result == "Success") {
|
||||
Toast.makeText(
|
||||
activity, response.data.message ?: "Device diagnostics uploaded successfully", Toast.LENGTH_LONG
|
||||
).show()
|
||||
|
||||
response.data.data?.let { diagnosticsData ->
|
||||
|
||||
val batteryLevel = diagnosticsData.additionalDetails?.batteryLevel
|
||||
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"Received success response but the result is not successful: ${response.data.message}",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
is Result.Error -> {
|
||||
// Handle the error scenario
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred: ${response.exception.message}",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
is Result.Loading -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private fun getDeviceId() {
|
||||
diagnosticsViewModel.progressBar.postValue(true)
|
||||
(activity as DiagnosticsActivity).mService.sendAndListenToHemoCube(
|
||||
@@ -175,6 +179,7 @@ class DiagnosticsFragment : Fragment() {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
private fun listenToHemoCube() {
|
||||
|
||||
val fullReadOutput = StringBuilder()
|
||||
|
||||
@@ -7,9 +7,12 @@ import android.os.BatteryManager
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.model.Response
|
||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsResponse
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.repository.Repository
|
||||
@@ -18,7 +21,7 @@ import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
@HiltViewModel
|
||||
class DiagnosticsViewModel @Inject constructor(
|
||||
private val repository: Repository,
|
||||
private val respository: Repository,
|
||||
context: Context,
|
||||
) : ViewModel() {
|
||||
var isServiceConnected = false
|
||||
@@ -27,16 +30,15 @@ class DiagnosticsViewModel @Inject constructor(
|
||||
|
||||
val deviceData = MutableLiveData<DeviceData?>()
|
||||
val fireBaseUpload = MutableLiveData<String>()
|
||||
val deviceDiagnosticsResponse = MutableLiveData<Result<DeviceDiagnosticsResponse>>()
|
||||
val deviceDiagnosticsResponse = MutableLiveData<com.example.hpostesting.data.Result<DeviceDiagnosticsResponse>>()
|
||||
private val batteryStatus: Intent? =
|
||||
IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { ifilter ->
|
||||
context.registerReceiver(null, ifilter)
|
||||
}
|
||||
|
||||
fun addDiagnosticsDataToDb(data: DiagnosticsData) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
when (val response = repository.addDiagnostics(data)) {
|
||||
when (val response = respository.addDiagnostics(data)) {
|
||||
is Response.Success -> {
|
||||
// Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||
fireBaseUpload.postValue("Success")
|
||||
@@ -57,13 +59,12 @@ class DiagnosticsViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
|
||||
|
||||
// fun deviceDiagnostics(deviceDiagnosticsRequest: DeviceDiagnosticsRequest) = viewModelScope.launch {
|
||||
// deviceDiagnosticsResponse.postValue(Result.Loading())
|
||||
// repository.deviceDiagnostics(deviceDiagnosticsRequest).let {
|
||||
// deviceDiagnosticsResponse.postValue(it)
|
||||
// }
|
||||
// }
|
||||
fun deviceDiagnostics(deviceDiagnosticsRequest: DeviceDiagnosticsRequest) = viewModelScope.launch {
|
||||
deviceDiagnosticsResponse.postValue(Result.Loading())
|
||||
respository.deviceDiagnostics(deviceDiagnosticsRequest).let {
|
||||
deviceDiagnosticsResponse.postValue(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun getBatteryLevel(): Float? {
|
||||
@@ -133,5 +134,4 @@ class DiagnosticsViewModel @Inject constructor(
|
||||
|
||||
return maxCapacity
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user