refactor and add tests

This commit is contained in:
Pritimay Sarkar
2024-01-26 11:20:13 +05:30
parent 3c4a1fa56b
commit 63331c2253
5 changed files with 121 additions and 28 deletions

View File

@@ -888,36 +888,38 @@ class HemoCubeFragment : Fragment() {
fun deviceRatioClassification(ratio: Double?): String {
try {
hemoCubeViewModel.messages.postValue("result classification")
if (ratio != null) {
if (ratio in 0.2..0.29) {
activity?.runOnUiThread {
binding.tvSubtitle4.setTextColor(
ContextCompat.getColor(
requireContext(),
R.color.green_2
)
)
}
return getString(R.string.normal)
// setSubtitleTextColor(R.color.green_2)
return "Normal"
}
if (ratio in 0.29..0.32)
return getString(R.string.negative_borderline)
return "Negative Borderline, Repeat Test"
if (ratio in 0.32..0.35)
return getString(R.string.sickle_cell_trait)
return "Sickle Cell Trait"
if (ratio in 0.35..0.38)
return getString(R.string.positive_for_sickle_cell)
return "Positive for Sickle Cell. HPLC for Confirmation"
if (ratio in 0.38..0.5)
return getString(R.string.sickle_cell_disease)
return "Sickle Cell Disease"
} else {
return getString(R.string.invalid)
return "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 "Invalid"
}
fun setSubtitleTextColor(colorResId: Int) {
activity?.runOnUiThread {
binding.tvSubtitle4.setTextColor(ContextCompat.getColor(requireContext(), colorResId))
}
}
fun handleException(e: Exception) {
showToast(R.string.error_classification)
Firebase.crashlytics.recordException(e)
}
fun slopeRatioClassification(ratio: Double?): String {