Compare commits
10 Commits
Bloodgroup
...
Bufferchec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac2bb91648 | ||
|
|
9db8e962d7 | ||
|
|
497a61c16b | ||
|
|
acd9262dfe | ||
|
|
f8ac0e81ce | ||
|
|
5a7a09817f | ||
|
|
ab09c659b9 | ||
|
|
14c15bb9ab | ||
|
|
0ca4083c16 | ||
|
|
662e2644f2 |
@@ -0,0 +1,19 @@
|
||||
package com.example.hpostesting.data.model.patient
|
||||
|
||||
data class BufferCheckData(
|
||||
var kitno: String = "",
|
||||
var deviceId: String? = "",
|
||||
var appVersion:String? = "",
|
||||
var deviceSerialNumber: String = "",
|
||||
var deviceType: String = "HEMOCUBE",
|
||||
var resultData: String = "",
|
||||
var led1Buffer: Double? = null,
|
||||
var led2Buffer: Double? = null,
|
||||
var led1Sample: Double? = null,
|
||||
var led2Sample: Double? = null,
|
||||
var led1Average: Double? = null,
|
||||
var led2Average: Double? = null,
|
||||
var deviceRatio: Double? = null,
|
||||
var calculatedRatio: Double? = null,
|
||||
var classificationResult: String = ""
|
||||
)
|
||||
@@ -1,25 +1,19 @@
|
||||
package com.example.hpostesting.data.repository
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.room.Room
|
||||
import com.example.hpostesting.data.dao.MyDatabase
|
||||
import com.example.hpostesting.data.model.PendingUploads
|
||||
import com.example.hpostesting.data.model.Response
|
||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.google.android.datatransport.runtime.dagger.Provides
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import com.google.firebase.firestore.ktx.firestore
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import com.google.firebase.storage.ktx.storage
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import javax.inject.Singleton
|
||||
|
||||
class DatabaseRepository : Repository {
|
||||
|
||||
@@ -57,6 +51,16 @@ class DatabaseRepository : Repository {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun addTestToDatabaseforBufferCheck(data: BufferCheckData?): Response<String> {
|
||||
return try {
|
||||
db.collection("buffers").add(data!!).await()
|
||||
Response.Success(data!!.kitno)
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean> {
|
||||
try {
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.hpostesting.presentation.adapter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -20,9 +22,20 @@ import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import android.widget.AutoCompleteTextView
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
|
||||
class UserListAdapter(
|
||||
options: FirestoreRecyclerOptions<UserData>, private val view: View, private val batLevel: Int
|
||||
|
||||
private val context: Context,
|
||||
private val hemoCubeViewModel: HemoCubeViewModel,
|
||||
options: FirestoreRecyclerOptions<UserData>,
|
||||
private val view: View,
|
||||
private val batLevel: Int,
|
||||
private val testDetails: HemoCubeTestData? = DataHolder.selectedTest?.toHemoCubeTestData(),
|
||||
) : FirestoreRecyclerAdapter<UserData, UserListAdapter.OrderItemViewHolder>(options) {
|
||||
|
||||
class OrderItemViewHolder(val binding: UserItemViewBinding) :
|
||||
@@ -40,7 +53,7 @@ class UserListAdapter(
|
||||
userName.text = "Name: ${model.name}"
|
||||
userId.text = "User ID:${model._id}"
|
||||
if (model.incubationTime == "") {
|
||||
btnStartIncubation.visibility = View.VISIBLE
|
||||
// btnStartIncubation.visibility = View.VISIBLE
|
||||
} else {
|
||||
userId.text =
|
||||
"User ID:${model._id} \n Time: ${isBetween15And30Minutes(model.incubationTime)} \n Started at: ${
|
||||
@@ -61,26 +74,106 @@ class UserListAdapter(
|
||||
} else {
|
||||
teststatus.text = "Test is Pending"
|
||||
}
|
||||
btnStartIncubation.setOnClickListener {
|
||||
it.visibility = View.GONE
|
||||
Firebase.firestore.collection("patientData").whereEqualTo("_id", model._id).get()
|
||||
.addOnSuccessListener { data ->
|
||||
if (data.documents.isNotEmpty()) {
|
||||
data.documents.forEach { userData ->
|
||||
Firebase.firestore.collection("patientData").document(userData.id)
|
||||
.update(
|
||||
|
||||
holder.binding.btnBlood.setOnClickListener {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val dialogView = inflater.inflate(R.layout.dialog_custom, null)
|
||||
|
||||
val builder = AlertDialog.Builder(context)
|
||||
.setView(dialogView)
|
||||
.setTitle("Add Blood Group")
|
||||
|
||||
val etBloodGroup = dialogView.findViewById<AutoCompleteTextView>(R.id.et_blood_group)
|
||||
|
||||
builder.setPositiveButton("OK") { dialog, which ->
|
||||
val bloodGroup = etBloodGroup.text.toString()
|
||||
if (bloodGroup.equals("Select Blood Group") || bloodGroup.isNullOrBlank()) {
|
||||
etBloodGroup.error = "Please enter your blood group"
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Please enter your blood group",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
// Check if hemoCubeViewModel and testDetails are not null
|
||||
val db: FirebaseFirestore = FirebaseFirestore.getInstance()
|
||||
|
||||
db.collection("patientData")
|
||||
.whereEqualTo("_id", model._id)
|
||||
.get()
|
||||
.addOnSuccessListener { userdata ->
|
||||
try {
|
||||
val document = userdata.documents[0]
|
||||
db.collection("patientData")
|
||||
.document(document.id)
|
||||
.update("bloodGroup", bloodGroup,
|
||||
"incubationTime", SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time).toString()
|
||||
).addOnSuccessListener {
|
||||
)
|
||||
.addOnSuccessListener {
|
||||
Toast.makeText(
|
||||
view.context, "Incubation started", Toast.LENGTH_SHORT
|
||||
context,
|
||||
"Blood group updated successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Failed to update blood group: ${e.message}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
// Handle the case where no documents are found for the specified ID
|
||||
Toast.makeText(
|
||||
context,
|
||||
"No user data found for the specified ID",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Error fetching user data: ${e.message}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
startListening()
|
||||
}
|
||||
}
|
||||
// Handle the selected blood group here
|
||||
}
|
||||
|
||||
builder.setNegativeButton("Cancel") { dialog, which ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
val alertDialog = builder.create()
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
btnStartIncubation.setOnClickListener {
|
||||
// it.visibility = View.GONE
|
||||
// Firebase.firestore.collection("patientData").whereEqualTo("_id", model._id).get()
|
||||
// .addOnSuccessListener { data ->
|
||||
// if (data.documents.isNotEmpty()) {
|
||||
// data.documents.forEach { userData ->
|
||||
// Firebase.firestore.collection("patientData").document(userData.id)
|
||||
// .update(
|
||||
// "incubationTime", SimpleDateFormat(
|
||||
// "yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
// ).format(Calendar.getInstance().time).toString()
|
||||
// ).addOnSuccessListener {
|
||||
// Toast.makeText(
|
||||
// view.context, "Incubation started", Toast.LENGTH_SHORT
|
||||
// ).show()
|
||||
// startListening()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
userCard.setOnClickListener {
|
||||
if (batLevel < 40) {
|
||||
@@ -130,6 +223,8 @@ class UserListAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun isBetween15And30Minutes(createdAt: String): Long {
|
||||
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
val createdAtDate: Date = formatter.parse(createdAt)!!
|
||||
@@ -142,4 +237,9 @@ class UserListAdapter(
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.hpostesting.presentation.buffercheck
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
@@ -13,9 +14,11 @@ import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||
import com.example.hpostesting.presentation.utils.UIUtils
|
||||
@@ -32,6 +35,8 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
private var currentDeviceData: DeviceData? = null
|
||||
private var resultData: String = ""
|
||||
private var kitno: String = ""
|
||||
private var isOnline = false
|
||||
private val messages = MutableLiveData<String>()
|
||||
private var isTestOngoing = false
|
||||
private var startListening = MutableLiveData(false)
|
||||
@@ -51,15 +56,43 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
binding.btnKit.visibility = View.GONE
|
||||
binding.btnSubmit.visibility = View.GONE
|
||||
binding.etBloodGroup.visibility = View.GONE
|
||||
|
||||
binding.nameEditText.setText("SMI/SC/")
|
||||
|
||||
binding.btnGo.setOnClickListener {
|
||||
val serialNumber = binding.nameEditText.text.toString().trim()
|
||||
if (serialNumber.isNotEmpty() && isSerialValid(serialNumber)) {
|
||||
kitno = serialNumber
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
} else {
|
||||
Toast.makeText(context, "Invalid KIT Number", Toast.LENGTH_LONG).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
activity?.runOnUiThread {
|
||||
binding.tvSubtitle2.visibility = View.GONE
|
||||
binding.etAbhaId.visibility = View.GONE
|
||||
binding.tvTitle.visibility = View.GONE
|
||||
binding.tvTitle2.visibility = View.GONE
|
||||
binding.btnGo.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
|
||||
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
}
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
|
||||
}
|
||||
binding.btnSubmit.isEnabled = false
|
||||
binding.btnSubmit.isClickable = false
|
||||
}
|
||||
|
||||
|
||||
private fun observeViewModel() {
|
||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
||||
currentDeviceData = it
|
||||
}
|
||||
@@ -69,11 +102,20 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID, ""))
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"No internet connection avaiable",
|
||||
Toast.LENGTH_SHORT
|
||||
requireContext(), "No internet connection avaiable", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
}
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
showToast("Kit result uploaded successfully")
|
||||
}
|
||||
if (result == "Local") {
|
||||
showToast("Kit result uploading failed, note it down manually")
|
||||
}
|
||||
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
messages.observe(viewLifecycleOwner) {
|
||||
@@ -118,10 +160,14 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
resultData += fullReadOutput.toString()
|
||||
|
||||
when {
|
||||
stringData.contains("ERROR 500") -> showError500Dialog()
|
||||
stringData.contains("ERROR 501") -> showError501Dialog()
|
||||
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||
stringData.contains("#Sample Completed") -> fetchResult()
|
||||
stringData.contains("#Sample Completed") -> {
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSubmit.isEnabled = true
|
||||
binding.btnSubmit.isClickable = true
|
||||
}
|
||||
fetchResult()
|
||||
}
|
||||
|
||||
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
||||
var validString: String
|
||||
@@ -143,40 +189,6 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun showError500Dialog() {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
"BUFFER ERROR",
|
||||
"Do you want to continue with existing buffer?",
|
||||
getString(R.string.noo),
|
||||
"Yes",
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
|
||||
override fun onClickPositiveButton() {
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
private fun showError501Dialog() {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
"SAMPLE ERROR",
|
||||
"Do you want to continue with Sample?",
|
||||
getString(R.string.noo),
|
||||
"Yes",
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {}
|
||||
|
||||
override fun onClickPositiveButton() {
|
||||
listenToHemoCube()
|
||||
startSampleProcess()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun showStartSampleDialog() {
|
||||
activity?.runOnUiThread {
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
@@ -199,6 +211,7 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
try {
|
||||
val result = validString.split(" ")
|
||||
if (result.size == 8) {
|
||||
val deviceSerialNo = result[2]
|
||||
val led1BufferForDevice = result[3].toDoubleOrNull()
|
||||
val led2BufferForDevice = result[4].toDoubleOrNull()
|
||||
val led1Sample = result[5].toDoubleOrNull()
|
||||
@@ -206,9 +219,23 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||
val deviceRatio = led1Average / led2Average
|
||||
val calculatedRatio = calculateRatio(deviceRatio)
|
||||
val calculatedRatio = 0.14
|
||||
val classificationResult = findResult(calculatedRatio)
|
||||
messages.postValue(classificationResult)
|
||||
val bufferData = BufferCheckData(
|
||||
kitno = kitno,
|
||||
led1Buffer = led1BufferForDevice,
|
||||
led2Buffer = led2BufferForDevice,
|
||||
led1Average = led1Average,
|
||||
led2Average = led2Average,
|
||||
led1Sample = led1Sample,
|
||||
led2Sample = led2Sample,
|
||||
deviceRatio = deviceRatio,
|
||||
calculatedRatio = calculatedRatio,
|
||||
classificationResult = classificationResult,
|
||||
deviceSerialNumber = deviceSerialNo
|
||||
)
|
||||
hemoCubeViewModel.uploadHemoCubeResultToDatabaseforbuffercheckN(bufferData)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(
|
||||
@@ -245,8 +272,7 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
|
||||
private fun startBufferProcess() {
|
||||
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(
|
||||
HemoCubeCommands.startBuffer,
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
@@ -257,8 +283,7 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
|
||||
private fun startSampleProcess() {
|
||||
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(
|
||||
HemoCubeCommands.startSample,
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
@@ -269,8 +294,7 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
|
||||
private fun fetchResult() {
|
||||
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(
|
||||
HemoCubeCommands.getSample,
|
||||
(activity as HemocubeBufferCheckActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.getSample,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {}
|
||||
|
||||
@@ -300,6 +324,15 @@ class HemoCubeBufferCheckFragment : Fragment() {
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun isSerialValid(s: String): Boolean {
|
||||
if (s.length != 17) {
|
||||
binding.nameEditText.error = getString(R.string.invalid_kit)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
private fun isValidResult(line: String): String {
|
||||
return if (line.contains("RESULT") && line.split(" ").size == 8) {
|
||||
line
|
||||
|
||||
@@ -42,6 +42,9 @@ class HomeFragment : Fragment() {
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
private lateinit var rvAdapter: UserListAdapter
|
||||
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
||||
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
@@ -151,8 +154,12 @@ class HomeFragment : Fragment() {
|
||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
|
||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root, batLevel)
|
||||
rvAdapter = view?.let {
|
||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions,
|
||||
it, batLevel)
|
||||
}!!
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
|
||||
rvAdapter.startListening()
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
@@ -195,11 +202,12 @@ class HomeFragment : Fragment() {
|
||||
val recyclerViewOptions =
|
||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||
.build()
|
||||
|
||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
|
||||
rvAdapter = UserListAdapter(recyclerViewOptions, binding.root, batLevel)
|
||||
rvAdapter = view?.let {
|
||||
UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions, it, batLevel)
|
||||
}!!
|
||||
binding.rvOrder.adapter = rvAdapter
|
||||
rvAdapter.startListening()
|
||||
}
|
||||
|
||||
@@ -64,25 +64,25 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
val bloodGroupText = binding.etBloodGroup.text.toString()
|
||||
if (bloodGroupText.isEmpty()) {
|
||||
binding.etBloodGroup.error = "Please enter your blood group"
|
||||
} else {
|
||||
activity?.runOnUiThread {
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
}
|
||||
hemoCubeViewModel.uploadHemoCubeResultToDatabase(
|
||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||
)
|
||||
}
|
||||
}
|
||||
if (isTestOngoing) {
|
||||
binding.btnKit.visibility = View.GONE
|
||||
binding.btnKit.isEnabled = false
|
||||
binding.btnKit.isClickable = false
|
||||
|
||||
}
|
||||
// binding.btnSubmit.setOnClickListener {
|
||||
// val bloodGroupText = binding.etBloodGroup.text.toString()
|
||||
// if (bloodGroupText.isEmpty()) {
|
||||
// binding.etBloodGroup.error = "Please enter your blood group"
|
||||
// } else {
|
||||
// activity?.runOnUiThread {
|
||||
// binding.progressBar.visibility = View.VISIBLE
|
||||
// }
|
||||
// hemoCubeViewModel.uploadHemoCubeResultToDatabase(
|
||||
// isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// if (isTestOngoing) {
|
||||
// binding.btnKit.visibility = View.GONE
|
||||
// binding.btnKit.isEnabled = false
|
||||
// binding.btnKit.isClickable = false
|
||||
//
|
||||
// }
|
||||
binding.btnSubmit.isEnabled = false
|
||||
binding.btnSubmit.isClickable = false
|
||||
|
||||
@@ -90,70 +90,70 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
||||
Log.e("nametext",binding.tvName.text.toString())
|
||||
|
||||
binding.btnKit.setOnClickListener {
|
||||
if (isTestOngoing) {
|
||||
val title = "WARNING"
|
||||
val message = "There is a on going test, do you want to stop it"
|
||||
val negativeText = getString(R.string.no)
|
||||
val positiveText = "Yes"
|
||||
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
title,
|
||||
message,
|
||||
negativeText,
|
||||
positiveText,
|
||||
object : MyDialogListener {
|
||||
override fun onClickNegativeButton() {
|
||||
|
||||
// binding.btnKit.setOnClickListener {
|
||||
// if (isTestOngoing) {
|
||||
// val title = "WARNING"
|
||||
// val message = "There is a on going test, do you want to stop it"
|
||||
// val negativeText = getString(R.string.no)
|
||||
// val positiveText = "Yes"
|
||||
//
|
||||
// UIUtils.createAlertDialog(requireContext(),
|
||||
// title,
|
||||
// message,
|
||||
// negativeText,
|
||||
// positiveText,
|
||||
// object : MyDialogListener {
|
||||
// override fun onClickNegativeButton() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// override fun onClickPositiveButton() {
|
||||
// resetKitCount()
|
||||
// val intent = Intent(context, KitScanActivity::class.java)
|
||||
// startActivity(intent)
|
||||
// (activity as HemocubeActivity).finish()
|
||||
// }
|
||||
// })
|
||||
// } else {
|
||||
// resetKitCount()
|
||||
// val intent = Intent(context, KitScanActivity::class.java)
|
||||
// startActivity(intent)
|
||||
// (activity as HemocubeActivity).finish()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onClickPositiveButton() {
|
||||
resetKitCount()
|
||||
val intent = Intent(context, KitScanActivity::class.java)
|
||||
startActivity(intent)
|
||||
(activity as HemocubeActivity).finish()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
resetKitCount()
|
||||
val intent = Intent(context, KitScanActivity::class.java)
|
||||
startActivity(intent)
|
||||
(activity as HemocubeActivity).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkBloodGroup() {
|
||||
binding.apply {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// private suspend fun checkBloodGroup() {
|
||||
// binding.apply {
|
||||
// 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()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun observeViewModel() {
|
||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
showToast("Test Results Uploaded Successfully")
|
||||
lifecycleScope.launch {
|
||||
checkBloodGroup()
|
||||
}
|
||||
// lifecycleScope.launch {
|
||||
// checkBloodGroup()
|
||||
// }
|
||||
}
|
||||
if (result == "Local") {
|
||||
showToast("Internet not available, test details stored locally")
|
||||
@@ -176,7 +176,7 @@ class HemoCubeFragment : Fragment() {
|
||||
val coefficient1 = coefficients[0]
|
||||
val coefficient2 = coefficients[1]
|
||||
val result = coefficient1 * coefficient2
|
||||
showToast("coefficients: $coefficient1, $coefficient2")
|
||||
// showToast("coefficients: $coefficient1, $coefficient2")
|
||||
}
|
||||
}
|
||||
isOnline = isNetworkAvailable
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.example.hpostesting.data.NetworkStatusLiveData
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||
import com.example.hpostesting.data.model.Response
|
||||
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
@@ -69,6 +70,18 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun uploadHemoCubeResultToDatabaseforbuffercheckN(bufferCheckData: BufferCheckData) =
|
||||
viewModelScope.launch {
|
||||
addResultTestToDbforbuffercheck(bufferCheckData)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fun getDeviceData(deviceId: String?) = viewModelScope.launch {
|
||||
deviceData.postValue(deviceId?.let { repository.getDeviceDataById(it) })
|
||||
}
|
||||
@@ -126,6 +139,29 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun addResultTestToDbforbuffercheck(bufferCheckData: BufferCheckData) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
|
||||
when (val response = repository.addTestToDatabaseforBufferCheck(bufferCheckData)) {
|
||||
is Response.Success -> {
|
||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||
fireBaseUpload.postValue("Success")
|
||||
}
|
||||
|
||||
is Response.Error -> {
|
||||
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
||||
fireBaseUpload.postValue("Error")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||
fireBaseUpload.postValue("Error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bulkAddResultTestToDb(userData: HemoCubeTestData) {
|
||||
viewModelScope.launch {
|
||||
userData.reportUploadTime = SimpleDateFormat(
|
||||
|
||||
24
app/src/main/res/layout/dialog_custom.xml
Normal file
24
app/src/main/res/layout/dialog_custom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/til_blood_group"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/et_blood_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/select_blood_group"
|
||||
android:inputType="none"
|
||||
android:labelFor="@id/til_blood_group"
|
||||
app:simpleItems="@array/blood_group" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
@@ -27,7 +27,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/step4"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_title" />
|
||||
@@ -45,6 +44,7 @@
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />-->
|
||||
|
||||
<TextView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/tv_name"
|
||||
style="@style/title2"
|
||||
android:layout_width="0dp"
|
||||
@@ -52,7 +52,7 @@
|
||||
android:layout_marginHorizontal="24dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn_submit" />
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_subtitle4"
|
||||
@@ -66,7 +66,7 @@
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />
|
||||
app:layout_constraintTop_toBottomOf="@id/et_abha_id" />
|
||||
|
||||
|
||||
<!-- <Button-->
|
||||
@@ -98,7 +98,55 @@
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/btn_submit" />-->
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title2"
|
||||
style="@style/title1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="48dp"
|
||||
android:text="@string/enter_kit_serial_number_manually"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/et_abha_id"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintEnd_toStartOf="@id/btn_go"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_title2">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/name_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLength="17"
|
||||
android:inputType="text"
|
||||
android:hint="@string/serial_number" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_go"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="24dp"
|
||||
android:text="@string/go"
|
||||
app:cornerRadius="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/et_abha_id"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toEndOf="@id/et_abha_id"
|
||||
app:layout_constraintTop_toTopOf="@id/et_abha_id" />
|
||||
|
||||
|
||||
<Button
|
||||
android:visibility="gone"
|
||||
android:id="@+id/btn_submit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -109,40 +157,40 @@
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/til_blood_group" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/til_blood_group"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4">
|
||||
<!-- <com.google.android.material.textfield.TextInputLayout-->
|
||||
<!-- android:id="@+id/til_blood_group"-->
|
||||
<!-- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginHorizontal="24dp"-->
|
||||
<!-- android:layout_marginTop="16dp"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/tv_subtitle4">-->
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/et_blood_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/select_blood_group"
|
||||
android:inputType="none"
|
||||
android:labelFor="@id/til_blood_group"
|
||||
app:simpleItems="@array/blood_group" />
|
||||
<!-- <AutoCompleteTextView-->
|
||||
<!-- android:id="@+id/et_blood_group"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:hint="@string/select_blood_group"-->
|
||||
<!-- android:inputType="none"-->
|
||||
<!-- android:labelFor="@id/til_blood_group"-->
|
||||
<!-- app:simpleItems="@array/blood_group" />-->
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<!-- </com.google.android.material.textfield.TextInputLayout>-->
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_kit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="@string/new_kit"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_kit"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_margin="10dp"-->
|
||||
<!-- android:text="@string/new_kit"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
||||
|
||||
<!-- <Button-->
|
||||
<!-- android:id="@+id/btn_buffer"-->
|
||||
@@ -181,7 +229,6 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
||||
|
||||
|
||||
@@ -79,9 +79,17 @@
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/start_incubation"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintStart_toEndOf="@+id/userImage"
|
||||
app:layout_constraintTop_toBottomOf="@+id/teststatus" />
|
||||
|
||||
app:layout_constraintStart_toEndOf="@+id/btn_blood"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/btn_blood" />
|
||||
<Button
|
||||
android:id="@+id/btn_blood"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/blood_group"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toStartOf="@+id/btn_startIncubation"
|
||||
app:layout_constraintTop_toBottomOf="@id/teststatus" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user