Compare commits
2 Commits
DigitalCar
...
HposUnitTe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7f3729dd6 | ||
|
|
a068ae492c |
@@ -71,15 +71,16 @@ dependencies {
|
|||||||
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'
|
||||||
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta10'
|
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta11'
|
||||||
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta10")
|
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta11")
|
||||||
|
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
testImplementation 'org.mockito:mockito-core:3.12.0'
|
||||||
|
testImplementation "androidx.arch.core:core-testing:2.2.0"
|
||||||
|
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
|
||||||
implementation 'com.opencsv:opencsv:4.6'
|
implementation 'com.opencsv:opencsv:4.6'
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ object Constants {
|
|||||||
"HC-V1-018",
|
"HC-V1-018",
|
||||||
"HC-V1-019",
|
"HC-V1-019",
|
||||||
"HC-V1-020",
|
"HC-V1-020",
|
||||||
"HCV-000-3001",
|
|
||||||
"HCV-000-3002",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const val password = "SMI@12345"
|
const val password = "SMI@12345"
|
||||||
@@ -71,7 +69,5 @@ 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 BUFFER_VALUE_3 = "BufferValue3"
|
|
||||||
const val BUFFER_VALUE_4 = "BufferValue4"
|
|
||||||
const val DEVICE_ID = "DEVICE_ID"
|
const val DEVICE_ID = "DEVICE_ID"
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|||||||
import com.google.android.datatransport.runtime.dagger.Provides
|
import com.google.android.datatransport.runtime.dagger.Provides
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 6, exportSchema = false)
|
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 3, exportSchema = false)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class MyDatabase : RoomDatabase() {
|
abstract class MyDatabase : RoomDatabase() {
|
||||||
abstract fun userDao(): UserDao
|
abstract fun userDao(): UserDao
|
||||||
|
|||||||
@@ -9,16 +9,12 @@ data class HemoCubeTestData(
|
|||||||
var _id: String = "",
|
var _id: String = "",
|
||||||
var name: String = "",
|
var name: String = "",
|
||||||
var birthYear: String = "",
|
var birthYear: String = "",
|
||||||
var state: String = "",
|
|
||||||
var abhaId: String = "",
|
|
||||||
var bloodGroup: String = "",
|
|
||||||
var userImageURL: String = "",
|
var userImageURL: String = "",
|
||||||
var location: UserData.Location? = null,
|
var location: UserData.Location? = null,
|
||||||
var reportUploadTime: String? = "",
|
var reportUploadTime: String? = "",
|
||||||
var testType: String? = "HEMOCUBE",
|
var testType: String? = "HEMOCUBE",
|
||||||
var testTime: String? = "",
|
var testTime: String? = "",
|
||||||
var testStatus: Boolean? = false,
|
var testStatus: Boolean? = false,
|
||||||
var gender: String = "",
|
|
||||||
var localFlag: Boolean = false,
|
var localFlag: Boolean = false,
|
||||||
var deviceId: String? = "",
|
var deviceId: String? = "",
|
||||||
var appVersion:String? = "",
|
var appVersion:String? = "",
|
||||||
@@ -28,16 +24,10 @@ data class HemoCubeTestData(
|
|||||||
var resultData: String = "",
|
var resultData: String = "",
|
||||||
var led1Buffer: Double? = null,
|
var led1Buffer: Double? = null,
|
||||||
var led2Buffer: Double? = null,
|
var led2Buffer: Double? = null,
|
||||||
var led3Buffer: Double? = null,
|
|
||||||
var led4Buffer: Double? = null,
|
|
||||||
var led1Sample: Double? = null,
|
var led1Sample: Double? = null,
|
||||||
var led2Sample: Double? = null,
|
var led2Sample: Double? = null,
|
||||||
var led3Sample: Double? = null,
|
|
||||||
var led4Sample: Double? = null,
|
|
||||||
var led1Average: Double? = null,
|
var led1Average: Double? = null,
|
||||||
var led2Average: Double? = null,
|
var led2Average: Double? = null,
|
||||||
var led3Average: Double? = null,
|
|
||||||
var led4Average: Double? = null,
|
|
||||||
var deviceRatio: Double? = null,
|
var deviceRatio: Double? = null,
|
||||||
var calculatedRatio: Double? = null,
|
var calculatedRatio: Double? = null,
|
||||||
var coefficients: String? = "",
|
var coefficients: String? = "",
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ data class UserData(
|
|||||||
var name: String = "",
|
var name: String = "",
|
||||||
var incubationTime: String = "",
|
var incubationTime: String = "",
|
||||||
var birthYear: String = "",
|
var birthYear: String = "",
|
||||||
var abhaId: String = "",
|
|
||||||
var userImageURL: String = "",
|
var userImageURL: String = "",
|
||||||
var gender: String ="",
|
|
||||||
var location: Location? = null,
|
var location: Location? = null,
|
||||||
var createdBy: String? = "",
|
var createdBy: String? = "",
|
||||||
var reportUploadTime: String? = "",
|
var reportUploadTime: String? = "",
|
||||||
@@ -21,7 +19,6 @@ data class UserData(
|
|||||||
var testStatus: Boolean? = false,
|
var testStatus: Boolean? = false,
|
||||||
var mobileId: String = "",
|
var mobileId: String = "",
|
||||||
var deviceId: String = "",
|
var deviceId: String = "",
|
||||||
var state: String = "",
|
|
||||||
var deviceSerialNumber: String = "",
|
var deviceSerialNumber: String = "",
|
||||||
var kitSerial: String = "",
|
var kitSerial: String = "",
|
||||||
var csvPath: String = "",
|
var csvPath: String = "",
|
||||||
@@ -47,6 +44,5 @@ fun UserData.toHemoCubeTestData() = HemoCubeTestData(
|
|||||||
birthYear = birthYear,
|
birthYear = birthYear,
|
||||||
userImageURL = userImageURL,
|
userImageURL = userImageURL,
|
||||||
testStatus = testStatus,
|
testStatus = testStatus,
|
||||||
location = location,
|
location = location
|
||||||
gender = gender
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.example.hpostesting.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.components.ViewModelComponent
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(ViewModelComponent::class)
|
||||||
|
object ViewModelModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun provideTestRightViewModel(
|
||||||
|
saveRawData: SaveRawData,
|
||||||
|
saveRawDataTest: SaveRawDataTest,
|
||||||
|
databaseRepository: DatabaseRepository,
|
||||||
|
userDao: UserDao,
|
||||||
|
context: Context
|
||||||
|
): TestRightViewModel {
|
||||||
|
return TestRightViewModel(saveRawData, saveRawDataTest, databaseRepository, userDao, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -138,4 +138,8 @@ class DatabaseRepository : Repository {
|
|||||||
// Find the DeviceData object with the specified deviceId
|
// Find the DeviceData object with the specified deviceId
|
||||||
return allDeviceDataList.find { it.deviceId == deviceId }
|
return allDeviceDataList.find { it.deviceId == deviceId }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.hpostesting.data.repository
|
package com.example.hpostesting.data.repository
|
||||||
|
|
||||||
interface Repository {
|
interface Repository {
|
||||||
|
abstract fun <UserData> addTestToDatabase(testDetails: UserData): Any
|
||||||
// suspend fun addToDatabase(data: PatientDetails)
|
// suspend fun addToDatabase(data: PatientDetails)
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ 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.diagnostics.DiagnosticsActivity
|
||||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightActivity
|
import com.example.hpostesting.presentation.testRight.TestRightActivity
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import java.util.Locale
|
|||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
private var _binding: FragmentHomeBinding? = null
|
private var _binding: FragmentHomeBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
||||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||||
private lateinit var rvAdapter: UserListAdapter
|
private lateinit var rvAdapter: UserListAdapter
|
||||||
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
private var batLevel: Int = 0 // Initialize with a default value, or obtain the actual battery level
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.fragment.app.activityViewModels
|
|
||||||
import com.example.hpostesting.data.DataHolder
|
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
|
||||||
import `in`.sminnovations.hpostesting.R
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDigitalCardBinding
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
class DigitalCardFragment : Fragment() {
|
|
||||||
private lateinit var binding: FragmentDigitalCardBinding
|
|
||||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
|
||||||
private lateinit var sharedPreferences: SharedPreferences
|
|
||||||
val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
|
|
||||||
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
|
||||||
): View {
|
|
||||||
binding = FragmentDigitalCardBinding.inflate(inflater, container, false)
|
|
||||||
sharedPreferences =
|
|
||||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
initViews()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initViews() {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
val originalDateStr = testDetails?.testTime
|
|
||||||
val originalDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
|
||||||
val originalDate: Date? = originalDateFormat.parse(originalDateStr)
|
|
||||||
val desiredDateFormat = SimpleDateFormat("MMM dd, yyyy")
|
|
||||||
val formattedDate: String = originalDate?.let { desiredDateFormat.format(it) } ?: "N/A"
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.progressBar.visibility = View.GONE
|
|
||||||
}
|
|
||||||
binding.name.text = "Name: ${testDetails?.name}"
|
|
||||||
binding.dob.text = "DOB: ${testDetails?.birthYear}"
|
|
||||||
binding.gender.text = "gender: ${testDetails?.gender}"
|
|
||||||
binding.State.text = "state: ${testDetails?.state}"
|
|
||||||
binding.abhaid.text = "ABHA ID: ${testDetails?.abhaId}"
|
|
||||||
binding.blood.text = "Blood Group: ${testDetails?.bloodGroup}"
|
|
||||||
binding.sicklecell.text = "Sickle-Cell: ${testDetails?.classificationResult}"
|
|
||||||
binding.issueDate.text = "Issue Date: $formattedDate"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,6 @@ import com.example.hpostesting.data.model.patient.DeviceData
|
|||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
import com.example.hpostesting.presentation.UsbServiceListener
|
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.diagnostics.DiagnosticsActivity
|
|
||||||
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.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
@@ -42,15 +41,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private var isUsingExistingBuffer = false
|
private var isUsingExistingBuffer = false
|
||||||
private var isTestOngoing = false
|
private var isTestOngoing = false
|
||||||
private var startListening = MutableLiveData<Boolean>(false)
|
private var startListening = MutableLiveData<Boolean>(false)
|
||||||
private val testingTrace = Firebase.performance.newTrace("testing_trace")
|
val testingTrace = Firebase.performance.newTrace("testing_trace")
|
||||||
private var led1BufferForDevice = 0.0
|
|
||||||
private var led2BufferForDevice = 0.0
|
|
||||||
private var led3BufferForDevice = 0.0
|
|
||||||
private var led4BufferForDevice = 0.0
|
|
||||||
private var led1SampleForDevice = 0.0
|
|
||||||
private var led2SampleForDevice = 0.0
|
|
||||||
private var led3SampleForDevice = 0.0
|
|
||||||
private var led4SampleForDevice = 0.0
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||||
@@ -64,9 +55,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
initViews()
|
initViews()
|
||||||
listenToHemoCube()
|
|
||||||
getDeviceInfo()
|
|
||||||
observeViewModel()
|
observeViewModel()
|
||||||
|
checkAndStartProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
@@ -78,58 +68,34 @@ class HemoCubeFragment : Fragment() {
|
|||||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (isTestOngoing) {
|
||||||
|
// binding.btnKit.visibility = View.GONE
|
||||||
|
// binding.btnKit.isEnabled = false
|
||||||
|
// binding.btnKit.isClickable = false
|
||||||
|
}
|
||||||
|
|
||||||
binding.tvTitle2.visibility = View.GONE
|
binding.tvTitle2.visibility = View.GONE
|
||||||
binding.etAbhaId.visibility = View.GONE
|
binding.etAbhaId.visibility = View.GONE
|
||||||
binding.nameEditText.visibility = View.GONE
|
binding.nameEditText.visibility = View.GONE
|
||||||
binding.tvTitle.visibility = View.GONE
|
binding.tvTitle.visibility = View.GONE
|
||||||
binding.btnGo.visibility = View.GONE
|
binding.btnGo.visibility = View.GONE
|
||||||
binding.btnSubmit.isEnabled = true
|
binding.btnSubmit.isEnabled = false
|
||||||
binding.btnSubmit.isClickable = true
|
binding.btnSubmit.isClickable = false
|
||||||
binding.btnPlacebuffer.visibility = View.GONE
|
|
||||||
|
|
||||||
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
||||||
binding.tvSubtitle4.text = "Config"
|
Log.e("nametext", binding.tvName.text.toString())
|
||||||
|
|
||||||
binding.btnSamplestart.setOnClickListener {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.tvSubtitle4.visibility = View.VISIBLE
|
|
||||||
binding.tvSubtitle4.text = "Sample Started"
|
|
||||||
}
|
|
||||||
startSampleProcess()
|
|
||||||
it.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.btnPlacebuffer.setOnClickListener {
|
|
||||||
if (isBufferValueAvailable()) {
|
|
||||||
showBufferAlertDialog()
|
|
||||||
} else {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.tvSubtitle4.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
checkAndStartProcess()
|
|
||||||
}
|
|
||||||
it.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeViewModel() {
|
private fun observeViewModel() {
|
||||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
if (result == "Success") {
|
if (result == "Success") {
|
||||||
showToast("Test Results Uploaded Successfully")
|
showToast("Test Results Uploaded Successfully")
|
||||||
|
val i = Intent(
|
||||||
val digitalCardFragment = DigitalCardFragment()
|
requireContext().applicationContext, DashboardActivity::class.java
|
||||||
val transaction = parentFragmentManager.beginTransaction()
|
)
|
||||||
transaction.replace(R.id.fragment_container, digitalCardFragment)
|
startActivity(i)
|
||||||
transaction.addToBackStack(null)
|
(activity as HemocubeActivity).finish()
|
||||||
transaction.commit()
|
|
||||||
|
|
||||||
// val i = Intent(
|
|
||||||
// requireContext().applicationContext, DashboardActivity::class.java
|
|
||||||
// )
|
|
||||||
// startActivity(i)
|
|
||||||
// (activity as HemocubeActivity).finish()
|
|
||||||
}
|
}
|
||||||
if (result == "Local") {
|
if (result == "Local") {
|
||||||
showToast("Internet not available, test details stored locally")
|
showToast("Internet not available, test details stored locally")
|
||||||
@@ -165,39 +131,42 @@ class HemoCubeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.messages.observe(viewLifecycleOwner) {
|
hemoCubeViewModel.messages.observe(viewLifecycleOwner) {
|
||||||
binding.tvSubtitle4.text = it
|
binding.tvSubtitle4.text = it
|
||||||
}
|
}
|
||||||
|
// startListening.observe(viewLifecycleOwner) {
|
||||||
|
// if (it) {
|
||||||
|
// lifecycleScope.launch {
|
||||||
|
// delay(1000)
|
||||||
|
// if (binding.tvSubtitle4.text.toString().isEmpty()) {
|
||||||
|
// (activity as HemocubeActivity).reconnectDevice()
|
||||||
|
// if (isBufferValueAvailable()) {
|
||||||
|
// showBufferAlertDialog()
|
||||||
|
// } else {
|
||||||
|
// listenToHemoCube()
|
||||||
|
// startBufferProcess()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAndStartProcess() {
|
private fun checkAndStartProcess() {
|
||||||
startBufferProcess()
|
if (isBufferValueAvailable()) {
|
||||||
|
showBufferAlertDialog()
|
||||||
|
} else {
|
||||||
|
listenToHemoCube()
|
||||||
|
startBufferProcess()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isBufferValueAvailable(): Boolean {
|
private fun isBufferValueAvailable(): Boolean {
|
||||||
return try {
|
return if (sharedPreferences.getString(
|
||||||
if (sharedPreferences.getString(
|
Constants.BUFFER_VALUE_1, ""
|
||||||
Constants.BUFFER_VALUE_1, ""
|
) != "" && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "") != ""
|
||||||
) != "" && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "") != ""
|
) {
|
||||||
&& sharedPreferences.getString(Constants.BUFFER_VALUE_3, "") != ""
|
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
|
||||||
&& sharedPreferences.getString(Constants.BUFFER_VALUE_4, "") != ""
|
?.toDouble()!! > 0.0 && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")
|
||||||
) {
|
?.toDouble()!! > 0.0
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
|
} else {
|
||||||
?.toDouble()!! > 0.0 && sharedPreferences.getString(
|
|
||||||
Constants.BUFFER_VALUE_2,
|
|
||||||
""
|
|
||||||
)
|
|
||||||
?.toDouble()!! > 0.0 && sharedPreferences.getString(
|
|
||||||
Constants.BUFFER_VALUE_3,
|
|
||||||
""
|
|
||||||
)
|
|
||||||
?.toDouble()!! > 0.0 && sharedPreferences.getString(
|
|
||||||
Constants.BUFFER_VALUE_4,
|
|
||||||
""
|
|
||||||
)
|
|
||||||
?.toDouble()!! > 0.0
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
showToast("error while getting existing buffer")
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,15 +184,13 @@ class HemoCubeFragment : Fragment() {
|
|||||||
positiveText,
|
positiveText,
|
||||||
object : MyDialogListener {
|
object : MyDialogListener {
|
||||||
override fun onClickNegativeButton() {
|
override fun onClickNegativeButton() {
|
||||||
|
listenToHemoCube()
|
||||||
startBufferProcess()
|
startBufferProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
override fun onClickPositiveButton() {
|
||||||
activity?.runOnUiThread {
|
listenToHemoCube()
|
||||||
binding.btnPlacebuffer.visibility = View.GONE
|
startSampleProcess()
|
||||||
binding.btnSamplestart.visibility = View.VISIBLE
|
|
||||||
binding.tvSubtitle4.text = "Place Sample"
|
|
||||||
}
|
|
||||||
isUsingExistingBuffer = true
|
isUsingExistingBuffer = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -259,112 +226,42 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDeviceInfo() {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
|
||||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
|
|
||||||
HemoCubeCommands.getDeviceId,
|
|
||||||
object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
|
||||||
data?.let {
|
|
||||||
val stringData = String(it)
|
|
||||||
hemoCubeViewModel.messages.postValue(stringData)
|
|
||||||
binding.tvSubtitle4.text = stringData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
||||||
if (stringData.contains("#")) {
|
if (stringData.contains("#")) {
|
||||||
|
hemoCubeViewModel.messages.postValue(stringData)
|
||||||
isTestOngoing = true
|
isTestOngoing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
resultData += stringData
|
resultData += stringData
|
||||||
|
|
||||||
when {
|
when {
|
||||||
stringData.contains("SN") -> {
|
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||||
val slData = stringData.split(" ")
|
stringData.contains("#Sample Completed") -> {
|
||||||
if (slData.size > 1) {
|
|
||||||
val hardwareId = slData[1].trim()
|
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(Constants.DEVICE_ID, hardwareId)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.btnPlacebuffer.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
hemoCubeViewModel.messages.postValue("Start")
|
|
||||||
}
|
|
||||||
|
|
||||||
stringData.contains("#BS") -> {
|
|
||||||
hemoCubeViewModel.messages.postValue("Buffer Started")
|
|
||||||
}
|
|
||||||
|
|
||||||
stringData.contains("#BC") -> {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.tvSubtitle4.text = "Buffer Completed"
|
|
||||||
binding.btnSamplestart.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stringData.contains("#SS") -> {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.tvSubtitle4.text = "Sample Started"
|
|
||||||
binding.btnSamplestart.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stringData.contains("#SC") -> {
|
|
||||||
binding.tvSubtitle4.text = "Sample Completed"
|
|
||||||
fetchResult()
|
fetchResult()
|
||||||
testingTrace.stop()
|
testingTrace.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
resultData.contains("REND") -> {
|
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
||||||
val resultLines = resultData.split("\\s+(?=LB|LS)".toRegex())
|
var validString: String
|
||||||
var bufferIntensity = resultLines[1].split(' ')[1].trim()
|
val results: List<String>
|
||||||
led1BufferForDevice = if (isUsingExistingBuffer) {
|
if (stringData.contains("RESULT")) {
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()!!
|
validString = isValidResult(stringData)
|
||||||
|
if (validString.isEmpty()) {
|
||||||
|
results = resultData.split("\n")
|
||||||
|
validString = parseResult(results)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
bufferIntensity.toDoubleOrNull()!!
|
results = resultData.split("\n")
|
||||||
|
validString = parseResult(results)
|
||||||
}
|
}
|
||||||
bufferIntensity = resultLines[2].split(' ')[1].trim()
|
if (validString.isNotEmpty()) {
|
||||||
led2BufferForDevice = if (isUsingExistingBuffer) {
|
handleValidResult(validString, resultData)
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()!!
|
|
||||||
} else {
|
|
||||||
bufferIntensity.toDoubleOrNull()!!
|
|
||||||
}
|
}
|
||||||
bufferIntensity = resultLines[3].split(' ')[1].trim()
|
|
||||||
led3BufferForDevice = if (isUsingExistingBuffer) {
|
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_3, "")?.toDoubleOrNull()!!
|
|
||||||
} else {
|
|
||||||
bufferIntensity.toDoubleOrNull()!!
|
|
||||||
}
|
|
||||||
bufferIntensity = resultLines[4].split(' ')[1].trim()
|
|
||||||
led4BufferForDevice = if (isUsingExistingBuffer) {
|
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_4, "")?.toDoubleOrNull()!!
|
|
||||||
} else {
|
|
||||||
bufferIntensity.toDoubleOrNull()!!
|
|
||||||
}
|
|
||||||
|
|
||||||
var sampleIntensity = resultLines[5].split(' ')[1].trim()
|
|
||||||
led1SampleForDevice = resultLines[5].split(' ')[1].trim().toDoubleOrNull()!!
|
|
||||||
sampleIntensity = resultLines[6].split(' ')[1].trim()
|
|
||||||
led2SampleForDevice = resultLines[6].split(' ')[1].trim().toDoubleOrNull()!!
|
|
||||||
sampleIntensity = resultLines[7].split(' ')[1].trim()
|
|
||||||
led3SampleForDevice = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!!
|
|
||||||
sampleIntensity = resultLines[8].split(' ')[1].split('\r')[0].trim()
|
|
||||||
led4SampleForDevice = resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
|
|
||||||
processResult()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun showError() {
|
private fun showError() {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
UIUtils.createAlertDialog(requireContext(),
|
||||||
@@ -394,65 +291,106 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processResult() {
|
private fun showStartSampleDialog() {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
UIUtils.createAlertDialog(requireContext(),
|
||||||
|
"Start Sample",
|
||||||
|
"Do you want to start sample reading?",
|
||||||
|
getString(R.string.no),
|
||||||
|
"Yes",
|
||||||
|
object : MyDialogListener {
|
||||||
|
override fun onClickNegativeButton() {}
|
||||||
|
|
||||||
|
override fun onClickPositiveButton() {
|
||||||
|
listenToHemoCube()
|
||||||
|
startSampleProcess()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun handleValidResult(validString: String, fullReadOutput: String) {
|
||||||
try {
|
try {
|
||||||
|
val result = validString.split(" ")
|
||||||
val deviceLog = resultData
|
val deviceLog = resultData
|
||||||
|
if (result.size == 8) {
|
||||||
val pInfo = requireActivity().packageManager.getPackageInfo(
|
val deviceSerialNo = result[2]
|
||||||
requireActivity().packageName, 0
|
with(sharedPreferences.edit()) {
|
||||||
)
|
putString(Constants.DEVICE_ID, deviceSerialNo)
|
||||||
val version = pInfo.versionName
|
apply()
|
||||||
|
|
||||||
val led1Average = log10(led1BufferForDevice?.div(led1SampleForDevice!!) ?: 0.0)
|
|
||||||
val led2Average = log10(led2BufferForDevice?.div(led2SampleForDevice!!) ?: 0.0)
|
|
||||||
val led3Average = log10(led3BufferForDevice?.div(led3SampleForDevice!!) ?: 0.0)
|
|
||||||
val led4Average = log10(led4BufferForDevice?.div(led4SampleForDevice!!) ?: 0.0)
|
|
||||||
val deviceRatio = led1Average / led3Average
|
|
||||||
|
|
||||||
if (led1Average < 0 || led2Average < 0) {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.errorMessage.text = "Warning: Negative Abs. Retake Blank Reading"
|
|
||||||
binding.errorMessage.visibility = View.VISIBLE
|
|
||||||
}
|
}
|
||||||
}
|
val loginId = sharedPreferences.getString(Constants.USER_ID, "").toString()
|
||||||
|
if (checkDeviceIdMismatch(deviceSerialNo, loginId)) {
|
||||||
DataHolder.hemoCubeTestData?.apply {
|
activity?.runOnUiThread {
|
||||||
deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()
|
binding.errorMessage.text = "Warning: Login Id is different"
|
||||||
led1Buffer = led1BufferForDevice
|
binding.errorMessage.visibility = View.VISIBLE
|
||||||
led2Buffer = led2BufferForDevice
|
|
||||||
led3Buffer = led3BufferForDevice
|
|
||||||
led4Buffer = led4BufferForDevice
|
|
||||||
appVersion = version
|
|
||||||
this.led1Sample = led1SampleForDevice
|
|
||||||
this.led2Sample = led2SampleForDevice
|
|
||||||
this.led3Sample = led3SampleForDevice
|
|
||||||
this.led4Sample = led4SampleForDevice
|
|
||||||
this.led1Average = led1Average
|
|
||||||
this.led2Average = led2Average
|
|
||||||
this.led3Average = led3Average
|
|
||||||
this.led4Average = led4Average
|
|
||||||
this.deviceRatio = deviceRatio
|
|
||||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
|
||||||
this.coefficients = currentDeviceData?.coefficients?.get(0)
|
|
||||||
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
|
||||||
this.classificationResult = findResult(calculatedRatio)
|
|
||||||
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
|
||||||
this.resultData = deviceLog
|
|
||||||
if (!isUsingExistingBuffer) {
|
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(Constants.BUFFER_VALUE_1, led1BufferForDevice.toString())
|
|
||||||
putString(Constants.BUFFER_VALUE_2, led2BufferForDevice.toString())
|
|
||||||
putString(Constants.BUFFER_VALUE_3, led3BufferForDevice.toString())
|
|
||||||
putString(Constants.BUFFER_VALUE_4, led4BufferForDevice.toString())
|
|
||||||
apply()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val led1BufferForDevice = if (isUsingExistingBuffer) {
|
||||||
|
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
||||||
|
} else {
|
||||||
|
result[3].toDoubleOrNull()
|
||||||
|
}
|
||||||
|
val led2BufferForDevice = if (isUsingExistingBuffer) {
|
||||||
|
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()
|
||||||
|
} else {
|
||||||
|
result[4].toDoubleOrNull()
|
||||||
|
}
|
||||||
|
val pInfo = requireActivity().packageManager.getPackageInfo(
|
||||||
|
requireActivity().packageName, 0
|
||||||
|
)
|
||||||
|
val version = pInfo.versionName
|
||||||
|
val led1Sample = result[5].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) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (led1Average < 0 || led2Average < 0) {
|
||||||
|
activity?.runOnUiThread{
|
||||||
|
binding.errorMessage.text = "Warning: Negative Abs. Retake Blank Reading"
|
||||||
|
binding.errorMessage.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DataHolder.hemoCubeTestData?.apply {
|
||||||
|
deviceId = deviceSerialNo
|
||||||
|
led1Buffer = led1BufferForDevice
|
||||||
|
led2Buffer = led2BufferForDevice
|
||||||
|
appVersion = version
|
||||||
|
this.led1Sample = led1Sample
|
||||||
|
this.led2Sample = led2Sample
|
||||||
|
this.led1Average = led1Average
|
||||||
|
this.led2Average = led2Average
|
||||||
|
this.deviceRatio = deviceRatio
|
||||||
|
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||||
|
this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||||
|
this.classificationResult = findResult(calculatedRatio)
|
||||||
|
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
||||||
|
this.resultData = deviceLog
|
||||||
|
if (!isUsingExistingBuffer) {
|
||||||
|
with(sharedPreferences.edit()) {
|
||||||
|
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
||||||
|
putString(Constants.BUFFER_VALUE_2, led2Buffer.toString())
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.btnSubmit.visibility = View.VISIBLE
|
binding.btnSubmit.visibility = View.VISIBLE
|
||||||
|
binding.btnSubmit.isEnabled = true
|
||||||
|
binding.btnSubmit.isClickable = true
|
||||||
|
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
||||||
}
|
}
|
||||||
binding.btnSubmit.isEnabled = true
|
}
|
||||||
binding.btnSubmit.isClickable = true
|
|
||||||
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
@@ -499,10 +437,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private fun startBufferProcess() {
|
private fun startBufferProcess() {
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.btnPlacebuffer.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
||||||
object : UsbServiceListener {
|
object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
override fun onUsbRead(data: ByteArray?) {}
|
||||||
@@ -546,6 +480,29 @@ class HemoCubeFragment : Fragment() {
|
|||||||
return coefficient1 * ratio + coefficient2
|
return coefficient1 * ratio + coefficient2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseResult(frames: List<String>): String {
|
||||||
|
val lines = mutableListOf<String>()
|
||||||
|
for (frame in frames.reversed()) {
|
||||||
|
if (frame.contains("REND") || frame.contains("RESULT")) lines += frame
|
||||||
|
if (frame.contains("RESULT")) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val line = lines.reversed().joinToString("").trim()
|
||||||
|
if (line.contains("RESULT") && line.split(" ").size == 8) {
|
||||||
|
return line
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isValidResult(line: String): String {
|
||||||
|
return if (line.contains("RESULT") && line.split(" ").size == 8) {
|
||||||
|
line
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
||||||
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -95,16 +95,10 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
testDetails?.kitSerial = sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
|
testDetails?.kitSerial = sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
|
||||||
testDetails?.led1Buffer = DataHolder.hemoCubeTestData?.led1Buffer
|
testDetails?.led1Buffer = DataHolder.hemoCubeTestData?.led1Buffer
|
||||||
testDetails?.led2Buffer = DataHolder.hemoCubeTestData?.led2Buffer
|
testDetails?.led2Buffer = DataHolder.hemoCubeTestData?.led2Buffer
|
||||||
testDetails?.led3Buffer = DataHolder.hemoCubeTestData?.led3Buffer
|
|
||||||
testDetails?.led4Buffer = DataHolder.hemoCubeTestData?.led4Buffer
|
|
||||||
testDetails?.led1Sample = DataHolder.hemoCubeTestData?.led1Sample
|
testDetails?.led1Sample = DataHolder.hemoCubeTestData?.led1Sample
|
||||||
testDetails?.led2Sample = DataHolder.hemoCubeTestData?.led2Sample
|
testDetails?.led2Sample = DataHolder.hemoCubeTestData?.led2Sample
|
||||||
testDetails?.led3Sample = DataHolder.hemoCubeTestData?.led3Sample
|
|
||||||
testDetails?.led4Sample = DataHolder.hemoCubeTestData?.led4Sample
|
|
||||||
testDetails?.led1Average = DataHolder.hemoCubeTestData?.led1Average
|
testDetails?.led1Average = DataHolder.hemoCubeTestData?.led1Average
|
||||||
testDetails?.led2Average = DataHolder.hemoCubeTestData?.led2Average
|
testDetails?.led2Average = DataHolder.hemoCubeTestData?.led2Average
|
||||||
testDetails?.led3Average = DataHolder.hemoCubeTestData?.led3Average
|
|
||||||
testDetails?.led4Average = DataHolder.hemoCubeTestData?.led4Average
|
|
||||||
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
||||||
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
||||||
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import `in`.sminnovations.hpostesting.databinding.ActivityTestRightBinding
|
|||||||
class TestRightActivity : AppCompatActivity() {
|
class TestRightActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityTestRightBinding
|
private lateinit var binding: ActivityTestRightBinding
|
||||||
private val viewModel by viewModels<TestRightViewModel>()
|
private val viewModel by viewModels<TestRightViewModel<Any?>>()
|
||||||
private var myMenu: Menu? = null
|
private var myMenu: Menu? = null
|
||||||
|
|
||||||
private lateinit var mDriver: UsbSerialDriver
|
private lateinit var mDriver: UsbSerialDriver
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpReferenceB
|
|||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class TestRightExpReference : Fragment() {
|
class TestRightExpReference : Fragment() {
|
||||||
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
private lateinit var binding: FragmentTestRightExpReferenceBinding
|
||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
||||||
private val TAG = "TestRightExpReference"
|
private val TAG = "TestRightExpReference"
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpSampleBind
|
|||||||
class TestRightExpSample : Fragment() {
|
class TestRightExpSample : Fragment() {
|
||||||
|
|
||||||
private lateinit var binding: FragmentTestRightExpSampleBinding
|
private lateinit var binding: FragmentTestRightExpSampleBinding
|
||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
||||||
|
|
||||||
private val TAG = "TestRightExpSample"
|
private val TAG = "TestRightExpSample"
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import kotlinx.coroutines.withContext
|
|||||||
class TestRightResults : Fragment() {
|
class TestRightResults : Fragment() {
|
||||||
|
|
||||||
private lateinit var binding: FragmentTestRightResultsBinding
|
private lateinit var binding: FragmentTestRightResultsBinding
|
||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel<Any?> by activityViewModels()
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.example.hpostesting.domain.TestRightResultCalculation
|
|||||||
import com.example.hpostesting.util.MyUtils
|
import com.example.hpostesting.util.MyUtils
|
||||||
import com.google.firebase.storage.FirebaseStorage
|
import com.google.firebase.storage.FirebaseStorage
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import dagger.hilt.android.scopes.ViewModelScoped
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.tasks.await
|
import kotlinx.coroutines.tasks.await
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -38,14 +39,16 @@ import kotlin.math.log10
|
|||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
|
@ViewModelScoped
|
||||||
class TestRightViewModel @Inject constructor(
|
class TestRightViewModel @Inject constructor(
|
||||||
private val saveRawData: SaveRawData,
|
private val saveRawData: SaveRawData,
|
||||||
private val saveRawDataTest: SaveRawDataTest,
|
private val saveRawDataTest: SaveRawDataTest,
|
||||||
private val repository: DatabaseRepository,
|
private val repository: DatabaseRepository,
|
||||||
private val userDao: UserDao,
|
private val userDao: UserDao,
|
||||||
context: Context
|
context: Context?
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
|
||||||
var isServiceConnected = false
|
var isServiceConnected = false
|
||||||
val progressBar = MutableLiveData(false)
|
val progressBar = MutableLiveData(false)
|
||||||
|
|
||||||
@@ -54,10 +57,10 @@ class TestRightViewModel @Inject constructor(
|
|||||||
|
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
|
|
||||||
val testDetails = DataHolder.selectedTest
|
var testDetails = DataHolder.selectedTest
|
||||||
|
|
||||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
private val _networkStatusLiveData = context?.let { NetworkStatusLiveData(it) }
|
||||||
val networkStatusLiveData: LiveData<Boolean>
|
val networkStatusLiveData: NetworkStatusLiveData?
|
||||||
get() = _networkStatusLiveData
|
get() = _networkStatusLiveData
|
||||||
|
|
||||||
val allUserData = userDao.getAll()
|
val allUserData = userDao.getAll()
|
||||||
@@ -439,7 +442,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||||
).format(Calendar.getInstance().time)
|
).format(Calendar.getInstance().time)
|
||||||
when (repository.addTestToDatabase(testDetails)) {
|
when (repository.addTestToDatabase(testDetails)) {
|
||||||
is Response.Success -> {
|
is Response.Success<*> -> {
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,43 +451,45 @@ class TestRightViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadResultToDatabase(context: Context, isOnline: Boolean,deviceSerialNumber: String) = viewModelScope.launch {
|
fun uploadResultToDatabase(context: Context, isOnline: Boolean, deviceSerialNumber: String) =
|
||||||
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
viewModelScope.launch {
|
||||||
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
||||||
testDetails?.csvPath = csvFilePath
|
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
||||||
testDetails?.reportPath = logTxtFilePath
|
testDetails?.csvPath = csvFilePath
|
||||||
testDetails?.deviceSerialNumber = deviceSerialNumber
|
testDetails?.reportPath = logTxtFilePath
|
||||||
if (isOnline) {
|
testDetails?.deviceSerialNumber = deviceSerialNumber
|
||||||
val storageRef = FirebaseStorage.getInstance().reference
|
if (isOnline) {
|
||||||
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
val storageRef = FirebaseStorage.getInstance().reference
|
||||||
|
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val csvFileUri = Uri.fromFile(File(csvFilePath))
|
val csvFileUri = Uri.fromFile(File(csvFilePath))
|
||||||
val logTxtFileUri = Uri.fromFile(File(logTxtFilePath))
|
val logTxtFileUri = Uri.fromFile(File(logTxtFilePath))
|
||||||
|
|
||||||
val csvUploadTask =
|
val csvUploadTask =
|
||||||
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!).putFile(csvFileUri)
|
storageTestDetailsRef.child(csvFileUri.lastPathSegment!!)
|
||||||
.await()
|
.putFile(csvFileUri)
|
||||||
val logUploadTask = storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!)
|
.await()
|
||||||
.putFile(logTxtFileUri).await()
|
val logUploadTask = storageTestDetailsRef.child(logTxtFileUri.lastPathSegment!!)
|
||||||
|
.putFile(logTxtFileUri).await()
|
||||||
|
|
||||||
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
||||||
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
||||||
val serialNumber = Constants.STATICID.firstOrNull { it == deviceSerialNumber }
|
val serialNumber = Constants.STATICID.firstOrNull { it == deviceSerialNumber }
|
||||||
testDetails?.csvPath = csvUri
|
testDetails?.csvPath = csvUri
|
||||||
testDetails?.reportPath = logUri
|
testDetails?.reportPath = logUri
|
||||||
|
|
||||||
addResultTestToDb()
|
addResultTestToDb()
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
// Handle the exception appropriately (e.g., log the error, display an error message)
|
// Handle the exception appropriately (e.g., log the error, display an error message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
testDetails?.testTime = SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||||
|
).format(Calendar.getInstance().time)
|
||||||
|
userDao.insertAll(testDetails!!)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
testDetails?.testTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
userDao.insertAll(testDetails!!)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun bulkUploadResultToDatabase(userData: UserData) = viewModelScope.launch {
|
fun bulkUploadResultToDatabase(userData: UserData) = viewModelScope.launch {
|
||||||
val storageRef = FirebaseStorage.getInstance().reference
|
val storageRef = FirebaseStorage.getInstance().reference
|
||||||
@@ -519,7 +524,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||||
).format(Calendar.getInstance().time)
|
).format(Calendar.getInstance().time)
|
||||||
when (repository.addTestToDatabase(userData)) {
|
when (repository.addTestToDatabase(userData)) {
|
||||||
is Response.Success -> {
|
is Response.Success<*> -> {
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class UsbService : Service() {
|
|||||||
fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) {
|
fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) {
|
||||||
mPort = driver.ports[0] // Most devices have just one port (port 0)
|
mPort = driver.ports[0] // Most devices have just one port (port 0)
|
||||||
mPort.open(connection)
|
mPort.open(connection)
|
||||||
mPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
||||||
isUsbConnected = true
|
isUsbConnected = true
|
||||||
Log.d(TAG, "My Usb Connected ${mPort.driver}")
|
Log.d(TAG, "My Usb Connected ${mPort.driver}")
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.0 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<vector android:height="24dp" android:tint="#000000"
|
|
||||||
android:viewportHeight="24" android:viewportWidth="24"
|
|
||||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
|
||||||
</vector>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -1,243 +0,0 @@
|
|||||||
<layout 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"
|
|
||||||
tools:context="com.example.hpostesting.presentation.hemocube.DigitalCardFragment">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/fragment_container">
|
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
|
||||||
android:id="@+id/userCard"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="350dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
app:cardBackgroundColor="#C0C0C0"
|
|
||||||
app:cardCornerRadius="25dp"
|
|
||||||
app:cardElevation="0dp"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="22dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/userImage"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
tools:src="@drawable/karnataka" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/userName"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:layout_marginStart="46dp"
|
|
||||||
app:layout_constraintTop_toBottomOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/userImage"
|
|
||||||
app:layout_constraintTop_toTopOf="@+id/userImage"
|
|
||||||
tools:src="@drawable/sickle_cell_gov_logo"/>
|
|
||||||
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/userImage3"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:layout_marginStart="36dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/userName"
|
|
||||||
app:layout_constraintTop_toTopOf="@+id/userName"
|
|
||||||
tools:src="@drawable/indianoil"/>
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/userImage4"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:layout_marginTop="30dp"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage"
|
|
||||||
tools:src="@drawable/person" />
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
|
||||||
android:id="@+id/userdetails"
|
|
||||||
android:layout_width="150dp"
|
|
||||||
android:layout_height="120dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
app:cardBackgroundColor="#FFFFFF"
|
|
||||||
app:cardCornerRadius="5dp"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/userImage4"
|
|
||||||
app:cardElevation="0dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/name"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage"
|
|
||||||
android:text="Name: Mariya" />
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/dob"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_marginTop="30dp"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/name"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/name"
|
|
||||||
android:text="DOB: 1998" />
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/gender"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/dob"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/dob"
|
|
||||||
android:text="gender: female" />
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/State"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_marginTop="70dp"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/gender"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/gender"
|
|
||||||
android:text="State: Kerala" />
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
|
||||||
<androidx.cardview.widget.CardView
|
|
||||||
android:id="@+id/userdetails2"
|
|
||||||
android:layout_width="150dp"
|
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:layout_height="120dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
app:cardBackgroundColor="#FFFFFF"
|
|
||||||
app:cardCornerRadius="5dp"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage3"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/userdetails"
|
|
||||||
app:cardElevation="0dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/abhaid"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:gravity="start"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage3"
|
|
||||||
android:text="ABHA-ID: XXXX-8734" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/blood"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginTop="30dp"
|
|
||||||
android:gravity="start"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage3"
|
|
||||||
android:text="Blood Group: O +ve" />
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/sicklecell"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:gravity="start"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="8sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage3"
|
|
||||||
android:text="Sickle-Cell: Normal (HbA)" />
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/issueDate"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginTop="70dp"
|
|
||||||
android:gravity="start"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userImage3"
|
|
||||||
android:text="Issue Date: Oct 2,2023" />
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
|
||||||
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/digitalcard"
|
|
||||||
android:backgroundTint="#00008B"
|
|
||||||
app:cardBackgroundColor="#00008B"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="16dp"
|
|
||||||
android:layout_marginTop="20dp"
|
|
||||||
android:text="@string/digital_card"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/userdetails" />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progressBar"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:elevation="12dp"
|
|
||||||
android:indeterminate="true"
|
|
||||||
android:indeterminateDrawable="@drawable/progressbar_drawable"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
</layout>
|
|
||||||
@@ -147,35 +147,8 @@
|
|||||||
app:layout_constraintHorizontal_bias="1.0"
|
app:layout_constraintHorizontal_bias="1.0"
|
||||||
app:layout_constraintStart_toEndOf="@id/et_abha_id"
|
app:layout_constraintStart_toEndOf="@id/et_abha_id"
|
||||||
app:layout_constraintTop_toTopOf="@id/et_abha_id" />
|
app:layout_constraintTop_toTopOf="@id/et_abha_id" />
|
||||||
<Button
|
|
||||||
android:visibility="gone"
|
|
||||||
android:id="@+id/btn_samplestart"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="16dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:clickable="false"
|
|
||||||
android:text="@string/Start_Sample"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_placebuffer" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btn_placebuffer"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="16dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:clickable="false"
|
|
||||||
android:text="@string/place_buffer"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:id="@+id/btn_submit"
|
android:id="@+id/btn_submit"
|
||||||
@@ -205,6 +178,61 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
||||||
|
|
||||||
|
<!-- <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" />-->
|
||||||
|
|
||||||
|
<!-- </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_buffer"-->
|
||||||
|
<!-- android:layout_width="wrap_content"-->
|
||||||
|
<!-- android:layout_height="wrap_content"-->
|
||||||
|
<!-- android:text="@string/new_buffer"-->
|
||||||
|
<!-- android:textColor="@color/white"-->
|
||||||
|
<!-- android:layout_margin="10dp"-->
|
||||||
|
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||||
|
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||||
|
<!-- app:layout_constraintEnd_toStartOf="@id/btn_kit"/>-->
|
||||||
|
|
||||||
|
<!-- <Button-->
|
||||||
|
<!-- android:id="@+id/btn_read"-->
|
||||||
|
<!-- android:layout_width="wrap_content"-->
|
||||||
|
<!-- android:layout_height="wrap_content"-->
|
||||||
|
<!-- android:text="@string/read"-->
|
||||||
|
<!-- android:layout_margin="16dp"-->
|
||||||
|
<!-- android:clickable="false"-->
|
||||||
|
<!-- app:layout_constraintTop_toBottomOf="@id/btn_set_reference"-->
|
||||||
|
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
||||||
|
|
||||||
|
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
|
|||||||
@@ -113,7 +113,7 @@
|
|||||||
<string name="sickle_find">Sickle Find</string>
|
<string name="sickle_find">Sickle Find</string>
|
||||||
<string name="submit">Submit</string>
|
<string name="submit">Submit</string>
|
||||||
<string name="diagnostics">Device Diagnostics</string>
|
<string name="diagnostics">Device Diagnostics</string>
|
||||||
<string name="place_buffer">Start</string>
|
<string name="place_buffer">Start Buffer</string>
|
||||||
<string name="Start_Sample">Start Sample</string>
|
<string name="Start_Sample">Start Sample</string>
|
||||||
<string name="new_kit">New Kit</string>
|
<string name="new_kit">New Kit</string>
|
||||||
<string name="new_buffer">New Buffer</string>
|
<string name="new_buffer">New Buffer</string>
|
||||||
@@ -158,7 +158,6 @@
|
|||||||
<string name="is_patient_married_yes_no">Is Patient Married? (Yes/No)</string>
|
<string name="is_patient_married_yes_no">Is Patient Married? (Yes/No)</string>
|
||||||
<string name="category">Category</string>
|
<string name="category">Category</string>
|
||||||
<string name="blood_group">Blood Group</string>
|
<string name="blood_group">Blood Group</string>
|
||||||
<string name="digital_card">Digital Counselling Card</string>
|
|
||||||
<string name="patient_medical_records">Patient Medical Records</string>
|
<string name="patient_medical_records">Patient Medical Records</string>
|
||||||
<string name="patient_address_details">Patient Address Details</string>
|
<string name="patient_address_details">Patient Address Details</string>
|
||||||
<string name="district">District</string>
|
<string name="district">District</string>
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.view.View
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mockito.ArgumentMatchers.any
|
||||||
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.verify
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
|
||||||
|
class HemocubeViewModelTest {
|
||||||
|
@Mock
|
||||||
|
private lateinit var mockSharedPreferences: SharedPreferences
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
||||||
|
|
||||||
|
private lateinit var hemoCubeFragment: HemoCubeFragment
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this)
|
||||||
|
hemoCubeFragment = HemoCubeFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `handleValidResult with valid input`() {
|
||||||
|
|
||||||
|
val validString = "valid string"
|
||||||
|
val fullReadOutput = "full read output"
|
||||||
|
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
|
||||||
|
`when`(mockActivity.runOnUiThread(any())).thenAnswer {
|
||||||
|
val runnable = it.getArgument(0, Runnable::class.java)
|
||||||
|
runnable.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Act
|
||||||
|
hemoCubeFragment.handleValidResult(validString, fullReadOutput)
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
// Add appropriate assertions based on the behavior you expect
|
||||||
|
verify(mockSharedPreferences).edit()
|
||||||
|
verify(mockBinding).btnSubmit.visibility = View.VISIBLE
|
||||||
|
verify(mockBinding).btnSubmit.isEnabled = true
|
||||||
|
// Add more verifications as needed
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Add more test cases for different scenarios if needed
|
||||||
|
}
|
||||||
@@ -1,17 +1,49 @@
|
|||||||
package com.example.hpostesting
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
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.data.model.PatientData
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
import junit.framework.Assert.assertEquals
|
import junit.framework.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
import java.math.RoundingMode
|
import java.math.RoundingMode
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
class TestRightViewModelTest {
|
class TestRightViewModelTest {
|
||||||
private val viewModel = TestRightViewModel()
|
|
||||||
|
@Mock
|
||||||
|
lateinit var mockContext: Context
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var mockRepository: DatabaseRepository
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var mockSaveRawData: SaveRawData
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var mockSaveRawDataTest: SaveRawDataTest
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var mockUserDao: UserDao
|
||||||
|
|
||||||
|
lateinit var viewModel: TestRightViewModel<Any?>
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
// Initialize mocks
|
||||||
|
MockitoAnnotations.initMocks(this)
|
||||||
|
|
||||||
|
// Create the ViewModel with mock dependencies
|
||||||
|
viewModel = TestRightViewModel(mockSaveRawData,mockSaveRawDataTest,mockRepository,mockUserDao,mockContext)
|
||||||
|
}
|
||||||
private val data = InputData()
|
private val data = InputData()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,8 +95,11 @@ class TestRightViewModelTest {
|
|||||||
viewModel.mapDeviceConstants(data.inputRead)
|
viewModel.mapDeviceConstants(data.inputRead)
|
||||||
viewModel.mapPixelNumberToWavelength()
|
viewModel.mapPixelNumberToWavelength()
|
||||||
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
||||||
viewModel.mapIntensityValues(TestDataGenerator().getInputSampleMapIntensityValues(), false)
|
val mapIntensityValues = viewModel.mapIntensityValues(
|
||||||
viewModel.patientDetails = PatientData("Surya", 2, "Male", TestRightResultType.UNDEFINED)
|
TestDataGenerator().getInputSampleMapIntensityValues(),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
viewModel.testDetails = UserData("Surya", "2", "Male")
|
||||||
viewModel.mapWavelengthToAbsorbance()
|
viewModel.mapWavelengthToAbsorbance()
|
||||||
|
|
||||||
val wavelengthList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
|
val wavelengthList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ buildscript {
|
|||||||
kotlin_version = '1.8.21'
|
kotlin_version = '1.8.21'
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:8.1.1'
|
classpath 'com.android.tools.build:gradle:8.0.2'
|
||||||
classpath 'com.google.gms:google-services:4.4.0'
|
classpath 'com.google.gms:google-services:4.4.0'
|
||||||
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.1'
|
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.1'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user