Compare commits
1 Commits
2.1.101
...
API-CALLS-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf2e904445 |
@@ -14,13 +14,13 @@ android {
|
|||||||
compileSdk 34
|
compileSdk 34
|
||||||
namespace 'in.sminnovations.hpostesting'
|
namespace 'in.sminnovations.hpostesting'
|
||||||
|
|
||||||
// dev - development, quality - qc, uat - User Acceptance Test, preprod - preproduction, prod - production
|
// prod - production, preprod - preproduction, quality - qc, dev - development
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "in.sminnovations.hpostesting.quality"
|
applicationId "in.sminnovations.hpostesting.quality"
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 101
|
versionCode 100
|
||||||
versionName "2.1.101"
|
versionName "2.1.100"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -112,8 +112,6 @@ dependencies {
|
|||||||
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
|
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
|
||||||
androidTestImplementation 'org.mockito:mockito-inline:3.12.4'
|
androidTestImplementation 'org.mockito:mockito-inline:3.12.4'
|
||||||
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
|
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
|
||||||
testImplementation 'org.powermock:powermock-api-mockito2:2.0.9'
|
|
||||||
testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
|
|
||||||
|
|
||||||
testImplementation "androidx.arch.core:core-testing:2.2.0"
|
testImplementation "androidx.arch.core:core-testing:2.2.0"
|
||||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package com.example.hpostesting.data.constant
|
|||||||
|
|
||||||
object Constants {
|
object Constants {
|
||||||
const val ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION"
|
const val ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION"
|
||||||
const val HEMOCUBE_USB_PERMISSION = "shanmukha.in.sickle_cell_homocube.USB_PERMISSION"
|
const val HOMOCUBE_USB_PERMISSION = "shanmukha.in.sickle_cell_homocube.USB_PERMISSION"
|
||||||
|
|
||||||
const val BASE_URL = "www.google.com"
|
const val BASE_URL = "www.google.com"
|
||||||
|
|
||||||
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
||||||
|
|
||||||
const val MOLBIO_INTEGRATION = false
|
const val MOLBIO_INTERGATION = false
|
||||||
const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in"
|
const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in"
|
||||||
const val deviceProvisionPassword = "f2ab0e7f9d69"
|
const val deviceProvisionPassword = "f2ab0e7f9d69"
|
||||||
const val DEVICE_ID_API = "deviceIDAPI"
|
const val DEVICE_ID_API = "deviceIDAPI"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.hpostesting.domain
|
package com.example.hpostesting.domain
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -31,7 +32,7 @@ class LogFileManagerImpl @Inject constructor(private val context: Context) : Log
|
|||||||
|
|
||||||
file
|
file
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
// Log.e("LogFileManager", "Error creating log file: ${e.message}")
|
Log.e("LogFileManager", "Error creating log file: ${e.message}")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,54 +208,74 @@ class KitScanActivity : AppCompatActivity(), IDcsSdkApiDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Setting up the SDK handler
|
||||||
|
|
||||||
//Setting up the SDK handler
|
//Setting up the SDK handler
|
||||||
sdkHandler = SDKHandler(this)
|
sdkHandler = SDKHandler(this)
|
||||||
|
|
||||||
|
//Registers a particular object which conforms to IDcsSdkApiDelegate interface as a receiver of SDK notifications.
|
||||||
|
|
||||||
//Registers a particular object which conforms to IDcsSdkApiDelegate interface as a receiver of SDK notifications.
|
//Registers a particular object which conforms to IDcsSdkApiDelegate interface as a receiver of SDK notifications.
|
||||||
sdkHandler!!.dcssdkSetDelegate(this)
|
sdkHandler!!.dcssdkSetDelegate(this)
|
||||||
|
|
||||||
|
//this command is telling the sdk that we're going to be connecting to the scanner via USB
|
||||||
|
|
||||||
//this command is telling the sdk that we're going to be connecting to the scanner via USB
|
//this command is telling the sdk that we're going to be connecting to the scanner via USB
|
||||||
sdkHandler!!.dcssdkSetOperationalMode(DCSSDKDefs.DCSSDK_MODE.DCSSDK_OPMODE_SNAPI)
|
sdkHandler!!.dcssdkSetOperationalMode(DCSSDKDefs.DCSSDK_MODE.DCSSDK_OPMODE_SNAPI)
|
||||||
|
|
||||||
|
|
||||||
|
//deciding what kind of notifications we want to receive. Explained more in the function
|
||||||
|
//first we use bitmapping to set these values into the notifications_mask.
|
||||||
|
|
||||||
|
|
||||||
//deciding what kind of notifications we want to receive. Explained more in the function
|
//deciding what kind of notifications we want to receive. Explained more in the function
|
||||||
//first we use bitmapping to set these values into the notifications_mask.
|
//first we use bitmapping to set these values into the notifications_mask.
|
||||||
var notifications_mask = 0
|
var notifications_mask = 0
|
||||||
// We would like to subscribe to all barcode events
|
// We would like to subscribe to all barcode events
|
||||||
|
// We would like to subscribe to all barcode events
|
||||||
notifications_mask =
|
notifications_mask =
|
||||||
notifications_mask or DCSSDKDefs.DCSSDK_EVENT.DCSSDK_EVENT_BARCODE.value
|
notifications_mask or DCSSDKDefs.DCSSDK_EVENT.DCSSDK_EVENT_BARCODE.value
|
||||||
|
// subscribe to events set in notification mask
|
||||||
|
// subscribe to events set in notification mask
|
||||||
sdkHandler!!.dcssdkSubsribeForEvents(notifications_mask)
|
sdkHandler!!.dcssdkSubsribeForEvents(notifications_mask)
|
||||||
|
|
||||||
|
|
||||||
|
//so adding all the scanners to the mScannerInfoList, then connecting to the first scanner.
|
||||||
|
//There's only one scanner so this step is unnecessary, I did it thinking about possible scalability.
|
||||||
|
//here I just get the list of available scanners which also returns the USB scanner attached to the tinker board.
|
||||||
|
|
||||||
|
|
||||||
|
//so adding all the scanners to the mScannerInfoList, then connecting to the first scanner.
|
||||||
|
//There's only one scanner so this step is unnecessary, I did it thinking about possible scalability.
|
||||||
|
//here I just get the list of available scanners which also returns the USB scanner attached to the tinker board.
|
||||||
mScannerInfoList.addAll(sdkHandler!!.dcssdkGetAvailableScannersList())
|
mScannerInfoList.addAll(sdkHandler!!.dcssdkGetAvailableScannersList())
|
||||||
Log.e("scannersize",sdkHandler!!.dcssdkGetAvailableScannersList().size.toString())
|
|
||||||
|
//I'm doing mScannerInfoList.get(0) because there's only one scanner which will be at position 0.
|
||||||
|
|
||||||
|
//I'm doing mScannerInfoList.get(0) because there's only one scanner which will be at position 0.
|
||||||
if (mScannerInfoList.isNotEmpty()) {
|
if (mScannerInfoList.isNotEmpty()) {
|
||||||
sdkHandler!!.dcssdkEstablishCommunicationSession(mScannerInfoList[0].scannerID)
|
sdkHandler!!.dcssdkEstablishCommunicationSession(mScannerInfoList[0].scannerID)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this,"Error", Toast.LENGTH_LONG).show()
|
Toast.makeText(this, "No scanner is Available", Toast.LENGTH_LONG).show()
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun pullTrigger() {
|
|
||||||
// Check if the list is not empty before accessing its elements
|
|
||||||
if (mScannerInfoList.isNotEmpty()) {
|
|
||||||
// Only proceed if the scanner is not active
|
|
||||||
if (!mScannerInfoList[0].isActive) {
|
|
||||||
sdkHandler?.dcssdkEstablishCommunicationSession(mScannerInfoList[0].scannerID)
|
|
||||||
}
|
|
||||||
val inXML = "<inArgs><scannerID> 1 </scannerID></inArgs>"
|
|
||||||
val outXML = StringBuilder()
|
|
||||||
val result: DCSSDK_RESULT =
|
|
||||||
sdkHandler!!.dcssdkExecuteCommandOpCodeInXMLForScanner(
|
|
||||||
DCSSDK_COMMAND_OPCODE.DCSSDK_DEVICE_PULL_TRIGGER, inXML, outXML, mScannerInfoList[0].scannerID // Ensure you're using the correct scanner ID
|
|
||||||
)
|
|
||||||
if (result == DCSSDK_RESULT.DCSSDK_RESULT_SUCCESS) {
|
|
||||||
Log.d("Scanning", "Success")
|
|
||||||
} else if (result == DCSSDK_RESULT.DCSSDK_RESULT_FAILURE) {
|
|
||||||
Log.d("Scanning", "Failed")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Handle the case where the list is empty, perhaps notify the user or log an error
|
|
||||||
Log.e("ScannerError", "No scanners are connected or available.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun pullTrigger() {
|
||||||
|
if (!mScannerInfoList[0].isActive) {
|
||||||
|
sdkHandler!!.dcssdkEstablishCommunicationSession(mScannerInfoList[0].scannerID)
|
||||||
|
}
|
||||||
|
val inXML = "<inArgs><scannerID> 1 </scannerID></inArgs>"
|
||||||
|
val outXML = StringBuilder()
|
||||||
|
val result: DCSSDK_RESULT =
|
||||||
|
sdkHandler!!.dcssdkExecuteCommandOpCodeInXMLForScanner(
|
||||||
|
DCSSDK_COMMAND_OPCODE.DCSSDK_DEVICE_PULL_TRIGGER, inXML, outXML, 1
|
||||||
|
)
|
||||||
|
if (result == DCSSDK_RESULT.DCSSDK_RESULT_SUCCESS) Log.d(
|
||||||
|
"Scanning",
|
||||||
|
"Success"
|
||||||
|
) else if (result == DCSSDK_RESULT.DCSSDK_RESULT_FAILURE) Log.d("Scanning", "Failed")
|
||||||
|
//new MyAsyncTask(1, DCSSDKDefs.DCSSDK_COMMAND_OPCODE.DCSSDK_DEVICE_PULL_TRIGGER,null).execute(inXML);
|
||||||
|
}
|
||||||
|
|
||||||
//this function is called if barcode is detected.
|
//this function is called if barcode is detected.
|
||||||
override fun dcssdkEventBarcode(barcodeData: ByteArray?, barcodeType: Int, fromScannerID: Int) {
|
override fun dcssdkEventBarcode(barcodeData: ByteArray?, barcodeType: Int, fromScannerID: Int) {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ class NatsManager(datacollector: DashboardActivity) {
|
|||||||
fun connect() {
|
fun connect() {
|
||||||
Log.d(TAG, "TRY TO CONNECT")
|
Log.d(TAG, "TRY TO CONNECT")
|
||||||
Thread {
|
Thread {
|
||||||
|
|
||||||
val seedString = "SUAEB5PUWNS6C2HUV3MFI6HUDEAPGPFPBHMI73NHIQATCDD2BWALVEZXZ4"
|
val seedString = "SUAEB5PUWNS6C2HUV3MFI6HUDEAPGPFPBHMI73NHIQATCDD2BWALVEZXZ4"
|
||||||
val seedBytes = seedString.toCharArray()
|
val seedBytes = seedString.toCharArray()
|
||||||
|
|
||||||
|
|||||||
@@ -145,18 +145,18 @@ class AutoDacActivity: AppCompatActivity() {
|
|||||||
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) {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,11 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.presentation.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentAutoDacBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentAutoDacBinding
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
class AutoDacFragment: Fragment() {
|
class AutoDacFragment: Fragment() {
|
||||||
|
|
||||||
@@ -145,19 +141,22 @@ class AutoDacFragment: Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resultData.contains("#CC")) {
|
if (resultData.contains("#CC")) {
|
||||||
autoDacViewModel.addAutoDacDataToDb(
|
|
||||||
DiagnosticsData(
|
|
||||||
deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString(),
|
|
||||||
deviceData = resultData,
|
|
||||||
runTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.ivCheck.visibility = View.VISIBLE
|
binding.ivCheck.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resultData.contains("END") || fullReadOutput.contains("END")) {
|
||||||
|
// autoDacViewModel.addAutoDacDataToDb(
|
||||||
|
// DiagnosticsData(
|
||||||
|
// deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString(),
|
||||||
|
// deviceData = resultData,
|
||||||
|
// runTime = SimpleDateFormat(
|
||||||
|
// "yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||||
|
// ).format(Calendar.getInstance().time)
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
override fun onUsbError(e: Exception?) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.example.hpostesting.presentation.buffercheck
|
package com.example.hpostesting.presentation.buffercheck
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
@@ -125,22 +124,21 @@ open class HemocubeBufferCheckActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("MutableImplicitPendingIntent")
|
|
||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||||
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,18 +144,18 @@ class CalibrationActivity: AppCompatActivity() {
|
|||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||||
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ class HomeFragment : Fragment() {
|
|||||||
loadUserData()
|
loadUserData()
|
||||||
setSearch()
|
setSearch()
|
||||||
checkForLocalDBData()
|
checkForLocalDBData()
|
||||||
|
// This function could be called directly where you need to perform the login operation.
|
||||||
|
forceLogin()
|
||||||
checkForTokenAndUpdate()
|
checkForTokenAndUpdate()
|
||||||
} else {
|
} else {
|
||||||
binding.internetAvailableCL.visibility = View.GONE
|
binding.internetAvailableCL.visibility = View.GONE
|
||||||
@@ -188,12 +190,31 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun forceLogin() {
|
||||||
|
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||||
|
val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||||
|
if (userID.isNotEmpty() && password.isNotEmpty() ) {
|
||||||
|
// Directly call the login API without checking the access token
|
||||||
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
|
} else {
|
||||||
|
Toast.makeText(
|
||||||
|
requireContext(),
|
||||||
|
"Contact Help and get your device provision done",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun checkForTokenAndUpdate() {
|
private fun checkForTokenAndUpdate() {
|
||||||
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||||
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||||
val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||||
if (userID.isNotEmpty() && password.isNotEmpty()) {
|
if (accessToken.isEmpty()) {
|
||||||
if (accessToken.isEmpty()) {
|
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
} else {
|
} else {
|
||||||
if (isTokenExpired(accessToken)) {
|
if (isTokenExpired(accessToken)) {
|
||||||
@@ -205,13 +226,6 @@ class HomeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Toast.makeText(
|
|
||||||
requireContext(),
|
|
||||||
"Contact Help and get your device provision done",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
hemoCubeViewModel.loginResponse.observe(viewLifecycleOwner) { response ->
|
hemoCubeViewModel.loginResponse.observe(viewLifecycleOwner) { response ->
|
||||||
when (response) {
|
when (response) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
|
|||||||
@@ -24,11 +24,15 @@ 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.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
|
import com.example.hpostesting.presentation.calibration.CalibrationFragment
|
||||||
|
import com.example.hpostesting.presentation.calibration.CalibrationViewModel
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
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.ActivityCalibrationBinding
|
||||||
import `in`.sminnovations.hpostesting.databinding.ActivityDeviceBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityDeviceBinding
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
@@ -144,18 +148,18 @@ class DeviceActivity : AppCompatActivity() {
|
|||||||
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) {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
@@ -32,7 +32,7 @@ class DeviceFragment : Fragment() {
|
|||||||
): View {
|
): View {
|
||||||
binding = FragmentDeviceBinding.inflate(inflater, container, false)
|
binding = FragmentDeviceBinding.inflate(inflater, container, false)
|
||||||
sharedPreferences =
|
sharedPreferences =
|
||||||
requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.example.hpostesting.presentation.deviceinfo
|
package com.example.hpostesting.presentation.deviceinfo
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
@@ -11,15 +14,16 @@ import javax.inject.Inject
|
|||||||
class DeviceViewModel @Inject constructor(
|
class DeviceViewModel @Inject constructor(
|
||||||
private val hemoCubeDao: HemoCubeDao,
|
private val hemoCubeDao: HemoCubeDao,
|
||||||
private val repository: Repository,
|
private val repository: Repository,
|
||||||
|
context: Context
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
var isServiceConnected = false
|
var isServiceConnected = false
|
||||||
val progressBar = MutableLiveData(false)
|
val progressBar = MutableLiveData(false)
|
||||||
val messages = MutableLiveData<String>()
|
val messages = MutableLiveData<String>()
|
||||||
// private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||||
// val allUserData = hemoCubeDao.getAll()
|
val allUserData = hemoCubeDao.getAll()
|
||||||
val deviceData = MutableLiveData<DeviceData?>()
|
val deviceData = MutableLiveData<DeviceData?>()
|
||||||
// val networkStatusLiveData: LiveData<Boolean>
|
val networkStatusLiveData: LiveData<Boolean>
|
||||||
// get() = _networkStatusLiveData
|
get() = _networkStatusLiveData
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -144,18 +144,18 @@ class DeviceProvisionActivity : AppCompatActivity() {
|
|||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||||
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,14 +146,40 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private fun handleUsbData() {
|
||||||
|
// when {
|
||||||
|
// resultData.contains("SNE") -> {
|
||||||
|
// val pattern = Regex("HPP1-\\d{4}")
|
||||||
|
// val matchResult = pattern.find(resultData)
|
||||||
|
// val hardwareId = matchResult?.value
|
||||||
|
//
|
||||||
|
// if (hardwareId.toString().length == 9) {
|
||||||
|
// with(sharedPreferences.edit()) {
|
||||||
|
// putString(Constants.DEVICE_ID, hardwareId)
|
||||||
|
// apply()
|
||||||
|
// }
|
||||||
|
// activity?.runOnUiThread {
|
||||||
|
// binding.btnSubmit.visibility = View.VISIBLE
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
private fun handleUsbData() {
|
private fun handleUsbData() {
|
||||||
when {
|
when {
|
||||||
resultData.contains("SNE") -> {
|
resultData.contains("SNE") -> {
|
||||||
val pattern = Regex("HPP1-\\d{4}")
|
// Updated pattern to match all specified formats
|
||||||
|
val pattern = Regex("HPP1-\\d{4}|HPP1-\\d{3}-\\d{4}|HCV-\\d{3}-\\d{4}")
|
||||||
val matchResult = pattern.find(resultData)
|
val matchResult = pattern.find(resultData)
|
||||||
val hardwareId = matchResult?.value
|
val hardwareId = matchResult?.value
|
||||||
|
|
||||||
if (hardwareId.toString().length == 9) {
|
// Assuming hardwareId validation is based on matching the pattern,
|
||||||
|
// so no need to check length explicitly here.
|
||||||
|
// If there are more specific requirements for validation,
|
||||||
|
// they need to be implemented accordingly.
|
||||||
|
if (hardwareId != null) { // Check if hardwareId is not null instead
|
||||||
with(sharedPreferences.edit()) {
|
with(sharedPreferences.edit()) {
|
||||||
putString(Constants.DEVICE_ID, hardwareId)
|
putString(Constants.DEVICE_ID, hardwareId)
|
||||||
apply()
|
apply()
|
||||||
@@ -165,4 +191,5 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,8 @@ 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.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
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
|
||||||
@@ -146,18 +148,18 @@ class DiagnosticsActivity : AppCompatActivity() {
|
|||||||
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) {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
when (it) {
|
when (it) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
uploadedToMolbio = true
|
uploadedToMolbio = true
|
||||||
if (Constants.MOLBIO_INTEGRATION) {
|
if (Constants.MOLBIO_INTERGATION) {
|
||||||
it.data.data?.get(0)?.rawData?.let { it1 ->
|
it.data.data?.get(0)?.rawData?.let { it1 ->
|
||||||
hemoCubeViewModel.updateMolbioFlag(
|
hemoCubeViewModel.updateMolbioFlag(
|
||||||
it1._id
|
it1._id
|
||||||
@@ -805,8 +805,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
calculatedPredictedDenovixRatio = fittedAbs3.div(fittedAbs1)
|
calculatedPredictedDenovixRatio = fittedAbs3.div(fittedAbs1)
|
||||||
|
|
||||||
val slope = (led4Average - led1Average) / (431-411)
|
val slope = (led1Average - led2Average) / (435 - 415)
|
||||||
val calculatedSlopeRatio = abs(led2Average / slope)
|
val calculatedSlopeRatio = abs(led3Average / slope)
|
||||||
val slopeClass = slopeRatioClassification(calculatedSlopeRatio)
|
val slopeClass = slopeRatioClassification(calculatedSlopeRatio)
|
||||||
|
|
||||||
if (fittedAbs1 <= fittedAbs2) {
|
if (fittedAbs1 <= fittedAbs2) {
|
||||||
@@ -874,8 +874,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
|
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
|
||||||
this.deviceRatioClass = deviceRatioClassification(deviceRatio)
|
this.deviceRatioClass = deviceRatioClassification(deviceRatio)
|
||||||
this.slopeRatioClass = slopeClass
|
this.slopeRatioClass = slopeClass
|
||||||
this.classificationResult = findResultWithAdditionalMethods(deviceRatio, deviceRatioClass, slopeRatio)
|
this.classificationResult = deviceRatioClass //findResult(calculatedRatio)
|
||||||
hemoCubeViewModel.messages.postValue("${this.classificationResult} ")
|
hemoCubeViewModel.messages.postValue("${this.deviceRatioClass} ${if (led4Average < 0.17) " - Low Hb" else ""}\n")
|
||||||
if (DataHolder.hemoCubeTestData?.testType == "HB")
|
if (DataHolder.hemoCubeTestData?.testType == "HB")
|
||||||
hemoCubeViewModel.messages.postValue("Hb: $calculatedHb4")
|
hemoCubeViewModel.messages.postValue("Hb: $calculatedHb4")
|
||||||
this.errorMessages = testState.allErrorMessages
|
this.errorMessages = testState.allErrorMessages
|
||||||
@@ -909,36 +909,50 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findResultWithAdditionalMethods(deviceRatio: Double?, deviceRatioClass: String?, slopeRatio: Double?): String {
|
fun findResult(calculatedRatio: Double?): String {
|
||||||
try {
|
try {
|
||||||
// hemoCubeViewModel.messages.postValue("post classification checks")
|
hemoCubeViewModel.messages.postValue("result classification")
|
||||||
if (deviceRatio != null) {
|
if (calculatedRatio != null) {
|
||||||
if (slopeRatio != null) {
|
if (calculatedRatio < 0.05)
|
||||||
if (deviceRatioClass == "Normal" && slopeRatio > 60.0)
|
return getString(R.string.error_repeat_test_higher_volume)
|
||||||
return "Negative Borderline, Repeat Test"
|
if (calculatedRatio in 0.05..0.155) {
|
||||||
|
return getString(R.string.normal)
|
||||||
}
|
}
|
||||||
|
if (calculatedRatio in 0.155..0.175)
|
||||||
|
return getString(R.string.negative_borderline)
|
||||||
|
if (calculatedRatio in 0.175..0.22)
|
||||||
|
return getString(R.string.sickle_cell_trait)
|
||||||
|
if (calculatedRatio in 0.22..0.25)
|
||||||
|
return getString(R.string.positive_for_sickle_cell)
|
||||||
|
if (calculatedRatio in 0.25..0.35)
|
||||||
|
return getString(R.string.sickle_cell_disease)
|
||||||
|
if (calculatedRatio > 0.35)
|
||||||
|
return getString(R.string.error_repeat_test_lower_volume)
|
||||||
|
} else {
|
||||||
|
return getString(R.string.invalid)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
handleException(e)
|
showToast(R.string.error_classification)
|
||||||
return "Error"
|
Firebase.crashlytics.recordException(e)
|
||||||
|
return getString(R.string.error)
|
||||||
}
|
}
|
||||||
return deviceRatioClass.toString()
|
return getString(R.string.invalid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deviceRatioClassification(ratio: Double?): String {
|
fun deviceRatioClassification(ratio: Double?): String {
|
||||||
try {
|
try {
|
||||||
if (ratio != null) {
|
if (ratio != null) {
|
||||||
if (ratio in 0.001..0.23) {
|
if (ratio in 0.1..0.29) {
|
||||||
// setSubtitleTextColor(R.color.green_2)
|
// setSubtitleTextColor(R.color.green_2)
|
||||||
return "Normal"
|
return "Normal"
|
||||||
}
|
}
|
||||||
if (ratio in 0.23..0.24)
|
|
||||||
return "Negative Borderline, Repeat Test"
|
|
||||||
if (ratio in 0.24..0.29)
|
|
||||||
return "Sickle Cell Trait"
|
|
||||||
if (ratio in 0.29..0.32)
|
if (ratio in 0.29..0.32)
|
||||||
|
return "Negative Borderline, Repeat Test"
|
||||||
|
if (ratio in 0.32..0.35)
|
||||||
|
return "Sickle Cell Trait"
|
||||||
|
if (ratio in 0.35..0.38)
|
||||||
return "Positive for Sickle Cell. HPLC for Confirmation"
|
return "Positive for Sickle Cell. HPLC for Confirmation"
|
||||||
if (ratio in 0.32..Double.POSITIVE_INFINITY)
|
if (ratio in 0.38..0.5)
|
||||||
return "Sickle Cell Disease"
|
return "Sickle Cell Disease"
|
||||||
} else {
|
} else {
|
||||||
return "Invalid"
|
return "Invalid"
|
||||||
|
|||||||
@@ -130,18 +130,18 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
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) {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,23 +127,23 @@ class TrueHemeActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("MutableImplicitPendingIntent", "UnspecifiedRegisterReceiverFlag")
|
@SuppressLint("MutableImplicitPendingIntent")
|
||||||
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) {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
||||||
registerReceiver(broadcastReceiver, filter)
|
registerReceiver(broadcastReceiver, filter)
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.example.hpostesting.presentation.trueheme
|
package com.example.hpostesting.presentation.trueheme
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
@@ -34,7 +33,6 @@ import kotlin.math.abs
|
|||||||
import kotlin.math.log10
|
import kotlin.math.log10
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
class TrueHemeFragment : Fragment() {
|
class TrueHemeFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var binding: FragmentTruehemeSampleBinding
|
private lateinit var binding: FragmentTruehemeSampleBinding
|
||||||
@@ -156,7 +154,7 @@ class TrueHemeFragment : Fragment() {
|
|||||||
when (it) {
|
when (it) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
uploadedToMolbio = true
|
uploadedToMolbio = true
|
||||||
if (Constants.MOLBIO_INTEGRATION) {
|
if (Constants.MOLBIO_INTERGATION) {
|
||||||
it.data.data?.get(0)?.rawData?.let { it1 ->
|
it.data.data?.get(0)?.rawData?.let { it1 ->
|
||||||
hemoCubeViewModel.updateMolbioFlag(
|
hemoCubeViewModel.updateMolbioFlag(
|
||||||
it1._id
|
it1._id
|
||||||
@@ -1143,8 +1141,4 @@ class TrueHemeFragment : Fragment() {
|
|||||||
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
|
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
|
||||||
return coefficient1 * ratio + coefficient2
|
return coefficient1 * ratio + coefficient2
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reconnect() {
|
|
||||||
(activity as HemocubeActivity).reconnectDevice()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package com.example.hpostesting
|
|
||||||
|
|
||||||
//
|
|
||||||
//@PrepareForTest(Object::class)
|
|
||||||
//class AuthInterceptorTest {
|
|
||||||
//
|
|
||||||
//// @Rule
|
|
||||||
//// val rule = PowerMockRule()
|
|
||||||
//
|
|
||||||
// @Mock
|
|
||||||
// private lateinit var sharedPreferences: SharedPreferences
|
|
||||||
//
|
|
||||||
// @Mock
|
|
||||||
// private lateinit var chain: Interceptor.Chain
|
|
||||||
//
|
|
||||||
// @Mock
|
|
||||||
// private lateinit var request: okhttp3.Request
|
|
||||||
//
|
|
||||||
// @Mock
|
|
||||||
// private lateinit var response: Response
|
|
||||||
//
|
|
||||||
// @Captor
|
|
||||||
// private lateinit var captor: ArgumentCaptor<okhttp3.Request>
|
|
||||||
//
|
|
||||||
// private lateinit var authInterceptor: AuthInterceptor
|
|
||||||
//
|
|
||||||
// @Before
|
|
||||||
// fun setup() {
|
|
||||||
// MockitoAnnotations.initMocks(this)
|
|
||||||
// authInterceptor = AuthInterceptor(sharedPreferences)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// fun intercept_withToken_shouldAddAuthorizationHeader() {
|
|
||||||
// // Arrange
|
|
||||||
// val accessToken = "fakeAccessToken"
|
|
||||||
// `when`(sharedPreferences.getString(Constants.ACCESS_TOKEN, null)).thenReturn(accessToken)
|
|
||||||
// `when`(chain.request()).thenReturn(request)
|
|
||||||
// `when`(chain.proceed(request)).thenReturn(response)
|
|
||||||
//
|
|
||||||
// // Act
|
|
||||||
// val result = authInterceptor.intercept(chain)
|
|
||||||
//
|
|
||||||
// // Assert
|
|
||||||
// verify(chain).proceed(captor.capture())
|
|
||||||
// assertEquals("Bearer $accessToken", captor.value.header("Authorization"))
|
|
||||||
// assertEquals(response, result)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// fun intercept_withoutToken_shouldNotAddAuthorizationHeader() {
|
|
||||||
// // Arrange
|
|
||||||
// `when`(sharedPreferences.getString(Constants.ACCESS_TOKEN, null)).thenReturn(null)
|
|
||||||
// `when`(chain.request()).thenReturn(request)
|
|
||||||
// `when`(chain.proceed(request)).thenReturn(response)
|
|
||||||
//
|
|
||||||
// // Act
|
|
||||||
// val result = authInterceptor.intercept(chain)
|
|
||||||
//
|
|
||||||
// // Assert
|
|
||||||
// verify(chain).proceed(captor.capture())
|
|
||||||
// assertEquals(null, captor.value.header("Authorization"))
|
|
||||||
// assertEquals(response, result)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.example.hpostesting
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.example.hpostesting.data.CsvWriter
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.robolectric.RobolectricTestRunner
|
|
||||||
import org.robolectric.annotation.Config
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
|
||||||
@Config(manifest = Config.NONE)
|
|
||||||
class CsvWriterTest {
|
|
||||||
|
|
||||||
private lateinit var csvWriter: CsvWriter
|
|
||||||
private lateinit var context: Context
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setUp() {
|
|
||||||
context = androidx.test.core.app.ApplicationProvider.getApplicationContext()
|
|
||||||
csvWriter = CsvWriter(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun writeCsv_Success() {
|
|
||||||
// Arrange
|
|
||||||
val fileName = "test.csv"
|
|
||||||
val data = listOf(
|
|
||||||
arrayOf("1", "A", "1990", "Positive", "2024-02-04", "image_url1", "John Doe"),
|
|
||||||
arrayOf("2", "B", "1985", "Negative", "2024-02-05", "image_url2", "Jane Doe")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = csvWriter.writeCsv(fileName, data)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.assertTrue(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// fun writeCsv_Failure() {
|
|
||||||
// // Arrange
|
|
||||||
// val fileName = "test.csv"
|
|
||||||
// val data = listOf(
|
|
||||||
// arrayOf("1", "A", "1990", "Positive", "2024-02-04", "image_url1", "John Doe"),
|
|
||||||
// arrayOf("2", "B", "1985", "Negative", "2024-02-05", "image_url2", "Jane Doe")
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// // Mocking Environment.getExternalStorageDirectory()
|
|
||||||
// val mockFile = Mockito.mock(File::class.java)
|
|
||||||
// Mockito.`when`(Environment.getExternalStorageDirectory()).thenReturn(mockFile)
|
|
||||||
// Mockito.`when`(mockFile.exists()).thenReturn(true)
|
|
||||||
//
|
|
||||||
// // Mocking FileWriter to simulate IOException
|
|
||||||
// val mockWriter = Mockito.mock(FileWriter::class.java)
|
|
||||||
// Mockito.`when`(mockWriter.write(Mockito.anyString())).thenThrow(IOException::class.java)
|
|
||||||
// Mockito.`when`(mockFile.absolutePath).thenReturn("/fake/path/to/file.csv")
|
|
||||||
// Mockito.`when`(FileWriter(mockFile)).thenReturn(mockWriter)
|
|
||||||
//
|
|
||||||
// // Act
|
|
||||||
// val result = csvWriter.writeCsv(fileName, data)
|
|
||||||
//
|
|
||||||
// // Assert
|
|
||||||
// Assert.assertFalse("Expected writeCsv to fail", result)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package com.example.hpostesting
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
|
||||||
import com.example.hpostesting.data.repository.Repository
|
|
||||||
import com.example.hpostesting.presentation.deviceinfo.DeviceViewModel
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner
|
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
|
||||||
class DeviceViewModelTest {
|
|
||||||
|
|
||||||
@get:Rule
|
|
||||||
val rule = InstantTaskExecutorRule()
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var hemoCubeDao: HemoCubeDao
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var repository: Repository
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var context: Context
|
|
||||||
|
|
||||||
private lateinit var viewModel: DeviceViewModel
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setup() {
|
|
||||||
viewModel = DeviceViewModel(hemoCubeDao, repository)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test initial state`() {
|
|
||||||
assert(!viewModel.isServiceConnected)
|
|
||||||
assert(!viewModel.progressBar.value!!)
|
|
||||||
assert(viewModel.messages.value == null)
|
|
||||||
// assert(viewModel.allUserData == hemoCubeDao.getAll())
|
|
||||||
// assert(viewModel.deviceData.value == null)
|
|
||||||
// assert(viewModel.networkStatusLiveData.value == false)
|
|
||||||
assert(viewModel.fireBaseUpload.value == null)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add more tests for other functions and interactions as needed
|
|
||||||
}
|
|
||||||
@@ -318,28 +318,28 @@ class HemoCubeFragmentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationNormal() {
|
fun testDeviceRatioClassificationNormal() {
|
||||||
val ratio = 0.22
|
val ratio = 0.25
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||||
assertEquals("Normal", result)
|
assertEquals("Normal", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationNegativeBorderline() {
|
fun testDeviceRatioClassificationNegativeBorderline() {
|
||||||
val ratio = 0.235
|
val ratio = 0.31
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||||
assertEquals("Negative Borderline, Repeat Test", result)
|
assertEquals("Negative Borderline, Repeat Test", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationSickleCellTrait() {
|
fun testDeviceRatioClassificationSickleCellTrait() {
|
||||||
val ratio = 0.25
|
val ratio = 0.34
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||||
assertEquals("Sickle Cell Trait", result)
|
assertEquals("Sickle Cell Trait", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
||||||
val ratio = 0.31
|
val ratio = 0.37
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||||
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
|
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
|
||||||
}
|
}
|
||||||
@@ -357,18 +357,4 @@ class HemoCubeFragmentTest {
|
|||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||||
assertEquals("Invalid", result)
|
assertEquals("Invalid", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun findResultWithAdditionalMethods_ValidInput_ReturnsNegativeBorderlineRepeatTest() {
|
|
||||||
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 70.0)).thenReturn("Negative Borderline, Repeat Test")
|
|
||||||
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 70.0)
|
|
||||||
assertEquals("Negative Borderline, Repeat Test", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun findResultWithAdditionalMethods_ValidInput_ReturnsDeviceRatioClassToString() {
|
|
||||||
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0)).thenReturn("Invalid")
|
|
||||||
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0)
|
|
||||||
assertEquals("Abnormal", result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package com.example.hpostesting
|
|
||||||
|
|
||||||
//
|
|
||||||
//class LogFileManagerImplTest {
|
|
||||||
//
|
|
||||||
// @Mock
|
|
||||||
// private lateinit var mockContext: Context
|
|
||||||
//
|
|
||||||
// private lateinit var logFileManager: LogFileManagerImpl
|
|
||||||
//
|
|
||||||
// @Before
|
|
||||||
// fun setUp() {
|
|
||||||
// mockContext = mock()
|
|
||||||
// logFileManager = LogFileManagerImpl(mockContext)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// fun testCreateLogFileSuccess() {
|
|
||||||
// // Mock filesDir
|
|
||||||
// whenever(mockContext.getString(R.string.app_name)).thenReturn("MockedAppName")
|
|
||||||
// val mockFilesDir = mock<File>()
|
|
||||||
// doReturn(true).whenever(mockContext).getFilesDir().exists()
|
|
||||||
// doReturn(mockFilesDir).whenever(mockContext).getFilesDir()
|
|
||||||
//
|
|
||||||
// // Set expected file name
|
|
||||||
// val expectedFileName = "hpos_1234567890.log"
|
|
||||||
// val currentTime = System.currentTimeMillis() / 1000L
|
|
||||||
// doReturn(true).whenever(mockFilesDir).createNewFile(expectedFileName)
|
|
||||||
// doReturn(mockFilesDir.absolutePath + File.separator + expectedFileName).whenever(mockFilesDir).absolutePath
|
|
||||||
//
|
|
||||||
// // Mock FileOutputStream
|
|
||||||
// val mockFileOutputStream = mock<FileOutputStream>()
|
|
||||||
// doReturn(mockFileOutputStream).whenever(FileOutputStream(mockFilesDir.absolutePath + File.separator + expectedFileName))
|
|
||||||
//
|
|
||||||
// // Call createLogFile and verify result
|
|
||||||
// val logFile = logFileManager.createLogFile()
|
|
||||||
//
|
|
||||||
// assertNotNull(logFile)
|
|
||||||
// assertTrue(logFile.exists())
|
|
||||||
// assertEquals(expectedFileName, logFile.name)
|
|
||||||
//
|
|
||||||
// // Verify FileOutputStream was called
|
|
||||||
// verify(mockFileOutputStream).write(any())
|
|
||||||
// verify(mockFileOutputStream).close()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// fun testCreateLogFileExistingFile() throws IOException {
|
|
||||||
// // Mock filesDir with existing file
|
|
||||||
// val mockFilesDir = mock<File>()
|
|
||||||
// val existingFile = mock<File>()
|
|
||||||
// doReturn(true).whenever(mockContext).getFilesDir().exists()
|
|
||||||
// doReturn(mockFilesDir).whenever(mockContext).getFilesDir()
|
|
||||||
// doReturn(true).whenever(mockFilesDir).exists()
|
|
||||||
// doReturn(listOf(existingFile)).whenever(mockFilesDir).listFiles()
|
|
||||||
//
|
|
||||||
// // Call createLogFile and expect exception
|
|
||||||
// try {
|
|
||||||
// logFileManager.createLogFile()
|
|
||||||
// fail("Expected IOException due to existing file")
|
|
||||||
// } catch (e: IOException) {
|
|
||||||
// // Expected behavior
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Verify FileOutputStream was not called
|
|
||||||
// verify(mockFilesDir, times(0)).createNewFile(anyString())
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// fun testCreateLogFileIOException() throws IOException {
|
|
||||||
// // Mock filesDir and IOException
|
|
||||||
// val mockFilesDir = mock<File>()
|
|
||||||
// doReturn(true).whenever(mockContext).getFilesDir().exists()
|
|
||||||
// doReturn(mockFilesDir).whenever(mockContext).getFilesDir()
|
|
||||||
// doReturn(true).whenever(mockFilesDir).exists()
|
|
||||||
// doThrow(IOException("Mock IOException")).whenever(mockFilesDir).createNewFile(anyString())
|
|
||||||
//
|
|
||||||
// // Call createLogFile and expect null result
|
|
||||||
// val logFile = logFileManager.createLogFile()
|
|
||||||
//
|
|
||||||
// assertNull(logFile)
|
|
||||||
//
|
|
||||||
// // Verify FileOutputStream was not called
|
|
||||||
// verify(mockFilesDir, times(0)).createNewFile(anyString())
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,350 +0,0 @@
|
|||||||
package com.example.hpostesting
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import com.example.hpostesting.presentation.trueheme.TrueHemeFragment
|
|
||||||
import junit.framework.TestCase
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Test
|
|
||||||
import org.mockito.ArgumentMatchers
|
|
||||||
import org.mockito.Mock
|
|
||||||
import org.mockito.Mockito
|
|
||||||
import org.mockito.MockitoAnnotations
|
|
||||||
|
|
||||||
class TrueHemeFragmentTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
lateinit var mockContext: Context
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private lateinit var mockSharedPreferences: SharedPreferences
|
|
||||||
|
|
||||||
private lateinit var fragment: TrueHemeFragment
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this)
|
|
||||||
fragment = TrueHemeFragment()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId to get device id`() {
|
|
||||||
// Arrange
|
|
||||||
Mockito.`when`(
|
|
||||||
mockSharedPreferences.getString(
|
|
||||||
ArgumentMatchers.anyString(),
|
|
||||||
ArgumentMatchers.anyString()
|
|
||||||
)
|
|
||||||
).thenReturn("dummy_value")
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val deviceId = fragment.extractV2HardwareId("SNS HPP1-9000 SNE")
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HPP1-9000", deviceId)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `updateDeviceId in shared pref`() {
|
|
||||||
// Arrange
|
|
||||||
Mockito.`when`(
|
|
||||||
mockSharedPreferences.getString(
|
|
||||||
ArgumentMatchers.anyString(),
|
|
||||||
ArgumentMatchers.anyString()
|
|
||||||
)
|
|
||||||
).thenReturn("HPP1-0001")
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val deviceId = mockSharedPreferences.getString(
|
|
||||||
ArgumentMatchers.anyString(),
|
|
||||||
ArgumentMatchers.anyString()
|
|
||||||
)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HPP1-0001", deviceId)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `allReadingsComplete check`() {
|
|
||||||
// Arrange
|
|
||||||
val repeatReadingCount = 1
|
|
||||||
val readingsPerSample = 1
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals(true, result)
|
|
||||||
TestCase.assertEquals(fragment.allReadingsComplete(0, 1), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV1HardwareId should return hardware ID when input contains SN`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "Some text SN ABC123 some more text"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV1HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("ABC123", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV1HardwareId should return null when input does not contain SN`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "Some text without SN"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV1HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertNull(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV1HardwareId should return null when input is empty`() {
|
|
||||||
// Arrange
|
|
||||||
val input = ""
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV1HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertNull(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV1HardwareId should return null when input is null`() {
|
|
||||||
// Arrange
|
|
||||||
val input: String? = null
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = input?.let { fragment.extractV1HardwareId(it) }
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertNull(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV1HardwareId should return hardware ID when input contains SN in a specific format`() {
|
|
||||||
// Arrange
|
|
||||||
val input = """
|
|
||||||
SN HCV-000-3001
|
|
||||||
#BS
|
|
||||||
#BC
|
|
||||||
#SS
|
|
||||||
#SC
|
|
||||||
RESULT
|
|
||||||
LB1 20636.32
|
|
||||||
LB2 15855.67
|
|
||||||
LB3 21801.36
|
|
||||||
LB4 18362.33
|
|
||||||
LS1 17287
|
|
||||||
LS2 14855.67
|
|
||||||
LS3 15282.31
|
|
||||||
LS4 9737.98
|
|
||||||
REND
|
|
||||||
""".trimIndent()
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV1HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HCV-000-3001", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should return the correct hardware ID when it exists in the input`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "SNS ABC123 SNE"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("ABC123", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should return null when no hardware ID is found in the input`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "No hardware ID in this input"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertNull(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should handle whitespace around the hardware ID`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "SNS XYZ789 SNE"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("XYZ789", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should handle provided input string with HCV-000-3013`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "SNS HCV-000-3013 SNE\n" +
|
|
||||||
"#SS1\n" +
|
|
||||||
"#SC1\n" +
|
|
||||||
"RESULT \n" +
|
|
||||||
"LB1 23411.00\n" +
|
|
||||||
"LB2 21417.00\n" +
|
|
||||||
"LB3 23869.00\n" +
|
|
||||||
"LB4 24967.00\n" +
|
|
||||||
"LS1 3401.00\n" +
|
|
||||||
"LS2 1107.00\n" +
|
|
||||||
"LS3 14410.00\n" +
|
|
||||||
"LS4 15047.00\n" +
|
|
||||||
"REND\n"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HCV-000-3013", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should handle provided input string with HPP1-4001`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "SNS HPP1-4001 SNE#SS1\n" +
|
|
||||||
"#SC1\n" +
|
|
||||||
"RESULT\n" +
|
|
||||||
"LB1 23777\n" +
|
|
||||||
"LB2 24130\n" +
|
|
||||||
"LB3 23442\n" +
|
|
||||||
"LB4 23945\n" +
|
|
||||||
"LS1 2521\n" +
|
|
||||||
"LS2 973\n" +
|
|
||||||
"LS3 10252\n" +
|
|
||||||
"LS4 11017\n" +
|
|
||||||
"REND\n"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HPP1-4001", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should handle provided input string with HPP1-000-4001`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "SNS HPP1-000-4001 SNE#SS1\n" +
|
|
||||||
"#SC1\n" +
|
|
||||||
"RESULT\n" +
|
|
||||||
"LB1 23777\n" +
|
|
||||||
"LB2 24130\n" +
|
|
||||||
"LB3 23442\n" +
|
|
||||||
"LB4 23945\n" +
|
|
||||||
"LS1 2521\n" +
|
|
||||||
"LS2 973\n" +
|
|
||||||
"LS3 10252\n" +
|
|
||||||
"LS4 11017\n" +
|
|
||||||
"REND\n"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HPP1-000-4001", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should handle provided input string with HPP-000-4001`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "SNS HPP-000-4001 SNE#SS1\n" +
|
|
||||||
"#SC1\n" +
|
|
||||||
"RESULT\n" +
|
|
||||||
"LB1 23777\n" +
|
|
||||||
"LB2 24130\n" +
|
|
||||||
"LB3 23442\n" +
|
|
||||||
"LB4 23945\n" +
|
|
||||||
"LS1 2521\n" +
|
|
||||||
"LS2 973\n" +
|
|
||||||
"LS3 10252\n" +
|
|
||||||
"LS4 11017\n" +
|
|
||||||
"REND\n"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HPP-000-4001", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractV2HardwareId should handle provided input string with HPP-000-5001`() {
|
|
||||||
// Arrange
|
|
||||||
val input = "SNS HPP-000-5001 SNE#SS1\n" +
|
|
||||||
"#SC1\n" +
|
|
||||||
"RESULT\n" +
|
|
||||||
"LB1 23777\n" +
|
|
||||||
"LB2 24130\n" +
|
|
||||||
"LB3 23442\n" +
|
|
||||||
"LB4 23945\n" +
|
|
||||||
"LS1 2521\n" +
|
|
||||||
"LS2 973\n" +
|
|
||||||
"LS3 10252\n" +
|
|
||||||
"LS4 11017\n" +
|
|
||||||
"REND\n"
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = fragment.extractV2HardwareId(input)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
TestCase.assertEquals("HPP-000-5001", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationNormal() {
|
|
||||||
val ratio = 0.25
|
|
||||||
val result = fragment.deviceRatioClassification(ratio)
|
|
||||||
TestCase.assertEquals("Normal", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationNegativeBorderline() {
|
|
||||||
val ratio = 0.31
|
|
||||||
val result = fragment.deviceRatioClassification(ratio)
|
|
||||||
TestCase.assertEquals("Negative Borderline, Repeat Test", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationSickleCellTrait() {
|
|
||||||
val ratio = 0.34
|
|
||||||
val result = fragment.deviceRatioClassification(ratio)
|
|
||||||
TestCase.assertEquals("Sickle Cell Trait", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
|
||||||
val ratio = 0.37
|
|
||||||
val result = fragment.deviceRatioClassification(ratio)
|
|
||||||
TestCase.assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationSickleCellDisease() {
|
|
||||||
val ratio = 0.45
|
|
||||||
val result = fragment.deviceRatioClassification(ratio)
|
|
||||||
TestCase.assertEquals("Sickle Cell Disease", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationInvalid() {
|
|
||||||
val ratio: Double? = null
|
|
||||||
val result = fragment.deviceRatioClassification(ratio)
|
|
||||||
TestCase.assertEquals("Invalid", result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user