Merge branch 'fix-kit-check' into 'Homocube'
fix diagnostics reading and kit check See merge request sminnovations/hpos!10
This commit is contained in:
@@ -2,7 +2,7 @@ package com.example.hpostesting.data.constant
|
|||||||
|
|
||||||
enum class HemoCubeCommands(val command: String) {
|
enum class HemoCubeCommands(val command: String) {
|
||||||
startBuffer("B\r"),
|
startBuffer("B\r"),
|
||||||
getBuffer("D\r"),
|
runDiagnostics("D\r"),
|
||||||
startSample("S\r"),
|
startSample("S\r"),
|
||||||
getSample("P\r"),
|
getSample("P\r"),
|
||||||
getDeviceId("I\r"),
|
getDeviceId("I\r"),
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ data class BufferCheckData(
|
|||||||
var led2Average: Double? = null,
|
var led2Average: Double? = null,
|
||||||
var deviceRatio: Double? = null,
|
var deviceRatio: Double? = null,
|
||||||
var calculatedRatio: Double? = null,
|
var calculatedRatio: Double? = null,
|
||||||
|
var coefficients: String? = "",
|
||||||
var classificationResult: String = "",
|
var classificationResult: String = "",
|
||||||
var testTime: String = ""
|
var testTime: String = ""
|
||||||
)
|
)
|
||||||
@@ -30,5 +30,6 @@ data class HemoCubeTestData(
|
|||||||
var led2Average: Double? = null,
|
var led2Average: Double? = null,
|
||||||
var deviceRatio: Double? = null,
|
var deviceRatio: Double? = null,
|
||||||
var calculatedRatio: Double? = null,
|
var calculatedRatio: Double? = null,
|
||||||
|
var coefficients: String? = "",
|
||||||
var classificationResult: String = ""
|
var classificationResult: String = ""
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -225,7 +225,8 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
|||||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||||
val deviceRatio = led1Average / led2Average
|
val deviceRatio = led1Average / led2Average
|
||||||
val classificationResult = findResult(deviceRatio)
|
val calculateRatio = calculateRatio(deviceRatio)
|
||||||
|
val classificationResult = findResult(calculateRatio)
|
||||||
messages.postValue(classificationResult)
|
messages.postValue(classificationResult)
|
||||||
val bufferData = BufferCheckData(
|
val bufferData = BufferCheckData(
|
||||||
deviceId= deviceId,
|
deviceId= deviceId,
|
||||||
@@ -237,7 +238,8 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
|||||||
led1Sample = led1Sample,
|
led1Sample = led1Sample,
|
||||||
led2Sample = led2Sample,
|
led2Sample = led2Sample,
|
||||||
deviceRatio = deviceRatio,
|
deviceRatio = deviceRatio,
|
||||||
calculatedRatio = calculateRatio(deviceRatio),
|
calculatedRatio = calculateRatio,
|
||||||
|
coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString(),
|
||||||
classificationResult = classificationResult,
|
classificationResult = classificationResult,
|
||||||
deviceSerialNumber = sharedPreferences.getString(Constants.USER_ID, "").toString(),
|
deviceSerialNumber = sharedPreferences.getString(Constants.USER_ID, "").toString(),
|
||||||
testTime = SimpleDateFormat(
|
testTime = SimpleDateFormat(
|
||||||
|
|||||||
@@ -11,20 +11,13 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.DataHolder
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
|
||||||
import com.example.hpostesting.presentation.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
|
||||||
import com.example.hpostesting.presentation.utils.UIUtils
|
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import `in`.sminnovations.hpostesting.R
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDiagnosticsBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentDiagnosticsBinding
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
@@ -38,7 +31,6 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
private var currentDeviceData: DeviceData? = null
|
private var currentDeviceData: DeviceData? = null
|
||||||
private var resultData: String = ""
|
private var resultData: String = ""
|
||||||
private val messages = MutableLiveData<String>()
|
private val messages = MutableLiveData<String>()
|
||||||
private var isTestOngoing = false
|
|
||||||
private var startListening = MutableLiveData(false)
|
private var startListening = MutableLiveData(false)
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@@ -58,11 +50,12 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
|
|
||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
|
binding.btnSubmit.visibility = View.GONE
|
||||||
listenToHemoCube()
|
listenToHemoCube()
|
||||||
getDeviceId()
|
getDeviceId()
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
binding.btnSubmit.visibility = View.GONE
|
binding.btnSubmit.visibility = View.GONE
|
||||||
getBufferdiagnostics()
|
runDeviceDiagnostics()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,27 +66,21 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
currentDeviceData = it
|
currentDeviceData = it
|
||||||
}
|
}
|
||||||
|
|
||||||
diagnosticsViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
|
||||||
if (isNetworkAvailable) {
|
|
||||||
// diagnosticsViewModel.getDeviceData(
|
|
||||||
// sharedPreferences.getString(
|
|
||||||
// Constants.USER_ID,
|
|
||||||
// ""
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
} else {
|
|
||||||
Toast.makeText(
|
|
||||||
requireContext(),
|
|
||||||
"No internet connection avaiable",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
messages.observe(viewLifecycleOwner) {
|
messages.observe(viewLifecycleOwner) {
|
||||||
binding.tvSubtitle4.text = it
|
binding.tvSubtitle4.text = it
|
||||||
Log.e("diagnostics",binding.tvSubtitle4.text.toString())
|
Log.e("diagnostics",binding.tvSubtitle4.text.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diagnosticsViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
|
if (result == "Success") {
|
||||||
|
showToast("Diagnostics data uploaded successfully")
|
||||||
|
}
|
||||||
|
if (result == "Local") {
|
||||||
|
showToast("Diagnostics uploading failed, note it down manually")
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDeviceId() {
|
private fun getDeviceId() {
|
||||||
@@ -105,15 +92,6 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
data?.let {
|
data?.let {
|
||||||
val stringData = String(it)
|
val stringData = String(it)
|
||||||
diagnosticsViewModel.messages.postValue(stringData)
|
diagnosticsViewModel.messages.postValue(stringData)
|
||||||
val pattern = Regex("([A-Z]+)\\s(\\d+)")
|
|
||||||
val matchResult = pattern.find(stringData)
|
|
||||||
if (matchResult != null) {
|
|
||||||
val (sn, hardwareId) = matchResult.destructured
|
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(com.example.hpostesting.data.constant.Constants.DEVICE_ID, hardwareId)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binding.tvSubtitle4.text = stringData
|
binding.tvSubtitle4.text = stringData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,10 +101,10 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getBufferdiagnostics() {
|
private fun runDeviceDiagnostics() {
|
||||||
diagnosticsViewModel.progressBar.postValue(true)
|
diagnosticsViewModel.progressBar.postValue(true)
|
||||||
(activity as DiagnosticsActivity).mService.sendAndListenToHemoCube(
|
(activity as DiagnosticsActivity).mService.sendAndListenToHemoCube(
|
||||||
HemoCubeCommands.getBuffer,
|
HemoCubeCommands.runDiagnostics,
|
||||||
object : UsbServiceListener {
|
object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
|
|
||||||
@@ -138,8 +116,6 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun listenToHemoCube() {
|
private fun listenToHemoCube() {
|
||||||
|
|
||||||
val fullReadOutput = StringBuilder()
|
val fullReadOutput = StringBuilder()
|
||||||
@@ -154,6 +130,19 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
fullReadOutput.append(stringData)
|
fullReadOutput.append(stringData)
|
||||||
resultData += stringData
|
resultData += stringData
|
||||||
binding.tvSubtitle4.text = resultData
|
binding.tvSubtitle4.text = resultData
|
||||||
|
if (stringData.contains("SN")) {
|
||||||
|
val slData = stringData.split(" ")
|
||||||
|
if (slData.size > 1) {
|
||||||
|
val hardwareId = slData[1].trim()
|
||||||
|
with(sharedPreferences.edit()) {
|
||||||
|
putString(Constants.DEVICE_ID, hardwareId)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
binding.btnSubmit.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultData.contains("END") || fullReadOutput.contains("END")) {
|
if (resultData.contains("END") || fullReadOutput.contains("END")) {
|
||||||
@@ -202,5 +191,7 @@ class DiagnosticsFragment : Fragment() {
|
|||||||
return parsedData
|
return parsedData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showToast(message: String) {
|
||||||
|
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -354,6 +354,14 @@ class HemoCubeFragment : Fragment() {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if (led1Average < 0 || led2Average < 0) {
|
||||||
|
activity?.runOnUiThread{
|
||||||
|
binding.errorMessage.text = "Warning: Negative Abs. Retake Blank Reading"
|
||||||
|
binding.errorMessage.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DataHolder.hemoCubeTestData?.apply {
|
DataHolder.hemoCubeTestData?.apply {
|
||||||
deviceId = deviceSerialNo
|
deviceId = deviceSerialNo
|
||||||
led1Buffer = led1BufferForDevice
|
led1Buffer = led1BufferForDevice
|
||||||
@@ -365,6 +373,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
this.led2Average = led2Average
|
this.led2Average = led2Average
|
||||||
this.deviceRatio = deviceRatio
|
this.deviceRatio = deviceRatio
|
||||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||||
|
this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||||
this.classificationResult = findResult(calculatedRatio)
|
this.classificationResult = findResult(calculatedRatio)
|
||||||
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
||||||
this.resultData = deviceLog
|
this.resultData = deviceLog
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
testDetails?.led2Average = DataHolder.hemoCubeTestData?.led2Average
|
testDetails?.led2Average = DataHolder.hemoCubeTestData?.led2Average
|
||||||
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
||||||
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
||||||
|
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
||||||
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
|
testDetails?.classificationResult = DataHolder.hemoCubeTestData?.classificationResult!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user