Compare commits
1 Commits
device-pro
...
API-CALLS-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf2e904445 |
@@ -14,13 +14,13 @@ android {
|
||||
compileSdk 34
|
||||
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 {
|
||||
applicationId "in.sminnovations.hpostesting.dev"
|
||||
applicationId "in.sminnovations.hpostesting.quality"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 111
|
||||
versionName "2.1.111"
|
||||
versionCode 100
|
||||
versionName "2.1.100"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -112,8 +112,6 @@ dependencies {
|
||||
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
|
||||
androidTestImplementation 'org.mockito:mockito-inline: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 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
|
||||
|
||||
@@ -1,205 +1,45 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "650071678820",
|
||||
"project_id": "hpos-af3cc",
|
||||
"storage_bucket": "hpos-af3cc.appspot.com"
|
||||
"project_number": "1004619739289",
|
||||
"project_id": "hpos-qa",
|
||||
"storage_bucket": "hpos-qa.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:650071678820:android:f1435a1c07f710036c6471",
|
||||
"mobilesdk_app_id": "1:1004619739289:android:f669b47552748433e5c808",
|
||||
"android_client_info": {
|
||||
"package_name": "com.example.hposconsentform"
|
||||
"package_name": "in.sminnovations.hposregistration.quality"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||
"current_key": "AIzaSyC4d4GhWHr_NMJAeBvnztQ_yQ3Qe9MAnLs"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:650071678820:android:7865bef608cdee6f6c6471",
|
||||
"mobilesdk_app_id": "1:1004619739289:android:8397cd1f0357bd89e5c808",
|
||||
"android_client_info": {
|
||||
"package_name": "com.smi.counselling"
|
||||
"package_name": "in.sminnovations.hpostesting.quality"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||
"current_key": "AIzaSyC4d4GhWHr_NMJAeBvnztQ_yQ3Qe9MAnLs"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:650071678820:android:2925e9ce3417d2386c6471",
|
||||
"android_client_info": {
|
||||
"package_name": "in.sminnovations.hemocube"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-srhm9spm9hjn4frcd3r6o02gdhdbtd15.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "in.sminnovations.hemocube",
|
||||
"certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:650071678820:android:7569c1cad4fc99916c6471",
|
||||
"android_client_info": {
|
||||
"package_name": "in.sminnovations.hposregistration"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-70kp5jvjda4r5diqch2kn4lc40p4f42g.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "in.sminnovations.hposregistration",
|
||||
"certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:650071678820:android:f96be19e5d43102b6c6471",
|
||||
"android_client_info": {
|
||||
"package_name": "in.sminnovations.hpostesting"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-l87dnr0bdj95get0khgnvfv2an1k6ogq.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "in.sminnovations.hpostesting",
|
||||
"certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:650071678820:android:a53292637abb7c0d6c6471",
|
||||
"android_client_info": {
|
||||
"package_name": "in.sminnovations.hpostesting.dev"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,8 +118,9 @@
|
||||
android:noHistory="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
@@ -159,7 +160,7 @@
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="com.example.hpostesting.dev.fileprovider"
|
||||
android:authorities="com.example.hpostesting.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
package com.example.hpostesting.data.api
|
||||
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
|
||||
interface PropertyProvider {
|
||||
|
||||
fun getProperty(key: String): String
|
||||
}
|
||||
|
||||
interface DeviceCommunicationHandler {
|
||||
fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener)
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@ package com.example.hpostesting.data.constant
|
||||
|
||||
object Constants {
|
||||
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 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 deviceProvisionPassword = "f2ab0e7f9d69"
|
||||
const val DEVICE_ID_API = "deviceIDAPI"
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
|
||||
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class, BufferCheckData::class], version = 25, exportSchema = false)
|
||||
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class, BufferCheckData::class], version = 24, exportSchema = false)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class MyDatabase : RoomDatabase() {
|
||||
abstract fun userDao(): UserDao
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.example.hpostesting.data.model.deviceprovision
|
||||
|
||||
data class ProvisionData(
|
||||
val username: String?,
|
||||
val password: String?,
|
||||
val natsToken: String?
|
||||
)
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.example.hpostesting.data.model.patient
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
||||
import com.google.firebase.firestore.PropertyName
|
||||
|
||||
@Entity(tableName = "device_table")
|
||||
@@ -16,12 +15,5 @@ data class DeviceData(
|
||||
@get:PropertyName("coefficients") @set:PropertyName("coefficients")
|
||||
var coefficients: List<Double> = emptyList(),
|
||||
@get:PropertyName("calibratedAt") @set:PropertyName("calibratedAt")
|
||||
var calibratedAt: String = "" ,
|
||||
@get:PropertyName("deviceProvisionResponse") @set:PropertyName("deviceProvisionResponse")
|
||||
var deviceProvisionResponse: String = "" ,
|
||||
@get:PropertyName("username") @set:PropertyName("username")
|
||||
var username: String = "",
|
||||
@get:PropertyName("password") @set:PropertyName("password")
|
||||
var password: String = ""
|
||||
|
||||
var calibratedAt: String = ""
|
||||
)
|
||||
@@ -203,31 +203,7 @@ class DatabaseRepository @Inject constructor(
|
||||
return allDeviceDataList.find { it.deviceId == deviceId }
|
||||
}
|
||||
|
||||
override suspend fun getDeviceResponse(data: DeviceData?): Response<String> {
|
||||
return try {
|
||||
db.collection("devices").add(data!!).await()
|
||||
Response.Success(data.deviceProvisionResponse)
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
override suspend fun uploadDeviceId(data: DeviceData): Response<String>? {
|
||||
return try {
|
||||
db.collection("devices").add(data!!).await()
|
||||
Response.Success(data.deviceId)
|
||||
} catch (e: Exception) {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
Response.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,8 +32,6 @@ interface Repository {
|
||||
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean>
|
||||
|
||||
suspend fun getDeviceDataById(deviceId: String): DeviceData?
|
||||
suspend fun getDeviceResponse(data: DeviceData?): Response<String>
|
||||
suspend fun uploadDeviceId(data: DeviceData): Response<String>?
|
||||
abstract fun <UserData> addTestToDatabase(testDetails: UserData): Any
|
||||
// suspend fun addToDatabase(data: PatientDetails)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.hpostesting.domain
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
@@ -31,7 +32,7 @@ class LogFileManagerImpl @Inject constructor(private val context: Context) : Log
|
||||
|
||||
file
|
||||
} catch (e: IOException) {
|
||||
// Log.e("LogFileManager", "Error creating log file: ${e.message}")
|
||||
Log.e("LogFileManager", "Error creating log file: ${e.message}")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,54 +208,74 @@ class KitScanActivity : AppCompatActivity(), IDcsSdkApiDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
//Setting up the SDK handler
|
||||
|
||||
//Setting up the SDK handler
|
||||
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.
|
||||
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
|
||||
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
|
||||
//first we use bitmapping to set these values into the notifications_mask.
|
||||
var notifications_mask = 0
|
||||
// We would like to subscribe to all barcode events
|
||||
// We would like to subscribe to all barcode events
|
||||
notifications_mask =
|
||||
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)
|
||||
|
||||
|
||||
//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())
|
||||
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()) {
|
||||
sdkHandler!!.dcssdkEstablishCommunicationSession(mScannerInfoList[0].scannerID)
|
||||
} else {
|
||||
Toast.makeText(this,"Error", 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.")
|
||||
Toast.makeText(this, "No scanner is Available", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
override fun dcssdkEventBarcode(barcodeData: ByteArray?, barcodeType: Int, fromScannerID: Int) {
|
||||
|
||||
@@ -23,7 +23,6 @@ class NatsManager(datacollector: DashboardActivity) {
|
||||
fun connect() {
|
||||
Log.d(TAG, "TRY TO CONNECT")
|
||||
Thread {
|
||||
|
||||
val seedString = "SUAEB5PUWNS6C2HUV3MFI6HUDEAPGPFPBHMI73NHIQATCDD2BWALVEZXZ4"
|
||||
val seedBytes = seedString.toCharArray()
|
||||
|
||||
|
||||
@@ -145,18 +145,18 @@ class AutoDacActivity: AppCompatActivity() {
|
||||
val mPendingIntent: PendingIntent
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
|
||||
@@ -12,15 +12,11 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
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.presentation.UsbServiceListener
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentAutoDacBinding
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
class AutoDacFragment: Fragment() {
|
||||
|
||||
@@ -145,19 +141,22 @@ class AutoDacFragment: Fragment() {
|
||||
}
|
||||
|
||||
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 {
|
||||
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?) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.example.hpostesting.presentation.buffercheck
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.PendingIntent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
@@ -125,22 +124,21 @@ open class HemocubeBufferCheckActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("MutableImplicitPendingIntent")
|
||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
|
||||
@@ -144,18 +144,18 @@ class CalibrationActivity: AppCompatActivity() {
|
||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
|
||||
@@ -19,13 +19,9 @@ import androidx.navigation.ui.navigateUp
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.constant.LanguageManager
|
||||
import com.example.hpostesting.presentation.NatsManager
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.testRight.UsbService
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.google.firebase.appdistribution.FirebaseAppDistribution
|
||||
import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
||||
@@ -162,7 +158,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
|
||||
val uri: Uri = FileProvider.getUriForFile(
|
||||
this,
|
||||
"com.example.hpostesting.dev.fileprovider",
|
||||
"com.example.hpostesting.fileprovider",
|
||||
file
|
||||
)
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class GalleryFragment : Fragment() {
|
||||
) {
|
||||
binding.btnDeviceProvision.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.btnDeviceProvision.visibility = View.VISIBLE
|
||||
binding.btnDeviceProvision.visibility = View.GONE
|
||||
}
|
||||
|
||||
binding.btnDeviceProvision.setOnClickListener {
|
||||
|
||||
@@ -19,20 +19,16 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.login.LoginRequest
|
||||
import com.example.hpostesting.data.model.login.LoginResponse
|
||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2Result
|
||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultRequest
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||
import com.example.hpostesting.presentation.KitScanActivity
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||
import com.example.hpostesting.presentation.assurance.AssuranceControlsActivity
|
||||
@@ -48,7 +44,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||
import org.json.JSONObject
|
||||
import java.nio.charset.Charset
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
@@ -67,9 +62,6 @@ class HomeFragment : Fragment() {
|
||||
private val homeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
|
||||
private var isTokenAvailable = false
|
||||
private var natsToken: String = ""
|
||||
private var deviceId: String = ""
|
||||
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
@@ -97,7 +89,7 @@ class HomeFragment : Fragment() {
|
||||
binding.labelQuickCapture.visibility = View.VISIBLE
|
||||
binding.btnQuickCapture.visibility = View.VISIBLE
|
||||
}
|
||||
getDeviceId()
|
||||
|
||||
checkUnprocessedCSVData()
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||
deleteIncompleteRegistrations(userData)
|
||||
@@ -118,20 +110,16 @@ class HomeFragment : Fragment() {
|
||||
binding.rvOrderOffline.adapter = adapter
|
||||
}
|
||||
}
|
||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) { deviceData ->
|
||||
val devicelist = mutableListOf<DeviceData>()
|
||||
if (deviceData != null) {
|
||||
devicelist.add(DeviceData(deviceData.deviceId))
|
||||
}
|
||||
|
||||
}
|
||||
viewModel.networkStatusLiveData?.observe(viewLifecycleOwner) { isConnected ->
|
||||
if (isConnected) {
|
||||
|
||||
binding.internetAvailableCL.visibility = View.VISIBLE
|
||||
binding.internetNotAvailableCL.visibility = View.GONE
|
||||
loadUserData()
|
||||
setSearch()
|
||||
checkForLocalDBData()
|
||||
// This function could be called directly where you need to perform the login operation.
|
||||
forceLogin()
|
||||
checkForTokenAndUpdate()
|
||||
} else {
|
||||
binding.internetAvailableCL.visibility = View.GONE
|
||||
@@ -200,19 +188,33 @@ class HomeFragment : Fragment() {
|
||||
binding.downloadCSV.setOnClickListener {
|
||||
showDownloadDialog(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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() {
|
||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
var password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||
var userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
||||
Log.e("idpass", userID)
|
||||
Log.e("idpass", password)
|
||||
Log.e("idpass", deviceId)
|
||||
if (userID.isNotEmpty() && password.isNotEmpty()) {
|
||||
if (accessToken.isEmpty()) {
|
||||
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||
val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||
if (accessToken.isEmpty()) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
if (isTokenExpired(accessToken)) {
|
||||
@@ -224,28 +226,6 @@ class HomeFragment : Fragment() {
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
}
|
||||
}
|
||||
}else if (deviceId.isNotEmpty()) {
|
||||
fetchDeviceCredentials()
|
||||
// This code will execute after credentials have been successfully fetched and stored.
|
||||
userID = sharedPreference.getString("username", "").toString()
|
||||
password = sharedPreference.getString("password", "").toString()
|
||||
accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
if (accessToken.isEmpty()) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
// Continue with your existing logic if the token is not empty.
|
||||
isTokenAvailable = true
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Contact Help and get your device provision done",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
hemoCubeViewModel.loginResponse.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
@@ -400,46 +380,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun fetchDeviceCredentials() {
|
||||
try {
|
||||
val db = Firebase.firestore
|
||||
// Ensure deviceId is not null or empty
|
||||
val deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").takeIf { it!!.isNotBlank() }
|
||||
?: throw IllegalStateException("Device ID is missing or blank.")
|
||||
|
||||
val deviceRef = db.collection("devices").whereEqualTo("deviceId", deviceId)
|
||||
|
||||
deviceRef.get()
|
||||
.addOnSuccessListener { documentSnapshot ->
|
||||
if (!documentSnapshot.isEmpty) {
|
||||
val deviceData = documentSnapshot.documents[0].toObject(DeviceData::class.java)
|
||||
deviceData?.let { data ->
|
||||
val username = data.username
|
||||
val password = data.password
|
||||
// Log for debugging
|
||||
Log.d("fetchDeviceCredentials", "Username: $username, Password: $password")
|
||||
// Save credentials in SharedPreferences
|
||||
with(sharedPreference.edit()) {
|
||||
putString("username", username)
|
||||
putString("password", password)
|
||||
apply()
|
||||
}
|
||||
hemoCubeViewModel.login(createLoginRequestData(username, password))
|
||||
} ?: Log.e("fetchDeviceCredentials", "Failed to parse device data.")
|
||||
} else {
|
||||
Log.e("fetchDeviceCredentials", "Document does not exist.")
|
||||
}
|
||||
}
|
||||
.addOnFailureListener { exception ->
|
||||
Log.e("fetchDeviceCredentials", "Error fetching device data", exception)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("fetchDeviceCredentials", "Error in fetchDeviceCredentials", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun loadUserData() {
|
||||
try {
|
||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
||||
@@ -822,44 +762,4 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDeviceId() {
|
||||
val handler = activity as? DeviceCommunicationHandler
|
||||
handler?.sendAndListenToDevice(
|
||||
HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {
|
||||
data?.let {
|
||||
val receivedData = String(it, Charset.forName("UTF-8"))
|
||||
// Assuming the device ID is the full content of the received data. Adjust if needed.
|
||||
deviceId =
|
||||
extractDeviceId(receivedData) // Implement this method based on your data format.
|
||||
if (deviceId.isNotEmpty()) {
|
||||
// Store the deviceId in SharedPreferences
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.DEVICE_ID, deviceId)
|
||||
apply()
|
||||
}
|
||||
// Optionally, you can update UI or proceed with further logic now that you have the device ID
|
||||
activity?.runOnUiThread {
|
||||
// Update your UI or trigger next steps here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
// Handle USB communication error
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
fun extractDeviceId(receivedData: String): String {
|
||||
// Example based on the format "SNS HPP1-3038 SNE"
|
||||
val regex = "SNS (\\w+) SNE".toRegex()
|
||||
val matchResult = regex.find(receivedData)
|
||||
return matchResult?.groups?.get(1)?.value ?: ""
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,21 +22,22 @@ import androidx.activity.viewModels
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.get
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.constant.LanguageManager
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
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.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityCalibrationBinding
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityDeviceBinding
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
@AndroidEntryPoint
|
||||
class DeviceActivity : AppCompatActivity(), DeviceCommunicationHandler {
|
||||
class DeviceActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityDeviceBinding
|
||||
private val deviceViewModel by viewModels<DeviceViewModel>()
|
||||
private var myMenu: Menu? = null
|
||||
@@ -147,18 +148,18 @@ class DeviceActivity : AppCompatActivity(), DeviceCommunicationHandler {
|
||||
val mPendingIntent: PendingIntent
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
@@ -180,8 +181,4 @@ class DeviceActivity : AppCompatActivity(), DeviceCommunicationHandler {
|
||||
deviceViewModel.isServiceConnected = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener) {
|
||||
mService.sendAndListenToHemoCube(command = HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND, listener)
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import android.annotation.SuppressLint
|
||||
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.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
@@ -32,7 +32,7 @@ class DeviceFragment : Fragment() {
|
||||
): View {
|
||||
binding = FragmentDeviceBinding.inflate(inflater, container, false)
|
||||
sharedPreferences =
|
||||
requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.example.hpostesting.presentation.deviceinfo
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.repository.Repository
|
||||
@@ -11,16 +14,16 @@ import javax.inject.Inject
|
||||
class DeviceViewModel @Inject constructor(
|
||||
private val hemoCubeDao: HemoCubeDao,
|
||||
private val repository: Repository,
|
||||
context: Context
|
||||
) : ViewModel() {
|
||||
var isServiceConnected = false
|
||||
val progressBar = MutableLiveData(false)
|
||||
val messages = MutableLiveData<String>()
|
||||
// private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||
// val allUserData = hemoCubeDao.getAll()
|
||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||
val allUserData = hemoCubeDao.getAll()
|
||||
val deviceData = MutableLiveData<DeviceData?>()
|
||||
// val networkStatusLiveData: LiveData<Boolean>
|
||||
// get() = _networkStatusLiveData
|
||||
val fireBaseUpload = MutableLiveData<String>()
|
||||
val fireBaseBulkUpload = MutableLiveData<String>()
|
||||
val networkStatusLiveData: LiveData<Boolean>
|
||||
get() = _networkStatusLiveData
|
||||
val fireBaseUpload = MutableLiveData<String>()
|
||||
|
||||
}
|
||||
@@ -21,11 +21,8 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.get
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.constant.LanguageManager
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.testRight.UsbService
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
@@ -34,7 +31,7 @@ import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityAutoDacBinding
|
||||
|
||||
@AndroidEntryPoint
|
||||
class DeviceProvisionActivity : AppCompatActivity(), DeviceCommunicationHandler {
|
||||
class DeviceProvisionActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityAutoDacBinding
|
||||
val viewModel: DeviceProvisionViewModel by viewModels()
|
||||
private var myMenu: Menu? = null
|
||||
@@ -147,18 +144,18 @@ class DeviceProvisionActivity : AppCompatActivity(), DeviceCommunicationHandler
|
||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
@@ -183,8 +180,4 @@ class DeviceProvisionActivity : AppCompatActivity(), DeviceCommunicationHandler
|
||||
viewModel.isServiceConnected = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener) {
|
||||
mService.sendAndListenToHemoCube(command = HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND, listener)
|
||||
}
|
||||
}
|
||||
@@ -4,35 +4,28 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
||||
|
||||
class DeviceProvisionFragment : Fragment() {
|
||||
|
||||
private var resultData: String = ""
|
||||
private lateinit var binding: FragmentDeviceProvisionBinding
|
||||
private val viewModel: DeviceProvisionViewModel by activityViewModels()
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
private lateinit var deviceProvisionResponse: String
|
||||
private var currentDeviceData: DeviceData? = null
|
||||
private var isOnline = false
|
||||
val deviceData = MutableLiveData<DeviceData?>()
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
@@ -40,11 +33,13 @@ class DeviceProvisionFragment : Fragment() {
|
||||
sharedPreferences = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initViews()
|
||||
observeViewModel()
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
listenToHemoCube()
|
||||
getDeviceId()
|
||||
@@ -60,11 +55,7 @@ class DeviceProvisionFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun observeViewModel() {
|
||||
viewModel.deviceData.observe(viewLifecycleOwner) {
|
||||
currentDeviceData = it
|
||||
}
|
||||
|
||||
viewModel.deviceProvisionResponse.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
@@ -89,31 +80,14 @@ class DeviceProvisionFragment : Fragment() {
|
||||
)
|
||||
apply()
|
||||
}
|
||||
startActivity(
|
||||
Intent(
|
||||
requireContext(),
|
||||
DashboardActivity::class.java
|
||||
)
|
||||
)
|
||||
startActivity(Intent(requireContext(), DashboardActivity::class.java))
|
||||
Toast.makeText(
|
||||
activity, "Device registered successfully", Toast.LENGTH_LONG
|
||||
).show()
|
||||
viewModel.addDeviceProvisionDataToDb(
|
||||
DeviceData(
|
||||
deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString(),
|
||||
username = response.data.data?.credentials?.username.toString(),
|
||||
password = response.data.data?.credentials?.password.toString(),
|
||||
deviceProvisionResponse = response.data.data.toString()
|
||||
)
|
||||
)
|
||||
// viewModel.addDeviceId(DeviceData(deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()))
|
||||
Log.e("idpass",response.toString())
|
||||
Log.e("idpass",response.data.data?.credentials?.username.toString())
|
||||
Log.e("idpass",deviceProvisionResponse)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error in device provision: ${response.data.message}",
|
||||
"An error occurred in device provision: ${response.data.message}",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
@@ -138,13 +112,6 @@ class DeviceProvisionFragment : Fragment() {
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
viewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||
if (result == "Success") {
|
||||
Toast.makeText(
|
||||
activity, "Device provision successfully uploaded to firebase", Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,8 +129,7 @@ class DeviceProvisionFragment : Fragment() {
|
||||
val fullReadOutput = StringBuilder()
|
||||
|
||||
try {
|
||||
(activity as DeviceProvisionActivity).mService.listenToHemoCube(object :
|
||||
UsbServiceListener {
|
||||
(activity as DeviceProvisionActivity).mService.listenToHemoCube(object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {
|
||||
data?.let {
|
||||
val stringData = String(it)
|
||||
@@ -179,14 +145,41 @@ class DeviceProvisionFragment : Fragment() {
|
||||
Firebase.crashlytics.recordException(e)
|
||||
}
|
||||
}
|
||||
|
||||
// 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() {
|
||||
when {
|
||||
resultData.contains("SNE") -> {
|
||||
val pattern = Regex("HCV-\\d{3}-\\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 hardwareId = matchResult?.value
|
||||
|
||||
if (hardwareId.toString().length == 12) {
|
||||
// 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()) {
|
||||
putString(Constants.DEVICE_ID, hardwareId)
|
||||
apply()
|
||||
@@ -198,4 +191,5 @@ class DeviceProvisionFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,11 @@
|
||||
package com.example.hpostesting.presentation.deviceprovision
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.model.Response
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.repository.Repository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -19,57 +13,17 @@ import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class DeviceProvisionViewModel @Inject constructor(
|
||||
private val databaseRepository: Repository,
|
||||
private val repository: Repository,
|
||||
context: Context,
|
||||
private val databaseRepository: Repository
|
||||
) : ViewModel() {
|
||||
|
||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||
var isServiceConnected = false
|
||||
val networkStatusLiveData: LiveData<Boolean> get() = _networkStatusLiveData
|
||||
|
||||
val deviceProvisionResponse = MutableLiveData<Result<DeviceProvisionResponse>>()
|
||||
val fireBaseUpload = MutableLiveData<String>()
|
||||
val fireBaseBulkUpload = MutableLiveData<String>()
|
||||
val deviceData = MutableLiveData<DeviceData?>()
|
||||
|
||||
fun deviceProvision(deviceProvisionRequest: DeviceProvisionRequest) = viewModelScope.launch {
|
||||
deviceProvisionResponse.postValue(Result.Loading())
|
||||
databaseRepository.deviceProvision(deviceProvisionRequest).let {
|
||||
deviceProvisionResponse.postValue(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun addDeviceId(data: DeviceData){
|
||||
viewModelScope.launch {
|
||||
try{
|
||||
repository.uploadDeviceId(data)
|
||||
fireBaseUpload.postValue("Successfully device Id uploaded to firebase")
|
||||
} catch (e: Exception) {
|
||||
// Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||
fireBaseUpload.postValue("Error")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun addDeviceProvisionDataToDb(data: DeviceData) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
when (val response = repository.getDeviceResponse(data)) {
|
||||
is Response.Success -> {
|
||||
// Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||
fireBaseUpload.postValue("Successfully device response uploaded to firebase")
|
||||
}
|
||||
|
||||
is Response.Error -> {
|
||||
// Log.e("Testdb", "Error uploading data to Firestore: $response")
|
||||
fireBaseUpload.postValue("Error")
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||
fireBaseUpload.postValue("Error")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import androidx.core.view.get
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
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.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||
@@ -146,18 +148,18 @@ class DiagnosticsActivity : AppCompatActivity() {
|
||||
val mPendingIntent: PendingIntent
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class HemoCubeFragment : Fragment() {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
uploadedToMolbio = true
|
||||
if (Constants.MOLBIO_INTEGRATION) {
|
||||
if (Constants.MOLBIO_INTERGATION) {
|
||||
it.data.data?.get(0)?.rawData?.let { it1 ->
|
||||
hemoCubeViewModel.updateMolbioFlag(
|
||||
it1._id
|
||||
@@ -805,8 +805,8 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
calculatedPredictedDenovixRatio = fittedAbs3.div(fittedAbs1)
|
||||
|
||||
val slope = (led4Average - led1Average) / (431-411)
|
||||
val calculatedSlopeRatio = abs(led2Average / slope)
|
||||
val slope = (led1Average - led2Average) / (435 - 415)
|
||||
val calculatedSlopeRatio = abs(led3Average / slope)
|
||||
val slopeClass = slopeRatioClassification(calculatedSlopeRatio)
|
||||
|
||||
if (fittedAbs1 <= fittedAbs2) {
|
||||
@@ -874,8 +874,8 @@ class HemoCubeFragment : Fragment() {
|
||||
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
|
||||
this.deviceRatioClass = deviceRatioClassification(deviceRatio)
|
||||
this.slopeRatioClass = slopeClass
|
||||
this.classificationResult = findResultWithAdditionalMethods(deviceRatio, deviceRatioClass, slopeRatio)
|
||||
hemoCubeViewModel.messages.postValue("${this.classificationResult} ")
|
||||
this.classificationResult = deviceRatioClass //findResult(calculatedRatio)
|
||||
hemoCubeViewModel.messages.postValue("${this.deviceRatioClass} ${if (led4Average < 0.17) " - Low Hb" else ""}\n")
|
||||
if (DataHolder.hemoCubeTestData?.testType == "HB")
|
||||
hemoCubeViewModel.messages.postValue("Hb: $calculatedHb4")
|
||||
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 {
|
||||
// hemoCubeViewModel.messages.postValue("post classification checks")
|
||||
if (deviceRatio != null) {
|
||||
if (slopeRatio != null) {
|
||||
if (deviceRatioClass == "Normal" && slopeRatio > 60.0)
|
||||
return "Negative Borderline, Repeat Test"
|
||||
hemoCubeViewModel.messages.postValue("result classification")
|
||||
if (calculatedRatio != null) {
|
||||
if (calculatedRatio < 0.05)
|
||||
return getString(R.string.error_repeat_test_higher_volume)
|
||||
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) {
|
||||
handleException(e)
|
||||
return "Error"
|
||||
showToast(R.string.error_classification)
|
||||
Firebase.crashlytics.recordException(e)
|
||||
return getString(R.string.error)
|
||||
}
|
||||
return deviceRatioClass.toString()
|
||||
return getString(R.string.invalid)
|
||||
}
|
||||
|
||||
fun deviceRatioClassification(ratio: Double?): String {
|
||||
try {
|
||||
if (ratio != null) {
|
||||
if (ratio in 0.001..0.23) {
|
||||
if (ratio in 0.1..0.29) {
|
||||
// setSubtitleTextColor(R.color.green_2)
|
||||
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)
|
||||
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"
|
||||
if (ratio in 0.32..Double.POSITIVE_INFINITY)
|
||||
if (ratio in 0.38..0.5)
|
||||
return "Sickle Cell Disease"
|
||||
} else {
|
||||
return "Invalid"
|
||||
|
||||
@@ -130,18 +130,18 @@ open class HemocubeActivity : AppCompatActivity() {
|
||||
val mPendingIntent: PendingIntent
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
|
||||
@@ -127,23 +127,23 @@ class TrueHemeActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("MutableImplicitPendingIntent", "UnspecifiedRegisterReceiverFlag")
|
||||
@SuppressLint("MutableImplicitPendingIntent")
|
||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||
val mPendingIntent: PendingIntent
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this, 0, Intent(Constants.HEMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
} else {
|
||||
mPendingIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
Intent(Constants.HEMOCUBE_USB_PERMISSION),
|
||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||
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)
|
||||
manager.requestPermission(device, mPendingIntent)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.example.hpostesting.presentation.trueheme
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
@@ -34,7 +33,6 @@ import kotlin.math.abs
|
||||
import kotlin.math.log10
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
@SuppressLint("SetTextI18n")
|
||||
class TrueHemeFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTruehemeSampleBinding
|
||||
@@ -156,7 +154,7 @@ class TrueHemeFragment : Fragment() {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
uploadedToMolbio = true
|
||||
if (Constants.MOLBIO_INTEGRATION) {
|
||||
if (Constants.MOLBIO_INTERGATION) {
|
||||
it.data.data?.get(0)?.rawData?.let { it1 ->
|
||||
hemoCubeViewModel.updateMolbioFlag(
|
||||
it1._id
|
||||
@@ -1143,8 +1141,4 @@ class TrueHemeFragment : Fragment() {
|
||||
val coefficient2 = currentDeviceData?.coefficients?.get(1) ?: 0.0
|
||||
return coefficient1 * ratio + coefficient2
|
||||
}
|
||||
|
||||
private fun reconnect() {
|
||||
(activity as HemocubeActivity).reconnectDevice()
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector android:height="24dp" android:tint="@color/primary"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@color/primary" android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
|
||||
</vector>
|
||||
@@ -77,13 +77,13 @@
|
||||
app:cornerRadius="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_deviceProvision" />
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_auto_dac" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_deviceProvision"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"
|
||||
android:visibility="gone"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:clickable="false"
|
||||
@@ -92,7 +92,7 @@
|
||||
app:cornerRadius="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_auto_dac" />
|
||||
app:layout_constraintTop_toBottomOf="@id/btn_deviceInfo" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_deviceInfo"
|
||||
|
||||
@@ -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
|
||||
fun testDeviceRatioClassificationNormal() {
|
||||
val ratio = 0.22
|
||||
val ratio = 0.25
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Normal", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceRatioClassificationNegativeBorderline() {
|
||||
val ratio = 0.235
|
||||
val ratio = 0.31
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Negative Borderline, Repeat Test", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceRatioClassificationSickleCellTrait() {
|
||||
val ratio = 0.25
|
||||
val ratio = 0.34
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Sickle Cell Trait", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
||||
val ratio = 0.31
|
||||
val ratio = 0.37
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
|
||||
}
|
||||
@@ -357,18 +357,4 @@ class HemoCubeFragmentTest {
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
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