From 4fef75b937142becf1c6b9ab062f5034a0677930 Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Tue, 6 Feb 2024 13:44:00 +0530 Subject: [PATCH] add new thresholds with additonal method and unit tests --- app/build.gradle | 6 +-- .../hpostesting/data/constant/Constants.kt | 2 +- .../presentation/hemocube/HemoCubeFragment.kt | 52 +++++++------------ .../presentation/trueheme/TrueHemeFragment.kt | 2 +- .../hpostesting/HemoCubeFragmentTest.kt | 22 ++++++-- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0fc5ccb..c881eb0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,13 +14,13 @@ android { compileSdk 34 namespace 'in.sminnovations.hpostesting' - // prod - production, preprod - preproduction, quality - qc, dev - development + // dev - development, quality - qc, uat - User Acceptance Test, preprod - preproduction, prod - production defaultConfig { applicationId "in.sminnovations.hpostesting.quality" minSdk 21 targetSdk 34 - versionCode 99 - versionName "2.1.99" + versionCode 101 + versionName "2.1.101" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt index d8aed49..c83e41b 100644 --- a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt +++ b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt @@ -8,7 +8,7 @@ object Constants { const val ABHA_APP_PACKAGE = "in.ndhm.phr" - const val MOLBIO_INTERGATION = false + const val MOLBIO_INTEGRATION = false const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in" const val deviceProvisionPassword = "f2ab0e7f9d69" const val DEVICE_ID_API = "deviceIDAPI" 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 e6312fd..70bb256 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 @@ -153,7 +153,7 @@ class HemoCubeFragment : Fragment() { when (it) { is Result.Success -> { uploadedToMolbio = true - if (Constants.MOLBIO_INTERGATION) { + if (Constants.MOLBIO_INTEGRATION) { it.data.data?.get(0)?.rawData?.let { it1 -> hemoCubeViewModel.updateMolbioFlag( it1._id @@ -805,8 +805,8 @@ class HemoCubeFragment : Fragment() { calculatedPredictedDenovixRatio = fittedAbs3.div(fittedAbs1) - val slope = (led1Average - led2Average) / (435 - 415) - val calculatedSlopeRatio = abs(led3Average / slope) + val slope = (led4Average - led1Average) / (431-411) + val calculatedSlopeRatio = abs(led2Average / slope) val slopeClass = slopeRatioClassification(calculatedSlopeRatio) if (fittedAbs1 <= fittedAbs2) { @@ -874,8 +874,8 @@ class HemoCubeFragment : Fragment() { this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio) this.deviceRatioClass = deviceRatioClassification(deviceRatio) this.slopeRatioClass = slopeClass - this.classificationResult = deviceRatioClass //findResult(calculatedRatio) - hemoCubeViewModel.messages.postValue("${this.deviceRatioClass} ${if (led4Average < 0.17) " - Low Hb" else ""}\n") + this.classificationResult = findResultWithAdditionalMethods(deviceRatio, deviceRatioClass, slopeRatio) + hemoCubeViewModel.messages.postValue("${this.classificationResult} ") if (DataHolder.hemoCubeTestData?.testType == "HB") hemoCubeViewModel.messages.postValue("Hb: $calculatedHb4") this.errorMessages = testState.allErrorMessages @@ -909,50 +909,36 @@ class HemoCubeFragment : Fragment() { } } - fun findResult(calculatedRatio: Double?): String { + fun findResultWithAdditionalMethods(deviceRatio: Double?, deviceRatioClass: String?, slopeRatio: Double?): String { try { - hemoCubeViewModel.messages.postValue("result classification") - if (calculatedRatio != null) { - if (calculatedRatio < 0.05) - return getString(R.string.error_repeat_test_higher_volume) - if (calculatedRatio in 0.05..0.155) { - return getString(R.string.normal) +// hemoCubeViewModel.messages.postValue("post classification checks") + if (deviceRatio != null) { + if (slopeRatio != null) { + if (deviceRatioClass == "Normal" && slopeRatio > 60.0) + return "Negative Borderline, Repeat Test" } - if (calculatedRatio in 0.155..0.175) - return getString(R.string.negative_borderline) - if (calculatedRatio in 0.175..0.22) - return getString(R.string.sickle_cell_trait) - if (calculatedRatio in 0.22..0.25) - return getString(R.string.positive_for_sickle_cell) - if (calculatedRatio in 0.25..0.35) - return getString(R.string.sickle_cell_disease) - if (calculatedRatio > 0.35) - return getString(R.string.error_repeat_test_lower_volume) - } else { - return getString(R.string.invalid) } } catch (e: Exception) { - showToast(R.string.error_classification) - Firebase.crashlytics.recordException(e) - return getString(R.string.error) + handleException(e) + return "Error" } - return getString(R.string.invalid) + return deviceRatioClass.toString() } fun deviceRatioClassification(ratio: Double?): String { try { if (ratio != null) { - if (ratio in 0.1..0.29) { + if (ratio in 0.001..0.23) { // setSubtitleTextColor(R.color.green_2) return "Normal" } - if (ratio in 0.29..0.32) + if (ratio in 0.23..0.24) return "Negative Borderline, Repeat Test" - if (ratio in 0.32..0.35) + if (ratio in 0.24..0.29) return "Sickle Cell Trait" - if (ratio in 0.35..0.38) + if (ratio in 0.29..0.32) return "Positive for Sickle Cell. HPLC for Confirmation" - if (ratio in 0.38..0.5) + if (ratio in 0.32..Double.POSITIVE_INFINITY) return "Sickle Cell Disease" } else { return "Invalid" diff --git a/app/src/main/java/com/example/hpostesting/presentation/trueheme/TrueHemeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/trueheme/TrueHemeFragment.kt index de000f5..de444e8 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/trueheme/TrueHemeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/trueheme/TrueHemeFragment.kt @@ -156,7 +156,7 @@ class TrueHemeFragment : Fragment() { when (it) { is Result.Success -> { uploadedToMolbio = true - if (Constants.MOLBIO_INTERGATION) { + if (Constants.MOLBIO_INTEGRATION) { it.data.data?.get(0)?.rawData?.let { it1 -> hemoCubeViewModel.updateMolbioFlag( it1._id diff --git a/app/src/test/java/com/example/hpostesting/HemoCubeFragmentTest.kt b/app/src/test/java/com/example/hpostesting/HemoCubeFragmentTest.kt index b9d1d21..e3c425f 100644 --- a/app/src/test/java/com/example/hpostesting/HemoCubeFragmentTest.kt +++ b/app/src/test/java/com/example/hpostesting/HemoCubeFragmentTest.kt @@ -318,28 +318,28 @@ class HemoCubeFragmentTest { @Test fun testDeviceRatioClassificationNormal() { - val ratio = 0.25 + val ratio = 0.22 val result = hemoCubeFragment.deviceRatioClassification(ratio) assertEquals("Normal", result) } @Test fun testDeviceRatioClassificationNegativeBorderline() { - val ratio = 0.31 + val ratio = 0.235 val result = hemoCubeFragment.deviceRatioClassification(ratio) assertEquals("Negative Borderline, Repeat Test", result) } @Test fun testDeviceRatioClassificationSickleCellTrait() { - val ratio = 0.34 + val ratio = 0.25 val result = hemoCubeFragment.deviceRatioClassification(ratio) assertEquals("Sickle Cell Trait", result) } @Test fun testDeviceRatioClassificationPositiveForSickleCell() { - val ratio = 0.37 + val ratio = 0.31 val result = hemoCubeFragment.deviceRatioClassification(ratio) assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result) } @@ -357,4 +357,18 @@ class HemoCubeFragmentTest { val result = hemoCubeFragment.deviceRatioClassification(ratio) assertEquals("Invalid", result) } + + @Test + fun findResultWithAdditionalMethods_ValidInput_ReturnsNegativeBorderlineRepeatTest() { +// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 70.0)).thenReturn("Negative Borderline, Repeat Test") + val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 70.0) + assertEquals("Negative Borderline, Repeat Test", result) + } + + @Test + fun findResultWithAdditionalMethods_ValidInput_ReturnsDeviceRatioClassToString() { +// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0)).thenReturn("Invalid") + val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0) + assertEquals("Abnormal", result) + } } \ No newline at end of file