Blood group
This commit is contained in:
@@ -15,7 +15,7 @@ android {
|
||||
namespace 'in.sminnovations.hpostesting'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "in.sminnovations.hpostesting"
|
||||
applicationId "in.sminnovations.hpostesting.prod"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 2
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -63,17 +62,11 @@ class HemoCubeFragment : Fragment() {
|
||||
private fun initViews() {
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
val bloodGroupText = binding.etBloodGroup.text.toString()
|
||||
if (bloodGroupText.isNullOrBlank() || bloodGroupText == "Select Blood Group") {
|
||||
if (bloodGroupText.isEmpty()) {
|
||||
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()
|
||||
fetchResult()
|
||||
}
|
||||
it.isEnabled = false
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
fetchResult()
|
||||
}
|
||||
if (isTestOngoing) {
|
||||
binding.btnKit.visibility = View.GONE
|
||||
@@ -112,19 +105,25 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkBloodGroup() {
|
||||
private suspend 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()
|
||||
val bloodGroup = etBloodGroup.text.toString()
|
||||
if (bloodGroup.isEmpty()) {
|
||||
etBloodGroup.error = "Please enter your blood group"
|
||||
} else {
|
||||
val db: FirebaseFirestore = Firebase.firestore
|
||||
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)
|
||||
withContext(Dispatchers.Main) {
|
||||
val i = Intent(
|
||||
requireContext().applicationContext, DashboardActivity::class.java
|
||||
)
|
||||
startActivity(i)
|
||||
(activity as HemocubeActivity).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,7 +133,9 @@ class HemoCubeFragment : Fragment() {
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
showToast("Test Results Uploaded Successfully")
|
||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
||||
lifecycleScope.launch {
|
||||
checkBloodGroup()
|
||||
}
|
||||
}
|
||||
if (result == "Local") {
|
||||
showToast("Internet not available, test details stored locally")
|
||||
@@ -144,7 +145,7 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID,""))
|
||||
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID, ""))
|
||||
|
||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
||||
currentDeviceData = it
|
||||
@@ -153,17 +154,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||
apply {
|
||||
DataHolder.hemoCubeTestData?.let {
|
||||
currentDeviceData?.coefficients?.let { coefficients ->
|
||||
val coefficient1 = coefficients[0]
|
||||
val coefficient2 = coefficients[1]
|
||||
val result = coefficient1 * coefficient2
|
||||
showToast("Result: $result")
|
||||
}
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
}
|
||||
|
||||
hemoCubeViewModel.messages.observe(viewLifecycleOwner) {
|
||||
@@ -349,7 +340,15 @@ class HemoCubeFragment : Fragment() {
|
||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||
val deviceRatio = led1Average / led2Average
|
||||
if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) {
|
||||
if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) {
|
||||
if (deviceRatio < 0.08) {
|
||||
if (deviceRatio > 1.07) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DataHolder.hemoCubeTestData?.apply {
|
||||
deviceId = deviceSerialNo
|
||||
led1Buffer = led1BufferForDevice
|
||||
@@ -374,7 +373,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
|
||||
}
|
||||
|
||||
@@ -387,8 +386,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private fun startBufferProcess() {
|
||||
hemoCubeViewModel.progressBar.postValue(true)
|
||||
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
|
||||
HemoCubeCommands.startBuffer,
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
@@ -401,8 +399,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private fun startSampleProcess() {
|
||||
hemoCubeViewModel.progressBar.postValue(true)
|
||||
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
|
||||
HemoCubeCommands.startSample,
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
@@ -415,8 +412,7 @@ class HemoCubeFragment : Fragment() {
|
||||
private fun fetchResult() {
|
||||
hemoCubeViewModel.progressBar.postValue(true)
|
||||
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
|
||||
HemoCubeCommands.getSample,
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.getSample,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user