Compare commits
31 Commits
dev-bulk-u
...
dev-Issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ba3b98d2d | ||
|
|
8e5294f564 | ||
|
|
547cf714a4 | ||
|
|
fd5fb6db22 | ||
|
|
9b2b64f248 | ||
|
|
06241008f1 | ||
|
|
0721be0114 | ||
|
|
23cf38445f | ||
|
|
6577842ba9 | ||
|
|
c52d9835cd | ||
|
|
9f04125f68 | ||
|
|
2b2c16df22 | ||
|
|
727040fabf | ||
|
|
80eb658b07 | ||
|
|
9314b155cd | ||
|
|
7f47e1dff8 | ||
|
|
be21430d0a | ||
|
|
d5b6910408 | ||
|
|
3609d728c1 | ||
|
|
7302ad669f | ||
|
|
ef98b09eaf | ||
|
|
89dc7f7234 | ||
|
|
f631a273d7 | ||
|
|
de74da3135 | ||
|
|
c5cb8a0983 | ||
|
|
6ddb491bc8 | ||
|
|
c5c0467e42 | ||
|
|
466d0e2afc | ||
|
|
45fd4861f4 | ||
|
|
1a3bb67dce | ||
|
|
3dd247b15d |
@@ -157,7 +157,7 @@ dependencies {
|
|||||||
implementation("com.squareup.okhttp3:okhttp:4.9.3")
|
implementation("com.squareup.okhttp3:okhttp:4.9.3")
|
||||||
|
|
||||||
implementation "androidx.preference:preference-ktx:1.2.1"
|
implementation "androidx.preference:preference-ktx:1.2.1"
|
||||||
implementation 'io.nats:jnats:2.11.2'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'
|
||||||
|
|
||||||
implementation("androidx.work:work-runtime-ktx:2.9.0")
|
implementation("androidx.work:work-runtime-ktx:2.9.0")
|
||||||
|
|
||||||
@@ -165,4 +165,6 @@ dependencies {
|
|||||||
implementation 'com.google.android.play:core:1.10.3'
|
implementation 'com.google.android.play:core:1.10.3'
|
||||||
|
|
||||||
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
||||||
|
implementation 'io.nats:jnats:2.11.4'
|
||||||
|
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -4,15 +4,15 @@
|
|||||||
"type": "APK",
|
"type": "APK",
|
||||||
"kind": "Directory"
|
"kind": "Directory"
|
||||||
},
|
},
|
||||||
"applicationId": "com.example.hpos",
|
"applicationId": "in.sminnovations.hpostesting.quality",
|
||||||
"variantName": "release",
|
"variantName": "release",
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": "SINGLE",
|
"type": "SINGLE",
|
||||||
"filters": [],
|
"filters": [],
|
||||||
"attributes": [],
|
"attributes": [],
|
||||||
"versionCode": 1,
|
"versionCode": 101,
|
||||||
"versionName": "1.0",
|
"versionName": "2.1.101",
|
||||||
"outputFile": "app-release.apk"
|
"outputFile": "app-release.apk"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -160,7 +160,7 @@
|
|||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="com.example.hpostesting.qa.fileprovider"
|
android:authorities="${applicationId}.fileprovider"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:grantUriPermissions="true">
|
android:grantUriPermissions="true">
|
||||||
<meta-data
|
<meta-data
|
||||||
|
|||||||
@@ -7,8 +7,11 @@ import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
|||||||
import com.example.hpostesting.data.model.updates.CheckUpdateResponse
|
import com.example.hpostesting.data.model.updates.CheckUpdateResponse
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
|
import okhttp3.Response
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Header
|
||||||
import retrofit2.http.Multipart
|
import retrofit2.http.Multipart
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
import retrofit2.http.PUT
|
import retrofit2.http.PUT
|
||||||
@@ -31,6 +34,10 @@ interface MolbioResultApi {
|
|||||||
@Body deviceUpdateRequest: DeviceUpdateRequest
|
@Body deviceUpdateRequest: DeviceUpdateRequest
|
||||||
): ResponseBody
|
): ResponseBody
|
||||||
|
|
||||||
|
@GET("deviceService/device/getClientCertificate")
|
||||||
|
suspend fun downloadClientCertificate(
|
||||||
|
): ResponseBody
|
||||||
|
|
||||||
@Multipart
|
@Multipart
|
||||||
@POST("deviceService/device/uploadLogs")
|
@POST("deviceService/device/uploadLogs")
|
||||||
suspend fun uploadLogs(
|
suspend fun uploadLogs(
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
package com.example.hpostesting.data.api
|
package com.example.hpostesting.data.api
|
||||||
|
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
|
|
||||||
interface PropertyProvider {
|
interface PropertyProvider {
|
||||||
|
|
||||||
fun getProperty(key: String): String
|
fun getProperty(key: String): String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DeviceCommunicationHandler {
|
||||||
|
fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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.HemoCubeTestData
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
|
|
||||||
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class, BufferCheckData::class], version = 24, exportSchema = false)
|
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class, BufferCheckData::class], version = 26, exportSchema = false)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class MyDatabase : RoomDatabase() {
|
abstract class MyDatabase : RoomDatabase() {
|
||||||
abstract fun userDao(): UserDao
|
abstract fun userDao(): UserDao
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.example.hpostesting.data.model.deviceprovision
|
||||||
|
|
||||||
|
data class ProvisionData(
|
||||||
|
val username: String?,
|
||||||
|
val password: String?,
|
||||||
|
val natsToken: String?
|
||||||
|
)
|
||||||
|
|
||||||
@@ -4,20 +4,20 @@ import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|||||||
|
|
||||||
data class MolbioV2ResultData(
|
data class MolbioV2ResultData(
|
||||||
val age: Int? = 0,
|
val age: Int? = 0,
|
||||||
val analysisDate: String? = "",
|
val analysisDate: String? = "2024-02-08 16:33:56",
|
||||||
val analysisStatus: String? = "",
|
val analysisStatus: String? = "",
|
||||||
val analysisType: String? = "",
|
val analysisType: String? = "",
|
||||||
val analysisTypeMethod: String? = "",
|
val analysisTypeMethod: String? = "",
|
||||||
val bloodGroup: String? = "",
|
val bloodGroup: String? = "",
|
||||||
val coefficients: List<Int>? = listOf(),
|
val coefficients: List<Int>? = listOf(),
|
||||||
val collectionLocation: List<Any>? = listOf(),
|
val collectionLocation: List<Any>? = listOf(),
|
||||||
val collectionTime: String? = "",
|
val collectionTime: String? = "2024-02-08 16:33:56",
|
||||||
val collector: String? = "",
|
val collector: String? = "",
|
||||||
val createdAt: String? = "",
|
val createdAt: String? = "",
|
||||||
val createdBy: Int? = 0,
|
val createdBy: Int? = 0,
|
||||||
val curveFitting: String? = "",
|
val curveFitting: String? = "",
|
||||||
val deviceId: Int? = 0,
|
val deviceId: Int? = 0,
|
||||||
val expiryTime: String? = "",
|
val expiryTime: String? = "2024-02-08 16:33:56",
|
||||||
val gender: String? = "",
|
val gender: String? = "",
|
||||||
val id: Int? = 0,
|
val id: Int? = 0,
|
||||||
val interpretation: String? = "",
|
val interpretation: String? = "",
|
||||||
@@ -32,7 +32,7 @@ data class MolbioV2ResultData(
|
|||||||
val testId: String? = "",
|
val testId: String? = "",
|
||||||
val testResult: String? = "",
|
val testResult: String? = "",
|
||||||
val testStatus: String? = "",
|
val testStatus: String? = "",
|
||||||
val testTime: String? = "",
|
val testTime: String? = "2024-02-08 16:33:56",
|
||||||
val testType: String? = "",
|
val testType: String? = "",
|
||||||
val thresholds: String? = "",
|
val thresholds: String? = "",
|
||||||
val underMedication: Boolean? = false,
|
val underMedication: Boolean? = false,
|
||||||
|
|||||||
@@ -15,5 +15,15 @@ data class DeviceData(
|
|||||||
@get:PropertyName("coefficients") @set:PropertyName("coefficients")
|
@get:PropertyName("coefficients") @set:PropertyName("coefficients")
|
||||||
var coefficients: List<Double> = emptyList(),
|
var coefficients: List<Double> = emptyList(),
|
||||||
@get:PropertyName("calibratedAt") @set:PropertyName("calibratedAt")
|
@get:PropertyName("calibratedAt") @set:PropertyName("calibratedAt")
|
||||||
var calibratedAt: String = ""
|
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 = "",
|
||||||
|
@get:PropertyName("natsToken") @set:PropertyName("natsToken")
|
||||||
|
var natsToken: String = "",
|
||||||
|
@get:PropertyName("natsTokenExpiry") @set:PropertyName("natsTokenExpiry")
|
||||||
|
var natsTokenExpiry: String = ""
|
||||||
)
|
)
|
||||||
@@ -77,6 +77,9 @@ class DatabaseRepository @Inject constructor(
|
|||||||
return safeApiCall { molbioResultApi.deviceUpdate(deviceUpdateRequest) }
|
return safeApiCall { molbioResultApi.deviceUpdate(deviceUpdateRequest) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun downloadClientCertificate(): Result<ResponseBody> {
|
||||||
|
return safeApiCall { molbioResultApi.downloadClientCertificate() }
|
||||||
|
}
|
||||||
override suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse> {
|
override suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse> {
|
||||||
return safeApiCall { molbioResultApi.uploadLogs(logFile) }
|
return safeApiCall { molbioResultApi.uploadLogs(logFile) }
|
||||||
}
|
}
|
||||||
@@ -203,7 +206,31 @@ class DatabaseRepository @Inject constructor(
|
|||||||
return allDeviceDataList.find { it.deviceId == deviceId }
|
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 {
|
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,8 @@ interface Repository {
|
|||||||
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean>
|
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean>
|
||||||
|
|
||||||
suspend fun getDeviceDataById(deviceId: String): DeviceData?
|
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
|
abstract fun <UserData> addTestToDatabase(testDetails: UserData): Any
|
||||||
// suspend fun addToDatabase(data: PatientDetails)
|
// suspend fun addToDatabase(data: PatientDetails)
|
||||||
|
|
||||||
@@ -45,5 +47,6 @@ interface Repository {
|
|||||||
|
|
||||||
suspend fun deviceUpdate(deviceUpdateRequest: DeviceUpdateRequest): Result<ResponseBody>
|
suspend fun deviceUpdate(deviceUpdateRequest: DeviceUpdateRequest): Result<ResponseBody>
|
||||||
|
|
||||||
|
suspend fun downloadClientCertificate(): Result<ResponseBody>
|
||||||
suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse>
|
suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse>
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ class KitScanActivity : AppCompatActivity(), IDcsSdkApiDelegate {
|
|||||||
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,"Scanner Is not available In this device", Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.example.hpostesting.presentation
|
package com.example.hpostesting.presentation
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import io.nats.client.AuthHandler
|
import io.nats.client.AuthHandler
|
||||||
import io.nats.client.Connection
|
import io.nats.client.Connection
|
||||||
@@ -8,9 +12,17 @@ import io.nats.client.Message
|
|||||||
import io.nats.client.NKey
|
import io.nats.client.NKey
|
||||||
import io.nats.client.Nats
|
import io.nats.client.Nats
|
||||||
import io.nats.client.Options
|
import io.nats.client.Options
|
||||||
|
import io.nats.client.support.SSLUtils
|
||||||
|
import java.io.FileInputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.security.GeneralSecurityException
|
import java.security.GeneralSecurityException
|
||||||
|
import java.security.KeyStore
|
||||||
|
import java.security.SecureRandom
|
||||||
|
import java.security.cert.CertificateFactory
|
||||||
|
import javax.net.ssl.KeyManagerFactory
|
||||||
|
import javax.net.ssl.SSLContext
|
||||||
|
import javax.net.ssl.TrustManagerFactory
|
||||||
|
|
||||||
|
|
||||||
class NatsManager(datacollector: DashboardActivity) {
|
class NatsManager(datacollector: DashboardActivity) {
|
||||||
@@ -19,103 +31,160 @@ class NatsManager(datacollector: DashboardActivity) {
|
|||||||
var nc: Connection? = null
|
var nc: Connection? = null
|
||||||
val datacollector = datacollector
|
val datacollector = datacollector
|
||||||
var connect = false
|
var connect = false
|
||||||
|
var sharedPreferences = datacollector.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
private fun createSSLContext(): SSLContext {
|
||||||
|
val keyStorePassword = "prime24".toCharArray() // Change as necessary
|
||||||
|
val clientCertPath = "/storage/sdcard0/Download/client.p12"
|
||||||
|
|
||||||
|
// Load client certificate and key
|
||||||
|
val keyStore = KeyStore.getInstance("PKCS12")
|
||||||
|
FileInputStream(clientCertPath).use { keyStoreInputStream ->
|
||||||
|
keyStore.load(keyStoreInputStream, keyStorePassword)
|
||||||
|
}
|
||||||
|
val caCertPath =
|
||||||
|
"/storage/sdcard0/Android/data/in.sminnovations.hpostesting.quality/files/NATS/clientCertificate/client-cert.pem"
|
||||||
|
val caCert = FileInputStream(caCertPath).use { inputStream ->
|
||||||
|
val certificateFactory = CertificateFactory.getInstance("X.509")
|
||||||
|
certificateFactory.generateCertificate(inputStream)
|
||||||
|
}
|
||||||
|
|
||||||
|
val trustStore = KeyStore.getInstance(KeyStore.getDefaultType()).apply {
|
||||||
|
load(null, null) // Initialize the keystore
|
||||||
|
setCertificateEntry("caCert", caCert) // Add the CA certificate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize key manager factory
|
||||||
|
val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
|
||||||
|
kmf.init(keyStore, keyStorePassword)
|
||||||
|
|
||||||
|
// Initialize trust manager factory
|
||||||
|
val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
|
||||||
|
tmf.init(trustStore)
|
||||||
|
|
||||||
|
// Initialize SSLContext
|
||||||
|
val sslContext = SSLContext.getInstance("TLS")
|
||||||
|
sslContext.init(kmf.keyManagers, tmf.trustManagers, SecureRandom())
|
||||||
|
|
||||||
|
return sslContext
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
fun connect() {
|
fun connect() {
|
||||||
Log.d(TAG, "TRY TO CONNECT")
|
Log.d(TAG, "TRY TO CONNECT")
|
||||||
Thread {
|
Thread {
|
||||||
|
|
||||||
val seedString = "SUAEB5PUWNS6C2HUV3MFI6HUDEAPGPFPBHMI73NHIQATCDD2BWALVEZXZ4"
|
|
||||||
val seedBytes = seedString.toCharArray()
|
|
||||||
|
|
||||||
val theNKey = NKey.fromSeed(seedBytes) // really should load from somewhere
|
|
||||||
|
|
||||||
val options = Options.Builder()
|
|
||||||
.server("nats://192.168.10.117:4222")
|
|
||||||
.authHandler(object : AuthHandler {
|
|
||||||
override fun getID(): CharArray? {
|
|
||||||
return try {
|
|
||||||
theNKey?.publicKey
|
|
||||||
} catch (ex: GeneralSecurityException) {
|
|
||||||
null
|
|
||||||
} catch (ex: IOException) {
|
|
||||||
null
|
|
||||||
} catch (ex: NullPointerException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sign(nonce: ByteArray): ByteArray? {
|
|
||||||
return try {
|
|
||||||
theNKey?.sign(nonce)
|
|
||||||
} catch (ex: GeneralSecurityException) {
|
|
||||||
null
|
|
||||||
} catch (ex: IOException) {
|
|
||||||
null
|
|
||||||
} catch (ex: NullPointerException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getJWT(): CharArray? {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
val seedString = sharedPreferences.getString(Constants.NATS_TOKEN, "")
|
||||||
|
val deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "")
|
||||||
|
Log.e("seedString", seedString.toString())
|
||||||
|
Log.d("nats deviceId", deviceId.toString())
|
||||||
|
val seedBytes = seedString?.toCharArray()
|
||||||
|
|
||||||
|
val theNKey = NKey.fromSeed(seedBytes) // really should load from somewhere
|
||||||
|
|
||||||
|
val options = Options.Builder()
|
||||||
|
.server("nats://nanodgx.in:4222")
|
||||||
|
.sslContext(SSLUtils.createOpenTLSContext())
|
||||||
|
.authHandler(object : AuthHandler {
|
||||||
|
override fun getID(): CharArray? {
|
||||||
|
return try {
|
||||||
|
theNKey?.publicKey
|
||||||
|
} catch (ex: GeneralSecurityException) {
|
||||||
|
null
|
||||||
|
} catch (ex: IOException) {
|
||||||
|
null
|
||||||
|
} catch (ex: NullPointerException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun sign(nonce: ByteArray): ByteArray? {
|
||||||
|
return try {
|
||||||
|
theNKey?.sign(nonce)
|
||||||
|
} catch (ex: GeneralSecurityException) {
|
||||||
|
null
|
||||||
|
} catch (ex: IOException) {
|
||||||
|
null
|
||||||
|
} catch (ex: NullPointerException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getJWT(): CharArray? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
|
||||||
nc = Nats.connect(options)
|
nc = Nats.connect(options)
|
||||||
Log.d(TAG, "Connected to Nats server ${options.servers.first()}")
|
Log.d(TAG, "Connected to Nats server ${options.servers.first()}")
|
||||||
connect = true
|
connect = true
|
||||||
datacollector.setConnect(true)
|
datacollector.setConnect(true)
|
||||||
|
|
||||||
|
if (nc?.status == Connection.Status.CONNECTED) {
|
||||||
|
Log.d("NATSCONNECTION", "NATS is successfully connected.")
|
||||||
|
|
||||||
nc?.publish(
|
val d = nc?.createDispatcher { msg: Message? ->
|
||||||
"server.hpos.HCV-000-3001.ping",
|
println("Nats dispatcher $msg")
|
||||||
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
}
|
||||||
)
|
|
||||||
nc?.publish(
|
|
||||||
"server.hpos.HCV-000-3001.health",
|
|
||||||
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
|
||||||
)
|
|
||||||
Log.d(TAG, "Published msg server.hpos.HCV-000-3001.ping on topic Testing")
|
|
||||||
val d = nc?.createDispatcher { msg: Message? ->
|
|
||||||
println("PRITIMOI SARKAR $msg")
|
|
||||||
}
|
|
||||||
|
|
||||||
d?.subscribe("device.hpos.HCV-000-3001.update") { msg ->
|
nc?.subscribe("device.hpos.${deviceId}.ping")
|
||||||
val response = String(msg.data, StandardCharsets.UTF_8)
|
|
||||||
datacollector. setResponse(response)
|
|
||||||
println("Message received (up to 100 times): $response")
|
|
||||||
}
|
|
||||||
|
|
||||||
d?.subscribe("device.hpos.HCV-000-3001.uploadlogs") { msg ->
|
nc?.publish(
|
||||||
val response = String(msg.data, StandardCharsets.UTF_8)
|
"server.hpos.${deviceId}.ping",
|
||||||
datacollector.setResponse(response + "uPLOAD")
|
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
||||||
println("Message received (up to 100 times): $response")
|
)
|
||||||
}
|
nc?.publish(
|
||||||
|
"server.hpos.${deviceId}.health",
|
||||||
|
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
||||||
|
)
|
||||||
|
|
||||||
d?.subscribe("device.hpos.HCV-000-3001.disable") { msg ->
|
d?.subscribe("device.hpos.${deviceId}.ping") { msg ->
|
||||||
val response = String(msg.data, StandardCharsets.UTF_8)
|
val response = String(msg.data, StandardCharsets.UTF_8)
|
||||||
datacollector.setResponse(response)
|
datacollector.setResponse(response)
|
||||||
println("Message received (up to 100 times): $response")
|
println("Message received (up to 100 times): $response")
|
||||||
}
|
Log.d(TAG, "subscribed msg ${msg} on topic ping")
|
||||||
|
}
|
||||||
|
|
||||||
d?.subscribe("device.hpos.HCV-000-3001.updatecustomer") { msg ->
|
d?.subscribe("device.hpos.${deviceId}.update") { msg ->
|
||||||
val response = String(msg.data, StandardCharsets.UTF_8)
|
val response = String(msg.data, StandardCharsets.UTF_8)
|
||||||
datacollector.setResponse(response)
|
datacollector.setResponse(response)
|
||||||
println("Message received (up to 100 times): $response")
|
println("Message received (up to 100 times): $response")
|
||||||
}
|
}
|
||||||
|
|
||||||
d?.subscribe("device.hpos.HCV-000-3001.checkupdate") { msg ->
|
d?.subscribe("device.hpos.${deviceId}.uploadlogs") { msg ->
|
||||||
val response = String(msg.data, StandardCharsets.UTF_8)
|
val response = String(msg.data, StandardCharsets.UTF_8)
|
||||||
datacollector.setResponse(response)
|
datacollector.setResponse(response + "UPLOAD")
|
||||||
println("Message received (up to 100 times): $response")
|
println("Message received (up to 100 times): $response")
|
||||||
|
}
|
||||||
|
|
||||||
|
d?.subscribe("device.hpos.${deviceId}.disable") { msg ->
|
||||||
|
val response = String(msg.data, StandardCharsets.UTF_8)
|
||||||
|
datacollector.setResponse(response)
|
||||||
|
println("Message received (up to 100 times): $response")
|
||||||
|
}
|
||||||
|
|
||||||
|
d?.subscribe("device.hpos.${deviceId}.updatecustomer") { msg ->
|
||||||
|
val response = String(msg.data, StandardCharsets.UTF_8)
|
||||||
|
datacollector.setResponse(response)
|
||||||
|
println("Message received (up to 100 times): $response")
|
||||||
|
}
|
||||||
|
|
||||||
|
d?.subscribe("device.hpos.${deviceId}.checkupdate") { msg ->
|
||||||
|
val response = String(msg.data, StandardCharsets.UTF_8)
|
||||||
|
datacollector.setResponse(response)
|
||||||
|
println("Message received (up to 100 times): $response")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d("NATSCONNECTION", "NATS is not connected. Current status: ${nc?.status}")
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (exp: Exception) {
|
} catch (exp: Exception) {
|
||||||
println(exp.printStackTrace())
|
println(exp.printStackTrace())
|
||||||
connect = false
|
connect = false
|
||||||
datacollector.setConnect(true)
|
datacollector.setConnect(false)
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
|
||||||
@@ -126,6 +195,16 @@ class NatsManager(datacollector: DashboardActivity) {
|
|||||||
Log.d(TAG, "Published msg ${msg} on topic ${topic}")
|
Log.d(TAG, "Published msg ${msg} on topic ${topic}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun sub(topic: String) {
|
||||||
|
val d = nc?.createDispatcher { msg: Message? ->
|
||||||
|
val response = String(msg?.data ?: ByteArray(0), StandardCharsets.UTF_8)
|
||||||
|
datacollector.onMessageReceived(topic, response)
|
||||||
|
Log.d(TAG, "Subscribed msg $msg on topic $topic")
|
||||||
|
}
|
||||||
|
|
||||||
|
d?.subscribe(topic)
|
||||||
|
}
|
||||||
|
|
||||||
fun close() {
|
fun close() {
|
||||||
nc?.close()
|
nc?.close()
|
||||||
Log.d(TAG, "Nats connection close")
|
Log.d(TAG, "Nats connection close")
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import android.app.DownloadManager
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
@@ -19,6 +21,7 @@ import androidx.navigation.ui.navigateUp
|
|||||||
import androidx.navigation.ui.setupActionBarWithNavController
|
import androidx.navigation.ui.setupActionBarWithNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import com.example.hpostesting.data.Result
|
import com.example.hpostesting.data.Result
|
||||||
|
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.NatsManager
|
import com.example.hpostesting.presentation.NatsManager
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
@@ -32,15 +35,22 @@ import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
|||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
open interface IDataCollector {
|
interface NatsMessageCallback {
|
||||||
|
fun onMessageReceived(topic: String, message: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
open interface IDataCollector: NatsMessageCallback {
|
||||||
fun setConnect(connect: Boolean)
|
fun setConnect(connect: Boolean)
|
||||||
fun setResponse(response: String)
|
fun setResponse(response: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DashboardActivity : AppCompatActivity(), IDataCollector {
|
class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||||
|
|
||||||
|
val TAG = "DashboardActivity"
|
||||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||||
private lateinit var binding: ActivityDashboardBinding
|
private lateinit var binding: ActivityDashboardBinding
|
||||||
|
lateinit var sharedPreferences: SharedPreferences
|
||||||
var responses: String = ""
|
var responses: String = ""
|
||||||
lateinit var nats: NatsManager
|
lateinit var nats: NatsManager
|
||||||
private var downloadId: Long = 0
|
private var downloadId: Long = 0
|
||||||
@@ -53,15 +63,27 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
super.attachBaseContext(newBase)
|
super.attachBaseContext(newBase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMessageReceived(topic: String, message: String) {
|
||||||
|
// Handle incoming messages from NATS
|
||||||
|
Log.d(TAG, "Received message on topic $topic: $message")
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
binding = ActivityDashboardBinding.inflate(layoutInflater)
|
binding = ActivityDashboardBinding.inflate(layoutInflater)
|
||||||
|
sharedPreferences = this.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
setSupportActionBar(binding.appBarDashboard.toolbar)
|
setSupportActionBar(binding.appBarDashboard.toolbar)
|
||||||
nats = NatsManager(this)
|
nats = NatsManager(this)
|
||||||
nats.connect()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
nats.pub("server.hpos.HCV-000-3001.ping", "THIS IS A TEST MSG")
|
nats.connect()
|
||||||
|
}
|
||||||
|
|
||||||
|
val deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "")
|
||||||
|
|
||||||
|
nats.sub("server.hpos.${deviceId}.ping")
|
||||||
|
nats.pub("server.hpos.${deviceId}.ping", "THIS IS A TEST MSG")
|
||||||
|
|
||||||
hemocubeViewModel.deviceUpdate.observe(this) { result ->
|
hemocubeViewModel.deviceUpdate.observe(this) { result ->
|
||||||
when (result) {
|
when (result) {
|
||||||
@@ -156,9 +178,10 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
val file = File(getExternalFilesDir("Updates"), "update.apk")
|
val file = File(getExternalFilesDir("Updates"), "update.apk")
|
||||||
file.setReadable(true, false) // Ensure the file is readable
|
file.setReadable(true, false) // Ensure the file is readable
|
||||||
|
|
||||||
|
val pInfo = baseContext.packageManager.getPackageInfo(baseContext.packageName, 0)
|
||||||
val uri: Uri = FileProvider.getUriForFile(
|
val uri: Uri = FileProvider.getUriForFile(
|
||||||
this,
|
this,
|
||||||
"com.example.hpostesting.qa.fileprovider",
|
"${pInfo}.fileprovider",
|
||||||
file
|
file
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class GalleryFragment : Fragment() {
|
|||||||
) {
|
) {
|
||||||
binding.btnDeviceProvision.visibility = View.VISIBLE
|
binding.btnDeviceProvision.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
binding.btnDeviceProvision.visibility = View.GONE
|
binding.btnDeviceProvision.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.btnDeviceProvision.setOnClickListener {
|
binding.btnDeviceProvision.setOnClickListener {
|
||||||
|
|||||||
@@ -19,16 +19,20 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.Result
|
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.Constants
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.login.LoginRequest
|
import com.example.hpostesting.data.model.login.LoginRequest
|
||||||
import com.example.hpostesting.data.model.login.LoginResponse
|
import com.example.hpostesting.data.model.login.LoginResponse
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2Result
|
import com.example.hpostesting.data.model.molbioresult.MolbioV2Result
|
||||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultRequest
|
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.HemoCubeTestData
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||||
import com.example.hpostesting.presentation.KitScanActivity
|
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.OfflineUserListAdapter
|
||||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||||
import com.example.hpostesting.presentation.assurance.AssuranceControlsActivity
|
import com.example.hpostesting.presentation.assurance.AssuranceControlsActivity
|
||||||
@@ -43,11 +47,19 @@ import com.google.firebase.perf.ktx.performance
|
|||||||
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.FragmentHomeBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||||
|
import okhttp3.ResponseBody
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import java.io.BufferedOutputStream
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.nio.charset.Charset
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
@@ -62,6 +74,9 @@ class HomeFragment : Fragment() {
|
|||||||
private val homeViewModel: HemoCubeViewModel by activityViewModels()
|
private val homeViewModel: HemoCubeViewModel by activityViewModels()
|
||||||
|
|
||||||
private var isTokenAvailable = false
|
private var isTokenAvailable = false
|
||||||
|
private var natsToken: String = ""
|
||||||
|
private var deviceId: String = ""
|
||||||
|
|
||||||
|
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@@ -89,7 +104,7 @@ class HomeFragment : Fragment() {
|
|||||||
binding.labelQuickCapture.visibility = View.VISIBLE
|
binding.labelQuickCapture.visibility = View.VISIBLE
|
||||||
binding.btnQuickCapture.visibility = View.VISIBLE
|
binding.btnQuickCapture.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
getDeviceId()
|
||||||
checkUnprocessedCSVData()
|
checkUnprocessedCSVData()
|
||||||
viewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
viewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||||
deleteIncompleteRegistrations(userData)
|
deleteIncompleteRegistrations(userData)
|
||||||
@@ -110,11 +125,18 @@ class HomeFragment : Fragment() {
|
|||||||
binding.rvOrderOffline.adapter = adapter
|
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 ->
|
viewModel.networkStatusLiveData?.observe(viewLifecycleOwner) { isConnected ->
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
|
|
||||||
binding.internetAvailableCL.visibility = View.VISIBLE
|
binding.internetAvailableCL.visibility = View.VISIBLE
|
||||||
binding.internetNotAvailableCL.visibility = View.GONE
|
binding.internetNotAvailableCL.visibility = View.GONE
|
||||||
|
binding.pendingTest.visibility = View.VISIBLE
|
||||||
loadUserData()
|
loadUserData()
|
||||||
setSearch()
|
setSearch()
|
||||||
checkForLocalDBData()
|
checkForLocalDBData()
|
||||||
@@ -128,21 +150,20 @@ class HomeFragment : Fragment() {
|
|||||||
MolbioV2Result(
|
MolbioV2Result(
|
||||||
rawData = userData,
|
rawData = userData,
|
||||||
analysisId = userData._id,
|
analysisId = userData._id,
|
||||||
analysisDate = "2024-02-08 16:33:56",
|
analysisDate = "2024-02-08 16:33:56",//userData.testTime,
|
||||||
analysisStatus = userData.classificationResult,
|
analysisStatus = userData.classificationResult,
|
||||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||||
interpretation = userData.classificationResult,
|
interpretation = userData.classificationResult,
|
||||||
testId = userData._id,
|
testId = userData._id,
|
||||||
testTime = userData.testTime,
|
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||||
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
if (!userData.molbioFlag && isTokenAvailable) {
|
|
||||||
userData.molbioFlag = true
|
userData.molbioFlag = true
|
||||||
hemoCubeViewModel.uploadResult(resultList)
|
hemoCubeViewModel.uploadResult(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userData.localFlag) {
|
if (!userData.localFlag) {
|
||||||
userData.localFlag = true
|
userData.localFlag = true
|
||||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||||
@@ -152,9 +173,9 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
binding.internetAvailableCL.visibility = View.GONE
|
binding.internetAvailableCL.visibility = View.GONE
|
||||||
|
binding.pendingTest.visibility = View.GONE
|
||||||
binding.internetNotAvailableCL.visibility = View.VISIBLE
|
binding.internetNotAvailableCL.visibility = View.VISIBLE
|
||||||
setUserId()
|
setUserId()
|
||||||
}
|
}
|
||||||
@@ -174,14 +195,13 @@ class HomeFragment : Fragment() {
|
|||||||
logoutUser(requireContext())
|
logoutUser(requireContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
binding.uploadData.setOnClickListener {
|
binding.uploadData.setOnClickListener {
|
||||||
showUploadDialog(requireContext())
|
showUploadDialog(requireContext())
|
||||||
}
|
}
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||||
|
|
||||||
val btnSaveLocalVisibility =
|
val btnSaveLocalVisibility =
|
||||||
if (userData.any { it.testStatus == true }) View.VISIBLE else View.GONE
|
if (userData.any { it.testStatus == true }) View.GONE else View.GONE
|
||||||
|
|
||||||
binding.downloadCSV.visibility = btnSaveLocalVisibility
|
binding.downloadCSV.visibility = btnSaveLocalVisibility
|
||||||
|
|
||||||
@@ -222,13 +242,17 @@ class HomeFragment : Fragment() {
|
|||||||
binding.downloadCSV.setOnClickListener {
|
binding.downloadCSV.setOnClickListener {
|
||||||
showDownloadDialog(requireContext())
|
showDownloadDialog(requireContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForTokenAndUpdate() {
|
private fun checkForTokenAndUpdate() {
|
||||||
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||||
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
var password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||||
val userID = sharedPreference.getString(Constants.DEVICE_ID_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 (userID.isNotEmpty() && password.isNotEmpty()) {
|
||||||
if (!isTokenAvailable) {
|
if (!isTokenAvailable) {
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
@@ -241,10 +265,25 @@ class HomeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||||
hemoCubeViewModel.uploadLogs()
|
hemoCubeViewModel.uploadLogs()
|
||||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||||
|
hemoCubeViewModel.downloadClientCertificate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}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(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
"Contact Help and get your device provision done",
|
"Contact Help and get your device provision done",
|
||||||
@@ -306,6 +345,41 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
hemoCubeViewModel.downloadcertificate.observe(viewLifecycleOwner) { response ->
|
||||||
|
when (response) {
|
||||||
|
is Result.Success -> {
|
||||||
|
val url = response.data
|
||||||
|
|
||||||
|
val fileName = "nats_certificate.zip"
|
||||||
|
val downloadDirectory = "NATS"
|
||||||
|
val file = downloadFile(url, requireContext(), fileName, downloadDirectory)
|
||||||
|
Toast.makeText(requireContext(), "NATS certificate Downloaded", Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
|
val unzipDirectoryPath = requireContext().getExternalFilesDir(null)?.absolutePath + "/$downloadDirectory"
|
||||||
|
unzip(file.absolutePath, unzipDirectoryPath)
|
||||||
|
Toast.makeText(requireContext(), "NATS certificate Extracted", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
is Result.Error -> {
|
||||||
|
response.exception.let { message ->
|
||||||
|
Toast.makeText(
|
||||||
|
activity,
|
||||||
|
"An error occurred in nats download: $message",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is Result.Loading -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
@@ -330,8 +404,11 @@ class HomeFragment : Fragment() {
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun isTokenExpired(token: String): Boolean {
|
private fun isTokenExpired(token: String): Boolean {
|
||||||
val parts = token.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
val parts = token.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||||
val decodedPayload = String(Base64.decode(parts[1], Base64.DEFAULT))
|
val decodedPayload = String(Base64.decode(parts[1], Base64.DEFAULT))
|
||||||
@@ -381,6 +458,60 @@ class HomeFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun downloadFile(responseBody: ResponseBody, context: Context, fileName: String, downloadDirectory: String): File {
|
||||||
|
// Ensure the download directory exists
|
||||||
|
val fileDir = File(context.getExternalFilesDir(null), downloadDirectory)
|
||||||
|
if (!fileDir.exists()) {
|
||||||
|
fileDir.mkdirs()
|
||||||
|
}
|
||||||
|
val file = File(fileDir, fileName)
|
||||||
|
Log.d("Download", "Starting download to $file")
|
||||||
|
responseBody.byteStream().use { inputStream ->
|
||||||
|
FileOutputStream(file).use { outputStream ->
|
||||||
|
inputStream.copyTo(outputStream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// After download
|
||||||
|
Log.d("Download", "Download completed to ${file.absolutePath}")
|
||||||
|
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun unzip(zipFilePath: String, destDirectory: String) {
|
||||||
|
val destDir = File(destDirectory)
|
||||||
|
if (!destDir.exists()) {
|
||||||
|
destDir.mkdir()
|
||||||
|
}
|
||||||
|
ZipInputStream(FileInputStream(zipFilePath)).use { zipIn ->
|
||||||
|
var entry: ZipEntry? = zipIn.nextEntry
|
||||||
|
while (entry != null) {
|
||||||
|
val filePath = destDirectory + File.separator + entry.name
|
||||||
|
if (!entry.isDirectory) {
|
||||||
|
extractFile(zipIn, filePath)
|
||||||
|
} else {
|
||||||
|
val dir = File(filePath)
|
||||||
|
dir.mkdir()
|
||||||
|
}
|
||||||
|
zipIn.closeEntry()
|
||||||
|
entry = zipIn.nextEntry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun extractFile(zipIn: ZipInputStream, filePath: String) {
|
||||||
|
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||||
|
val bytesIn = ByteArray(4096)
|
||||||
|
var read: Int
|
||||||
|
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
||||||
|
bos.write(bytesIn, 0, read)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setUserId() {
|
private fun setUserId() {
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
val userId = binding.userId.text.toString()
|
val userId = binding.userId.text.toString()
|
||||||
@@ -406,6 +537,48 @@ 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
|
||||||
|
val natsToken = data.natsToken
|
||||||
|
// Log for debugging
|
||||||
|
Log.d("fetchDeviceCredentials", "Username: $username, Password: $password")
|
||||||
|
// Save credentials in SharedPreferences
|
||||||
|
with(sharedPreference.edit()) {
|
||||||
|
putString("username", username)
|
||||||
|
putString("password", password)
|
||||||
|
putString(Constants.NATS_TOKEN, natsToken)
|
||||||
|
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() {
|
private fun loadUserData() {
|
||||||
try {
|
try {
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
|
||||||
@@ -575,7 +748,7 @@ class HomeFragment : Fragment() {
|
|||||||
private fun checkUnprocessedCSVData() {
|
private fun checkUnprocessedCSVData() {
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
val downloadDataVisibility =
|
val downloadDataVisibility =
|
||||||
if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.VISIBLE else View.GONE
|
if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.GONE else View.GONE
|
||||||
binding.downloadCSV.visibility = downloadDataVisibility
|
binding.downloadCSV.visibility = downloadDataVisibility
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -630,39 +803,6 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
|
||||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
|
||||||
userDataList.forEach { userData ->
|
|
||||||
if (!userData.molbioFlag && isTokenAvailable) {
|
|
||||||
resultList.results?.add(
|
|
||||||
MolbioV2Result(
|
|
||||||
rawData = userData,
|
|
||||||
analysisId = userData._id,
|
|
||||||
analysisDate = "2024-02-08 16:33:56", //userData.reportUploadTime,
|
|
||||||
analysisStatus = userData.classificationResult,
|
|
||||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
|
||||||
interpretation = userData.classificationResult,
|
|
||||||
testId = userData._id,
|
|
||||||
testTime = userData.testTime,
|
|
||||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
|
||||||
expiryTime = "2024-02-08 16:33:56",//userData.testTime,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!userData.localFlag){
|
|
||||||
userData.localFlag = true
|
|
||||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
|
||||||
}
|
|
||||||
if (!userData.molbioFlag && isTokenAvailable) {
|
|
||||||
userData.molbioFlag = true
|
|
||||||
hemoCubeViewModel.uploadResult(resultList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dialog.dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { kitDataList ->
|
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { kitDataList ->
|
||||||
kitDataList.forEach { userData ->
|
kitDataList.forEach { userData ->
|
||||||
if (!userData.localFlag) {
|
if (!userData.localFlag) {
|
||||||
@@ -672,6 +812,37 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
|
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||||
|
userDataList.forEach { userData ->
|
||||||
|
if (!userData.molbioFlag && isTokenAvailable) {
|
||||||
|
resultList.results?.add(
|
||||||
|
MolbioV2Result(
|
||||||
|
rawData = userData,
|
||||||
|
analysisId = userData._id,
|
||||||
|
analysisDate = "2024-02-08 16:33:56",//userData.testTime,
|
||||||
|
analysisStatus = userData.classificationResult,
|
||||||
|
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||||
|
interpretation = userData.classificationResult,
|
||||||
|
testId = userData._id,
|
||||||
|
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||||
|
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||||
|
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
userData.molbioFlag = true
|
||||||
|
hemoCubeViewModel.uploadResult(resultList)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userData.localFlag) {
|
||||||
|
userData.localFlag = true
|
||||||
|
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||||
@@ -791,4 +962,44 @@ 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,8 +22,11 @@ import androidx.activity.viewModels
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.get
|
import androidx.core.view.get
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
|
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||||
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.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
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
|
||||||
@@ -33,7 +36,7 @@ import `in`.sminnovations.hpostesting.databinding.ActivityDeviceBinding
|
|||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DeviceActivity : AppCompatActivity() {
|
class DeviceActivity : AppCompatActivity(), DeviceCommunicationHandler {
|
||||||
private lateinit var binding: ActivityDeviceBinding
|
private lateinit var binding: ActivityDeviceBinding
|
||||||
private val deviceViewModel by viewModels<DeviceViewModel>()
|
private val deviceViewModel by viewModels<DeviceViewModel>()
|
||||||
private var myMenu: Menu? = null
|
private var myMenu: Menu? = null
|
||||||
@@ -177,4 +180,8 @@ class DeviceActivity : AppCompatActivity() {
|
|||||||
deviceViewModel.isServiceConnected = false
|
deviceViewModel.isServiceConnected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener) {
|
||||||
|
mService.sendAndListenToHemoCube(command = HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND, listener)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ class DeviceViewModel @Inject constructor(
|
|||||||
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>()
|
||||||
|
val fireBaseBulkUpload = MutableLiveData<String>()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,8 +21,11 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.get
|
import androidx.core.view.get
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
|
import com.example.hpostesting.data.api.DeviceCommunicationHandler
|
||||||
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.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
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
|
||||||
@@ -31,7 +34,7 @@ import `in`.sminnovations.hpostesting.R
|
|||||||
import `in`.sminnovations.hpostesting.databinding.ActivityAutoDacBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityAutoDacBinding
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class DeviceProvisionActivity : AppCompatActivity() {
|
class DeviceProvisionActivity : AppCompatActivity(), DeviceCommunicationHandler {
|
||||||
private lateinit var binding: ActivityAutoDacBinding
|
private lateinit var binding: ActivityAutoDacBinding
|
||||||
val viewModel: DeviceProvisionViewModel by viewModels()
|
val viewModel: DeviceProvisionViewModel by viewModels()
|
||||||
private var myMenu: Menu? = null
|
private var myMenu: Menu? = null
|
||||||
@@ -180,4 +183,8 @@ class DeviceProvisionActivity : AppCompatActivity() {
|
|||||||
viewModel.isServiceConnected = false
|
viewModel.isServiceConnected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener) {
|
||||||
|
mService.sendAndListenToHemoCube(command = HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND, listener)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,19 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.Result
|
import com.example.hpostesting.data.Result
|
||||||
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.deviceprovision.DeviceProvisionRequest
|
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.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
@@ -21,11 +24,14 @@ import com.google.firebase.ktx.Firebase
|
|||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
||||||
|
|
||||||
class DeviceProvisionFragment : Fragment() {
|
class DeviceProvisionFragment : Fragment() {
|
||||||
|
|
||||||
private var resultData: String = ""
|
private var resultData: String = ""
|
||||||
private lateinit var binding: FragmentDeviceProvisionBinding
|
private lateinit var binding: FragmentDeviceProvisionBinding
|
||||||
private val viewModel: DeviceProvisionViewModel by activityViewModels()
|
private val viewModel: DeviceProvisionViewModel by activityViewModels()
|
||||||
private lateinit var sharedPreferences: SharedPreferences
|
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(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
@@ -33,13 +39,11 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
sharedPreferences = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
sharedPreferences = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
initViews()
|
initViews()
|
||||||
observeViewModel()
|
observeViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
listenToHemoCube()
|
listenToHemoCube()
|
||||||
getDeviceId()
|
getDeviceId()
|
||||||
@@ -55,7 +59,11 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun observeViewModel() {
|
private fun observeViewModel() {
|
||||||
|
viewModel.deviceData.observe(viewLifecycleOwner) {
|
||||||
|
currentDeviceData = it
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.deviceProvisionResponse.observe(viewLifecycleOwner) { response ->
|
viewModel.deviceProvisionResponse.observe(viewLifecycleOwner) { response ->
|
||||||
when (response) {
|
when (response) {
|
||||||
@@ -74,20 +82,44 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
Constants.NATS_TOKEN,
|
Constants.NATS_TOKEN,
|
||||||
response.data.data?.device?.deviceUser?.natsToken
|
response.data.data?.device?.deviceUser?.natsToken
|
||||||
)
|
)
|
||||||
|
response.data.data?.device?.deviceUser?.natsToken?.let {
|
||||||
|
Log.e("natstoken",
|
||||||
|
it
|
||||||
|
)
|
||||||
|
}
|
||||||
putString(
|
putString(
|
||||||
Constants.NATS_TOKEN_EXPIRE_DATE,
|
Constants.NATS_TOKEN_EXPIRE_DATE,
|
||||||
response.data.data?.device?.deviceUser?.natsTokenExpiry
|
response.data.data?.device?.deviceUser?.natsTokenExpiry
|
||||||
)
|
)
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
startActivity(Intent(requireContext(), DashboardActivity::class.java))
|
startActivity(
|
||||||
|
Intent(
|
||||||
|
requireContext(),
|
||||||
|
DashboardActivity::class.java
|
||||||
|
)
|
||||||
|
)
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity, "Device registered successfully", Toast.LENGTH_LONG
|
activity, "Device registered successfully", Toast.LENGTH_LONG
|
||||||
).show()
|
).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(),
|
||||||
|
natsToken = response.data.data?.device?.deviceUser?.natsToken.toString(),
|
||||||
|
natsTokenExpiry = response.data.data?.device?.deviceUser?.natsTokenExpiry.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 {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity,
|
activity,
|
||||||
"An error occurred in device provision: ${response.data.message}",
|
"An error in device provision: ${response.data.message}",
|
||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
binding.btnSubmit.visibility = View.VISIBLE
|
binding.btnSubmit.visibility = View.VISIBLE
|
||||||
@@ -112,6 +144,13 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
viewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
|
if (result == "Success") {
|
||||||
|
Toast.makeText(
|
||||||
|
activity, "Device provision successfully uploaded to firebase", Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDeviceId() {
|
private fun getDeviceId() {
|
||||||
@@ -128,7 +167,8 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
val fullReadOutput = StringBuilder()
|
val fullReadOutput = StringBuilder()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(activity as DeviceProvisionActivity).mService.listenToHemoCube(object : UsbServiceListener {
|
(activity as DeviceProvisionActivity).mService.listenToHemoCube(object :
|
||||||
|
UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
data?.let {
|
data?.let {
|
||||||
val stringData = String(it)
|
val stringData = String(it)
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.example.hpostesting.data.Result
|
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.DeviceProvisionRequest
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionResponse
|
||||||
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -13,17 +15,54 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class DeviceProvisionViewModel @Inject constructor(
|
class DeviceProvisionViewModel @Inject constructor(
|
||||||
private val databaseRepository: Repository
|
private val repository: Repository,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
var isServiceConnected = false
|
var isServiceConnected = false
|
||||||
|
|
||||||
val deviceProvisionResponse = MutableLiveData<Result<DeviceProvisionResponse>>()
|
val deviceProvisionResponse = MutableLiveData<Result<DeviceProvisionResponse>>()
|
||||||
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
|
val fireBaseBulkUpload = MutableLiveData<String>()
|
||||||
|
val deviceData = MutableLiveData<DeviceData?>()
|
||||||
|
|
||||||
fun deviceProvision(deviceProvisionRequest: DeviceProvisionRequest) = viewModelScope.launch {
|
fun deviceProvision(deviceProvisionRequest: DeviceProvisionRequest) = viewModelScope.launch {
|
||||||
deviceProvisionResponse.postValue(Result.Loading())
|
deviceProvisionResponse.postValue(Result.Loading())
|
||||||
databaseRepository.deviceProvision(deviceProvisionRequest).let {
|
repository.deviceProvision(deviceProvisionRequest).let {
|
||||||
deviceProvisionResponse.postValue(it)
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -643,10 +643,10 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
|
||||||
assignDefaultDevice(resultData)
|
assignDefaultDevice(resultData)
|
||||||
testState.allErrorMessages += "Calibration configuration for this device id is not found\n"
|
// testState.allErrorMessages += "Calibration configuration for this device id is not found\n"
|
||||||
}
|
}
|
||||||
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
|
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
|
||||||
testState.allErrorMessages += "ADC thresholds for this device id are not found\n"
|
// testState.allErrorMessages += "ADC thresholds for this device id are not found\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,9 +743,9 @@ class HemoCubeFragment : Fragment() {
|
|||||||
)?.get(0)!!
|
)?.get(0)!!
|
||||||
) {
|
) {
|
||||||
// validationError = true
|
// validationError = true
|
||||||
testState.allErrorMessages += "Error: Invalid Test. Improper buffer reading (low)"
|
// testState.allErrorMessages += "Error: Invalid Test. Improper buffer reading (low)"
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.errorMessage.text = getString(R.string.error_improper_buffer_low)
|
// binding.errorMessage.text = getString(R.string.error_improper_buffer_low)
|
||||||
// binding.errorMessage.visibility = View.VISIBLE
|
// binding.errorMessage.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -763,11 +763,11 @@ class HemoCubeFragment : Fragment() {
|
|||||||
)?.get(1)!!
|
)?.get(1)!!
|
||||||
) {
|
) {
|
||||||
// validationError = true
|
// validationError = true
|
||||||
testState.allErrorMessages += "Error: Invalid Test. Improper buffer reading (high)" + "\n"
|
// testState.allErrorMessages += "Error: Invalid Test. Improper buffer reading (high)" + "\n"
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.errorMessage.text =
|
// binding.errorMessage.text =
|
||||||
getString(R.string.error_improper_buffer_high)
|
getString(R.string.error_improper_buffer_high)
|
||||||
binding.errorMessage.visibility = View.VISIBLE
|
// binding.errorMessage.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,9 +811,9 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
if (fittedAbs1 <= fittedAbs2) {
|
if (fittedAbs1 <= fittedAbs2) {
|
||||||
// validationError = true
|
// validationError = true
|
||||||
testState.allErrorMessages += "Error: Invalid Test. Problem with de-oxygenation" + "\n"
|
// testState.allErrorMessages += "Error: Invalid Test. Problem with de-oxygenation" + "\n"
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.errorMessage.text = getString(R.string.error_invalid_test)
|
// binding.errorMessage.text = getString(R.string.error_invalid_test)
|
||||||
// binding.errorMessage.visibility = View.VISIBLE
|
// binding.errorMessage.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -837,9 +837,9 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
if (fittedAbs3 < 0.1) {
|
if (fittedAbs3 < 0.1) {
|
||||||
// validationError = true
|
// validationError = true
|
||||||
testState.allErrorMessages += "Error: Low Hb. Repeat test" + "\n"
|
// testState.allErrorMessages += "Error: Low Hb. Repeat test" + "\n"
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.errorMessage.text = "Error: Low Hb. Repeat test"
|
// binding.errorMessage.text = "Error: Low Hb. Repeat test"
|
||||||
// binding.errorMessage.visibility = View.VISIBLE
|
// binding.errorMessage.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
hemoCubeViewModel.messages.postValue("${this.classificationResult} \n Device Ratio: ${"%.3f".format(this.deviceRatio)} \n Slope Ratio: ${"%.3f".format(this.slopeRatio)}")
|
hemoCubeViewModel.messages.postValue("${this.classificationResult} \n Device Ratio: ${"%.3f".format(this.deviceRatio)}")
|
||||||
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
|
||||||
@@ -928,17 +928,17 @@ class HemoCubeFragment : Fragment() {
|
|||||||
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.016..0.22) {
|
||||||
// setSubtitleTextColor(R.color.green_2)
|
// setSubtitleTextColor(R.color.green_2)
|
||||||
return "Normal"
|
return "Normal"
|
||||||
}
|
}
|
||||||
if (ratio in 0.23..0.24)
|
if (ratio in 0.22..0.24)
|
||||||
return "Negative Borderline, Repeat Test"
|
return "Negative Borderline"
|
||||||
if (ratio in 0.24..0.29)
|
if (ratio in 0.24..0.32)
|
||||||
return "Sickle Cell Trait"
|
return "Sickle Cell Trait"
|
||||||
if (ratio in 0.29..0.32)
|
if (ratio in 0.32..0.37)
|
||||||
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.37..0.56)
|
||||||
return "Sickle Cell Disease"
|
return "Sickle Cell Disease"
|
||||||
} else {
|
} else {
|
||||||
return "Invalid"
|
return "Invalid"
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
val checkUpdate = MutableLiveData<Result<CheckUpdateResponse>>()
|
val checkUpdate = MutableLiveData<Result<CheckUpdateResponse>>()
|
||||||
|
|
||||||
val deviceUpdate = MutableLiveData<Result<ResponseBody>>()
|
val deviceUpdate = MutableLiveData<Result<ResponseBody>>()
|
||||||
|
val downloadcertificate = MutableLiveData<Result<ResponseBody>>()
|
||||||
|
|
||||||
val uploadLogs = MutableLiveData<Result<UploadLogsResponse>?>()
|
val uploadLogs = MutableLiveData<Result<UploadLogsResponse>?>()
|
||||||
|
|
||||||
@@ -155,6 +156,13 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun downloadClientCertificate() = viewModelScope.launch {
|
||||||
|
downloadcertificate.postValue(Result.Loading())
|
||||||
|
repository.downloadClientCertificate().let {
|
||||||
|
downloadcertificate.postValue(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun startPeriodicCheckUpdate() {
|
fun startPeriodicCheckUpdate() {
|
||||||
val periodicRequest = PeriodicWorkRequestBuilder<CheckUpdateWorker>(
|
val periodicRequest = PeriodicWorkRequestBuilder<CheckUpdateWorker>(
|
||||||
repeatInterval = 1, repeatIntervalTimeUnit = TimeUnit.MINUTES
|
repeatInterval = 1, repeatIntervalTimeUnit = TimeUnit.MINUTES
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="com.example.hpostesting.presentation.dashboard.GalleryFragment">
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:context="com.example.hpostesting.presentation.dashboard.GalleryFragment">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_subtitle4"
|
android:id="@+id/tv_subtitle4"
|
||||||
@@ -79,20 +84,6 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_auto_dac" />
|
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="gone"
|
|
||||||
android:layout_marginHorizontal="16dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:clickable="false"
|
|
||||||
android:text="@string/deviceProvision"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
app:cornerRadius="16dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_deviceInfo" />
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btn_deviceInfo"
|
android:id="@+id/btn_deviceInfo"
|
||||||
@@ -108,6 +99,20 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_calibration" />
|
app:layout_constraintTop_toBottomOf="@id/btn_calibration" />
|
||||||
|
|
||||||
|
<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:layout_marginHorizontal="16dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:clickable="false"
|
||||||
|
android:text="@string/deviceProvision"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
app:cornerRadius="16dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/btn_deviceInfo" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btn_firefox"
|
android:id="@+id/btn_firefox"
|
||||||
@@ -137,4 +142,5 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_firefox" />
|
app:layout_constraintTop_toBottomOf="@id/btn_firefox" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</ScrollView>
|
||||||
@@ -12,6 +12,12 @@
|
|||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
android:id="@+id/cardView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:cardCornerRadius="16dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imageView"
|
android:id="@+id/imageView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -19,6 +25,7 @@
|
|||||||
android:contentDescription="@string/nav_header_desc"
|
android:contentDescription="@string/nav_header_desc"
|
||||||
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||||
app:srcCompat="@mipmap/hpos_icon" />
|
app:srcCompat="@mipmap/hpos_icon" />
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ class HemoCubeFragmentTest {
|
|||||||
fun testDeviceRatioClassificationNegativeBorderline() {
|
fun testDeviceRatioClassificationNegativeBorderline() {
|
||||||
val ratio = 0.235
|
val ratio = 0.235
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||||
assertEquals("Negative Borderline, Repeat Test", result)
|
assertEquals("Negative Borderline", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -339,7 +339,7 @@ class HemoCubeFragmentTest {
|
|||||||
|
|
||||||
@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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user