diff --git a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt index b79ea1a..e677416 100644 --- a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt +++ b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt @@ -70,4 +70,11 @@ object Constants { const val BUFFER_VALUE_1 = "BufferValue1" const val BUFFER_VALUE_2 = "BufferValue2" const val DEVICE_ID = "DEVICE_ID" + + val COEFFICIENTS: Map>> = mapOf( + "HC-V1-001" to listOf( + listOf(1.5,0.0), + listOf(0.0,0.0) + ) + ) } \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt b/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt index 1b6c95d..ee6f2ad 100644 --- a/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt +++ b/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt @@ -11,6 +11,7 @@ data class UserData( var name: String = "", var incubationTime: String = "", var birthYear: String = "", + var bloodGroup: String = "", var userImageURL: String = "", var location: Location? = null, var createdBy: String? = "", @@ -41,6 +42,7 @@ data class UserData( fun UserData.toHemoCubeTestData() = HemoCubeTestData( _id = _id, name = name, + bloodGroup = bloodGroup, birthYear = birthYear, userImageURL = userImageURL, testStatus = testStatus, diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt index 19baf33..a3ff49b 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt @@ -73,30 +73,43 @@ class HomeFragment : Fragment() { } hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData -> deleteHemoCubeIncompleteRegistrations(userData) + if (userData.isNotEmpty()) { + val userList = mutableListOf() + userData.forEach { + if (it.testStatus == false) { + userList.add(it) + } + } + val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager + val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) + adapter = OfflineUserListAdapter(binding.root, batLevel) + adapter.differ.submitList(userList) + binding.rvOrderOffline.adapter = adapter + } } viewModel.networkStatusLiveData?.observe(viewLifecycleOwner) { isConnected -> - if (isConnected) { - binding.internetAvailableCL.visibility = View.VISIBLE - binding.internetNotAvailableCL.visibility = View.GONE - loadUserData() - setSearch() - checkForLocalDBData() - } else { - binding.internetAvailableCL.visibility = View.GONE - binding.internetNotAvailableCL.visibility = View.VISIBLE - setUserId() - } +// if (isConnected) { +// binding.internetAvailableCL.visibility = View.VISIBLE +// binding.internetNotAvailableCL.visibility = View.GONE +// loadUserData() +// setSearch() +// checkForLocalDBData() +// } else { + binding.internetAvailableCL.visibility = View.GONE + binding.internetNotAvailableCL.visibility = View.VISIBLE + setUserId() +// } } hemoCubeViewModel.fireBaseBulkUpload.observe(viewLifecycleOwner) { result -> if (result == "Success") { Toast.makeText( requireContext(), - "Test Results Uploaded Successfully", + R.string.test_upload, Toast.LENGTH_SHORT ).show() } if (result == "Error") { - Toast.makeText(requireContext(), "Test Results Upload Failed", Toast.LENGTH_SHORT) + Toast.makeText(requireContext(), R.string.test_upload_failed, Toast.LENGTH_SHORT) .show() } } @@ -120,10 +133,19 @@ class HomeFragment : Fragment() { private fun setUserId() { binding.btnSubmit.setOnClickListener { val userId = binding.userId.text.toString() - if (userId.length >= 18) { - val userData = UserData(_id = userId) - DataHolder.selectedTest = userData - findNavController().navigate(R.id.action_nav_home_to_mainActivity) + val bloodGroup = binding.etBloodGroup.text + + if (userId.length >= 18 && !bloodGroup.equals("Select Blood Group") || !bloodGroup.isNullOrBlank()) { + hemoCubeViewModel.addUser( + HemoCubeTestData( + _id = userId, bloodGroup = bloodGroup.toString(), incubationTime = SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss", Locale.getDefault() + ).format(Calendar.getInstance().time).toString() + ) + ) +// val userData = UserData(_id = userId) +// DataHolder.selectedTest = userData +// findNavController().navigate(R.id.action_nav_home_to_mainActivity) } else { val errorMessage = getString(R.string.user_id_error_message) Toast.makeText(requireContext(), errorMessage, Toast.LENGTH_SHORT).show() @@ -155,10 +177,12 @@ class HomeFragment : Fragment() { val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) - rvAdapter = view?.let { - UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions, - it, batLevel, requireActivity()) - }!! + rvAdapter = view?.let { + UserListAdapter( + requireContext(), hemoCubeViewModel, recyclerViewOptions, + it, batLevel, requireActivity() + ) + }!! binding.rvOrder.adapter = rvAdapter rvAdapter.startListening() @@ -176,14 +200,14 @@ class HomeFragment : Fragment() { private fun logoutUser(context: Context) { val builder = AlertDialog.Builder(context) - builder.setTitle("Log Out") - builder.setMessage("Do you want to LogOut the Application?") - builder.setPositiveButton("Yes") { dialog, _ -> + builder.setTitle(R.string.log_out) + builder.setMessage(R.string.do_log_out) + builder.setPositiveButton(R.string.yes) { dialog, _ -> saveUserId("") findNavController().navigate(R.id.action_nav_home_to_loginFragment) dialog.dismiss() } - builder.setNegativeButton("No") { dialog, _ -> + builder.setNegativeButton(R.string.no) { dialog, _ -> dialog.dismiss() } @@ -206,8 +230,9 @@ class HomeFragment : Fragment() { val partition = dateFormat.format(currentDate) val searchTerm = partition + search val searchField = field + "Search" - val query = Firebase.firestore.collection("patientData").orderBy(searchField).startAt(searchTerm) - .endAt(searchTerm + "\uf8ff") + val query = + Firebase.firestore.collection("patientData").orderBy(searchField).startAt(searchTerm) + .endAt(searchTerm + "\uf8ff") query.get().addOnSuccessListener { userSearchTrace.stop() } @@ -218,7 +243,14 @@ class HomeFragment : Fragment() { batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) rvAdapter = view?.let { - UserListAdapter(requireContext(), hemoCubeViewModel, recyclerViewOptions, it, batLevel, requireActivity()) + UserListAdapter( + requireContext(), + hemoCubeViewModel, + recyclerViewOptions, + it, + batLevel, + requireActivity() + ) }!! binding.rvOrder.adapter = rvAdapter rvAdapter.startListening() @@ -272,7 +304,8 @@ class HomeFragment : Fragment() { } hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList -> - val uploadDataVisibility = if (userDataList.any { !it.localFlag }) View.VISIBLE else View.GONE + val uploadDataVisibility = + if (userDataList.any { !it.localFlag && it.testStatus == true}) View.VISIBLE else View.GONE binding.uploadData.visibility = uploadDataVisibility } } @@ -331,7 +364,7 @@ class HomeFragment : Fragment() { private fun deleteHemoCubeIncompleteRegistrations(userDataList: List) { userDataList.forEach { userData -> - if (userData.testTime?.isEmpty() == true) { + if (userData._id.isEmpty()) { hemoCubeViewModel.deleteById(userData._id) } } diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt index 75769de..ce29492 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt @@ -39,6 +39,7 @@ class HemoCubeFragment : Fragment() { private var currentDeviceData: DeviceData? = null private var resultData: String = "" private var isUsingExistingBuffer = false + private var loginId: String = "" private var isTestOngoing = false private var startListening = MutableLiveData(false) val testingTrace = Firebase.performance.newTrace("testing_trace") @@ -98,7 +99,8 @@ class HemoCubeFragment : Fragment() { (activity as HemocubeActivity).finish() } if (result == "Local") { - showToast("Internet not available, test details stored locally") + showToast("test details stored locally") +// showToast("Internet not available, test details stored locally") startActivity(Intent(requireActivity(), DashboardActivity::class.java)) } if (result == "Error") { @@ -345,6 +347,10 @@ class HemoCubeFragment : Fragment() { val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0) val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0) val deviceRatio = led1Average / led2Average + val coefficientsList = Constants.COEFFICIENTS[loginId] + val coefficient1 = coefficientsList?.get(0)?.get(0) + val coefficient2 = coefficientsList?.get(0)?.get(1) + val coefficientsString = "$coefficient1,$coefficient2" // if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) { // if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) { // if (deviceRatio < 0.08) { @@ -373,7 +379,8 @@ class HemoCubeFragment : Fragment() { this.led2Average = led2Average this.deviceRatio = deviceRatio this.calculatedRatio = calculateRatio(deviceRatio) - this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString() +// this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString() + this.coefficients = coefficientsString this.classificationResult = findResult(calculatedRatio) hemoCubeViewModel.messages.postValue(this.classificationResult) this.resultData = deviceLog @@ -475,8 +482,8 @@ class HemoCubeFragment : Fragment() { } private fun calculateRatio(ratio: Double): Double { - val coefficient1 = currentDeviceData?.coefficients?.get(0) ?: 0.0 - val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0 + val coefficient1: Double = (Constants.COEFFICIENTS[loginId]?.get(0)?.get(0)) as Double + val coefficient2: Double = (Constants.COEFFICIENTS[loginId]?.get(1)?.get(0)) as Double return coefficient1 * ratio + coefficient2 } @@ -508,4 +515,17 @@ class HemoCubeFragment : Fragment() { return true return false } + + + + + + + + + + + + + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f75c24f..d88440b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,10 +190,23 @@ Upload Cancel Upload done successfully - Test Completed - Select Blood Group - All registered user are tested successfully - Incubate - Check Buffer - + Battery level is low than 40%, please charge the device to continue testing + Test has been already conducted for this user + Incubation has not completed 15 minutes + Incubation crossed 30 minutes, need to repeat the incubation + Incubation not started for this user + Test concluded + Test is Pending + Please enter your blood group + Please enter your blood group + Blood group updated successfully + Failed to update blood group: %1$s + No user data found for the specified ID + Device is Disconnected + No device found + Invalid KIT Number + Internet is Not Available + Internet not available, test details stored locally + Error uploading data, test details stored locally + error while getting existing buffer \ No newline at end of file