Compare commits

...

5 Commits

Author SHA1 Message Date
smileomi18@gmail.com
a25402fc26 production errors 2023-09-12 13:21:40 +05:30
smileomi18@gmail.com
388af0adf6 production errors 2023-09-12 13:04:57 +05:30
smileomi18@gmail.com
57a0c2103a production errors 2023-09-12 12:58:56 +05:30
smileomi18@gmail.com
057abbd87c Calculated ratio error code added 2023-09-07 13:51:07 +05:30
mohamedkaif356
c3775eeea1 Error code added 2023-09-07 13:31:02 +05:30
15 changed files with 447 additions and 149 deletions

View File

@@ -52,11 +52,11 @@ android {
dependencies { dependencies {
implementation 'androidx.core:core-ktx:1.10.1' implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0' implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
//firebase //firebase
implementation platform('com.google.firebase:firebase-bom:32.1.0') implementation platform('com.google.firebase:firebase-bom:32.1.0')
@@ -66,7 +66,7 @@ dependencies {
implementation 'com.google.firebase:firebase-auth-ktx' implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-storage-ktx' implementation 'com.google.firebase:firebase-storage-ktx'
implementation 'com.firebaseui:firebase-ui-firestore:8.0.2' implementation 'com.firebaseui:firebase-ui-firestore:8.0.2'
implementation 'com.google.android.gms:play-services-auth:20.6.0' implementation 'com.google.android.gms:play-services-auth:20.7.0'
implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1' implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation 'com.google.android.things:androidthings:1.0' implementation 'com.google.android.things:androidthings:1.0'
@@ -77,7 +77,7 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
implementation 'com.opencsv:opencsv:4.6' implementation 'com.opencsv:opencsv:4.6'
implementation 'com.github.mik3y:usb-serial-for-android:3.5.1' implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
@@ -102,8 +102,8 @@ dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2' annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
// Navigation Component // Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:2.7.1" implementation "androidx.navigation:navigation-fragment-ktx:2.7.2"
implementation "androidx.navigation:navigation-ui-ktx:2.7.1" implementation "androidx.navigation:navigation-ui-ktx:2.7.2"
//Dagger - Hilt //Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.46" implementation "com.google.dagger:hilt-android:2.46"

View File

@@ -13,8 +13,11 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.usb.host" /> <uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" /> <uses-permission android:name="android.permission.USB_PERMISSION" />
<application <application
android:name="com.example.hpostesting.HPOSTestingApplication" android:name="com.example.hpostesting.HPOSTestingApplication"
android:allowBackup="true" android:allowBackup="true"
@@ -26,6 +29,11 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.HPOSTesting" android:theme="@style/Theme.HPOSTesting"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name="com.example.hpostesting.presentation.BloodCollectingMethodActivity"
android:exported="true"
android:noHistory="true"
android:theme="@style/Theme.HPOS.NoActionBar" />
<activity <activity
android:name="com.example.hpostesting.presentation.hemocube.HemocubeActivity" android:name="com.example.hpostesting.presentation.hemocube.HemocubeActivity"
android:exported="false" android:exported="false"
@@ -91,7 +99,7 @@
</activity> </activity>
<activity <activity
android:name="com.journeyapps.barcodescanner.CaptureActivity" android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait" android:screenOrientation="fullSensor"
android:stateNotNeeded="true" android:stateNotNeeded="true"
tools:replace="android:screenOrientation" /> tools:replace="android:screenOrientation" />
</application> </application>

View File

@@ -5,6 +5,8 @@ import android.content.Context
import androidx.room.Room import androidx.room.Room
import com.example.hpostesting.data.dao.MyDatabase import com.example.hpostesting.data.dao.MyDatabase
import com.google.android.datatransport.runtime.dagger.Provides import com.google.android.datatransport.runtime.dagger.Provides
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreSettings
import dagger.hilt.android.HiltAndroidApp import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -13,7 +15,14 @@ import javax.inject.Singleton
@HiltAndroidApp @HiltAndroidApp
class HPOSTestingApplication: Application() { class HPOSTestingApplication: Application() {
override fun onCreate() {
super.onCreate()
val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
val firestoreSettings = FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(true) // Enable offline persistence if needed
.build()
val firestore = FirebaseFirestore.getInstance()
firestore.firestoreSettings = firestoreSettings
}
} }

View File

@@ -55,4 +55,8 @@ object Constants {
const val KIT_COUNT = "KitCount" const val KIT_COUNT = "KitCount"
const val BUFFER_VALUE_1 = "BufferValue1" const val BUFFER_VALUE_1 = "BufferValue1"
const val BUFFER_VALUE_2 = "BufferValue2" const val BUFFER_VALUE_2 = "BufferValue2"
const val BLOOD_COLLECTING_METHOD = "bloodCollectingMethod"
const val VENOUS_BLOOD = "venousBlood"
const val FINGER_PRICK_BLOOD = "fingerPrickBlood"
} }

View File

@@ -0,0 +1,57 @@
package com.example.hpostesting.presentation
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.hpostesting.data.DataHolder
import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
import com.example.hpostesting.presentation.testRight.TestRightActivity
import `in`.sminnovations.hpostesting.databinding.ActivityBloodCollectingMethodBinding
class BloodCollectingMethodActivity : AppCompatActivity() {
private lateinit var binding: ActivityBloodCollectingMethodBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityBloodCollectingMethodBinding.inflate(layoutInflater)
setContentView(binding.root)
init()
}
private fun init() {
setSupportActionBar(binding.toolbar)
binding.btnGo.setOnClickListener {
DataHolder.usbConnected.observe(this) {
if (it) {
if (binding.venousBloodRadioButton.isChecked) {
moveToNext(Constants.VENOUS_BLOOD)
} else {
moveToNext(Constants.FINGER_PRICK_BLOOD)
}
} else {
Toast.makeText(this, "No Device Connected", Toast.LENGTH_SHORT).show()
}
}
}
}
private fun moveToNext(bloodCollectingMethod: String) {
DataHolder.deviceType.observe(this) { deviceType ->
when (deviceType) {
Constants.DEVICE_TYPE_HOMOCUBE -> {
val intent = Intent(applicationContext, HemocubeActivity::class.java)
intent.putExtra(Constants.BLOOD_COLLECTING_METHOD, bloodCollectingMethod)
startActivity(intent)
}
Constants.DEVICE_TYPE_TEST_RIGHT -> {
val intent = Intent(applicationContext, TestRightActivity::class.java)
intent.putExtra(Constants.BLOOD_COLLECTING_METHOD, bloodCollectingMethod)
startActivity(intent)
}
}
}
}
}

View File

@@ -5,13 +5,14 @@ import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.example.hpostesting.data.DataHolder import com.example.hpostesting.data.DataHolder
import com.example.hpostesting.data.constant.Constants import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.presentation.dashboard.DashboardActivity import com.example.hpostesting.presentation.dashboard.DashboardActivity
import com.example.hpostesting.presentation.hemocube.HemocubeActivity import com.google.android.material.snackbar.Snackbar
import com.example.hpostesting.presentation.testRight.TestRightActivity import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.journeyapps.barcodescanner.ScanContract import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanIntentResult import com.journeyapps.barcodescanner.ScanIntentResult
import com.journeyapps.barcodescanner.ScanOptions import com.journeyapps.barcodescanner.ScanOptions
@@ -52,10 +53,35 @@ class KitScanActivity : AppCompatActivity() {
moveToNext() moveToNext()
} }
// if (checkHemoCubeKitData()) {
// DataHolder.selectedTest!!.kitSerial =
// sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
// moveToNext()
// } else {
// with(sharedPreference.edit()) {
// putString(Constants.KIT_NUMBER, "")
// putInt(Constants.KIT_COUNT, 0)
// putString(Constants.BUFFER_VALUE_1, "")
// putString(Constants.BUFFER_VALUE_2, "")
// apply()
// }
if (checkHemoCubeKitData()) { if (checkHemoCubeKitData()) {
try {
DataHolder.selectedTest!!.kitSerial = DataHolder.selectedTest!!.kitSerial =
sharedPreference.getString(Constants.KIT_NUMBER, "").toString() sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
moveToNext() moveToNext()
} catch (e: NullPointerException) {
// Handle the NullPointerException here
e.printStackTrace() // You can log the exception for debugging
FirebaseCrashlytics.getInstance().recordException(e)
val errorMessage = "An error occurred: ${e.message}"
val rootView = findViewById<View>(android.R.id.content)
Snackbar.make(rootView, errorMessage, Snackbar.LENGTH_LONG).show()
// Optionally, show a user-friendly error message to the user
// Toast.makeText(applicationContext, "An error occurred", Toast.LENGTH_SHORT).show()
}
} else { } else {
with(sharedPreference.edit()) { with(sharedPreference.edit()) {
putString(Constants.KIT_NUMBER, "") putString(Constants.KIT_NUMBER, "")
@@ -64,6 +90,8 @@ class KitScanActivity : AppCompatActivity() {
putString(Constants.BUFFER_VALUE_2, "") putString(Constants.BUFFER_VALUE_2, "")
apply() apply()
} }
} }
binding.nameEditText.setText("SMI/SC/") binding.nameEditText.setText("SMI/SC/")
@@ -107,22 +135,10 @@ class KitScanActivity : AppCompatActivity() {
} }
private fun moveToNext() { private fun moveToNext() {
val i = Intent(applicationContext, BloodCollectingMethodActivity::class.java)
DataHolder.deviceType.observe(this) { deviceType ->
when (deviceType) {
Constants.DEVICE_TYPE_HOMOCUBE -> {
val i = Intent(applicationContext, HemocubeActivity::class.java)
startActivity(i) startActivity(i)
} }
Constants.DEVICE_TYPE_TEST_RIGHT -> {
val i = Intent(applicationContext, TestRightActivity::class.java)
startActivity(i)
}
}
}
}
private fun startScanningNow() { private fun startScanningNow() {
val options = ScanOptions() val options = ScanOptions()
options.setDesiredBarcodeFormats(ScanOptions.QR_CODE) options.setDesiredBarcodeFormats(ScanOptions.QR_CODE)

View File

@@ -21,6 +21,8 @@ import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.data.model.patient.UserData import com.example.hpostesting.data.model.patient.UserData
import com.example.hpostesting.data.model.test.TestType import com.example.hpostesting.data.model.test.TestType
import com.google.android.gms.location.* import com.google.android.gms.location.*
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.hoho.android.usbserial.driver.UsbSerialProber import com.hoho.android.usbserial.driver.UsbSerialProber
import `in`.sminnovations.hpostesting.R import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.ActivityMainBinding import `in`.sminnovations.hpostesting.databinding.ActivityMainBinding
@@ -234,6 +236,22 @@ class MainActivity : AppCompatActivity() {
return return
} }
// fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
// location?.let {
// DataHolder.selectedTest!!.location =
// UserData.Location(location.latitude, location.longitude)
// DataHolder.location =
// UserData.Location(location.latitude, location.longitude)
// } ?: run {
// requestLocationUpdates()
// }
// }.addOnFailureListener { exception: Exception ->
// exception.printStackTrace()
// }
fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? -> fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
location?.let { location?.let {
DataHolder.selectedTest!!.location = DataHolder.selectedTest!!.location =
@@ -244,8 +262,19 @@ class MainActivity : AppCompatActivity() {
requestLocationUpdates() requestLocationUpdates()
} }
}.addOnFailureListener { exception: Exception -> }.addOnFailureListener { exception: Exception ->
// Handle the exception here
exception.printStackTrace() exception.printStackTrace()
FirebaseCrashlytics.getInstance().recordException(exception)
// Display an error message to the user using a Snackbar
val errorMessage = "An error occurred: ${exception.message}"
val rootView = findViewById<View>(android.R.id.content)
Snackbar.make(rootView, errorMessage, Snackbar.LENGTH_LONG).show()
} }
} }
private fun requestLocationUpdates() { private fun requestLocationUpdates() {

View File

@@ -39,7 +39,7 @@ class SplashActivity : AppCompatActivity() {
binding = ActivitySplashBinding.inflate(layoutInflater) binding = ActivitySplashBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
setupFirestoreCache() // setupFirestoreCache()
setupStaticConstants() setupStaticConstants()
requestPermissions() requestPermissions()
@@ -50,12 +50,12 @@ class SplashActivity : AppCompatActivity() {
Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID) Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)
} }
private fun setupFirestoreCache() { // private fun setupFirestoreCache() {
val settings = FirebaseFirestoreSettings.Builder() // val settings = FirebaseFirestoreSettings.Builder()
.setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED) // .setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED)
.build() // .build()
Firebase.firestore.firestoreSettings = settings // Firebase.firestore.firestoreSettings = settings
} // }
private fun requestPermissions() { private fun requestPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

View File

@@ -25,7 +25,7 @@ class GalleryFragment : Fragment() {
// val galleryViewModel = // val galleryViewModel =
// ViewModelProvider(this).get(GalleryViewModel::class.java) // ViewModelProvider(this).get(GalleryViewModel::class.java)
// _binding = FragmentGalleryBinding.inflate(inflater, container, false) _binding = FragmentGalleryBinding.inflate(inflater, container, false)
val root: View = binding.root val root: View = binding.root
// val textView: TextView = binding.textGallery // val textView: TextView = binding.textGallery

View File

@@ -37,8 +37,16 @@ class HomeFragment : Fragment() {
private lateinit var sharedPreference: SharedPreferences private lateinit var sharedPreference: SharedPreferences
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View { ): View? {
_binding = FragmentHomeBinding.inflate(inflater, container, false) _binding = FragmentHomeBinding.inflate(inflater, container, false)
// Check if _binding is null
if (_binding == null) {
// Handle the case where binding could not be initialized
// You may want to log an error or return a default view in this case
return super.onCreateView(inflater, container, savedInstanceState)
}
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE) sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
DataHolder.selectedTest = null DataHolder.selectedTest = null

View File

@@ -21,6 +21,7 @@ import com.example.hpostesting.presentation.UsbServiceListener
import com.example.hpostesting.presentation.dashboard.DashboardActivity import com.example.hpostesting.presentation.dashboard.DashboardActivity
import com.example.hpostesting.presentation.utils.MyDialogListener import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils import com.example.hpostesting.presentation.utils.UIUtils
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.ktx.firestore import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase import com.google.firebase.ktx.Firebase
@@ -43,7 +44,6 @@ class HemoCubeFragment : Fragment() {
private var resultData: String = "" private var resultData: String = ""
private var isUsingExistingBuffer = false private var isUsingExistingBuffer = false
private var isTestOngoing = false private var isTestOngoing = false
private var bloodGroup: String = ""
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View { ): View {
@@ -242,8 +242,6 @@ class HemoCubeFragment : Fragment() {
resultData += fullReadOutput.toString() resultData += fullReadOutput.toString()
when { when {
stringData.contains("ERROR 500") -> showError500Dialog()
stringData.contains("ERROR 501") -> showError501Dialog()
stringData.contains("#Buffer Completed") -> showStartSampleDialog() stringData.contains("#Buffer Completed") -> showStartSampleDialog()
stringData.contains("#Sample Completed") -> { stringData.contains("#Sample Completed") -> {
activity?.runOnUiThread { activity?.runOnUiThread {
@@ -272,38 +270,6 @@ class HemoCubeFragment : 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() { private fun showStartSampleDialog() {
activity?.runOnUiThread { activity?.runOnUiThread {
UIUtils.createAlertDialog(requireContext(), UIUtils.createAlertDialog(requireContext(),
@@ -324,45 +290,146 @@ class HemoCubeFragment : Fragment() {
private fun handleValidResult(validString: String, fullReadOutput: String) { private fun handleValidResult(validString: String, fullReadOutput: String) {
try { try {
val result = validString.split(" ") val result = validString.split(" ")
if (result.size == 8) { if (result.size != 8) return
val deviceSerialNo = result[2] val deviceSerialNo = result[2]
val led1BufferForDevice = if (isUsingExistingBuffer) { val led1BufferForDevice =
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull() getLedBufferValue(isUsingExistingBuffer, Constants.BUFFER_VALUE_1, result[3])
} else { val led2BufferForDevice =
result[3].toDoubleOrNull() getLedBufferValue(isUsingExistingBuffer, Constants.BUFFER_VALUE_2, result[4])
}
val led2BufferForDevice = if (isUsingExistingBuffer) {
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()
} else {
result[4].toDoubleOrNull()
}
val version = BuildConfig.VERSION_NAME val version = BuildConfig.VERSION_NAME
val led1Sample = result[5].toDoubleOrNull() val led1Sample = result[5].toDoubleOrNull()
val led2Sample = result[6].toDoubleOrNull() val led2Sample = result[6].toDoubleOrNull()
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) {
val led1Average = calculateAverage(led1BufferForDevice, led1Sample)
val led2Average = calculateAverage(led2BufferForDevice, led2Sample)
val deviceRatio = led1Average / led2Average
val calculatedRatio = calculateRatio(deviceRatio)
val isBufferValid = validateBuffer(led1BufferForDevice, led2BufferForDevice)
val isSampleValid =
validateSample(led1Sample, led1BufferForDevice, led2Sample, led2BufferForDevice)
val isCalculatedRatioValid = validateCalculatedRatio(deviceRatio)
when {
!isBufferValid -> showError(
"Buffer error",
"Check for Empty curved, disconnected and reconnect the device, and please retest this sample again with a new blank"
)
!isSampleValid -> showError(
"Sample error",
"Check for Empty curved, disconnected and reconnect the device, and please retest this sample again with a new blank"
)
!validateBloodVolume(led1Average, led2Average) -> {
showError(
"Low Blood Volume",
"Please retest this sample with a higher volume of blood"
)
}
!validateHighBloodVolume(led1Average, led2Average) -> {
showError(
"High Blood Volume",
"Please retest this sample by diluting the sample in the buffer"
)
}
!isCalculatedRatioValid -> showError(
"calculated Ratio error",
"Check for Empty curved, disconnected and reconnect the device, and please retest this sample again with a new blank"
)
else -> processValidData(
deviceSerialNo,
led1BufferForDevice,
led2BufferForDevice,
version,
led1Sample,
led2Sample,
led1Average,
led2Average,
deviceRatio,
fullReadOutput,
calculatedRatio
)
}
} catch (_: Exception) {
// handle exception or log it if necessary
} }
} }
private fun getLedBufferValue(
usingExistingBuffer: Boolean, bufferConstant: String, resultValue: String
): Double? {
return if (usingExistingBuffer) {
sharedPreferences.getString(bufferConstant, "")?.toDoubleOrNull()
} else {
resultValue.toDoubleOrNull()
} }
} }
private fun calculateAverage(bufferForDevice: Double?, sample: Double?): Double {
return log10(bufferForDevice?.div(sample ?: 1.0) ?: 0.0)
}
private fun validateBuffer(led1Buffer: Double?, led2Buffer: Double?): Boolean {
return led1Buffer!! in 20001.0..23999.0 && led2Buffer!! in 20001.0..23999.0
}
private fun validateSample(
sample1: Double?, buffer1: Double?, sample2: Double?, buffer2: Double?
): Boolean {
return sample1 != null && sample1 < buffer1!! && sample1 < 24000 && sample2 != null && sample2 < buffer2!! && sample2 < 24000
}
private fun validateBloodVolume(average1: Double, average2: Double): Boolean {
return average1 > 0.08 && average2 > 0.08
}
private fun validateCalculatedRatio(deviceRatio: Double): Boolean {
return deviceRatio > 0.08 && deviceRatio < 0.3
}
private fun validateHighBloodVolume(average1: Double, average2: Double): Boolean {
return average1 < 1.07 && average2 < 1.07
}
private fun showError(title: String, message: String) {
customErrorDialogBox(title, message)
}
private fun processValidData(
deviceId: String,
led1Buffer: Double?,
led2Buffer: Double?,
appVersion: String,
led1Sample: Double?,
led2Sample: Double?,
led1Average: Double,
led2Average: Double,
deviceRatio: Double,
resultData: String,
calculatedRatio: Double
) {
val threshold =
if ((activity as HemocubeActivity).bloodCollectingMethod == Constants.FINGER_PRICK_BLOOD) 0.05 else 0.06
if (led1Average > threshold) {
DataHolder.hemoCubeTestData?.apply { DataHolder.hemoCubeTestData?.apply {
deviceId = deviceSerialNo this.deviceId = deviceId
led1Buffer = led1BufferForDevice this.led1Buffer = led1Buffer
led2Buffer = led2BufferForDevice this.led2Buffer = led2Buffer
appVersion = version this.appVersion = appVersion
this.led1Sample = led1Sample this.led1Sample = led1Sample
this.led2Sample = led2Sample this.led2Sample = led2Sample
this.led1Average = led1Average this.led1Average = led1Average
this.led2Average = led2Average this.led2Average = led2Average
this.deviceRatio = deviceRatio this.deviceRatio = deviceRatio
this.calculatedRatio = calculateRatio(deviceRatio) this.calculatedRatio = calculatedRatio
this.resultData = fullReadOutput this.resultData = resultData
if (!isBufferValueAvailable()) { if (!isBufferValueAvailable()) {
with(sharedPreferences.edit()) { with(sharedPreferences.edit()) {
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString()) putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
@@ -374,12 +441,37 @@ class HemoCubeFragment : Fragment() {
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "") isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
) )
} }
} else {
showError(
"Low Blood Volume",
"Please repeat the test with 10 µl of blood added to 1 ml of buffer"
)
}
} }
} catch (_: Exception) { private fun customErrorDialogBox(title: String, message: String) {
activity?.runOnUiThread {
MaterialAlertDialogBuilder(requireContext()).setTitle(title).setMessage(message)
.setPositiveButton("OK") { dialog, _ ->
if (title == "Buffer error" || title == "Sample error") {
with(sharedPreferences.edit()) {
putString(Constants.BUFFER_VALUE_1, "")
putString(Constants.BUFFER_VALUE_2, "")
apply()
}
finishTestingActivity()
} else {
finishTestingActivity()
}
dialog.dismiss()
}.show()
}
} }
private fun finishTestingActivity() {
val i = Intent(requireContext().applicationContext, DashboardActivity::class.java)
startActivity(i)
(activity as HemocubeActivity).finish()
} }
private fun showToast(message: String) { private fun showToast(message: String) {

View File

@@ -3,7 +3,6 @@ package com.example.hpostesting.presentation.hemocube
import android.app.PendingIntent import android.app.PendingIntent
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.ComponentName import android.content.ComponentName
import android.content.ContentValues.TAG
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
@@ -11,29 +10,23 @@ import android.content.ServiceConnection
import android.hardware.usb.UsbDevice import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbDeviceConnection import android.hardware.usb.UsbDeviceConnection
import android.hardware.usb.UsbManager import android.hardware.usb.UsbManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.os.IBinder import android.os.IBinder
import android.util.Log import android.util.Log
import android.view.Menu import android.view.Menu
import android.widget.Toast import android.widget.Toast
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.get import androidx.core.view.get
import com.example.hpostesting.data.DataHolder import com.example.hpostesting.data.DataHolder
import com.example.hpostesting.data.constant.Constants import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.presentation.testRight.TestRightExpReference
import com.example.hpostesting.presentation.testRight.TestRightExpSample
import com.example.hpostesting.presentation.testRight.TestRightViewModel
import com.example.hpostesting.presentation.testRight.UsbService import com.example.hpostesting.presentation.testRight.UsbService
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationCallback
import com.hoho.android.usbserial.driver.UsbSerialDriver import com.hoho.android.usbserial.driver.UsbSerialDriver
import com.hoho.android.usbserial.driver.UsbSerialProber import com.hoho.android.usbserial.driver.UsbSerialProber
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import `in`.sminnovations.hpostesting.R import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.ActivityHemocubeBinding import `in`.sminnovations.hpostesting.databinding.ActivityHemocubeBinding
import `in`.sminnovations.hpostesting.databinding.ActivityMainBinding
@AndroidEntryPoint @AndroidEntryPoint
class HemocubeActivity : AppCompatActivity() { class HemocubeActivity : AppCompatActivity() {
@@ -47,6 +40,8 @@ class HemocubeActivity : AppCompatActivity() {
private val TAG = "HemoCube" private val TAG = "HemoCube"
var bloodCollectingMethod = ""
private val broadcastReceiver = object : BroadcastReceiver() { private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
@@ -84,6 +79,7 @@ class HemocubeActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityHemocubeBinding.inflate(layoutInflater) binding = ActivityHemocubeBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
bloodCollectingMethod = intent.getStringExtra(Constants.BLOOD_COLLECTING_METHOD).toString()
setSupportActionBar(binding.myToolbar) setSupportActionBar(binding.myToolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
setupListener() setupListener()
@@ -94,9 +90,11 @@ class HemocubeActivity : AppCompatActivity() {
DataHolder.usbConnected.observe(this) { DataHolder.usbConnected.observe(this) {
Log.d("USB OBSERVE", "HemoCube called -> $it") Log.d("USB OBSERVE", "HemoCube called -> $it")
if (it) { if (it) {
myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24) myMenu?.get(0)?.icon =
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
} else { } else {
myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24) myMenu?.get(0)?.icon =
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
Toast.makeText(this, "Device is Disconnected", Toast.LENGTH_SHORT).show() Toast.makeText(this, "Device is Disconnected", Toast.LENGTH_SHORT).show()
} }
} }
@@ -123,16 +121,15 @@ class HemocubeActivity : AppCompatActivity() {
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) { private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
val mPendingIntent: PendingIntent val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { PendingIntent.getBroadcast(
mPendingIntent = PendingIntent.getBroadcast(
this, this,
0, 0,
Intent(Constants.HOMOCUBE_USB_PERMISSION), Intent(Constants.HOMOCUBE_USB_PERMISSION),
PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_MUTABLE
) )
} else { } else {
mPendingIntent = PendingIntent.getBroadcast( PendingIntent.getBroadcast(
this, this,
0, 0,
Intent(Constants.HOMOCUBE_USB_PERMISSION), Intent(Constants.HOMOCUBE_USB_PERMISSION),
@@ -169,6 +166,7 @@ class HemocubeActivity : AppCompatActivity() {
menuInflater.inflate(R.menu.my_menu, menu) menuInflater.inflate(R.menu.my_menu, menu)
return true return true
} }
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
if (viewModel.isServiceConnected) { if (viewModel.isServiceConnected) {

View File

@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hpostesting.presentation.BloodCollectingMethodActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:theme="@style/Theme.HPOS.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.HPOS.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<TextView
android:id="@+id/tv_title"
style="@style/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="16dp"
android:text="@string/select_blood_collecting_method"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_bar_layout" />
<RadioGroup
android:id="@+id/bloodTypeRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_title">
<RadioButton
android:id="@+id/venousBloodRadioButton"
style="@style/title1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/venous_blood" />
<RadioButton
android:id="@+id/fingerPrickBloodRadioButton"
style="@style/title1_1"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/finger_prick_blood" />
</RadioGroup>
<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_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bloodTypeRadioGroup" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".presentation.KitScanActivity"> tools:context="com.example.hpostesting.presentation.KitScanActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout" android:id="@+id/app_bar_layout"

View File

@@ -190,5 +190,8 @@
<string name="test_completed">Test Completed</string> <string name="test_completed">Test Completed</string>
<string name="select_blood_group">Select Blood Group</string> <string name="select_blood_group">Select Blood Group</string>
<string name="all_registered_user_are_tested_successfully">All registered user are tested successfully</string> <string name="all_registered_user_are_tested_successfully">All registered user are tested successfully</string>
<string name="venous_blood">Venous Blood</string>
<string name="finger_prick_blood">Finger Prick Blood</string>
<string name="select_blood_collecting_method">Select blood collecting method</string>
</resources> </resources>