Counselling app displaying Image Probability ratio added

This commit is contained in:
Mariya
2024-01-22 09:23:16 +05:30
parent 1413145976
commit 659d56123e
9 changed files with 95 additions and 23 deletions

View File

@@ -117,6 +117,7 @@ class DigitalCardFragment : Fragment() {
} }
} }
@SuppressLint("SuspiciousIndentation")
private fun loadUserDetails(selectedAbhaId: String) { private fun loadUserDetails(selectedAbhaId: String) {
try { try {
val patientQuery = Firebase.firestore.collection("patientData") val patientQuery = Firebase.firestore.collection("patientData")

View File

@@ -12,9 +12,11 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels 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.HemoCubeTestData
import com.example.hpostesting.data.model.patient.toHemoCubeTestData import com.example.hpostesting.data.model.patient.toHemoCubeTestData
import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.crashlytics.ktx.crashlytics
@@ -25,7 +27,7 @@ import com.smi.counselling.data.DataHolder
import com.smi.counselling.databinding.FragmentHomeBinding import com.smi.counselling.databinding.FragmentHomeBinding
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import java.util.Locale import java.util.Locale
data class ClassificationResult(val imageResource: Int, val text: String,val imageResource1: Int)
@AndroidEntryPoint @AndroidEntryPoint
class HomeFragment : Fragment() { class HomeFragment : Fragment() {
private var _binding: FragmentHomeBinding? = null private var _binding: FragmentHomeBinding? = null
@@ -83,7 +85,8 @@ class HomeFragment : Fragment() {
when { when {
binding.maledetails.visibility == View.VISIBLE && binding.femaledetails.visibility == View.VISIBLE -> { binding.maledetails.visibility == View.VISIBLE && binding.femaledetails.visibility == View.VISIBLE -> {
binding.btnSubmit.visibility = View.GONE 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 = val femaleAdapter =
ArrayAdapter(requireContext(), R.layout.dropdown_item, femaleAbhaIdList) 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 { activity?.runOnUiThread {
binding.resultImage.visibility = View.VISIBLE
binding.result.visibility = View.VISIBLE binding.result.visibility = View.VISIBLE
binding.resultratioimg.visibility = View.VISIBLE
binding.maledetails.visibility = View.GONE binding.maledetails.visibility = View.GONE
binding.femaledetails.visibility = View.GONE binding.femaledetails.visibility = View.GONE
val parent1Classification = maleresult val parent1Classification = maleresult
@@ -277,54 +286,78 @@ class HomeFragment : Fragment() {
Log.e("Result", "Parent 1 Classification: $parent1Classification") Log.e("Result", "Parent 1 Classification: $parent1Classification")
Log.e("Result", "Parent 2 Classification: $parent2Classification") Log.e("Result", "Parent 2 Classification: $parent2Classification")
val classification = classifyChild(parent1Classification, parent2Classification) val classificationResult = classifyChild(parent1Classification, parent2Classification)
Log.e("Result", "Classification Result: $classification") Glide.with(this)
textView.text = "Sickle-cell-Result: $classification" .load(classificationResult.imageResource)
.into(imageView)
textView.text = classificationResult.text
} }
} }
private fun classifyChild( private fun classifyChild(
parent1Classification: String, parent1Classification: String,
parent2Classification: String parent2Classification: String
): String { ): ClassificationResult {
val parent1 = parent1Classification.trim().lowercase(Locale.getDefault()) val parent1 = parent1Classification.trim().lowercase(Locale.getDefault())
val parent2 = parent2Classification.trim().lowercase(Locale.getDefault()) val parent2 = parent2Classification.trim().lowercase(Locale.getDefault())
return when { return when {
parent1 == "sickle cell disease" && parent2 == "sickle cell disease" -> { 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" -> { 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" -> { 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" -> { 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" -> { 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" -> { 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" -> { 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" -> { 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 -> { 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() super.onDestroyView()
_binding = null _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")
}
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -219,20 +219,46 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/maledetails" /> app:layout_constraintTop_toBottomOf="@id/maledetails" />
<!-- ... Other views ... -->
<TextView <TextView
android:id="@+id/result" android:id="@+id/result"
android:layout_width="200dp" android:layout_width="wrap_content"
android:layout_height="150dp" android:layout_height="wrap_content"
android:visibility="gone" android:visibility="gone"
android:gravity="center" android:gravity="center"
android:layout_marginTop="50dp"
android:textColor="@color/red" android:textColor="@color/red"
android:textStyle="bold" 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_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_submit" app:layout_constraintTop_toBottomOf="@id/btn_submit"
android:text="Sicklecell: normal" /> app:srcCompat="@drawable/sicklecell_6" />
<Button <Button
android:id="@+id/btn_digital" android:id="@+id/btn_digital"