Counselling app displaying Image Probability ratio added
This commit is contained in:
@@ -117,6 +117,7 @@ class DigitalCardFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SuspiciousIndentation")
|
||||
private fun loadUserDetails(selectedAbhaId: String) {
|
||||
try {
|
||||
val patientQuery = Firebase.firestore.collection("patientData")
|
||||
|
||||
@@ -12,9 +12,11 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.bumptech.glide.Glide
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
@@ -25,7 +27,7 @@ import com.smi.counselling.data.DataHolder
|
||||
import com.smi.counselling.databinding.FragmentHomeBinding
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.Locale
|
||||
|
||||
data class ClassificationResult(val imageResource: Int, val text: String,val imageResource1: Int)
|
||||
@AndroidEntryPoint
|
||||
class HomeFragment : Fragment() {
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
@@ -83,7 +85,8 @@ class HomeFragment : Fragment() {
|
||||
when {
|
||||
binding.maledetails.visibility == View.VISIBLE && binding.femaledetails.visibility == View.VISIBLE -> {
|
||||
binding.btnSubmit.visibility = View.GONE
|
||||
classifyAndDisplay(testDetails, binding.result)
|
||||
binding.resultImage.visibility = View.VISIBLE
|
||||
classifyAndDisplay(testDetails, binding.resultImage,binding.result,binding.resultratioimg)
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +123,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
// Setup adapters outside the runOnUiThread block
|
||||
val femaleAdapter =
|
||||
ArrayAdapter(requireContext(), R.layout.dropdown_item, femaleAbhaIdList)
|
||||
|
||||
@@ -266,9 +268,16 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
|
||||
private fun classifyAndDisplay(hemoCubeTestData: HemoCubeTestData?, textView: TextView) {
|
||||
private fun classifyAndDisplay(
|
||||
hemoCubeTestData: HemoCubeTestData?,
|
||||
imageView: ImageView,
|
||||
textView: TextView,
|
||||
imageView1: ImageView
|
||||
) {
|
||||
activity?.runOnUiThread {
|
||||
binding.resultImage.visibility = View.VISIBLE
|
||||
binding.result.visibility = View.VISIBLE
|
||||
binding.resultratioimg.visibility = View.VISIBLE
|
||||
binding.maledetails.visibility = View.GONE
|
||||
binding.femaledetails.visibility = View.GONE
|
||||
val parent1Classification = maleresult
|
||||
@@ -277,54 +286,78 @@ class HomeFragment : Fragment() {
|
||||
Log.e("Result", "Parent 1 Classification: $parent1Classification")
|
||||
Log.e("Result", "Parent 2 Classification: $parent2Classification")
|
||||
|
||||
val classification = classifyChild(parent1Classification, parent2Classification)
|
||||
Log.e("Result", "Classification Result: $classification")
|
||||
textView.text = "Sickle-cell-Result: $classification"
|
||||
val classificationResult = classifyChild(parent1Classification, parent2Classification)
|
||||
Glide.with(this)
|
||||
.load(classificationResult.imageResource)
|
||||
.into(imageView)
|
||||
textView.text = classificationResult.text
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun classifyChild(
|
||||
parent1Classification: String,
|
||||
parent2Classification: String
|
||||
): String {
|
||||
): ClassificationResult {
|
||||
val parent1 = parent1Classification.trim().lowercase(Locale.getDefault())
|
||||
val parent2 = parent2Classification.trim().lowercase(Locale.getDefault())
|
||||
|
||||
return when {
|
||||
parent1 == "sickle cell disease" && parent2 == "sickle cell disease" -> {
|
||||
"child will be 100% chance of the child having the disease"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_1,
|
||||
"If both parents have sickle cell disease, there is a 100% chance that their children will be born with the disease",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
parent1 == "sickle cell trait" && parent2 == "sickle cell disease" -> {
|
||||
"child will be 50% chance of being diseased and 50% chance of being a carrier"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_2,"If one parent has sickle cell trait and the other has sickle cell disease, then children have a 50% chance of being diseased and 50% of being carriers",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
parent1 == "sickle cell disease" && parent2 == "sickle cell trait" -> {
|
||||
"child will be 50% chance of being diseased and 50% chance of being a carrier"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_2,"If one parent has sickle cell trait and the other has sickle cell disease, then children have a 50% chance of being diseased and 50% of being carriers",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
parent1 == "normal" && parent2 == "sickle cell disease" -> {
|
||||
"child will be 100% chance of being a carrier"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_3,"if one parent is normal and the other has sickle cell disease, then children have a 100% chance of being carriers",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
parent1 == "sickle cell disease" && parent2 == "normal" -> {
|
||||
"child will be 100% chance of being a carrier"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_3,"if one parent is normal and the other has sickle cell disease, then children have a 100% chance of being carriers",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
parent1 == "sickle cell trait" && parent2 == "sickle cell trait" -> {
|
||||
"child will be 25% chance of being diseased, 25% chance of being normal, and 50% chance of being a carrier"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_4,"if both parents have sickle cell trait, their children have a 25% chance of being diseased, a 25% chance of being normal, \n" +
|
||||
"and a 50% chance of being carriers",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
parent1 == "sickle cell trait" && parent2 == "normal" -> {
|
||||
"child will be 50% chance of being normal and 50% chance of being a carrier"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_5,"If one parent has sickle cell trait and the other is normal, then children have a 50% chance of being normal and 50% \n" +
|
||||
"chance of being carriers",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
parent1 == "normal" && parent2 == "sickle cell trait" -> {
|
||||
"child will be 50% chance of being normal and 50% chance of being a carrier"
|
||||
ClassificationResult(
|
||||
R.drawable.sicklecell_5,"If one parent has sickle cell trait and the other is normal, then children have a 50% chance of being normal and 50% \n" +
|
||||
"chance of being carriers",R.drawable.sicklecell_6
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
"Unknown result"
|
||||
ClassificationResult(R.drawable.sickle_cell_gov_logo, "No Match found",R.drawable.sicklecell_6)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,5 +367,17 @@ class HomeFragment : Fragment() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
|
||||
private fun setImageResource(context: Context, imageResource: Int) {
|
||||
when (context) {
|
||||
is Fragment -> {
|
||||
val imageView = context.view?.findViewById<ImageView>(R.id.resultImage)
|
||||
imageView?.setImageResource(imageResource)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unsupported context type")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
BIN
app/src/main/res/drawable/sicklecell_1.png
Normal file
BIN
app/src/main/res/drawable/sicklecell_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
BIN
app/src/main/res/drawable/sicklecell_2.png
Normal file
BIN
app/src/main/res/drawable/sicklecell_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
app/src/main/res/drawable/sicklecell_3.png
Normal file
BIN
app/src/main/res/drawable/sicklecell_3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
app/src/main/res/drawable/sicklecell_4.png
Normal file
BIN
app/src/main/res/drawable/sicklecell_4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.0 KiB |
BIN
app/src/main/res/drawable/sicklecell_5.png
Normal file
BIN
app/src/main/res/drawable/sicklecell_5.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
app/src/main/res/drawable/sicklecell_6.png
Normal file
BIN
app/src/main/res/drawable/sicklecell_6.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -219,20 +219,46 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/maledetails" />
|
||||
|
||||
<!-- ... Other views ... -->
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/result"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="150dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="50dp"
|
||||
android:textColor="@color/red"
|
||||
android:textStyle="bold"
|
||||
android:textSize="15sp"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/resultImage"
|
||||
android:text="Sicklecell: normal" />
|
||||
<ImageView
|
||||
android:id="@+id/resultImage"
|
||||
android:visibility="invisible"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:scaleType="fitCenter"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/resultratioimg"
|
||||
app:srcCompat="@drawable/sicklecell_6"/>
|
||||
<ImageView
|
||||
android:id="@+id/resultratioimg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:visibility="gone"
|
||||
android:layout_weight="1"
|
||||
android:scaleType="fitCenter"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_submit"
|
||||
android:text="Sicklecell: normal" />
|
||||
app:srcCompat="@drawable/sicklecell_6" />
|
||||
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_digital"
|
||||
|
||||
Reference in New Issue
Block a user