diff --git a/app/src/main/java/com/smi/counselling/data/dashboard/DigitalCardFragment.kt b/app/src/main/java/com/smi/counselling/data/dashboard/DigitalCardFragment.kt index 348f8d9..04637d6 100644 --- a/app/src/main/java/com/smi/counselling/data/dashboard/DigitalCardFragment.kt +++ b/app/src/main/java/com/smi/counselling/data/dashboard/DigitalCardFragment.kt @@ -117,6 +117,7 @@ class DigitalCardFragment : Fragment() { } } + @SuppressLint("SuspiciousIndentation") private fun loadUserDetails(selectedAbhaId: String) { try { val patientQuery = Firebase.firestore.collection("patientData") diff --git a/app/src/main/java/com/smi/counselling/data/dashboard/HomeFragment.kt b/app/src/main/java/com/smi/counselling/data/dashboard/HomeFragment.kt index 0234d99..6d165c0 100644 --- a/app/src/main/java/com/smi/counselling/data/dashboard/HomeFragment.kt +++ b/app/src/main/java/com/smi/counselling/data/dashboard/HomeFragment.kt @@ -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) @@ -129,7 +131,7 @@ class HomeFragment : Fragment() { activity?.runOnUiThread { - binding.abhaidtext.addTextChangedListener(object : TextWatcher { + binding.abhaidtext.addTextChangedListener(object : TextWatcher{ override fun beforeTextChanged( s: CharSequence?, start: Int, @@ -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(R.id.resultImage) + imageView?.setImageResource(imageResource) + } + else -> throw IllegalArgumentException("Unsupported context type") + } + } + } diff --git a/app/src/main/res/drawable/sicklecell_1.png b/app/src/main/res/drawable/sicklecell_1.png new file mode 100644 index 0000000..2a4bb77 Binary files /dev/null and b/app/src/main/res/drawable/sicklecell_1.png differ diff --git a/app/src/main/res/drawable/sicklecell_2.png b/app/src/main/res/drawable/sicklecell_2.png new file mode 100644 index 0000000..1ea89e4 Binary files /dev/null and b/app/src/main/res/drawable/sicklecell_2.png differ diff --git a/app/src/main/res/drawable/sicklecell_3.png b/app/src/main/res/drawable/sicklecell_3.png new file mode 100644 index 0000000..c4f7006 Binary files /dev/null and b/app/src/main/res/drawable/sicklecell_3.png differ diff --git a/app/src/main/res/drawable/sicklecell_4.png b/app/src/main/res/drawable/sicklecell_4.png new file mode 100644 index 0000000..8ada5af Binary files /dev/null and b/app/src/main/res/drawable/sicklecell_4.png differ diff --git a/app/src/main/res/drawable/sicklecell_5.png b/app/src/main/res/drawable/sicklecell_5.png new file mode 100644 index 0000000..f70f66b Binary files /dev/null and b/app/src/main/res/drawable/sicklecell_5.png differ diff --git a/app/src/main/res/drawable/sicklecell_6.png b/app/src/main/res/drawable/sicklecell_6.png new file mode 100644 index 0000000..c999c52 Binary files /dev/null and b/app/src/main/res/drawable/sicklecell_6.png differ diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 6b0fc10..17fb0d1 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -219,20 +219,46 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/maledetails" /> + + + + + + app:srcCompat="@drawable/sicklecell_6" /> + +