Compare commits
1 Commits
nats_certi
...
2.1.101
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fef75b937 |
@@ -14,13 +14,13 @@ android {
|
||||
compileSdk 34
|
||||
namespace 'in.sminnovations.hpostesting'
|
||||
|
||||
// prod - production, preprod - preproduction, quality - qc, dev - development
|
||||
// dev - development, quality - qc, uat - User Acceptance Test, preprod - preproduction, prod - production
|
||||
defaultConfig {
|
||||
applicationId "in.sminnovations.hpostesting.quality"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 99
|
||||
versionName "2.1.99"
|
||||
versionCode 101
|
||||
versionName "2.1.101"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -157,7 +157,7 @@ dependencies {
|
||||
implementation("com.squareup.okhttp3:okhttp:4.9.3")
|
||||
|
||||
implementation "androidx.preference:preference-ktx:1.2.1"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'
|
||||
implementation 'io.nats:jnats:2.11.2'
|
||||
|
||||
implementation("androidx.work:work-runtime-ktx:2.9.0")
|
||||
|
||||
@@ -165,6 +165,4 @@ dependencies {
|
||||
implementation 'com.google.android.play:core:1.10.3'
|
||||
|
||||
implementation fileTree(dir: 'libs', include: ['*.aar'])
|
||||
implementation 'io.nats:jnats:2.11.4'
|
||||
|
||||
}
|
||||
BIN
app/release/hpos-app.apk
Normal file
BIN
app/release/hpos-app.apk
Normal file
Binary file not shown.
@@ -4,15 +4,15 @@
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "in.sminnovations.hpostesting.quality",
|
||||
"applicationId": "com.example.hpos",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 101,
|
||||
"versionName": "2.1.101",
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -119,8 +119,7 @@
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
@@ -7,11 +7,8 @@ import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
||||
import com.example.hpostesting.data.model.updates.CheckUpdateResponse
|
||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.PUT
|
||||
@@ -34,10 +31,6 @@ interface MolbioResultApi {
|
||||
@Body deviceUpdateRequest: DeviceUpdateRequest
|
||||
): ResponseBody
|
||||
|
||||
@GET("deviceService/device/getClientCertificate")
|
||||
suspend fun downloadClientCertificate(
|
||||
): ResponseBody
|
||||
|
||||
@Multipart
|
||||
@POST("deviceService/device/uploadLogs")
|
||||
suspend fun uploadLogs(
|
||||
|
||||
@@ -8,7 +8,7 @@ object Constants {
|
||||
|
||||
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
||||
|
||||
const val MOLBIO_INTERGATION = false
|
||||
const val MOLBIO_INTEGRATION = false
|
||||
const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in"
|
||||
const val deviceProvisionPassword = "f2ab0e7f9d69"
|
||||
const val DEVICE_ID_API = "deviceIDAPI"
|
||||
|
||||
@@ -77,9 +77,6 @@ class DatabaseRepository @Inject constructor(
|
||||
return safeApiCall { molbioResultApi.deviceUpdate(deviceUpdateRequest) }
|
||||
}
|
||||
|
||||
override suspend fun downloadClientCertificate(): Result<ResponseBody> {
|
||||
return safeApiCall { molbioResultApi.downloadClientCertificate() }
|
||||
}
|
||||
override suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse> {
|
||||
return safeApiCall { molbioResultApi.uploadLogs(logFile) }
|
||||
}
|
||||
|
||||
@@ -45,6 +45,5 @@ interface Repository {
|
||||
|
||||
suspend fun deviceUpdate(deviceUpdateRequest: DeviceUpdateRequest): Result<ResponseBody>
|
||||
|
||||
suspend fun downloadClientCertificate(): Result<ResponseBody>
|
||||
suspend fun uploadLogs(logFile: MultipartBody.Part): Result<UploadLogsResponse>
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.example.hpostesting.presentation
|
||||
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.example.hpostesting.presentation.assurance.AssuranceControlsActivity
|
||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||
import io.nats.client.AuthHandler
|
||||
import io.nats.client.Connection
|
||||
@@ -11,21 +8,9 @@ import io.nats.client.Message
|
||||
import io.nats.client.NKey
|
||||
import io.nats.client.Nats
|
||||
import io.nats.client.Options
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Paths
|
||||
import java.security.GeneralSecurityException
|
||||
import java.security.KeyStore
|
||||
import java.security.SecureRandom
|
||||
import java.security.cert.CertificateFactory
|
||||
import javax.net.ssl.KeyManager
|
||||
import javax.net.ssl.KeyManagerFactory
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.TrustManager
|
||||
import javax.net.ssl.TrustManagerFactory
|
||||
|
||||
|
||||
class NatsManager(datacollector: DashboardActivity) {
|
||||
@@ -35,57 +20,17 @@ class NatsManager(datacollector: DashboardActivity) {
|
||||
val datacollector = datacollector
|
||||
var connect = false
|
||||
|
||||
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() {
|
||||
Log.d(TAG, "TRY TO CONNECT")
|
||||
Thread {
|
||||
|
||||
val seedString = "SUAJH5VMO6GDRQA6QTXCLIJMS74IWIUTU3NJVYIOTZF2LBWUPD77DA2ZEA"
|
||||
Log.e("seedString",seedString)
|
||||
val seedString = "SUAEB5PUWNS6C2HUV3MFI6HUDEAPGPFPBHMI73NHIQATCDD2BWALVEZXZ4"
|
||||
val seedBytes = seedString.toCharArray()
|
||||
|
||||
val theNKey = NKey.fromSeed(seedBytes) // really should load from somewhere
|
||||
|
||||
val options = Options.Builder()
|
||||
.server("nats://nanodgx.in:4222")
|
||||
.sslContext(createSSLContext())
|
||||
.server("nats://192.168.10.117:4222")
|
||||
.authHandler(object : AuthHandler {
|
||||
override fun getID(): CharArray? {
|
||||
return try {
|
||||
@@ -123,11 +68,6 @@ class NatsManager(datacollector: DashboardActivity) {
|
||||
connect = true
|
||||
datacollector.setConnect(true)
|
||||
|
||||
if (nc?.status == Connection.Status.CONNECTED) {
|
||||
Log.e("NATSCONNECTION", "NATS is successfully connected.")
|
||||
} else {
|
||||
Log.e("NATSCONNECTION", "NATS is not connected. Current status: ${nc?.status}")
|
||||
}
|
||||
|
||||
nc?.publish(
|
||||
"server.hpos.HCV-000-3001.ping",
|
||||
@@ -142,7 +82,6 @@ class NatsManager(datacollector: DashboardActivity) {
|
||||
println("PRITIMOI SARKAR $msg")
|
||||
}
|
||||
|
||||
|
||||
d?.subscribe("device.hpos.HCV-000-3001.update") { msg ->
|
||||
val response = String(msg.data, StandardCharsets.UTF_8)
|
||||
datacollector. setResponse(response)
|
||||
@@ -176,7 +115,7 @@ class NatsManager(datacollector: DashboardActivity) {
|
||||
} catch (exp: Exception) {
|
||||
println(exp.printStackTrace())
|
||||
connect = false
|
||||
datacollector.setConnect(false)
|
||||
datacollector.setConnect(true)
|
||||
}
|
||||
}.start()
|
||||
|
||||
|
||||
@@ -3,19 +3,14 @@ package com.example.hpostesting.presentation.assurance
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.hpostesting.presentation.NatsManager
|
||||
import com.example.hpostesting.presentation.dashboard.IDataCollector
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.databinding.ActivityAssuranceControlsBinding
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AssuranceControlsActivity: AppCompatActivity(), IDataCollector {
|
||||
class AssuranceControlsActivity: AppCompatActivity() {
|
||||
lateinit var binding: ActivityAssuranceControlsBinding
|
||||
lateinit var sharedPreference: SharedPreferences
|
||||
lateinit var nats: NatsManager
|
||||
var responses: String = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -29,21 +24,5 @@ class AssuranceControlsActivity: AppCompatActivity(), IDataCollector {
|
||||
.replace(binding.fgAssuranceControls.id, AssuranceControlsFragment())
|
||||
.commit()
|
||||
}
|
||||
|
||||
// nats = NatsManager(this)
|
||||
// nats.connect()
|
||||
// nats.pub("server.hpos.HCV-000-3001.ping", "THIS IS A TEST MSG")
|
||||
}
|
||||
|
||||
override fun setConnect(connect: Boolean) {
|
||||
if(connect){
|
||||
Log.i("NATS Connection", connect.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun setResponse(response: String) {
|
||||
|
||||
responses = responses+response+"\n"
|
||||
println(responses)
|
||||
}
|
||||
}
|
||||
@@ -43,19 +43,11 @@ import com.google.firebase.perf.ktx.performance
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||
import okhttp3.ResponseBody
|
||||
import org.json.JSONObject
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URL
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HomeFragment : Fragment() {
|
||||
@@ -70,6 +62,7 @@ class HomeFragment : Fragment() {
|
||||
private val homeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
|
||||
private var isTokenAvailable = false
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
@@ -210,7 +203,6 @@ class HomeFragment : Fragment() {
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
hemoCubeViewModel.downloadClientCertificate()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -220,11 +212,6 @@ class HomeFragment : Fragment() {
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
hemoCubeViewModel.loginResponse.observe(viewLifecycleOwner) { response ->
|
||||
when (response) {
|
||||
is Result.Success -> {
|
||||
@@ -279,41 +266,6 @@ 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) {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
@@ -338,11 +290,8 @@ class HomeFragment : Fragment() {
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun isTokenExpired(token: String): Boolean {
|
||||
val parts = token.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val decodedPayload = String(Base64.decode(parts[1], Base64.DEFAULT))
|
||||
@@ -392,60 +341,6 @@ 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() {
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
val userId = binding.userId.text.toString()
|
||||
|
||||
@@ -4,7 +4,6 @@ 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
|
||||
@@ -75,11 +74,6 @@ class DeviceProvisionFragment : Fragment() {
|
||||
Constants.NATS_TOKEN,
|
||||
response.data.data?.device?.deviceUser?.natsToken
|
||||
)
|
||||
response.data.data?.device?.deviceUser?.natsToken?.let {
|
||||
Log.e("natstoken",
|
||||
it
|
||||
)
|
||||
}
|
||||
putString(
|
||||
Constants.NATS_TOKEN_EXPIRE_DATE,
|
||||
response.data.data?.device?.deviceUser?.natsTokenExpiry
|
||||
|
||||
@@ -153,7 +153,7 @@ class HemoCubeFragment : Fragment() {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
uploadedToMolbio = true
|
||||
if (Constants.MOLBIO_INTERGATION) {
|
||||
if (Constants.MOLBIO_INTEGRATION) {
|
||||
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 = (led1Average - led2Average) / (435 - 415)
|
||||
val calculatedSlopeRatio = abs(led3Average / slope)
|
||||
val slope = (led4Average - led1Average) / (431-411)
|
||||
val calculatedSlopeRatio = abs(led2Average / 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 = deviceRatioClass //findResult(calculatedRatio)
|
||||
hemoCubeViewModel.messages.postValue("${this.deviceRatioClass} ${if (led4Average < 0.17) " - Low Hb" else ""}\n")
|
||||
this.classificationResult = findResultWithAdditionalMethods(deviceRatio, deviceRatioClass, slopeRatio)
|
||||
hemoCubeViewModel.messages.postValue("${this.classificationResult} ")
|
||||
if (DataHolder.hemoCubeTestData?.testType == "HB")
|
||||
hemoCubeViewModel.messages.postValue("Hb: $calculatedHb4")
|
||||
this.errorMessages = testState.allErrorMessages
|
||||
@@ -909,50 +909,36 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
fun findResult(calculatedRatio: Double?): String {
|
||||
fun findResultWithAdditionalMethods(deviceRatio: Double?, deviceRatioClass: String?, slopeRatio: Double?): String {
|
||||
try {
|
||||
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)
|
||||
// hemoCubeViewModel.messages.postValue("post classification checks")
|
||||
if (deviceRatio != null) {
|
||||
if (slopeRatio != null) {
|
||||
if (deviceRatioClass == "Normal" && slopeRatio > 60.0)
|
||||
return "Negative Borderline, Repeat Test"
|
||||
}
|
||||
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) {
|
||||
showToast(R.string.error_classification)
|
||||
Firebase.crashlytics.recordException(e)
|
||||
return getString(R.string.error)
|
||||
handleException(e)
|
||||
return "Error"
|
||||
}
|
||||
return getString(R.string.invalid)
|
||||
return deviceRatioClass.toString()
|
||||
}
|
||||
|
||||
fun deviceRatioClassification(ratio: Double?): String {
|
||||
try {
|
||||
if (ratio != null) {
|
||||
if (ratio in 0.1..0.29) {
|
||||
if (ratio in 0.001..0.23) {
|
||||
// setSubtitleTextColor(R.color.green_2)
|
||||
return "Normal"
|
||||
}
|
||||
if (ratio in 0.29..0.32)
|
||||
if (ratio in 0.23..0.24)
|
||||
return "Negative Borderline, Repeat Test"
|
||||
if (ratio in 0.32..0.35)
|
||||
if (ratio in 0.24..0.29)
|
||||
return "Sickle Cell Trait"
|
||||
if (ratio in 0.35..0.38)
|
||||
if (ratio in 0.29..0.32)
|
||||
return "Positive for Sickle Cell. HPLC for Confirmation"
|
||||
if (ratio in 0.38..0.5)
|
||||
if (ratio in 0.32..Double.POSITIVE_INFINITY)
|
||||
return "Sickle Cell Disease"
|
||||
} else {
|
||||
return "Invalid"
|
||||
|
||||
@@ -79,7 +79,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
val checkUpdate = MutableLiveData<Result<CheckUpdateResponse>>()
|
||||
|
||||
val deviceUpdate = MutableLiveData<Result<ResponseBody>>()
|
||||
val downloadcertificate = MutableLiveData<Result<ResponseBody>>()
|
||||
|
||||
val uploadLogs = MutableLiveData<Result<UploadLogsResponse>?>()
|
||||
|
||||
@@ -142,9 +141,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fun checkUpdate(checkUpdateRequest: CheckUpdateRequest) = viewModelScope.launch {
|
||||
checkUpdate.postValue(Result.Loading())
|
||||
repository.checkUpdate(checkUpdateRequest).let {
|
||||
@@ -159,17 +155,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun downloadClientCertificate() = viewModelScope.launch {
|
||||
downloadcertificate.postValue(Result.Loading())
|
||||
repository.downloadClientCertificate().let {
|
||||
downloadcertificate.postValue(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fun startPeriodicCheckUpdate() {
|
||||
val periodicRequest = PeriodicWorkRequestBuilder<CheckUpdateWorker>(
|
||||
repeatInterval = 1, repeatIntervalTimeUnit = TimeUnit.MINUTES
|
||||
|
||||
@@ -156,7 +156,7 @@ class TrueHemeFragment : Fragment() {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
uploadedToMolbio = true
|
||||
if (Constants.MOLBIO_INTERGATION) {
|
||||
if (Constants.MOLBIO_INTEGRATION) {
|
||||
it.data.data?.get(0)?.rawData?.let { it1 ->
|
||||
hemoCubeViewModel.updateMolbioFlag(
|
||||
it1._id
|
||||
|
||||
@@ -318,28 +318,28 @@ class HemoCubeFragmentTest {
|
||||
|
||||
@Test
|
||||
fun testDeviceRatioClassificationNormal() {
|
||||
val ratio = 0.25
|
||||
val ratio = 0.22
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Normal", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceRatioClassificationNegativeBorderline() {
|
||||
val ratio = 0.31
|
||||
val ratio = 0.235
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Negative Borderline, Repeat Test", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceRatioClassificationSickleCellTrait() {
|
||||
val ratio = 0.34
|
||||
val ratio = 0.25
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Sickle Cell Trait", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
||||
val ratio = 0.37
|
||||
val ratio = 0.31
|
||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
|
||||
}
|
||||
@@ -357,4 +357,18 @@ 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user