Merge branch 'blood-group' into 'Homocube'

Blood group

See merge request sminnovations/hpos!1
This commit is contained in:
Mariya Varghese
2023-08-16 10:22:40 +00:00
4 changed files with 48 additions and 12 deletions

View File

@@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import com.example.hpostesting.data.DataHolder
import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.data.constant.HemoCubeCommands
@@ -20,8 +21,15 @@ import com.example.hpostesting.presentation.UsbServiceListener
import com.example.hpostesting.presentation.dashboard.DashboardActivity
import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
import kotlin.math.log10
class HemoCubeFragment : Fragment() {
@@ -34,7 +42,7 @@ class HemoCubeFragment : Fragment() {
private var resultData: String = ""
private var isUsingExistingBuffer = false
private var isTestOngoing = false
private var bloodGroup: String = ""
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
@@ -53,6 +61,15 @@ class HemoCubeFragment : Fragment() {
private fun initViews() {
binding.btnSubmit.setOnClickListener {
val bloodGroupText = binding.etBloodGroup.text.toString()
if (bloodGroupText.isNullOrBlank() || bloodGroupText == "Select Blood Group") {
binding.etBloodGroup.error = "Please enter your blood group"
Toast.makeText(context, "Please enter your blood group", Toast.LENGTH_SHORT).show()
} else {
binding.etBloodGroup.error = null
bloodGroup = bloodGroupText
checkBloodGroup()
}
it.isEnabled = false
binding.progressBar.visibility = View.VISIBLE
fetchResult()
@@ -91,6 +108,24 @@ class HemoCubeFragment : Fragment() {
}
}
private fun checkBloodGroup() {
binding.apply {
// bloodGroup = etBloodGroup.text.toString()
val db: FirebaseFirestore = Firebase.firestore
// Launch a new coroutine scope
lifecycleScope.launch {
val userdata =
db.collection("patientData").whereEqualTo("_id", hemoCubeViewModel.testDetails?._id)
.get().await()
if (userdata.documents.isNotEmpty()) {
db.collection("patientData").document(userdata.documents[0].id)
.update("bloodGroup", bloodGroup)
}
}
}
}
private fun observeViewModel() {
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
if (result == "Success") {

View File

@@ -30,7 +30,7 @@ class HemoCubeViewModel @Inject constructor(
) : ViewModel() {
var isServiceConnected = false
val progressBar = MutableLiveData(false)
private val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
val messages = MutableLiveData<String>()
private val sharedPreference: SharedPreferences = context.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)