refactoring hemocube fragment and add tests
This commit is contained in:
@@ -25,12 +25,10 @@ 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.ktx.Firebase
|
||||
import com.google.firebase.perf.ktx.performance
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.round
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class HemoCubeFragment : Fragment() {
|
||||
@@ -44,7 +42,6 @@ class HemoCubeFragment : Fragment() {
|
||||
private var resultData: String = ""
|
||||
private var currentResultData: String = ""
|
||||
private var isUsingExistingBuffer = false
|
||||
private var loginId: String = ""
|
||||
private var isTestOngoing = false
|
||||
private var startListening = MutableLiveData<Boolean>(false)
|
||||
private var led1BufferForDevice = 0.0
|
||||
@@ -59,7 +56,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private var fittedAbs2 = 0.0
|
||||
private var fittedAbs3 = 0.0
|
||||
private var fittedAbs4 = 0.0
|
||||
private var _predictedDenovixRatio = 0.0
|
||||
private var calculatedPredictedDenovixRatio = 0.0
|
||||
private var validationError = false
|
||||
private var deviceHardwareId = ""
|
||||
private var allErrorMessages = ""
|
||||
@@ -211,9 +208,9 @@ class HemoCubeFragment : Fragment() {
|
||||
apply {
|
||||
DataHolder.hemoCubeTestData?.let {
|
||||
currentDeviceData?.coefficients?.let { coefficients ->
|
||||
val coefficient1 = coefficients[0]
|
||||
val coefficient2 = coefficients[1]
|
||||
val result = coefficient1 * coefficient2
|
||||
// val coefficient1 = coefficients[0]
|
||||
// val coefficient2 = coefficients[1]
|
||||
// val result = coefficient1 * coefficient2
|
||||
}
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
@@ -394,7 +391,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
resultData.contains("#SS") && this.testStatusCode < TestStatus.SAMPLE_STARTED.code -> {
|
||||
(resultData.contains("#SS") || resultData.contains("#SS1")) && this.testStatusCode < TestStatus.SAMPLE_STARTED.code -> {
|
||||
this.testStatusCode = TestStatus.SAMPLE_STARTED.code
|
||||
activity?.runOnUiThread {
|
||||
binding.tvSubtitle4.text = getString(R.string.sample_started)
|
||||
@@ -402,7 +399,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
resultData.contains("#SC") && this.testStatusCode < TestStatus.SAMPLE_COMPLETED.code -> {
|
||||
(resultData.contains("#SC") || resultData.contains("#SC1")) && this.testStatusCode < TestStatus.SAMPLE_COMPLETED.code -> {
|
||||
this.testStatusCode = TestStatus.SAMPLE_COMPLETED.code
|
||||
hemoCubeViewModel.messages.postValue(
|
||||
getString(R.string.sample_completed) + "\n" + getString(R.string.gathering_data))
|
||||
@@ -574,7 +571,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
fun processHardwareId(resultData: String) {
|
||||
val hardwareId = "HCV-000-3001" //extractMiddleString(resultData)
|
||||
val hardwareId = extractMiddleString(resultData)
|
||||
|
||||
if (!hardwareId.isNullOrBlank()) {
|
||||
updateDeviceId(hardwareId)
|
||||
@@ -582,17 +579,17 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.btnPlacebuffer.visibility = View.VISIBLE
|
||||
}
|
||||
hemoCubeViewModel.messages.postValue(getString(R.string.start))
|
||||
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
deviceHardwareId = "HCV-000-3001"
|
||||
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"
|
||||
}
|
||||
} else {
|
||||
hemoCubeViewModel.messages.postValue("Config error")
|
||||
}
|
||||
|
||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||
deviceHardwareId = "HCV-000-3001"
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
fun extractMiddleString(input: String): String? {
|
||||
@@ -696,25 +693,25 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
val slope1 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(1)?.get(0)
|
||||
val intercept1 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(1)?.get(1)
|
||||
val _hb1 = (led3Average - intercept1!!) / slope1!!
|
||||
val calculatedHb1 = (led1Average - intercept1!!) / slope1!!
|
||||
|
||||
val slope2 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(0)
|
||||
val intercept = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(1)
|
||||
val _hb2 = (led4Average - intercept!!) / slope2!!
|
||||
val calculatedHb2 = (led2Average - intercept!!) / slope2!!
|
||||
|
||||
val slope3 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(2)?.get(0)
|
||||
val intercept3 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(2)?.get(1)
|
||||
val _hb3 = (led3Average - intercept3!!) / slope3!!
|
||||
val calculatedHb3 = (led3Average - intercept3!!) / slope3!!
|
||||
|
||||
val slope4 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(0)
|
||||
val intercept4 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(1)
|
||||
val _hb4 = (led4Average - intercept4!!) / slope4!!
|
||||
val calculatedHb4 = (led4Average - intercept4!!) / slope4!!
|
||||
|
||||
_predictedDenovixRatio = fittedAbs3.div(fittedAbs1)
|
||||
calculatedPredictedDenovixRatio = fittedAbs3.div(fittedAbs1)
|
||||
|
||||
val slope = (led1Average - led2Average) / (435 - 415)
|
||||
val _slopeRatio = abs(led3Average / slope)
|
||||
val slopeClass = slopeRatioClassification(_slopeRatio)
|
||||
val calculatedSlopeRatio = abs(led3Average / slope)
|
||||
val slopeClass = slopeRatioClassification(calculatedSlopeRatio)
|
||||
|
||||
if (fittedAbs1 <= fittedAbs2) {
|
||||
validationError = true
|
||||
@@ -733,7 +730,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
if ((led1Average < 0.7 || led2Average < 0.7 || led3Average < 0.7 || led4Average < 0.7) && _slopeRatio > 35.0) {
|
||||
if ((led1Average < 0.7 || led2Average < 0.7 || led3Average < 0.7 || led4Average < 0.7) && calculatedSlopeRatio > 35.0) {
|
||||
validationError = true
|
||||
activity?.runOnUiThread {
|
||||
binding.errorMessage.text = "Severely Low Hb. Repeat test with 12 ul in 2 ml Buffer"
|
||||
@@ -769,12 +766,12 @@ class HemoCubeFragment : Fragment() {
|
||||
this.abs2 = fittedAbs2
|
||||
this.abs3 = fittedAbs3
|
||||
this.abs4 = fittedAbs4
|
||||
this.hb3 = _hb3
|
||||
this.hb4 = _hb4
|
||||
this.hb3 = calculatedHb3
|
||||
this.hb4 = calculatedHb4
|
||||
this.deviceRatio = deviceRatio
|
||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||
this.predictedDenovixRatio = _predictedDenovixRatio
|
||||
this.slopeRatio = _slopeRatio
|
||||
this.predictedDenovixRatio = calculatedPredictedDenovixRatio
|
||||
this.slopeRatio = calculatedSlopeRatio
|
||||
this.coefficients = currentDeviceData?.coefficients?.get(0)
|
||||
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
|
||||
@@ -783,7 +780,7 @@ 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: $_hb4")
|
||||
hemoCubeViewModel.messages.postValue("HB: $calculatedHb4")
|
||||
this.errorMessages = allErrorMessages
|
||||
this.resultData = deviceLog
|
||||
this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString()
|
||||
|
||||
Reference in New Issue
Block a user