Compare commits
7 Commits
dev-molbio
...
DEV_UAT
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5e03e3fab | ||
|
|
a97fd86c86 | ||
|
|
41a66766d1 | ||
|
|
3f9d1d110f | ||
|
|
af3f152e26 | ||
|
|
339a2d0d70 | ||
|
|
8fd91e0961 |
3
.idea/gradle.xml
generated
3
.idea/gradle.xml
generated
@@ -4,8 +4,9 @@
|
|||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
<option name="testRunner" value="GRADLE" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
<option name="gradleJvm" value="jbr-17" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|||||||
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@@ -1,4 +1,3 @@
|
|||||||
/build
|
/build
|
||||||
/release
|
|
||||||
/google-services*
|
/google-services*
|
||||||
/idea
|
/idea
|
||||||
@@ -19,8 +19,8 @@ android {
|
|||||||
applicationId "in.sminnovations.hpostesting.dev"
|
applicationId "in.sminnovations.hpostesting.dev"
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 120
|
versionCode 114
|
||||||
versionName "2.1.120"
|
versionName "2.1.114"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -80,16 +80,16 @@ dependencies {
|
|||||||
implementation 'com.google.firebase:firebase-auth-ktx'
|
implementation 'com.google.firebase:firebase-auth-ktx'
|
||||||
implementation 'com.google.firebase:firebase-storage-ktx'
|
implementation 'com.google.firebase:firebase-storage-ktx'
|
||||||
implementation 'com.firebaseui:firebase-ui-firestore:8.0.2'
|
implementation 'com.firebaseui:firebase-ui-firestore:8.0.2'
|
||||||
implementation 'com.google.android.gms:play-services-auth:21.0.0'
|
implementation 'com.google.android.gms:play-services-auth:20.7.0'
|
||||||
implementation 'com.google.android.gms:play-services-location:21.1.0'
|
implementation 'com.google.android.gms:play-services-location:21.1.0'
|
||||||
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
|
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
|
||||||
implementation 'com.google.android.things:androidthings:1.0'
|
implementation 'com.google.android.things:androidthings:1.0'
|
||||||
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta12'
|
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta11'
|
||||||
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta12")
|
implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta11")
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
implementation 'com.google.android.play:core:1.10.3'
|
implementation 'com.google.android.play:core:1.10.3'
|
||||||
implementation 'io.nats:jnats:2.11.4'
|
implementation 'io.nats:jnats:2.11.2'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -143,8 +143,8 @@ dependencies {
|
|||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
|
||||||
|
|
||||||
// Navigation Component
|
// Navigation Component
|
||||||
implementation "androidx.navigation:navigation-fragment-ktx:2.7.7"
|
implementation "androidx.navigation:navigation-fragment-ktx:2.7.6"
|
||||||
implementation "androidx.navigation:navigation-ui-ktx:2.7.7"
|
implementation "androidx.navigation:navigation-ui-ktx:2.7.6"
|
||||||
|
|
||||||
//Dagger - Hilt
|
//Dagger - Hilt
|
||||||
implementation "com.google.dagger:hilt-android:2.46"
|
implementation "com.google.dagger:hilt-android:2.46"
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="com.example.hpostesting.HPOSTestingApplication"
|
android:name="com.example.hpostesting.HPOSTestingApplication"
|
||||||
android:largeHeap="true"
|
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
android:fullBackupContent="@xml/backup_rules"
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
@@ -117,15 +116,18 @@
|
|||||||
android:name="com.example.hpostesting.presentation.testRight.UsbService"
|
android:name="com.example.hpostesting.presentation.testRight.UsbService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpostesting.presentation.SplashActivity"
|
android:name="com.example.hpostesting.presentation.SplashActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:noHistory="true"
|
android:noHistory="true"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
<!-- <category android:name="android.intent.category.HOME" />-->
|
||||||
|
<!-- <category android:name="android.intent.category.DEFAULT" />-->
|
||||||
|
<!-- <category android:name="android.intent.category.MONKEY"/>-->
|
||||||
|
<!-- <category android:name="android.intent.category.LAUNCHER_APP" />-->
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
@@ -162,7 +164,7 @@
|
|||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:stateNotNeeded="true"
|
android:stateNotNeeded="true"
|
||||||
tools:replace="android:screenOrientation" />
|
tools:replace="android:screenOrientation" />
|
||||||
<!-- ${applicationId}-->
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="${applicationId}.fileprovider"
|
android:authorities="${applicationId}.fileprovider"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.util
|
package com.example.hpostesting.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.data.constant
|
package com.example.hpostesting.data
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.util
|
package com.example.hpostesting.data
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.util
|
package com.example.hpostesting.data
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.util
|
package com.example.hpostesting.data
|
||||||
|
|
||||||
sealed class Result<out T : Any> {
|
sealed class Result<out T : Any> {
|
||||||
data class Success<out T : Any>(val data: T) : Result<T>()
|
data class Success<out T : Any>(val data: T) : Result<T>()
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
package com.example.hpostesting.presentation.utils
|
package com.example.hpostesting.data.api
|
||||||
|
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
|
|
||||||
|
interface PropertyProvider {
|
||||||
|
|
||||||
|
fun getProperty(key: String): String
|
||||||
|
}
|
||||||
|
|
||||||
interface DeviceCommunicationHandler {
|
interface DeviceCommunicationHandler {
|
||||||
fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener)
|
fun sendAndListenToDevice(command: HemoCubeCommands, listener: UsbServiceListener)
|
||||||
@@ -5,7 +5,7 @@ object Constants {
|
|||||||
const val HEMOCUBE_USB_PERMISSION = "shanmukha.in.sickle_cell_homocube.USB_PERMISSION"
|
const val HEMOCUBE_USB_PERMISSION = "shanmukha.in.sickle_cell_homocube.USB_PERMISSION"
|
||||||
|
|
||||||
const val BASE_URL = "www.google.com"
|
const val BASE_URL = "www.google.com"
|
||||||
const val DOCUMENT_ID_FOR_UPDATE ="2o71vBKLqdgEKYtFG8Lb"
|
|
||||||
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
||||||
|
|
||||||
const val MOLBIO_INTEGRATION = true
|
const val MOLBIO_INTEGRATION = true
|
||||||
@@ -67,8 +67,6 @@ object Constants {
|
|||||||
val STATICID = listOf(
|
val STATICID = listOf(
|
||||||
"FACTORY",
|
"FACTORY",
|
||||||
"ADMIN",
|
"ADMIN",
|
||||||
"PQUSER",
|
|
||||||
"QCUSER",
|
|
||||||
"VIZ-1000-0004",
|
"VIZ-1000-0004",
|
||||||
"VIZ-1000-0005",
|
"VIZ-1000-0005",
|
||||||
"VIZ-1000-0006",
|
"VIZ-1000-0006",
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import androidx.room.Update
|
|
||||||
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
|
||||||
@Dao
|
@Dao
|
||||||
@@ -13,12 +12,6 @@ interface HemoCubeDao {
|
|||||||
@Query("SELECT * from hemo_cube_test_table")
|
@Query("SELECT * from hemo_cube_test_table")
|
||||||
fun getAll(): LiveData<List<HemoCubeTestData>>
|
fun getAll(): LiveData<List<HemoCubeTestData>>
|
||||||
|
|
||||||
@Query("SELECT * from hemo_cube_test_table WHERE molbioFlag=false")
|
|
||||||
fun getMolbioPending(): List<HemoCubeTestData>
|
|
||||||
|
|
||||||
@Query("SELECT * from hemo_cube_test_table WHERE localFlag=false")
|
|
||||||
fun getFirebasePending():List<HemoCubeTestData>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(hemoCubeTestData: HemoCubeTestData)
|
suspend fun insertAll(hemoCubeTestData: HemoCubeTestData)
|
||||||
|
|
||||||
@@ -36,8 +29,4 @@ interface HemoCubeDao {
|
|||||||
|
|
||||||
@Query("UPDATE hemo_cube_test_table SET isCSVCreated = :newValue WHERE _id = :id")
|
@Query("UPDATE hemo_cube_test_table SET isCSVCreated = :newValue WHERE _id = :id")
|
||||||
suspend fun updateCSVFieldById(id: String, newValue: Boolean)
|
suspend fun updateCSVFieldById(id: String, newValue: Boolean)
|
||||||
|
|
||||||
@Query("SELECT * from hemo_cube_test_table WHERE localFlag = 0")
|
|
||||||
fun getPendingUser(): LiveData<List<HemoCubeTestData>>
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import com.example.hpostesting.data.model.patient.UserData
|
|||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [UserData::class, HemoCubeTestData::class, DeviceData::class, BufferCheckData::class],
|
entities = [UserData::class, HemoCubeTestData::class, DeviceData::class, BufferCheckData::class],
|
||||||
version = 29,
|
version = 26,
|
||||||
exportSchema = false
|
exportSchema = false
|
||||||
)
|
)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
|
|||||||
@@ -89,9 +89,8 @@ class LocalFileDataSourceImpl @Inject constructor() : LocalFileDataSource {
|
|||||||
)
|
)
|
||||||
csvWriter.writeNext(header)
|
csvWriter.writeNext(header)
|
||||||
|
|
||||||
// Filter and write data rows where testStatus is true
|
// Write data rows
|
||||||
val filteredDataList = dataList.filter { it.testStatus == true }
|
for (data in dataList) {
|
||||||
for (data in filteredDataList) {
|
|
||||||
val row = arrayOf(
|
val row = arrayOf(
|
||||||
data._id,
|
data._id,
|
||||||
data.name,
|
data.name,
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.example.hpostesting.data.encryption
|
||||||
|
|
||||||
|
import android.security.keystore.KeyGenParameterSpec
|
||||||
|
import android.security.keystore.KeyProperties
|
||||||
|
import android.util.Base64
|
||||||
|
import javax.crypto.Cipher
|
||||||
|
import javax.crypto.KeyGenerator
|
||||||
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
|
|
||||||
|
object AESCrypt {
|
||||||
|
private const val ALGORITHM = "AES"
|
||||||
|
private const val KEY = "your_secret_key"
|
||||||
|
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun encrypt(value: String): String {
|
||||||
|
val keySpec = SecretKeySpec(KEY.toByteArray(), ALGORITHM)
|
||||||
|
val cipher = Cipher.getInstance(ALGORITHM)
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, keySpec)
|
||||||
|
val encryptedBytes = cipher.doFinal(value.toByteArray())
|
||||||
|
return Base64.encodeToString(encryptedBytes, Base64.DEFAULT)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun decrypt(encrypted: String?): String {
|
||||||
|
val keySpec = SecretKeySpec(KEY.toByteArray(), ALGORITHM)
|
||||||
|
val cipher = Cipher.getInstance(ALGORITHM)
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, keySpec)
|
||||||
|
val encryptedBytes = Base64.decode(encrypted, Base64.DEFAULT)
|
||||||
|
val decryptedBytes = cipher.doFinal(encryptedBytes)
|
||||||
|
return String(decryptedBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
//generates a secret key for the encryption functions to use
|
||||||
|
//TODO: Generating keys requires a higher API level. ask someone if this is okay.
|
||||||
|
}
|
||||||
@@ -26,14 +26,4 @@ data class DeviceData(
|
|||||||
var natsToken: String = "",
|
var natsToken: String = "",
|
||||||
@get:PropertyName("natsTokenExpiry") @set:PropertyName("natsTokenExpiry")
|
@get:PropertyName("natsTokenExpiry") @set:PropertyName("natsTokenExpiry")
|
||||||
var natsTokenExpiry: String = "",
|
var natsTokenExpiry: String = "",
|
||||||
@get:PropertyName("deviceUpdateAvailable") @set:PropertyName("deviceUpdateAvailable")
|
|
||||||
var deviceUpdateAvailable: Boolean = false,
|
|
||||||
@get:PropertyName("updatePath") @set:PropertyName("updatePath")
|
|
||||||
var updatePath: String = "",
|
|
||||||
@get:PropertyName("deviceVersion") @set:PropertyName("deviceVersion")
|
|
||||||
var deviceVersion: String = "",
|
|
||||||
@get:PropertyName("globalUpdateDone") @set:PropertyName("globalUpdateDone")
|
|
||||||
var globalUpdateDone: Boolean = false,
|
|
||||||
@get:PropertyName("globalUpdateIgnore") @set:PropertyName("globalUpdateIgnore")
|
|
||||||
var globalUpdateIgnore: Boolean = false,
|
|
||||||
)
|
)
|
||||||
@@ -5,8 +5,7 @@ import androidx.room.PrimaryKey
|
|||||||
|
|
||||||
@Entity(tableName = "hemo_cube_test_table")
|
@Entity(tableName = "hemo_cube_test_table")
|
||||||
data class HemoCubeTestData(
|
data class HemoCubeTestData(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey
|
||||||
var sampleid: Int = 0,
|
|
||||||
var _id: String = "",
|
var _id: String = "",
|
||||||
var name: String = "",
|
var name: String = "",
|
||||||
var incubationTime: String = "",
|
var incubationTime: String = "",
|
||||||
@@ -79,7 +78,6 @@ data class HemoCubeTestData(
|
|||||||
var prdClassification: String = "",
|
var prdClassification: String = "",
|
||||||
var deviceRatioClass: String = "",
|
var deviceRatioClass: String = "",
|
||||||
var slopeRatioClass: String = "",
|
var slopeRatioClass: String = "",
|
||||||
var borderlineMethod2Class: String = "",
|
|
||||||
var errorMessages: String = "",
|
var errorMessages: String = "",
|
||||||
var batteryLevel: String = "",
|
var batteryLevel: String = "",
|
||||||
var batteryCapacity: String = "",
|
var batteryCapacity: String = "",
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.example.hpostesting.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.components.ViewModelComponent
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(ViewModelComponent::class)
|
||||||
|
object ViewModelModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun provideTestRightViewModel(
|
||||||
|
saveRawData: SaveRawData,
|
||||||
|
saveRawDataTest: SaveRawDataTest,
|
||||||
|
databaseRepository: DatabaseRepository,
|
||||||
|
userDao: UserDao,
|
||||||
|
context: Context
|
||||||
|
): TestRightViewModel {
|
||||||
|
return TestRightViewModel(saveRawData, saveRawDataTest, databaseRepository, userDao, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.example.hpostesting.data.repository
|
package com.example.hpostesting.data.repository
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.data.Result
|
||||||
import com.example.hpostesting.data.api.MolbioAuthApi
|
import com.example.hpostesting.data.api.MolbioAuthApi
|
||||||
import com.example.hpostesting.data.api.MolbioResultApi
|
import com.example.hpostesting.data.api.MolbioResultApi
|
||||||
import com.example.hpostesting.data.model.PendingUploads
|
import com.example.hpostesting.data.model.PendingUploads
|
||||||
@@ -109,7 +109,20 @@ class DatabaseRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addTestToDatabase(data: UserData?): Response<String> {
|
override suspend fun addTestToDatabase(data: UserData?): Response<String> {
|
||||||
TODO("Not yet implemented")
|
return try {
|
||||||
|
val userdata =
|
||||||
|
db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
||||||
|
if (userdata.documents.isNotEmpty()) {
|
||||||
|
userdata.documents.forEach {
|
||||||
|
db.collection("patientData").document(it.id).update("testStatus", true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
db.collection("testData").add(data).await()
|
||||||
|
Response.Success(data._id)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Firebase.crashlytics.recordException(e)
|
||||||
|
Response.Error(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addTestToDatabaseforBufferCheck(data: BufferCheckData?): Response<String> {
|
override suspend fun addTestToDatabaseforBufferCheck(data: BufferCheckData?): Response<String> {
|
||||||
@@ -234,22 +247,4 @@ class DatabaseRepository @Inject constructor(
|
|||||||
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
override fun <UserData> addTestToDatabase(testDetails: UserData): Any {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addTestToDatabasefornew(data: HemoCubeTestData?): Response<String> {
|
|
||||||
return try {
|
|
||||||
val userdata =
|
|
||||||
db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
|
||||||
if (userdata.documents.isNotEmpty()) {
|
|
||||||
userdata.documents.forEach {
|
|
||||||
db.collection("patientData").document(it.id).update("testStatus", true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.collection("testData").add(data).await()
|
|
||||||
Response.Success(data._id)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Firebase.crashlytics.recordException(e)
|
|
||||||
Response.Error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.example.hpostesting.data.repository
|
package com.example.hpostesting.data.repository
|
||||||
|
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.data.Result
|
||||||
import com.example.hpostesting.data.model.Response
|
import com.example.hpostesting.data.model.Response
|
||||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
||||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsResponse
|
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsResponse
|
||||||
@@ -25,7 +25,6 @@ import okhttp3.ResponseBody
|
|||||||
|
|
||||||
interface Repository {
|
interface Repository {
|
||||||
suspend fun addTestToDatabase(data: HemoCubeTestData?): Response<String>
|
suspend fun addTestToDatabase(data: HemoCubeTestData?): Response<String>
|
||||||
suspend fun addTestToDatabasefornew(data: HemoCubeTestData?): Response<String>
|
|
||||||
|
|
||||||
suspend fun addTestToDatabase(data: UserData?): Response<String>
|
suspend fun addTestToDatabase(data: UserData?): Response<String>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.di
|
package com.example.hpostesting.domain.di
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -7,7 +7,7 @@ import android.content.res.AssetManager
|
|||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.example.hpostesting.data.api.MolbioAuthApi
|
import com.example.hpostesting.data.api.MolbioAuthApi
|
||||||
import com.example.hpostesting.data.api.MolbioResultApi
|
import com.example.hpostesting.data.api.MolbioResultApi
|
||||||
import com.example.hpostesting.util.PropertyProvider
|
import com.example.hpostesting.data.api.PropertyProvider
|
||||||
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
import com.example.hpostesting.data.dao.MyDatabase
|
import com.example.hpostesting.data.dao.MyDatabase
|
||||||
@@ -22,8 +22,6 @@ import com.example.hpostesting.domain.LogFileManager
|
|||||||
import com.example.hpostesting.domain.LogFileManagerImpl
|
import com.example.hpostesting.domain.LogFileManagerImpl
|
||||||
import com.example.hpostesting.domain.SaveRawData
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
import com.example.hpostesting.domain.SaveRawDataTest
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListenerImpl
|
|
||||||
import com.example.hpostesting.util.PropertyProviderImpl
|
import com.example.hpostesting.util.PropertyProviderImpl
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
@@ -147,7 +145,7 @@ object AppModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideRetrofit(
|
fun provideRetrofit(
|
||||||
propertyProvider: PropertyProvider, @Named("Auth") client: OkHttpClient
|
propertyProvider: PropertyProvider,@Named("Auth") client: OkHttpClient
|
||||||
): Retrofit {
|
): Retrofit {
|
||||||
return Retrofit.Builder().baseUrl(propertyProvider.getProperty("BASE_URL")).client(client)
|
return Retrofit.Builder().baseUrl(propertyProvider.getProperty("BASE_URL")).client(client)
|
||||||
.addConverterFactory(GsonConverterFactory.create()).build()
|
.addConverterFactory(GsonConverterFactory.create()).build()
|
||||||
@@ -181,10 +179,4 @@ object AppModule {
|
|||||||
fun provideLocalFileDataSource(): LocalFileDataSource {
|
fun provideLocalFileDataSource(): LocalFileDataSource {
|
||||||
return LocalFileDataSourceImpl()
|
return LocalFileDataSourceImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideUsbServiceListener(context: Context): UsbServiceListener {
|
|
||||||
return UsbServiceListenerImpl(context)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.example.hpostesting.encryption
|
|
||||||
|
|
||||||
import android.util.Base64
|
|
||||||
import javax.crypto.Cipher
|
|
||||||
import javax.crypto.SecretKeyFactory
|
|
||||||
import javax.crypto.spec.IvParameterSpec
|
|
||||||
import javax.crypto.spec.PBEKeySpec
|
|
||||||
import javax.crypto.spec.SecretKeySpec
|
|
||||||
|
|
||||||
object Encryption {
|
|
||||||
private const val AES_MODE = "AES/CBC/PKCS5Padding"
|
|
||||||
private const val KEY_SPEC_ALGORITHM = "PBKDF2WithHmacSHA1"
|
|
||||||
private const val SALT = "Bigtec"
|
|
||||||
private const val ITERATION_COUNT = 10000
|
|
||||||
private const val KEY_LENGTH = 256
|
|
||||||
private val FIXED_IV = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
|
|
||||||
|
|
||||||
fun encrypt(textToEncrypt: String, password: String): String {
|
|
||||||
val salt = SALT.toByteArray()
|
|
||||||
val factory = SecretKeyFactory.getInstance(KEY_SPEC_ALGORITHM)
|
|
||||||
val spec = PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH)
|
|
||||||
val tmp = factory.generateSecret(spec)
|
|
||||||
val key = SecretKeySpec(tmp.encoded, "AES")
|
|
||||||
val cipher = Cipher.getInstance(AES_MODE)
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, key, IvParameterSpec(FIXED_IV))
|
|
||||||
val encryptedBytes = cipher.doFinal(textToEncrypt.toByteArray(Charsets.UTF_8))
|
|
||||||
return Base64.encodeToString(encryptedBytes, Base64.NO_WRAP)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun decrypt(encryptedText: String, password: String): String {
|
|
||||||
val salt = SALT.toByteArray()
|
|
||||||
val encryptedBytes = Base64.decode(encryptedText, Base64.NO_WRAP)
|
|
||||||
val factory = SecretKeyFactory.getInstance(KEY_SPEC_ALGORITHM)
|
|
||||||
val spec = PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH)
|
|
||||||
val tmp = factory.generateSecret(spec)
|
|
||||||
val key = SecretKeySpec(tmp.encoded, "AES")
|
|
||||||
val cipher = Cipher.getInstance(AES_MODE)
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, key, IvParameterSpec(FIXED_IV))
|
|
||||||
val decryptedBytes = cipher.doFinal(encryptedBytes)
|
|
||||||
return String(decryptedBytes, Charsets.UTF_8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ import android.view.View
|
|||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.example.hpostesting.presentation
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
|
class MainViewModel : ViewModel() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.presentation.utils
|
package com.example.hpostesting.presentation
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -125,8 +125,13 @@ class NatsManager(datacollector: DashboardActivity) {
|
|||||||
|
|
||||||
if (nc?.status == Connection.Status.CONNECTED) {
|
if (nc?.status == Connection.Status.CONNECTED) {
|
||||||
Log.d("NATSCONNECTION", "NATS is successfully connected.")
|
Log.d("NATSCONNECTION", "NATS is successfully connected.")
|
||||||
|
|
||||||
|
val d = nc?.createDispatcher { msg: Message? ->
|
||||||
|
println("Nats dispatcher $msg")
|
||||||
|
}
|
||||||
|
|
||||||
nc?.subscribe("device.hpos.${deviceId}.ping")
|
nc?.subscribe("device.hpos.${deviceId}.ping")
|
||||||
// Log.d(TAG, "Nats subscribed with ping-"+d)
|
|
||||||
nc?.publish(
|
nc?.publish(
|
||||||
"server.hpos.${deviceId}.ping",
|
"server.hpos.${deviceId}.ping",
|
||||||
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
||||||
@@ -135,10 +140,7 @@ class NatsManager(datacollector: DashboardActivity) {
|
|||||||
"server.hpos.${deviceId}.health",
|
"server.hpos.${deviceId}.health",
|
||||||
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
"ALIVE".toByteArray(StandardCharsets.UTF_8)
|
||||||
)
|
)
|
||||||
val d = nc?.createDispatcher { msg: Message? ->
|
|
||||||
println("Nats dispatcher $msg")
|
|
||||||
Log.d(TAG, "Nats dispatcher--$msg")
|
|
||||||
}
|
|
||||||
d?.subscribe("device.hpos.${deviceId}.ping") { 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)
|
||||||
@@ -170,11 +172,10 @@ class NatsManager(datacollector: DashboardActivity) {
|
|||||||
println("Message received (up to 100 times): $response")
|
println("Message received (up to 100 times): $response")
|
||||||
}
|
}
|
||||||
|
|
||||||
d?.subscribe("device.hpos.${deviceId}.checkUpdate") { msg ->
|
d?.subscribe("device.hpos.${deviceId}.checkupdate") { 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) on topic checkupdate: $response")
|
println("Message received (up to 100 times): $response")
|
||||||
Log.d(TAG, "subscribed msg ${msg} on topic checkupdate")
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d("NATSCONNECTION", "NATS is not connected. Current status: ${nc?.status}")
|
Log.d("NATSCONNECTION", "NATS is not connected. Current status: ${nc?.status}")
|
||||||
@@ -13,7 +13,7 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.example.hpostesting.util.MyUtils
|
import com.example.hpostesting.util.MyUtils
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.hpostesting.presentation.utils
|
package com.example.hpostesting.presentation
|
||||||
|
|
||||||
interface UsbServiceListener {
|
interface UsbServiceListener {
|
||||||
fun onUsbRead(data: ByteArray?)
|
fun onUsbRead(data: ByteArray?)
|
||||||
@@ -11,7 +11,7 @@ import androidx.navigation.findNavController
|
|||||||
import androidx.recyclerview.widget.AsyncListDiffer
|
import androidx.recyclerview.widget.AsyncListDiffer
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.model.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
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import androidx.fragment.app.FragmentActivity
|
|||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.firebase.ui.firestore.FirestoreRecyclerAdapter
|
import com.firebase.ui.firestore.FirestoreRecyclerAdapter
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ import android.widget.AdapterView
|
|||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.Spinner
|
import android.widget.Spinner
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
@@ -161,8 +162,8 @@ class AssuranceControlsFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
DataHolder.hemoCubeTestData!!._id = currentUnixTime.toString() + "SMI"
|
DataHolder.hemoCubeTestData!!._id = currentUnixTime.toString() + "SMI"
|
||||||
DataHolder.hemoCubeTestData!!.solution = binding.spinnerSolutions.selectedItem.toString()
|
DataHolder.hemoCubeTestData!!.solution = binding.spinnerSolutions.selectedItem.toString()
|
||||||
DataHolder.hemoCubeTestData!!.concentration = binding.spinnerConcentration.selectedItem.toString()
|
DataHolder.hemoCubeTestData!!.name = binding.spinnerConcentration.selectedItem.toString()
|
||||||
DataHolder.hemoCubeTestData!!.name = "${DataHolder.hemoCubeTestData!!.solution} ${DataHolder.hemoCubeTestData!!.concentration} ${DataHolder.hemoCubeTestData!!.volume}"
|
"${DataHolder.hemoCubeTestData!!.solution} ${DataHolder.hemoCubeTestData!!.concentration} ${DataHolder.hemoCubeTestData!!.volume}"
|
||||||
|
|
||||||
DataHolder.selectedTest = UserData()
|
DataHolder.selectedTest = UserData()
|
||||||
DataHolder.selectedTest?._id = DataHolder.hemoCubeTestData!!._id
|
DataHolder.selectedTest?._id = DataHolder.hemoCubeTestData!!._id
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import com.example.hpostesting.data.constant.Constants
|
|||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentAutoDacBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentAutoDacBinding
|
||||||
@@ -163,10 +163,10 @@ class AutoDacFragment : Fragment() {
|
|||||||
val slData = stringData.split(" ")
|
val slData = stringData.split(" ")
|
||||||
if (slData.size > 1) {
|
if (slData.size > 1) {
|
||||||
val hardwareId = slData[1].trim()
|
val hardwareId = slData[1].trim()
|
||||||
// with(sharedPreferences.edit()) {
|
with(sharedPreferences.edit()) {
|
||||||
// putString(Constants.DEVICE_ID, hardwareId)
|
putString(Constants.DEVICE_ID, hardwareId)
|
||||||
// apply()
|
apply()
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.btnSubmit.visibility = View.VISIBLE
|
binding.btnSubmit.visibility = View.VISIBLE
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.example.hpostesting.presentation.blank
|
||||||
|
|
||||||
|
class BlankActivity {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.example.hpostesting.presentation.blank
|
||||||
|
|
||||||
|
class BlankFragment {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.example.hpostesting.presentation.blank
|
||||||
|
|
||||||
|
class BlankViewModel {
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ 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.patient.BufferCheckData
|
import com.example.hpostesting.data.model.patient.BufferCheckData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ 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.calibration.CalibrationData
|
import com.example.hpostesting.data.model.calibration.CalibrationData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.presentation.utils.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
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.dashboard
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.os.BatteryManager
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.fragment.app.activityViewModels
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|
||||||
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
|
||||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
|
||||||
import `in`.sminnovations.hpostesting.R
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentActivitiesBinding
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
|
||||||
|
|
||||||
class ActivitiesFragment : Fragment() {
|
|
||||||
private lateinit var binding: FragmentActivitiesBinding
|
|
||||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
|
||||||
private lateinit var adapter: OfflineUserListAdapter
|
|
||||||
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
|
||||||
): View {
|
|
||||||
binding = FragmentActivitiesBinding.inflate(inflater, container, false)
|
|
||||||
|
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
hemoCubeViewModel.allPendingUserToUpload.observe(viewLifecycleOwner) { userData ->
|
|
||||||
|
|
||||||
if (userData.isNotEmpty()) {
|
|
||||||
binding.rvOrderOffline.visibility = View.VISIBLE
|
|
||||||
binding.noDataText.visibility = View.GONE
|
|
||||||
val bm =
|
|
||||||
requireContext().getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
|
||||||
val batLevel: Int = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
|
||||||
adapter = OfflineUserListAdapter(binding.root, batLevel)
|
|
||||||
adapter.differ.submitList(userData)
|
|
||||||
binding.rvOrderOffline.adapter = adapter
|
|
||||||
}else{
|
|
||||||
binding.rvOrderOffline.visibility = View.GONE
|
|
||||||
binding.noDataText.visibility = View.VISIBLE
|
|
||||||
Log.d("Activities","Nothing to show")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.example.hpostesting.presentation.dashboard
|
package com.example.hpostesting.presentation.dashboard
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.app.DownloadManager
|
||||||
|
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.content.SharedPreferences
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -20,11 +20,10 @@ import androidx.navigation.ui.AppBarConfiguration
|
|||||||
import androidx.navigation.ui.navigateUp
|
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.util.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.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
import com.example.hpostesting.presentation.NatsManager
|
||||||
import com.example.hpostesting.presentation.utils.NatsManager
|
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.example.hpostesting.presentation.jig.JigActivity
|
import com.example.hpostesting.presentation.jig.JigActivity
|
||||||
import com.google.android.material.navigation.NavigationView
|
import com.google.android.material.navigation.NavigationView
|
||||||
@@ -32,9 +31,9 @@ import com.google.firebase.appdistribution.FirebaseAppDistribution
|
|||||||
import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
||||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import `in`.sminnovations.hpostesting.BuildConfig
|
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
||||||
|
import okhttp3.ResponseBody
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
interface NatsMessageCallback {
|
interface NatsMessageCallback {
|
||||||
@@ -50,7 +49,6 @@ open interface IDataCollector: NatsMessageCallback {
|
|||||||
class DashboardActivity : AppCompatActivity(), IDataCollector {
|
class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||||
|
|
||||||
val TAG = "DashboardActivity"
|
val TAG = "DashboardActivity"
|
||||||
private var isRegistered = false
|
|
||||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||||
private lateinit var binding: ActivityDashboardBinding
|
private lateinit var binding: ActivityDashboardBinding
|
||||||
lateinit var sharedPreferences: SharedPreferences
|
lateinit var sharedPreferences: SharedPreferences
|
||||||
@@ -59,7 +57,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
private var downloadId: Long = 0
|
private var downloadId: Long = 0
|
||||||
// TODO: Remove hemocube viewmodel
|
// TODO: Remove hemocube viewmodel
|
||||||
private val hemocubeViewModel: HemoCubeViewModel by viewModels()
|
private val hemocubeViewModel: HemoCubeViewModel by viewModels()
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
|
||||||
override fun attachBaseContext(newBase: Context?) {
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
||||||
LanguageManager.setLocale(newBase, languageCode)
|
LanguageManager.setLocale(newBase, languageCode)
|
||||||
@@ -68,14 +66,13 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
|
|
||||||
override fun onMessageReceived(topic: String, message: String) {
|
override fun onMessageReceived(topic: String, message: String) {
|
||||||
// Handle incoming messages from NATS
|
// Handle incoming messages from NATS
|
||||||
|
|
||||||
Log.d(TAG, "Received message on topic $topic: $message")
|
Log.d(TAG, "Received message on topic $topic: $message")
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetWorldReadable")
|
|
||||||
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)
|
sharedPreferences = this.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
@@ -84,9 +81,6 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
nats.connect()
|
nats.connect()
|
||||||
}
|
}
|
||||||
val versionName = getAppVersion(this@DashboardActivity) + " [ " + getAppEnvironment(this@DashboardActivity) + " ]"
|
|
||||||
binding.appBarDashboard.versionName.text = versionName
|
|
||||||
|
|
||||||
|
|
||||||
val deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "")
|
val deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "")
|
||||||
|
|
||||||
@@ -97,22 +91,15 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
when (result) {
|
when (result) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
// Handle success
|
// Handle success
|
||||||
val apk = result.data
|
val apkUrl = result.data
|
||||||
val file = File(getExternalFilesDir("Updates"), "update.apk")
|
// val apkUrl = "https://dl.dropboxusercontent.com/s/fi/1c3nn7t0co431hicl3hrt/app-debug.apk?rlkey=e4uf13ty1dpcked614vy1aaqp&dl=0"
|
||||||
file.setReadable(true, false) // Ensure the file is readable
|
initiateUpdate(apkUrl.toString())
|
||||||
apk.byteStream().use { input ->
|
Log.d("ApI", "APK URL: $apkUrl")
|
||||||
file.outputStream().use { output ->
|
// Toast.makeText(
|
||||||
input.copyTo(output)
|
// this,
|
||||||
}
|
// "APK UPLOAD ${result.data}",
|
||||||
}
|
// Toast.LENGTH_SHORT
|
||||||
Log.d("Responsebodyformat", "Responsebodyformat: ")
|
// ).show()
|
||||||
installApk(file)
|
|
||||||
Log.e("ApI", "APK URL: $apk")
|
|
||||||
Toast.makeText(
|
|
||||||
this,
|
|
||||||
"${result.data}",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
@@ -130,14 +117,13 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val drawerLayout: DrawerLayout = binding.drawerLayout
|
val drawerLayout: DrawerLayout = binding.drawerLayout
|
||||||
val navView: NavigationView = binding.navView
|
val navView: NavigationView = binding.navView
|
||||||
val navController = findNavController(R.id.nav_host_fragment_content_dashboard)
|
val navController = findNavController(R.id.nav_host_fragment_content_dashboard)
|
||||||
|
|
||||||
appBarConfiguration = AppBarConfiguration(
|
appBarConfiguration = AppBarConfiguration(
|
||||||
setOf(
|
setOf(
|
||||||
R.id.nav_home, R.id.nav_profile, R.id.nav_activity,R.id.nav_settings
|
R.id.nav_home, R.id.nav_profile, R.id.nav_settings
|
||||||
), drawerLayout
|
), drawerLayout
|
||||||
)
|
)
|
||||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
@@ -149,8 +135,6 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
menuInflater.inflate(R.menu.dashboard, menu)
|
menuInflater.inflate(R.menu.dashboard, menu)
|
||||||
@@ -162,15 +146,52 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initiateUpdate(responseBody: String) {
|
||||||
|
val apkUrl = responseBody
|
||||||
|
if (!isValidHttpUrl(apkUrl)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val request = DownloadManager.Request(Uri.parse(apkUrl))
|
||||||
|
request.setTitle("App Update")
|
||||||
|
request.setDescription("Downloading update...")
|
||||||
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||||
|
request.setDestinationInExternalFilesDir(this, "Updates", "update.apk")
|
||||||
|
|
||||||
|
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||||
|
downloadId = downloadManager.enqueue(request)
|
||||||
|
|
||||||
|
// Register a BroadcastReceiver to receive the download complete event
|
||||||
|
// val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
||||||
|
// registerReceiver(downloadReceiver, filter)
|
||||||
|
}
|
||||||
|
private fun extractApkUrl(responseBody: ResponseBody): String {
|
||||||
|
return responseBody.string()
|
||||||
|
}
|
||||||
|
private fun isValidHttpUrl(url: String): Boolean {
|
||||||
|
return url.startsWith("http://") || url.startsWith("https://")
|
||||||
|
}
|
||||||
|
private val downloadReceiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
|
||||||
|
if (id == downloadId) {
|
||||||
|
installApk()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun installApk() {
|
||||||
|
val file = File(getExternalFilesDir("Updates"), "update.apk")
|
||||||
|
file.setReadable(true, false) // Ensure the file is readable
|
||||||
|
|
||||||
private fun installApk(file: File) {
|
|
||||||
val pInfo = baseContext.packageManager.getPackageInfo(baseContext.packageName, 0)
|
val pInfo = baseContext.packageManager.getPackageInfo(baseContext.packageName, 0)
|
||||||
val uri: Uri = FileProvider.getUriForFile(
|
val uri: Uri = FileProvider.getUriForFile(
|
||||||
this,
|
this,
|
||||||
"${BuildConfig.APPLICATION_ID}.fileprovider",
|
"${pInfo}.fileprovider",
|
||||||
file
|
file
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create an intent to install the APK
|
||||||
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
||||||
installIntent.data = uri
|
installIntent.data = uri
|
||||||
installIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
installIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||||
@@ -186,14 +207,8 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
if(isRegistered) {
|
|
||||||
try {
|
|
||||||
// unregisterReceiver(downloadReceiver)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.d("HomeFragment", e.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
// unregisterReceiver(downloadReceiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@@ -243,32 +258,8 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun setResponse(response: String) {
|
override fun setResponse(response: String) {
|
||||||
|
|
||||||
responses = responses+response+"\n"
|
responses = responses+response+"\n"
|
||||||
println(responses)
|
println(responses)
|
||||||
// if (response.contains("checkUpdate")) {
|
|
||||||
// hemocubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
|
|
||||||
return DeviceUpdateRequest(
|
|
||||||
serial_no = sharedPreference.getString(Constants.DEVICE_ID, "")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
private fun getAppVersion(context: Context): String {
|
|
||||||
return try {
|
|
||||||
val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
|
||||||
pInfo.versionName
|
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
|
||||||
"N/A"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private fun getAppEnvironment(context: Context): String {
|
|
||||||
return try {
|
|
||||||
val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
|
||||||
pInfo.packageName.substringAfterLast('.')
|
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
|
||||||
"N/A"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -21,12 +21,12 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.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.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.utils.DeviceCommunicationHandler
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.utils.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
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.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.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.utils.DeviceCommunicationHandler
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.utils.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
|
||||||
@@ -93,7 +93,6 @@ class DeviceProvisionActivity : AppCompatActivity(), DeviceCommunicationHandler
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
setupListener()
|
setupListener()
|
||||||
connectUsb(false)
|
connectUsb(false)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupListener() {
|
private fun setupListener() {
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ 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.os.Environment
|
|
||||||
import android.provider.Settings
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -14,20 +12,18 @@ 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 androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.util.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.encryption.AESCrypt
|
||||||
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.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.encryption.Encryption
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.google.android.gms.ads.identifier.AdvertisingIdClient
|
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
||||||
import java.io.File
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
|
|
||||||
class DeviceProvisionFragment : Fragment() {
|
class DeviceProvisionFragment : Fragment() {
|
||||||
private var resultData: String = ""
|
private var resultData: String = ""
|
||||||
@@ -122,20 +118,16 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
password = response.data.data?.credentials?.password.toString(),
|
password = response.data.data?.credentials?.password.toString(),
|
||||||
deviceProvisionResponse = response.data.data.toString(),
|
deviceProvisionResponse = response.data.data.toString(),
|
||||||
natsToken = response.data.data?.device?.deviceUser?.natsToken.toString(),
|
natsToken = response.data.data?.device?.deviceUser?.natsToken.toString(),
|
||||||
natsTokenExpiry = response.data.data?.device?.deviceUser?.natsTokenExpiry.toString(),
|
natsTokenExpiry = response.data.data?.device?.deviceUser?.natsTokenExpiry.toString()
|
||||||
globalUpdateIgnore = false,
|
|
||||||
globalUpdateDone = false,
|
|
||||||
deviceUpdateAvailable = false
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
encryptAndSaveToFile(
|
|
||||||
response.data.data?.credentials?.username.toString(),
|
|
||||||
response.data.data?.credentials?.password.toString()
|
|
||||||
)
|
|
||||||
// viewModel.addDeviceId(DeviceData(deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()))
|
// viewModel.addDeviceId(DeviceData(deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()))
|
||||||
Log.e("idpass", response.toString())
|
Log.e("idpass", response.toString())
|
||||||
Log.e("idpass", response.data.data?.credentials?.username.toString())
|
Log.e("idpass", response.data.data?.credentials?.username.toString())
|
||||||
Log.e("idpass", deviceProvisionResponse)
|
Log.e("idpass", deviceProvisionResponse)
|
||||||
|
|
||||||
|
saveDataToLocalFile(response.data.data?.credentials?.username.toString(), response.data.data?.credentials?.password.toString())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity,
|
activity,
|
||||||
@@ -232,24 +224,17 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun encryptAndSaveToFile(username: String, password: String) {
|
|
||||||
val messageToEncrypt = "$username\n$password"
|
|
||||||
val encryptionKey =
|
|
||||||
Settings.Secure.getString(context?.contentResolver, Settings.Secure.ANDROID_ID)
|
|
||||||
val encryptedString = Encryption.encrypt(messageToEncrypt, encryptionKey)
|
|
||||||
Log.d("DEVICE ID/encryptionKey", encryptionKey)
|
|
||||||
val target = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
|
||||||
val file = File(target, "credentials.txt")
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
//saves username and password to a local file after encrypting it.
|
||||||
file.createNewFile()
|
private fun saveDataToLocalFile( username : String, password : String){
|
||||||
}
|
val deviceID = sharedPreferences.getString(Constants.DEVICE_ID, "").toString();
|
||||||
|
val encryptedUsername = AESCrypt.encrypt(username)
|
||||||
|
val encryptedPassword = AESCrypt.encrypt(password)
|
||||||
file.writeText(encryptedString)
|
val encryptedData = deviceID + "\n" + encryptedUsername + "\n" + encryptedPassword
|
||||||
|
|
||||||
Log.d("Encrypted Message", encryptedString)
|
|
||||||
|
|
||||||
|
val fileOutputStream = requireContext().openFileOutput("credentials.txt", Context.MODE_PRIVATE)
|
||||||
|
fileOutputStream.write(encryptedData.toByteArray())
|
||||||
|
fileOutputStream.close()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package com.example.hpostesting.presentation.deviceprovision
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.data.Result
|
||||||
import com.example.hpostesting.data.model.Response
|
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
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ 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 androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.data.Result
|
||||||
import com.example.hpostesting.util.Result.Success
|
import com.example.hpostesting.data.Result.Success
|
||||||
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.devicediagnostics.AdditionalDetails
|
import com.example.hpostesting.data.model.devicediagnostics.AdditionalDetails
|
||||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDiagnosticsBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentDiagnosticsBinding
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.example.hpostesting.presentation.diagnostics
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.data.Result
|
||||||
import com.example.hpostesting.data.model.Response
|
import com.example.hpostesting.data.model.Response
|
||||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsRequest
|
||||||
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsResponse
|
import com.example.hpostesting.data.model.devicediagnostics.DeviceDiagnosticsResponse
|
||||||
@@ -25,7 +25,7 @@ class DiagnosticsViewModel @Inject constructor(
|
|||||||
|
|
||||||
val deviceData = MutableLiveData<DeviceData?>()
|
val deviceData = MutableLiveData<DeviceData?>()
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
val deviceDiagnosticsResponse = MutableLiveData<Result<DeviceDiagnosticsResponse>>()
|
val deviceDiagnosticsResponse = MutableLiveData<com.example.hpostesting.data.Result<DeviceDiagnosticsResponse>>()
|
||||||
// private val batteryStatus: Intent? =
|
// private val batteryStatus: Intent? =
|
||||||
// IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { ifilter ->
|
// IntentFilter(Intent.ACTION_BATTERY_CHANGED).let { ifilter ->
|
||||||
// context.registerReceiver(null, ifilter)
|
// context.registerReceiver(null, ifilter)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDigitalCardBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentDigitalCardBinding
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube
|
package com.example.hpostesting.presentation.hemocube
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
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
|
||||||
@@ -14,15 +12,15 @@ import androidx.core.content.ContextCompat
|
|||||||
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 androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.util.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.constant.TestStatus
|
import com.example.hpostesting.data.constant.TestStatus
|
||||||
import com.example.hpostesting.data.model.TestState
|
import com.example.hpostesting.data.model.TestState
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||||
import com.example.hpostesting.presentation.utils.UIUtils
|
import com.example.hpostesting.presentation.utils.UIUtils
|
||||||
@@ -92,11 +90,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
observeViewModel()
|
observeViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
binding.btnSubmit.isEnabled = false
|
|
||||||
binding.btnSubmit.isClickable = false
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
binding.btnSubmit.visibility = View.GONE
|
binding.btnSubmit.visibility = View.GONE
|
||||||
@@ -111,6 +106,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
binding.nameEditText.visibility = View.GONE
|
binding.nameEditText.visibility = View.GONE
|
||||||
binding.tvTitle.visibility = View.GONE
|
binding.tvTitle.visibility = View.GONE
|
||||||
binding.btnGo.visibility = View.GONE
|
binding.btnGo.visibility = View.GONE
|
||||||
|
// binding.btnSubmit.isEnabled = false
|
||||||
|
// binding.btnSubmit.isClickable = false
|
||||||
binding.btnPlacebuffer.visibility = View.GONE
|
binding.btnPlacebuffer.visibility = View.GONE
|
||||||
|
|
||||||
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
||||||
@@ -150,7 +147,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
if (result == "Success") {
|
if (result == "Success") {
|
||||||
uploadedToCloud = true
|
uploadedToCloud = true
|
||||||
var accessToken = sharedPreferences.getString(Constants.ACCESS_TOKEN, "").toString()
|
|
||||||
showToast(R.string.test_upload)
|
showToast(R.string.test_upload)
|
||||||
if (Constants.MOLBIO_INTEGRATION) {
|
if (Constants.MOLBIO_INTEGRATION) {
|
||||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||||
@@ -163,8 +159,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
handleReadingFinish()
|
handleReadingFinish()
|
||||||
hemoCubeViewModel.uploadLogs()
|
|
||||||
hemoCubeViewModel.downloadClientCertificate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
@@ -173,11 +167,10 @@ class HemoCubeFragment : Fragment() {
|
|||||||
it.exception.let { message ->
|
it.exception.let { message ->
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity,
|
activity,
|
||||||
"$message",
|
"An error occurred: $message",
|
||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
)
|
)
|
||||||
.show()
|
.show()
|
||||||
Log.d("resultuploadfail1", message.toString())
|
|
||||||
}
|
}
|
||||||
handleReadingFinish()
|
handleReadingFinish()
|
||||||
}
|
}
|
||||||
@@ -592,7 +585,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
led1Gain4 = resultLines[5].split(' ')[1].trim().toDoubleOrNull()!!
|
led1Gain4 = resultLines[5].split(' ')[1].trim().toDoubleOrNull()!!
|
||||||
led2Gain4 = resultLines[6].split(' ')[1].trim().toDoubleOrNull()!!
|
led2Gain4 = resultLines[6].split(' ')[1].trim().toDoubleOrNull()!!
|
||||||
led3Gain4 = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!!
|
led3Gain4 = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!!
|
||||||
led4Gain4 = resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
|
led4Gain4 =
|
||||||
|
resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
|
||||||
}
|
}
|
||||||
|
|
||||||
finishReading()
|
finishReading()
|
||||||
@@ -770,7 +764,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
val led3Average = log10(led3BufferForDevice.div(led3SampleForDevice))
|
val led3Average = log10(led3BufferForDevice.div(led3SampleForDevice))
|
||||||
val led4Average = log10(led4BufferForDevice.div(led4SampleForDevice))
|
val led4Average = log10(led4BufferForDevice.div(led4SampleForDevice))
|
||||||
val deviceRatio = led2Average / led1Average
|
val deviceRatio = led2Average / led1Average
|
||||||
val borderlineMetric = (led1Average - led2Average) / deviceRatio
|
|
||||||
|
|
||||||
if (led1BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)
|
if (led1BufferForDevice < Constants.BUFFER_INTENSITY_THRESHOLDS[deviceHardwareId]?.get(0)
|
||||||
?.get(0)!!
|
?.get(0)!!
|
||||||
@@ -868,7 +861,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val absorbanceLowerLimit = 0.0
|
var absorbanceLowerLimit = 0.0
|
||||||
if (led1Average < absorbanceLowerLimit || led2Average < absorbanceLowerLimit || led3Average < absorbanceLowerLimit || led4Average < absorbanceLowerLimit) {
|
if (led1Average < absorbanceLowerLimit || led2Average < absorbanceLowerLimit || led3Average < absorbanceLowerLimit || led4Average < absorbanceLowerLimit) {
|
||||||
validationError = true
|
validationError = true
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
@@ -915,13 +908,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||||
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
|
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
|
||||||
this.deviceRatioClass = deviceRatioClassification(deviceRatio)
|
this.deviceRatioClass = deviceRatioClassification(deviceRatio)
|
||||||
this.borderlineMethod2Class = reclassifyWithBorderlineMethod2(deviceRatio, deviceRatioBorderlineThresholds(deviceRatio), led2Average)
|
|
||||||
this.slopeRatioClass = slopeClass
|
this.slopeRatioClass = slopeClass
|
||||||
this.classificationResult = findResultWithAdditionalMethods(
|
this.classificationResult = deviceRatioClass
|
||||||
deviceRatio,
|
|
||||||
deviceRatioClass,
|
|
||||||
borderlineMetric
|
|
||||||
)
|
|
||||||
hemoCubeViewModel.messages.postValue(
|
hemoCubeViewModel.messages.postValue(
|
||||||
"${this.classificationResult} \n Device Ratio: ${
|
"${this.classificationResult} \n Device Ratio: ${
|
||||||
"%.3f".format(
|
"%.3f".format(
|
||||||
@@ -962,48 +950,17 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reclassifyWithBorderlineMethod2(deviceRatio: Double?, deviceRatioClass: String?, led2Average: Double?): String {
|
|
||||||
try {
|
|
||||||
if (deviceRatio != null && led2Average != null) {
|
|
||||||
if (deviceRatioClass == "Negative Borderline") {
|
|
||||||
return if (led2Average >= 0.15)
|
|
||||||
"Borderline. Normal"
|
|
||||||
else
|
|
||||||
"Borderline. Sickle Cell Trait"
|
|
||||||
}
|
|
||||||
if (deviceRatioClass == "Positive for Sickle Cell. HPLC for Confirmation") {
|
|
||||||
return if (led2Average >= 0.19)
|
|
||||||
"Borderline. Sickle Cell Trait"
|
|
||||||
else
|
|
||||||
"Borderline. Sickle Cell Disease"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
handleException(e)
|
|
||||||
return "Error"
|
|
||||||
}
|
|
||||||
return deviceRatioClass.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun findResultWithAdditionalMethods(
|
fun findResultWithAdditionalMethods(
|
||||||
deviceRatio: Double?,
|
deviceRatio: Double?,
|
||||||
deviceRatioClass: String?,
|
deviceRatioClass: String?,
|
||||||
borderlineMetric: Double?,
|
slopeRatio: Double?,
|
||||||
): String {
|
): String {
|
||||||
try {
|
try {
|
||||||
// hemoCubeViewModel.messages.postValue("post classification checks")
|
// hemoCubeViewModel.messages.postValue("post classification checks")
|
||||||
if (deviceRatio != null && borderlineMetric != null) {
|
if (deviceRatio != null) {
|
||||||
if (deviceRatioClass == "Negative Borderline") {
|
if (slopeRatio != null) {
|
||||||
return if (borderlineMetric >= 2.4)
|
if (deviceRatioClass == "Normal" && slopeRatio > 45.0)
|
||||||
"Borderline. Normal"
|
return "Negative Borderline, Repeat Test"
|
||||||
else
|
|
||||||
"Borderline. Sickle Cell Trait"
|
|
||||||
}
|
|
||||||
if (deviceRatioClass == "Positive for Sickle Cell. HPLC for Confirmation") {
|
|
||||||
return if (borderlineMetric >= 1.34)
|
|
||||||
"Borderline. Sickle Cell Trait"
|
|
||||||
else
|
|
||||||
"Borderline. Sickle Cell Disease"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -1013,46 +970,20 @@ class HemoCubeFragment : Fragment() {
|
|||||||
return deviceRatioClass.toString()
|
return deviceRatioClass.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deviceRatioBorderlineThresholds(ratio: Double?): String {
|
|
||||||
try {
|
|
||||||
if (ratio != null) {
|
|
||||||
val roundedRatio = String.format("%.3f", ratio).toDouble()
|
|
||||||
if (roundedRatio >= 0.11 && roundedRatio < 0.237) {
|
|
||||||
// setSubtitleTextColor(R.color.green_2)
|
|
||||||
return "Normal"
|
|
||||||
}
|
|
||||||
if (roundedRatio in 0.237..0.242)
|
|
||||||
return "Negative Borderline"
|
|
||||||
if (roundedRatio in 0.242..0.318)
|
|
||||||
return "Sickle Cell Trait"
|
|
||||||
if (roundedRatio >= 0.318 && roundedRatio < 0.356)
|
|
||||||
return "Positive for Sickle Cell. HPLC for Confirmation"
|
|
||||||
if (roundedRatio in 0.356..0.7)
|
|
||||||
return "Sickle Cell Disease"
|
|
||||||
} else {
|
|
||||||
return "Invalid"
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
handleException(e)
|
|
||||||
return "Error"
|
|
||||||
}
|
|
||||||
return "Invalid"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deviceRatioClassification(ratio: Double?): String {
|
fun deviceRatioClassification(ratio: Double?): String {
|
||||||
try {
|
try {
|
||||||
if (ratio != null) {
|
if (ratio != null) {
|
||||||
if (ratio in 0.16..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.25)
|
if (ratio in 0.22..0.24)
|
||||||
return "Negative Borderline"
|
return "Negative Borderline"
|
||||||
if (ratio in 0.25..0.31)
|
if (ratio in 0.24..0.32)
|
||||||
return "Sickle Cell Trait"
|
return "Sickle Cell Trait"
|
||||||
if (ratio in 0.31..0.36)
|
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.36..0.7)
|
if (ratio in 0.37..0.56)
|
||||||
return "Sickle Cell Disease"
|
return "Sickle Cell Disease"
|
||||||
} else {
|
} else {
|
||||||
return "Invalid"
|
return "Invalid"
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
import androidx.work.PeriodicWorkRequestBuilder
|
import androidx.work.PeriodicWorkRequestBuilder
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import com.example.hpostesting.util.CsvWriter
|
import com.example.hpostesting.data.CsvWriter
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.util.NetworkStatusLiveData
|
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||||
import com.example.hpostesting.util.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.dao.HemoCubeBufferDao
|
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
@@ -38,7 +38,6 @@ import com.example.hpostesting.data.repository.Repository
|
|||||||
import com.example.hpostesting.domain.CheckUpdateWorker
|
import com.example.hpostesting.domain.CheckUpdateWorker
|
||||||
import com.example.hpostesting.domain.LogFileManager
|
import com.example.hpostesting.domain.LogFileManager
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
@@ -89,8 +88,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
|
|
||||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||||
val allUserData = hemoCubeDao.getAll()
|
val allUserData = hemoCubeDao.getAll()
|
||||||
val allLocalData = hemoCubeDao.getAll()
|
|
||||||
val allPendingUserToUpload = hemoCubeDao.getPendingUser()
|
|
||||||
val allKitTestData = hemoCubeBufferDao.getAll()
|
val allKitTestData = hemoCubeBufferDao.getAll()
|
||||||
val deviceData = MutableLiveData<DeviceData?>()
|
val deviceData = MutableLiveData<DeviceData?>()
|
||||||
|
|
||||||
@@ -140,102 +137,12 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun uploadResult(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
fun uploadResult(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
||||||
resultUpload.postValue(Result.Loading())
|
resultUpload.postValue(Result.Loading())
|
||||||
|
Log.d("API CALL", "UPLOADED RESULT")
|
||||||
repository.uploadResults(molbioV2ResultRequest).let {
|
repository.uploadResults(molbioV2ResultRequest).let {
|
||||||
resultUpload.postValue(it)
|
resultUpload.postValue(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun uploadResultfornew(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
|
||||||
resultUpload.postValue(Result.Loading())
|
|
||||||
repository.uploadResults(molbioV2ResultRequest).let {
|
|
||||||
resultUpload.postValue(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun sendDataToMolbio() = viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
|
|
||||||
Log.d("molbio","getting in sendMolbio")
|
|
||||||
val resultList = MolbioV2ResultRequest(mutableListOf())
|
|
||||||
val pendingData = hemoCubeDao.getMolbioPending()
|
|
||||||
Log.d("molbio","pending size"+pendingData.size)
|
|
||||||
pendingData.forEach{
|
|
||||||
userData ->
|
|
||||||
val currentTimeFormatted = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
|
||||||
Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
val bufferIntensityThreshold =
|
|
||||||
Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId]?.toString()
|
|
||||||
?: "defaultThreshold" // Handle possible nulls safely
|
|
||||||
resultList.results?.add(
|
|
||||||
MolbioV2Result(
|
|
||||||
rawData = userData,
|
|
||||||
analysisId = userData._id,
|
|
||||||
analysisDate = currentTimeFormatted,
|
|
||||||
analysisStatus = userData.classificationResult
|
|
||||||
?: "defaultStatus", // Handle possible nulls
|
|
||||||
thresholds = bufferIntensityThreshold,
|
|
||||||
interpretation = userData.classificationResult
|
|
||||||
?: "defaultInterpretation", // Handle possible nulls
|
|
||||||
testId = userData._id,
|
|
||||||
testTime = currentTimeFormatted,
|
|
||||||
collectionTime = currentTimeFormatted,
|
|
||||||
expiryTime = currentTimeFormatted
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
resultList.results?.forEach { result ->
|
|
||||||
result.rawData?.let { sanitizeDoubleValues(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resultList.results?.isNotEmpty() == true) {
|
|
||||||
uploadMoblioBulkResults(resultList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun uploadMoblioBulkResults(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
|
||||||
Log.d("molbio","upload called")
|
|
||||||
repository.uploadResults(molbioV2ResultRequest).let {
|
|
||||||
when (it) {
|
|
||||||
is Result.Success -> {
|
|
||||||
it.data.data?.forEach { id ->
|
|
||||||
id.rawData?.let { it1 ->
|
|
||||||
updateMolbioFlag(
|
|
||||||
it1._id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is Result.Error -> {
|
|
||||||
Log.d("result","result upload error")
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
Log.d("result","result upload else")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun sendDataToFirebase() = viewModelScope.launch ( Dispatchers.IO ) {
|
|
||||||
val pendingData = hemoCubeDao.getFirebasePending()
|
|
||||||
pendingData.forEach{
|
|
||||||
userData ->
|
|
||||||
if (userData != null) {
|
|
||||||
if (!userData.localFlag) {
|
|
||||||
bulkAddResultTestToDb(userData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun checkUpdate(checkUpdateRequest: CheckUpdateRequest) = viewModelScope.launch {
|
fun checkUpdate(checkUpdateRequest: CheckUpdateRequest) = viewModelScope.launch {
|
||||||
checkUpdate.postValue(Result.Loading())
|
checkUpdate.postValue(Result.Loading())
|
||||||
repository.checkUpdate(checkUpdateRequest).let {
|
repository.checkUpdate(checkUpdateRequest).let {
|
||||||
@@ -280,9 +187,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fun getPendingUser() = viewModelScope.launch {
|
|
||||||
// allPendingUserToUpload.postValue(hemoCubeDao.getPendingUser(true))
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun uploadHemoCubeResultToDatabaseForBufferCheck(
|
fun uploadHemoCubeResultToDatabaseForBufferCheck(
|
||||||
isOnline: Boolean,
|
isOnline: Boolean,
|
||||||
@@ -387,7 +291,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
testDetails?.prdClassification = DataHolder.hemoCubeTestData?.prdClassification.toString()
|
testDetails?.prdClassification = DataHolder.hemoCubeTestData?.prdClassification.toString()
|
||||||
testDetails?.deviceRatioClass = DataHolder.hemoCubeTestData?.deviceRatioClass.toString()
|
testDetails?.deviceRatioClass = DataHolder.hemoCubeTestData?.deviceRatioClass.toString()
|
||||||
testDetails?.slopeRatioClass = DataHolder.hemoCubeTestData?.slopeRatioClass.toString()
|
testDetails?.slopeRatioClass = DataHolder.hemoCubeTestData?.slopeRatioClass.toString()
|
||||||
testDetails?.borderlineMethod2Class = DataHolder.hemoCubeTestData?.borderlineMethod2Class.toString()
|
|
||||||
testDetails?.errorMessages = DataHolder.hemoCubeTestData?.errorMessages.toString()
|
testDetails?.errorMessages = DataHolder.hemoCubeTestData?.errorMessages.toString()
|
||||||
testDetails?.batteryLevel = DataHolder.hemoCubeTestData?.batteryLevel.toString()
|
testDetails?.batteryLevel = DataHolder.hemoCubeTestData?.batteryLevel.toString()
|
||||||
testDetails?.batteryCapacity = DataHolder.hemoCubeTestData?.batteryCapacity.toString()
|
testDetails?.batteryCapacity = DataHolder.hemoCubeTestData?.batteryCapacity.toString()
|
||||||
@@ -418,24 +321,20 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
testDetails.localFlag = true
|
testDetails.localFlag = true
|
||||||
if (Constants.MOLBIO_INTEGRATION) {
|
if (Constants.MOLBIO_INTEGRATION) {
|
||||||
// Sanitize testDetails before using it in the API call
|
|
||||||
val sanitizedTestDetails = sanitizeDoubleValues(testDetails)
|
|
||||||
|
|
||||||
// Now, use sanitizedTestDetails for the API call
|
|
||||||
uploadResult(
|
uploadResult(
|
||||||
MolbioV2ResultRequest(
|
MolbioV2ResultRequest(
|
||||||
mutableListOf(
|
mutableListOf(
|
||||||
MolbioV2Result(
|
MolbioV2Result(
|
||||||
rawData = sanitizedTestDetails,
|
rawData = testDetails,
|
||||||
analysisId = sanitizedTestDetails._id,
|
analysisId = testDetails._id,
|
||||||
analysisDate = sanitizedTestDetails.testTime,
|
analysisDate = testDetails.testTime,
|
||||||
analysisStatus = sanitizedTestDetails.classificationResult,
|
analysisStatus = testDetails.classificationResult,
|
||||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[sanitizedTestDetails.deviceId]?.toString(),
|
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[testDetails.deviceId].toString(),
|
||||||
interpretation = sanitizedTestDetails.classificationResult,
|
interpretation = testDetails.classificationResult,
|
||||||
testId = sanitizedTestDetails._id,
|
testId = testDetails._id,
|
||||||
testTime = sanitizedTestDetails.testTime,
|
testTime = testDetails.testTime,
|
||||||
collectionTime = sanitizedTestDetails.testTime,
|
collectionTime = testDetails.testTime,
|
||||||
expiryTime = sanitizedTestDetails.testTime,
|
expiryTime = testDetails.testTime,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -477,19 +376,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
|
|
||||||
hemoCubeTestData::class.java.declaredFields.forEach { field ->
|
|
||||||
if (field.type == Double::class.javaObjectType || field.type == Double::class.javaPrimitiveType) {
|
|
||||||
field.isAccessible = true
|
|
||||||
val value = field.get(hemoCubeTestData) as Double?
|
|
||||||
if (value != null && (value.isInfinite() || value.isNaN())) {
|
|
||||||
field.set(hemoCubeTestData, 0.0) // Replace with a suitable default value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hemoCubeTestData
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateLocalFlag(userId: String) = viewModelScope.launch {
|
private fun updateLocalFlag(userId: String) = viewModelScope.launch {
|
||||||
hemoCubeDao.updateFieldById(id = userId, true)
|
hemoCubeDao.updateFieldById(id = userId, true)
|
||||||
}
|
}
|
||||||
@@ -522,8 +408,6 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
||||||
fireBaseUpload.postValue("Error")
|
fireBaseUpload.postValue("Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||||
|
|||||||
@@ -11,18 +11,16 @@ import android.content.ServiceConnection
|
|||||||
import android.hardware.usb.UsbDevice
|
import android.hardware.usb.UsbDevice
|
||||||
import android.hardware.usb.UsbDeviceConnection
|
import android.hardware.usb.UsbDeviceConnection
|
||||||
import android.hardware.usb.UsbManager
|
import android.hardware.usb.UsbManager
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
@@ -45,7 +43,6 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
private val TAG = "HemoCube"
|
private val TAG = "HemoCube"
|
||||||
|
|
||||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
@@ -85,7 +82,6 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
super.attachBaseContext(newBase)
|
super.attachBaseContext(newBase)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityHemocubeBinding.inflate(layoutInflater)
|
binding = ActivityHemocubeBinding.inflate(layoutInflater)
|
||||||
@@ -110,7 +106,6 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
|
||||||
open fun connectUsb(permissionGranted: Boolean) {
|
open fun connectUsb(permissionGranted: Boolean) {
|
||||||
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
||||||
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
||||||
@@ -130,7 +125,6 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
|
||||||
@SuppressLint("MutableImplicitPendingIntent")
|
@SuppressLint("MutableImplicitPendingIntent")
|
||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||||
val mPendingIntent: PendingIntent
|
val mPendingIntent: PendingIntent
|
||||||
@@ -148,21 +142,15 @@ open class HemocubeActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
val filter = IntentFilter(Constants.HEMOCUBE_USB_PERMISSION)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
registerReceiver(broadcastReceiver, filter)
|
||||||
registerReceiver(broadcastReceiver, filter, RECEIVER_EXPORTED)
|
|
||||||
}else{
|
|
||||||
registerReceiver(broadcastReceiver, filter)
|
|
||||||
}
|
|
||||||
manager.requestPermission(device, mPendingIntent)
|
manager.requestPermission(device, mPendingIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun setupService() {
|
fun setupService() {
|
||||||
val intent = Intent(this, UsbService::class.java)
|
val intent = Intent(this, UsbService::class.java)
|
||||||
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
|
||||||
open fun reconnectDevice() {
|
open fun reconnectDevice() {
|
||||||
mService.disconnect()
|
mService.disconnect()
|
||||||
unbindService(connection)
|
unbindService(connection)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
import com.example.hpostesting.presentation.testRight.UsbService
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
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
|
||||||
@@ -132,7 +132,7 @@ class TestRightActivity : AppCompatActivity() {
|
|||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
Intent(Constants.ACTION_USB_PERMISSION),
|
Intent(Constants.ACTION_USB_PERMISSION),
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
mPendingIntent = PendingIntent.getBroadcast(
|
mPendingIntent = PendingIntent.getBroadcast(
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ 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 com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.TestRightCommands
|
import com.example.hpostesting.data.constant.TestRightCommands
|
||||||
import com.example.hpostesting.data.model.ErrorMessage
|
import com.example.hpostesting.data.model.ErrorMessage
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||||
import com.example.hpostesting.presentation.utils.UIUtils
|
import com.example.hpostesting.presentation.utils.UIUtils
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.TestRightCommands
|
import com.example.hpostesting.data.constant.TestRightCommands
|
||||||
import com.example.hpostesting.data.model.ErrorMessage
|
import com.example.hpostesting.data.model.ErrorMessage
|
||||||
import com.example.hpostesting.data.model.test.TestType
|
import com.example.hpostesting.data.model.test.TestType
|
||||||
import com.example.hpostesting.presentation.MainActivity
|
import com.example.hpostesting.presentation.MainActivity
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||||
import com.example.hpostesting.presentation.utils.UIUtils
|
import com.example.hpostesting.presentation.utils.UIUtils
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ 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 com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||||
import com.example.hpostesting.data.model.test.TestType
|
import com.example.hpostesting.data.model.test.TestType
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import android.net.Uri
|
|||||||
import androidx.lifecycle.MutableLiveData
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.util.NetworkStatusLiveData
|
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.dao.UserDao
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
import com.example.hpostesting.data.model.CalculationVariableForTest
|
import com.example.hpostesting.data.model.CalculationVariableForTest
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import android.util.Log
|
|||||||
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.constant.TestRightCommands
|
import com.example.hpostesting.data.constant.TestRightCommands
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialPort
|
import com.hoho.android.usbserial.driver.UsbSerialPort
|
||||||
import com.hoho.android.usbserial.util.SerialInputOutputManager
|
import com.hoho.android.usbserial.util.SerialInputOutputManager
|
||||||
@@ -33,53 +33,32 @@ class UsbService : Service() {
|
|||||||
var bus: UsbServiceListener? = null
|
var bus: UsbServiceListener? = null
|
||||||
|
|
||||||
fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) {
|
fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) {
|
||||||
try {
|
mPort = driver.ports[0] // Most devices have just one port (port 0)
|
||||||
mPort = driver.ports[0]
|
mPort.open(connection)
|
||||||
mPort.open(connection)
|
mPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
||||||
|
isUsbConnected = true
|
||||||
|
Log.d(TAG, "My Usb Connected ${mPort.driver}")
|
||||||
|
|
||||||
if (mPort.device.vendorId == 6790 && mPort.device.productId == 29987)
|
val usbIoManager = SerialInputOutputManager(mPort,
|
||||||
mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
object : SerialInputOutputManager.Listener {
|
||||||
else
|
override fun onNewData(data: ByteArray?) {
|
||||||
mPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
|
listener?.onUsbRead(data)
|
||||||
|
}
|
||||||
|
|
||||||
isUsbConnected = true
|
override fun onRunError(e: Exception?) {
|
||||||
Log.d(TAG, "Usb Connected ${mPort.driver}")
|
Log.e(TAG, "onRunError() called inside eventDrivenWrite()")
|
||||||
|
listener?.onUsbError(e)
|
||||||
|
}
|
||||||
|
|
||||||
val usbIoManager = SerialInputOutputManager(mPort,
|
})
|
||||||
object : SerialInputOutputManager.Listener {
|
usbIoManager.start();
|
||||||
override fun onNewData(data: ByteArray?) {
|
|
||||||
listener?.onUsbRead(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onRunError(e: Exception?) {
|
|
||||||
Log.e(TAG, "onRunError() called")
|
|
||||||
listener?.onUsbError(e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
usbIoManager.start()
|
|
||||||
} catch (ioException: IOException) {
|
|
||||||
Log.e(TAG, "IOException during USB connection: ${ioException.message}", ioException)
|
|
||||||
listener?.onUsbError(ioException)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Error connecting USB: ${e.message}", e)
|
|
||||||
listener?.onUsbError(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun disconnect() {
|
fun disconnect() {
|
||||||
try {
|
if (isUsbConnected) {
|
||||||
if (isUsbConnected) {
|
mPort.close()
|
||||||
mPort.close()
|
isUsbConnected = false;
|
||||||
isUsbConnected = false
|
Log.d(TAG, "My Usb disconnected:: ${mPort.driver}")
|
||||||
Log.d(TAG, "USB Port closed successfully:: ${mPort.driver}")
|
|
||||||
} else {
|
|
||||||
Log.d(TAG, "USB Port is not connected")
|
|
||||||
}
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Log.e(TAG, "Error closing USB Port: ${e.message}", e)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "An unexpected error occurred: ${e.message}", e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
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.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.LanguageManager
|
import com.example.hpostesting.data.constant.LanguageManager
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -14,15 +13,15 @@ import androidx.core.content.ContextCompat
|
|||||||
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 androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.util.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.constant.TestStatus
|
import com.example.hpostesting.data.constant.TestStatus
|
||||||
import com.example.hpostesting.data.model.TestState
|
import com.example.hpostesting.data.model.TestState
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||||
@@ -1156,8 +1155,6 @@ class TrueHemeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun reconnect() {
|
private fun reconnect() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
(activity as HemocubeActivity).reconnectDevice()
|
||||||
(activity as HemocubeActivity).reconnectDevice()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,10 +12,10 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
import androidx.work.PeriodicWorkRequestBuilder
|
import androidx.work.PeriodicWorkRequestBuilder
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import com.example.hpostesting.util.CsvWriter
|
import com.example.hpostesting.data.CsvWriter
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.util.NetworkStatusLiveData
|
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||||
import com.example.hpostesting.util.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.dao.HemoCubeBufferDao
|
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.utils
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.Log
|
|
||||||
import android.widget.Toast
|
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
|
||||||
|
|
||||||
class UsbServiceListenerImpl(private val context: Context): UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
|
||||||
if (data != null) {
|
|
||||||
val receivedData = String(data)
|
|
||||||
logData(receivedData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
showToast("USB Error: ${e?.message}")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showToast(message: String) {
|
|
||||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun logData(data: String) {
|
|
||||||
Log.d("UsbServiceListener", "Received data from USB: $data")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11
app/src/main/java/com/example/hpostesting/test.kt
Normal file
11
app/src/main/java/com/example/hpostesting/test.kt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
fun main(){
|
||||||
|
val dateFormat = SimpleDateFormat("MM:HHddMMyyyy", Locale.getDefault())
|
||||||
|
val currentDate = Date()
|
||||||
|
print(dateFormat.format(currentDate))
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.example.hpostesting.util
|
|
||||||
|
|
||||||
interface PropertyProvider {
|
|
||||||
|
|
||||||
fun getProperty(key: String): String
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.hpostesting.util
|
package com.example.hpostesting.util
|
||||||
|
|
||||||
import android.content.res.AssetManager
|
import android.content.res.AssetManager
|
||||||
|
import com.example.hpostesting.data.api.PropertyProvider
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
|
||||||
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM14,17L7,17v-2h7v2zM17,13L7,13v-2h10v2zM17,9L7,9L7,7h10v2z"/>
|
|
||||||
|
|
||||||
</vector>
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
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=".presentation.dashboard.DashboardActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -16,17 +16,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:background="?attr/colorPrimary"
|
android:background="?attr/colorPrimary"
|
||||||
app:popupTheme="@style/Theme.HPOS.PopupOverlay" >
|
app:popupTheme="@style/Theme.HPOS.PopupOverlay" />
|
||||||
<TextView
|
|
||||||
android:id="@+id/version_name"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="--"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:layout_gravity="end"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:layout_marginEnd="15dp"/>
|
|
||||||
</androidx.appcompat.widget.Toolbar>
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RelativeLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/titleText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="Upload Pending List(Local data)"
|
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:textSize="21sp"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
/>
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/rv_order_offline"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/titleText"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
|
||||||
tools:listitem="@layout/offline_user_list_view" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/noDataText"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:text="All up-to-date"
|
|
||||||
android:textSize="22sp"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
@@ -217,7 +217,6 @@
|
|||||||
android:text="no device message"
|
android:text="no device message"
|
||||||
android:textColor="@color/black"
|
android:textColor="@color/black"
|
||||||
android:textSize="11sp"
|
android:textSize="11sp"
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/error_message" />
|
app:layout_constraintTop_toBottomOf="@id/error_message" />
|
||||||
|
|
||||||
|
|||||||
@@ -38,20 +38,10 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:padding="24dp">
|
android:padding="24dp">
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/btnLogout1"
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="30dp"
|
|
||||||
android:layout_marginEnd="10dp"
|
|
||||||
android:src="@drawable/baseline_logout_24"
|
|
||||||
app:layout_constraintTop_toTopOf="@+id/internetNotAvailableCL"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_title_no_internet"
|
android:id="@+id/tv_title_no_internet"
|
||||||
style="@style/title1"
|
style="@style/title1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_marginTop="24dp"
|
android:layout_marginTop="24dp"
|
||||||
@@ -135,27 +125,6 @@
|
|||||||
<!-- app:layout_constraintBottom_toBottomOf="@+id/rv_order_offline"-->
|
<!-- app:layout_constraintBottom_toBottomOf="@+id/rv_order_offline"-->
|
||||||
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
<!-- app:layout_constraintStart_toStartOf="parent" />-->
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/label1"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/new_kit"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/btnNewKitoffline"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
||||||
android:id="@+id/btnNewKitoffline"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="8dp"
|
|
||||||
android:backgroundTint="@color/primary"
|
|
||||||
android:contentDescription="@string/new_kit"
|
|
||||||
android:src="@drawable/ic_add"
|
|
||||||
app:elevation="1dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
|||||||
@@ -12,13 +12,9 @@
|
|||||||
android:id="@+id/nav_profile"
|
android:id="@+id/nav_profile"
|
||||||
android:icon="@drawable/control_panel"
|
android:icon="@drawable/control_panel"
|
||||||
android:title="@string/profile" />
|
android:title="@string/profile" />
|
||||||
<item
|
|
||||||
android:id="@+id/nav_activity"
|
|
||||||
android:icon="@drawable/shows_activity_24"
|
|
||||||
android:title="@string/action_activity" />
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_settings"
|
android:id="@+id/nav_settings"
|
||||||
android:icon="@drawable/baseline_settings_24"
|
android:icon="@drawable/baseline_settings_24"
|
||||||
android:title="@string/menu_settings" />
|
android:title="@string/menu_settings" />
|
||||||
</group>
|
</group>
|
||||||
</menu>
|
</menu>
|
||||||
@@ -32,11 +32,6 @@
|
|||||||
android:name="com.example.hpostesting.presentation.dashboard.SlideshowFragment"
|
android:name="com.example.hpostesting.presentation.dashboard.SlideshowFragment"
|
||||||
android:label="@string/action_settings"
|
android:label="@string/action_settings"
|
||||||
tools:layout="@layout/fragment_slideshow" />
|
tools:layout="@layout/fragment_slideshow" />
|
||||||
<fragment
|
|
||||||
android:id="@+id/nav_activity"
|
|
||||||
android:name="com.example.hpostesting.presentation.dashboard.ActivitiesFragment"
|
|
||||||
android:label="@string/action_activity"
|
|
||||||
tools:layout="@layout/fragment_activities" />
|
|
||||||
<activity
|
<activity
|
||||||
android:id="@+id/mainActivity"
|
android:id="@+id/mainActivity"
|
||||||
android:name="com.example.hpostesting.presentation.MainActivity"
|
android:name="com.example.hpostesting.presentation.MainActivity"
|
||||||
|
|||||||
@@ -271,5 +271,4 @@
|
|||||||
<string name="deviceinfo">डिवाइस जानकारी</string>
|
<string name="deviceinfo">डिवाइस जानकारी</string>
|
||||||
|
|
||||||
<string name="downloadcsv">सीएसवी डाउनलोड करें</string>
|
<string name="downloadcsv">सीएसवी डाउनलोड करें</string>
|
||||||
<string name="action_activity">Activities</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -270,7 +270,6 @@
|
|||||||
<string name="add_blood_group">ರಕ್ತ ಗುಂಡನ್ನು ಸೇರಿಸಿ</string>
|
<string name="add_blood_group">ರಕ್ತ ಗುಂಡನ್ನು ಸೇರಿಸಿ</string>
|
||||||
<string name="ok">ಸರಿ</string>
|
<string name="ok">ಸರಿ</string>
|
||||||
<string name="downloadcsv">CSV ಡೌನ್ಲೋಡ್ ಮಾಡಿ</string>
|
<string name="downloadcsv">CSV ಡೌನ್ಲೋಡ್ ಮಾಡಿ</string>
|
||||||
<string name="action_activity">Activities</string>
|
|
||||||
<!-- Add translations for other strings -->
|
<!-- Add translations for other strings -->
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -273,5 +273,4 @@
|
|||||||
<string name="select_language">Select your preferred language</string>
|
<string name="select_language">Select your preferred language</string>
|
||||||
<string name="app_language">App Language</string>
|
<string name="app_language">App Language</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="action_activity">Activities</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -3,15 +3,18 @@ package com.example.hpostesting
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
import com.example.hpostesting.util.NetworkStatusLiveData
|
import androidx.lifecycle.Observer
|
||||||
|
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
import com.example.hpostesting.data.model.Response
|
import com.example.hpostesting.data.model.Response
|
||||||
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||||
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
import com.example.hpostesting.presentation.autodac.AutoDacViewModel
|
import com.example.hpostesting.presentation.autodac.AutoDacViewModel
|
||||||
import io.mockk.*
|
import io.mockk.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||||
import kotlinx.coroutines.test.setMain
|
import kotlinx.coroutines.test.setMain
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.example.hpostesting
|
package com.example.hpostesting
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.example.hpostesting.util.CsvWriter
|
import com.example.hpostesting.data.CsvWriter
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|||||||
@@ -1,5 +1,26 @@
|
|||||||
package com.example.hpostesting
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.fragment.app.testing.FragmentScenario
|
||||||
|
import androidx.fragment.app.testing.launchFragmentInContainer
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
|
import com.example.hpostesting.presentation.deviceinfo.DeviceActivity
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
|
import com.google.firebase.ktx.Firebase
|
||||||
|
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceBinding
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.*
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
|
||||||
class DeviceFragmentTest {
|
class DeviceFragmentTest {
|
||||||
//
|
//
|
||||||
// @Mock
|
// @Mock
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.example.hpostesting
|
|||||||
|
|
||||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.data.Result
|
||||||
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.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.example.hpostesting
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||||
|
import junit.framework.TestCase
|
||||||
import junit.framework.TestCase.assertEquals
|
import junit.framework.TestCase.assertEquals
|
||||||
import junit.framework.TestCase.assertNull
|
import junit.framework.TestCase.assertNull
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@@ -13,9 +17,18 @@ import org.mockito.MockitoAnnotations
|
|||||||
|
|
||||||
class HemoCubeFragmentTest {
|
class HemoCubeFragmentTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var mockContext: Context
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var mockSharedPreferences: SharedPreferences
|
private lateinit var mockSharedPreferences: SharedPreferences
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
||||||
|
|
||||||
private lateinit var hemoCubeFragment: HemoCubeFragment
|
private lateinit var hemoCubeFragment: HemoCubeFragment
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -38,7 +51,7 @@ class HemoCubeFragmentTest {
|
|||||||
val deviceId = hemoCubeFragment.extractV2HardwareId("SNS HPP1-9000 SNE")
|
val deviceId = hemoCubeFragment.extractV2HardwareId("SNS HPP1-9000 SNE")
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertEquals("HPP1-9000", deviceId)
|
TestCase.assertEquals("HPP1-9000", deviceId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -58,7 +71,7 @@ class HemoCubeFragmentTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertEquals("HPP1-0001", deviceId)
|
TestCase.assertEquals("HPP1-0001", deviceId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -71,8 +84,8 @@ class HemoCubeFragmentTest {
|
|||||||
val result = hemoCubeFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
val result = hemoCubeFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertEquals(true, result)
|
TestCase.assertEquals(true, result)
|
||||||
assertEquals(hemoCubeFragment.allReadingsComplete(0, 1), false)
|
TestCase.assertEquals(hemoCubeFragment.allReadingsComplete(0, 1), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -303,13 +316,6 @@ class HemoCubeFragmentTest {
|
|||||||
assertEquals("HPP-000-5001", result)
|
assertEquals("HPP-000-5001", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationNormalWithStartRange() {
|
|
||||||
val ratio = 0.16
|
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
||||||
assertEquals("Normal", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationNormal() {
|
fun testDeviceRatioClassificationNormal() {
|
||||||
val ratio = 0.22
|
val ratio = 0.22
|
||||||
@@ -325,33 +331,19 @@ class HemoCubeFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationSickleCellTraitLowerBound() {
|
fun testDeviceRatioClassificationSickleCellTrait() {
|
||||||
val ratio = 0.251
|
val ratio = 0.25
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
||||||
assertEquals("Sickle Cell Trait", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationSickleCellTraitUpperBound() {
|
|
||||||
val ratio = 0.309
|
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
||||||
assertEquals("Sickle Cell Trait", result)
|
assertEquals("Sickle Cell Trait", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
||||||
val ratio = 0.359
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDeviceRatioClassificationSickleCellDiseaseLowerBound() {
|
|
||||||
val ratio = 0.361
|
|
||||||
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
||||||
assertEquals("Sickle Cell Disease", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDeviceRatioClassificationSickleCellDisease() {
|
fun testDeviceRatioClassificationSickleCellDisease() {
|
||||||
val ratio = 0.45
|
val ratio = 0.45
|
||||||
@@ -367,166 +359,44 @@ class HemoCubeFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineNormal() {
|
fun findResultWithAdditionalMethods_ValidInput_ReturnsNegativeBorderlineRepeatTest() {
|
||||||
val result =
|
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 70.0)).thenReturn("Negative Borderline, Repeat Test")
|
||||||
hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Negative Borderline", 2.5)
|
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 70.0)
|
||||||
assertEquals("Borderline. Normal", result)
|
assertEquals("Negative Borderline, Repeat Test", result)
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellTrait1() {
|
|
||||||
val result =
|
|
||||||
hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Negative Borderline", 2.2)
|
|
||||||
assertEquals("Borderline. Sickle Cell Trait", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellTrait2() {
|
|
||||||
val result = hemoCubeFragment.findResultWithAdditionalMethods(
|
|
||||||
0.5,
|
|
||||||
"Positive for Sickle Cell. HPLC for Confirmation",
|
|
||||||
1.35
|
|
||||||
)
|
|
||||||
assertEquals("Borderline. Sickle Cell Trait", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellDisease() {
|
|
||||||
val result = hemoCubeFragment.findResultWithAdditionalMethods(
|
|
||||||
0.5,
|
|
||||||
"Positive for Sickle Cell. HPLC for Confirmation",
|
|
||||||
1.33
|
|
||||||
)
|
|
||||||
assertEquals("Borderline. Sickle Cell Disease", result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun findResultWithAdditionalMethods_NormalDeviceRatio_ReturnsNormalBelowSlopeRatioThreshold() {
|
fun findResultWithAdditionalMethods_NormalDeviceRatio_ReturnsNormalBelowSlopeRatioThreshold() {
|
||||||
|
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 70.0)).thenReturn("Negative Borderline, Repeat Test")
|
||||||
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 30.0)
|
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Normal", 30.0)
|
||||||
assertEquals("Normal", result)
|
assertEquals("Normal", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun findResultWithAdditionalMethods_NBL_ReturnsNBL() {
|
fun findResultWithAdditionalMethods_NBL_ReturnsNBL() {
|
||||||
val result = hemoCubeFragment.findResultWithAdditionalMethods(
|
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0)).thenReturn("Invalid")
|
||||||
0.5,
|
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Negative Borderline, Repeat Test", 70.0)
|
||||||
"Negative Borderline, Repeat Test",
|
|
||||||
70.0
|
|
||||||
)
|
|
||||||
assertEquals("Negative Borderline, Repeat Test", result)
|
assertEquals("Negative Borderline, Repeat Test", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun findResultWithAdditionalMethods_SCT_ReturnsSCT() {
|
fun findResultWithAdditionalMethods_SCT_ReturnsSCT() {
|
||||||
val result =
|
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0)).thenReturn("Invalid")
|
||||||
hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Sickle Cell Trait", 70.0)
|
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Sickle Cell Trait", 70.0)
|
||||||
assertEquals("Sickle Cell Trait", result)
|
assertEquals("Sickle Cell Trait", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun findResultWithAdditionalMethods_PBL_ReturnsPBL() {
|
fun findResultWithAdditionalMethods_PBL_ReturnsPBL() {
|
||||||
val result = hemoCubeFragment.findResultWithAdditionalMethods(
|
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0)).thenReturn("Invalid")
|
||||||
0.5,
|
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Positive for Sickle Cell. HPLC for Confirmation", 70.0)
|
||||||
"Positive for Sickle Cell. HPLC for Confirmation",
|
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
|
||||||
1.35
|
|
||||||
)
|
|
||||||
assertEquals("Borderline. Sickle Cell Trait", result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun findResultWithAdditionalMethods_SCD_ReturnsSCD() {
|
fun findResultWithAdditionalMethods_SCD_ReturnsSCD() {
|
||||||
val result =
|
// `when`(hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Abnormal", 70.0)).thenReturn("Invalid")
|
||||||
hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Sickle Cell Disease", 70.0)
|
val result = hemoCubeFragment.findResultWithAdditionalMethods(0.5, "Sickle Cell Disease", 70.0)
|
||||||
assertEquals("Sickle Cell Disease", result)
|
assertEquals("Sickle Cell Disease", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testReclassifyWithBorderlineMethod2_NegativeBorderlineToNormal() {
|
|
||||||
// Arrange
|
|
||||||
val deviceRatio = 0.1
|
|
||||||
val deviceRatioClass = "Negative Borderline"
|
|
||||||
val led2Average = 0.2
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = hemoCubeFragment.reclassifyWithBorderlineMethod2(
|
|
||||||
deviceRatio,
|
|
||||||
deviceRatioClass,
|
|
||||||
led2Average
|
|
||||||
)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertEquals("Borderline. Normal", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testReclassifyWithBorderlineMethod2_NegativeBorderlineToSCT() {
|
|
||||||
// Arrange
|
|
||||||
val deviceRatio = 0.1
|
|
||||||
val deviceRatioClass = "Negative Borderline"
|
|
||||||
val led2Average = 0.14
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = hemoCubeFragment.reclassifyWithBorderlineMethod2(
|
|
||||||
deviceRatio,
|
|
||||||
deviceRatioClass,
|
|
||||||
led2Average
|
|
||||||
)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertEquals("Borderline. Sickle Cell Trait", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testReclassifyWithBorderlineMethod2_PositiveSickleCell() {
|
|
||||||
// Arrange
|
|
||||||
val deviceRatio = 0.2
|
|
||||||
val deviceRatioClass = "Positive for Sickle Cell. HPLC for Confirmation"
|
|
||||||
val led2Average = 0.18
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = hemoCubeFragment.reclassifyWithBorderlineMethod2(
|
|
||||||
deviceRatio,
|
|
||||||
deviceRatioClass,
|
|
||||||
led2Average
|
|
||||||
)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertEquals("Borderline. Sickle Cell Disease", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testReclassifyWithBorderlineMethod2_PositiveSickleCellToSCT() {
|
|
||||||
// Arrange
|
|
||||||
val deviceRatio = 0.2
|
|
||||||
val deviceRatioClass = "Positive for Sickle Cell. HPLC for Confirmation"
|
|
||||||
val led2Average = 0.195
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = hemoCubeFragment.reclassifyWithBorderlineMethod2(
|
|
||||||
deviceRatio,
|
|
||||||
deviceRatioClass,
|
|
||||||
led2Average
|
|
||||||
)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertEquals("Borderline. Sickle Cell Trait", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testReclassifyWithBorderlineMethod2_PositiveSickleCellToSCD() {
|
|
||||||
// Arrange
|
|
||||||
val deviceRatio = 0.2
|
|
||||||
val deviceRatioClass = "Positive for Sickle Cell. HPLC for Confirmation"
|
|
||||||
val led2Average = 0.189
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val result = hemoCubeFragment.reclassifyWithBorderlineMethod2(
|
|
||||||
deviceRatio,
|
|
||||||
deviceRatioClass,
|
|
||||||
led2Average
|
|
||||||
)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertEquals("Borderline. Sickle Cell Disease", result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ package com.example.hpostesting
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.data.Result
|
||||||
import com.example.hpostesting.data.model.login.LoginResponse
|
import com.example.hpostesting.data.model.login.LoginResponse
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
import com.example.hpostesting.domain.LogFileManager
|
import com.example.hpostesting.domain.LogFileManager
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
package com.example.hpostesting
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.example.hpostesting.data.DataHolder
|
||||||
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
|
import junit.framework.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
import java.math.RoundingMode
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
class TestRightViewModelTest {
|
class TestRightViewModelTest {
|
||||||
// private val viewModel = TestRightViewModel()
|
// private val viewModel = TestRightViewModel()
|
||||||
// private val data = InputData()
|
// private val data = InputData()
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ buildscript {
|
|||||||
kotlin_version = '1.8.21'
|
kotlin_version = '1.8.21'
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:8.2.2'
|
classpath 'com.android.tools.build:gradle:8.1.1'
|
||||||
classpath 'com.google.gms:google-services:4.4.1'
|
classpath 'com.google.gms:google-services:4.4.0'
|
||||||
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.1.0'
|
classpath 'com.google.firebase:firebase-appdistribution-gradle:4.0.1'
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Mon Mar 04 17:08:24 IST 2024
|
#Mon Jun 12 17:07:47 IST 2023
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
BIN
keystore.jks
BIN
keystore.jks
Binary file not shown.
Reference in New Issue
Block a user