fix backward compatibility of device id and refactor
This commit is contained in:
@@ -1246,7 +1246,7 @@ object Constants {
|
||||
listOf(23500, 26250),
|
||||
listOf(23500, 26250),
|
||||
),
|
||||
"HCV-000-1015" to listOf(
|
||||
"HCV-000-3013" to listOf(
|
||||
listOf(23500, 26250),
|
||||
listOf(23500, 26250),
|
||||
listOf(23500, 26250),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.example.hpostesting.data.model
|
||||
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
|
||||
data class TestState (
|
||||
var testDetails: HemoCubeTestData? = null,
|
||||
var isOnline: Boolean = false,
|
||||
var currentDeviceData: DeviceData? = null,
|
||||
var resultData: String = "",
|
||||
var currentResultData: String = "",
|
||||
var isUsingExistingBuffer: Boolean = false,
|
||||
var isTestOngoing: Boolean = false,
|
||||
var led1BufferForDevice: Double = 0.0,
|
||||
var led2BufferForDevice: Double = 0.0,
|
||||
var led3BufferForDevice: Double = 0.0,
|
||||
var led4BufferForDevice: Double = 0.0,
|
||||
var led1SampleForDevice: Double = 0.0,
|
||||
var led2SampleForDevice: Double = 0.0,
|
||||
var led3SampleForDevice: Double = 0.0,
|
||||
var led4SampleForDevice: Double = 0.0,
|
||||
var fittedAbs1: Double = 0.0,
|
||||
var fittedAbs2: Double = 0.0,
|
||||
var fittedAbs3: Double = 0.0,
|
||||
var fittedAbs4: Double = 0.0,
|
||||
var calculatedPredictedDenovixRatio: Double = 0.0,
|
||||
var validationError: Boolean = false,
|
||||
var deviceHardwareId: String = "",
|
||||
var allErrorMessages: String = "",
|
||||
var testStatusCode: Double = 0.0,
|
||||
var repeatReadingCount: Int = 0,
|
||||
var readingsPerSample: Int = Constants.READINGS_PER_SAMPLE,
|
||||
var uploadedToCloud: Boolean = false,
|
||||
var uploadedToMolbio: Boolean = false
|
||||
)
|
||||
@@ -17,6 +17,7 @@ import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.constant.TestStatus
|
||||
import com.example.hpostesting.data.model.TestState
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
@@ -65,6 +66,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private var readingsPerSample = Constants.READINGS_PER_SAMPLE
|
||||
private var uploadedToCloud = false
|
||||
private var uploadedToMolbio = false
|
||||
lateinit var testState: TestState
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
@@ -72,6 +74,11 @@ class HemoCubeFragment : Fragment() {
|
||||
binding = FragmentHemoCubeReferenceBinding.inflate(inflater, container, false)
|
||||
sharedPreferences =
|
||||
requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
|
||||
testState = TestState(
|
||||
testDetails = DataHolder.selectedTest?.toHemoCubeTestData(),
|
||||
)
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -362,7 +369,7 @@ class HemoCubeFragment : Fragment() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun handleUsbData(stringData: String) {
|
||||
fun handleUsbData(stringData: String) {
|
||||
if (stringData.contains("#")) {
|
||||
isTestOngoing = true
|
||||
}
|
||||
@@ -376,7 +383,7 @@ class HemoCubeFragment : Fragment() {
|
||||
processV2HardwareId(resultData)
|
||||
}
|
||||
|
||||
(resultData.contains("SN") && !resultData.contains("SNE")) && this.testStatusCode > TestStatus.SAMPLE_STARTED.code -> {
|
||||
(resultData.contains("SN") && !resultData.contains("SNS") && !resultData.contains("SNE") && resultData.length >= 15) && this.testStatusCode < TestStatus.CONFIG_COMPLETED.code -> {
|
||||
processV1HardwareId(resultData)
|
||||
}
|
||||
|
||||
@@ -587,10 +594,10 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
assignDefaultDevice(resultData)
|
||||
allErrorMessages += "Calibration configuration for this device id is not found\n"
|
||||
testState.allErrorMessages += "Calibration configuration for this device id is not found\n"
|
||||
}
|
||||
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
|
||||
allErrorMessages += "ADC thresholds for this device id are not found\n"
|
||||
testState.allErrorMessages += "ADC thresholds for this device id are not found\n"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,19 +623,15 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
assignDefaultDevice(resultData)
|
||||
allErrorMessages += "Calibration configuration for this device id is not found\n"
|
||||
testState.allErrorMessages += "Calibration configuration for this device id is not found\n"
|
||||
}
|
||||
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
|
||||
allErrorMessages += "ADC thresholds for this device id are not found\n"
|
||||
testState.allErrorMessages += "ADC thresholds for this device id are not found\n"
|
||||
}
|
||||
}
|
||||
|
||||
fun assignDefaultDevice(configData: String) {
|
||||
deviceHardwareId = "HCV-000-3001"
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.DEVICE_ID, configData)
|
||||
apply()
|
||||
}
|
||||
testStatusCode = TestStatus.CONFIG_COMPLETED.code
|
||||
activity?.runOnUiThread {
|
||||
binding.btnPlacebuffer.visibility = View.VISIBLE
|
||||
@@ -691,7 +694,7 @@ class HemoCubeFragment : Fragment() {
|
||||
)?.get(0)!!
|
||||
) {
|
||||
validationError = true
|
||||
allErrorMessages += "Error: Invalid Test. Improper buffer reading (low)"
|
||||
testState.allErrorMessages += "Error: Invalid Test. Improper buffer reading (low)"
|
||||
activity?.runOnUiThread {
|
||||
binding.errorMessage.text = getString(R.string.error_improper_buffer_low)
|
||||
// binding.errorMessage.visibility = View.VISIBLE
|
||||
@@ -711,7 +714,7 @@ class HemoCubeFragment : Fragment() {
|
||||
)?.get(1)!!
|
||||
) {
|
||||
validationError = true
|
||||
allErrorMessages += "Error: Invalid Test. Improper buffer reading (high)" + "\n"
|
||||
testState.allErrorMessages += "Error: Invalid Test. Improper buffer reading (high)" + "\n"
|
||||
activity?.runOnUiThread {
|
||||
binding.errorMessage.text =
|
||||
getString(R.string.error_improper_buffer_high)
|
||||
@@ -759,7 +762,7 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
if (fittedAbs1 <= fittedAbs2) {
|
||||
validationError = true
|
||||
allErrorMessages += "Error: Invalid Test. Problem with de-oxygenation" + "\n"
|
||||
testState.allErrorMessages += "Error: Invalid Test. Problem with de-oxygenation" + "\n"
|
||||
activity?.runOnUiThread {
|
||||
binding.errorMessage.text = getString(R.string.error_invalid_test)
|
||||
// binding.errorMessage.visibility = View.VISIBLE
|
||||
@@ -784,7 +787,7 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
if (fittedAbs3 < 0.1) {
|
||||
validationError = true
|
||||
allErrorMessages += "Error: Low Hb. Repeat test" + "\n"
|
||||
testState.allErrorMessages += "Error: Low Hb. Repeat test" + "\n"
|
||||
activity?.runOnUiThread {
|
||||
binding.errorMessage.text = "Error: Low Hb. Repeat test"
|
||||
// binding.errorMessage.visibility = View.VISIBLE
|
||||
@@ -824,8 +827,8 @@ class HemoCubeFragment : Fragment() {
|
||||
this.classificationResult = deviceRatioClass //findResult(calculatedRatio)
|
||||
hemoCubeViewModel.messages.postValue("${this.deviceRatioClass} ${if (led4Average < 0.17) " - Low Hb" else ""}\n")
|
||||
if (DataHolder.hemoCubeTestData?.testType == "HB")
|
||||
hemoCubeViewModel.messages.postValue("HB: $calculatedHb4")
|
||||
this.errorMessages = allErrorMessages
|
||||
hemoCubeViewModel.messages.postValue("Hb: $calculatedHb4")
|
||||
this.errorMessages = testState.allErrorMessages
|
||||
this.resultData = deviceLog
|
||||
this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString()
|
||||
this.batteryCapacity =
|
||||
|
||||
Reference in New Issue
Block a user