Compare commits
8 Commits
Hb_HemoCub
...
crashanaly
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a25402fc26 | ||
|
|
388af0adf6 | ||
|
|
57a0c2103a | ||
|
|
057abbd87c | ||
|
|
c3775eeea1 | ||
|
|
882fdb7374 | ||
|
|
b6e086c407 | ||
|
|
53c2fd5ad4 |
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -1,3 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="DesignSurface">
|
<component name="DesignSurface">
|
||||||
<option name="filePathToZoomLevelMap">
|
<option name="filePathToZoomLevelMap">
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ android {
|
|||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding true
|
viewBinding true
|
||||||
|
buildConfig = true
|
||||||
}
|
}
|
||||||
lint {
|
lint {
|
||||||
abortOnError false
|
abortOnError false
|
||||||
@@ -51,11 +52,11 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.10.1'
|
implementation 'androidx.core:core-ktx:1.12.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'com.google.android.material:material:1.9.0'
|
implementation 'com.google.android.material:material:1.9.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
|
||||||
|
|
||||||
//firebase
|
//firebase
|
||||||
implementation platform('com.google.firebase:firebase-bom:32.1.0')
|
implementation platform('com.google.firebase:firebase-bom:32.1.0')
|
||||||
@@ -65,7 +66,7 @@ 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:20.6.0'
|
implementation 'com.google.android.gms:play-services-auth:20.7.0'
|
||||||
implementation 'com.google.android.gms:play-services-location:21.0.1'
|
implementation 'com.google.android.gms:play-services-location:21.0.1'
|
||||||
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'
|
||||||
@@ -76,7 +77,7 @@ dependencies {
|
|||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
|
||||||
|
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
|
||||||
implementation 'com.opencsv:opencsv:4.6'
|
implementation 'com.opencsv:opencsv:4.6'
|
||||||
implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
|
implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
|
||||||
|
|
||||||
@@ -92,17 +93,17 @@ dependencies {
|
|||||||
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
||||||
|
|
||||||
//Room
|
//Room
|
||||||
implementation "androidx.room:room-ktx:2.6.0-alpha03"
|
implementation "androidx.room:room-ktx:2.6.0-beta01"
|
||||||
implementation "androidx.room:room-runtime:2.6.0-alpha03"
|
implementation "androidx.room:room-runtime:2.6.0-beta01"
|
||||||
kapt ("androidx.room:room-compiler:2.6.0-alpha03")
|
kapt ("androidx.room:room-compiler:2.6.0-beta01")
|
||||||
|
|
||||||
//image
|
//image
|
||||||
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
implementation 'com.github.bumptech.glide:glide:4.13.2'
|
||||||
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.0"
|
implementation "androidx.navigation:navigation-fragment-ktx:2.7.2"
|
||||||
implementation "androidx.navigation:navigation-ui-ktx:2.7.0"
|
implementation "androidx.navigation:navigation-ui-ktx:2.7.2"
|
||||||
|
|
||||||
//Dagger - Hilt
|
//Dagger - Hilt
|
||||||
implementation "com.google.dagger:hilt-android:2.46"
|
implementation "com.google.dagger:hilt-android:2.46"
|
||||||
|
|||||||
BIN
app/release/hpos-app.apk
Normal file
BIN
app/release/hpos-app.apk
Normal file
Binary file not shown.
@@ -4,15 +4,15 @@
|
|||||||
"type": "APK",
|
"type": "APK",
|
||||||
"kind": "Directory"
|
"kind": "Directory"
|
||||||
},
|
},
|
||||||
"applicationId": "in.sminnovations.hpostesting",
|
"applicationId": "com.example.hpos",
|
||||||
"variantName": "release",
|
"variantName": "release",
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": "SINGLE",
|
"type": "SINGLE",
|
||||||
"filters": [],
|
"filters": [],
|
||||||
"attributes": [],
|
"attributes": [],
|
||||||
"versionCode": 2,
|
"versionCode": 1,
|
||||||
"versionName": "2.0.1",
|
"versionName": "1.0",
|
||||||
"outputFile": "app-release.apk"
|
"outputFile": "app-release.apk"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -13,8 +13,11 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.usb.host" />
|
<uses-feature android:name="android.hardware.usb.host" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.USB_PERMISSION" />
|
<uses-permission android:name="android.permission.USB_PERMISSION" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="com.example.hpostesting.HPOSTestingApplication"
|
android:name="com.example.hpostesting.HPOSTestingApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -27,14 +30,12 @@
|
|||||||
android:theme="@style/Theme.HPOSTesting"
|
android:theme="@style/Theme.HPOSTesting"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpostesting.presentation.hemocube.HemoCubeActivity"
|
android:name="com.example.hpostesting.presentation.BloodCollectingMethodActivity"
|
||||||
android:exported="false"
|
android:exported="true"
|
||||||
android:noHistory="true"
|
android:noHistory="true"
|
||||||
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
android:theme="@style/Theme.HPOS.NoActionBar" />
|
||||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
|
||||||
android:windowSoftInputMode="adjustPan" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpostesting.presentation.hemocube.hb.HBHemoCubeActivity"
|
android:name="com.example.hpostesting.presentation.hemocube.HemocubeActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:noHistory="true"
|
android:noHistory="true"
|
||||||
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
||||||
@@ -98,7 +99,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="fullSensor"
|
||||||
android:stateNotNeeded="true"
|
android:stateNotNeeded="true"
|
||||||
tools:replace="android:screenOrientation" />
|
tools:replace="android:screenOrientation" />
|
||||||
</application>
|
</application>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import android.content.Context
|
|||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.example.hpostesting.data.dao.MyDatabase
|
import com.example.hpostesting.data.dao.MyDatabase
|
||||||
import com.google.android.datatransport.runtime.dagger.Provides
|
import com.google.android.datatransport.runtime.dagger.Provides
|
||||||
|
import com.google.firebase.firestore.FirebaseFirestore
|
||||||
|
import com.google.firebase.firestore.FirebaseFirestoreSettings
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -13,7 +15,14 @@ import javax.inject.Singleton
|
|||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
class HPOSTestingApplication: Application() {
|
class HPOSTestingApplication: Application() {
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
|
val firestoreSettings = FirebaseFirestoreSettings.Builder()
|
||||||
|
.setPersistenceEnabled(true) // Enable offline persistence if needed
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val firestore = FirebaseFirestore.getInstance()
|
||||||
|
firestore.firestoreSettings = firestoreSettings
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.example.hpostesting.data
|
package com.example.hpostesting.data
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.example.hpostesting.data.model.patient.HBHemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.data.model.test.TestRightDeviceConstants
|
import com.example.hpostesting.data.model.test.TestRightDeviceConstants
|
||||||
@@ -24,8 +23,8 @@ object DataHolder {
|
|||||||
val intensityReferenceArray = ArrayList<Double>()
|
val intensityReferenceArray = ArrayList<Double>()
|
||||||
var selectedTest: UserData? = null
|
var selectedTest: UserData? = null
|
||||||
var hemoCubeTestData: HemoCubeTestData? = null
|
var hemoCubeTestData: HemoCubeTestData? = null
|
||||||
var HbHemoCubeTestData: HBHemoCubeTestData? = null
|
|
||||||
var kitSerial: String = ""
|
var kitSerial: String = ""
|
||||||
var location: UserData.Location? = null
|
var location: UserData.Location? = null
|
||||||
var testExp: Boolean = true
|
var testExp: Boolean = true
|
||||||
|
var hemocubeResult: Double? = null
|
||||||
}
|
}
|
||||||
@@ -56,6 +56,7 @@ object Constants {
|
|||||||
const val BUFFER_VALUE_1 = "BufferValue1"
|
const val BUFFER_VALUE_1 = "BufferValue1"
|
||||||
const val BUFFER_VALUE_2 = "BufferValue2"
|
const val BUFFER_VALUE_2 = "BufferValue2"
|
||||||
|
|
||||||
const val HB_BUFFER_VALUE_1 = "HBBufferValue1"
|
const val BLOOD_COLLECTING_METHOD = "bloodCollectingMethod"
|
||||||
const val HB_KIT_NUMBER = "HBKitNumber"
|
const val VENOUS_BLOOD = "venousBlood"
|
||||||
|
const val FINGER_PRICK_BLOOD = "fingerPrickBlood"
|
||||||
}
|
}
|
||||||
@@ -4,5 +4,5 @@ enum class HemoCubeCommands(val command: String) {
|
|||||||
startBuffer("B\r"),
|
startBuffer("B\r"),
|
||||||
getBuffer("Q\r"),
|
getBuffer("Q\r"),
|
||||||
startSample("S\r"),
|
startSample("S\r"),
|
||||||
getSample("R\r"),
|
getSample("P\r"),
|
||||||
}
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.example.hpostesting.data.dao
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.example.hpostesting.data.model.patient.HBHemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
|
||||||
@Dao
|
|
||||||
interface HBHemoCubeDao {
|
|
||||||
@Query("SELECT * from HBHemoCubeTest_table")
|
|
||||||
fun getAll(): LiveData<List<HBHemoCubeTestData>>
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun insertAll(hbHemoCubeTestData: HBHemoCubeTestData)
|
|
||||||
|
|
||||||
@Query("SELECT * FROM HBHemoCubeTest_table WHERE _id = :id")
|
|
||||||
suspend fun getUserByID(id: String): HBHemoCubeTestData
|
|
||||||
|
|
||||||
@Query("DELETE FROM HBHemoCubeTest_table WHERE _id = :id")
|
|
||||||
suspend fun deleteById(id: String)
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,19 @@
|
|||||||
package com.example.hpostesting.data.dao
|
package com.example.hpostesting.data.dao
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.HBHemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
|
import com.google.android.datatransport.runtime.dagger.Provides
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Database(
|
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 3, exportSchema = false)
|
||||||
entities = [UserData::class, HemoCubeTestData::class, DeviceData::class, HBHemoCubeTestData::class],
|
|
||||||
version = 3,
|
|
||||||
exportSchema = false
|
|
||||||
)
|
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class MyDatabase : RoomDatabase() {
|
abstract class MyDatabase : RoomDatabase() {
|
||||||
abstract fun userDao(): UserDao
|
abstract fun userDao(): UserDao
|
||||||
abstract fun hemoCubeDao(): HemoCubeDao
|
abstract fun hemoCubeDao(): HemoCubeDao
|
||||||
|
|
||||||
abstract fun hbHemoCubeDao(): HBHemoCubeDao
|
|
||||||
}
|
}
|
||||||
@@ -14,8 +14,6 @@ data class DeviceData(
|
|||||||
var deviceType: String = "",
|
var deviceType: String = "",
|
||||||
@get:PropertyName("coefficients") @set:PropertyName("coefficients")
|
@get:PropertyName("coefficients") @set:PropertyName("coefficients")
|
||||||
var coefficients: List<Double> = emptyList(),
|
var coefficients: List<Double> = emptyList(),
|
||||||
@get:PropertyName("hbCoefficients") @set:PropertyName("hbCoefficients")
|
|
||||||
var hbCoefficients: List<Double> = emptyList(),
|
|
||||||
@get:PropertyName("calibratedAt") @set:PropertyName("calibratedAt")
|
@get:PropertyName("calibratedAt") @set:PropertyName("calibratedAt")
|
||||||
var calibratedAt: String = ""
|
var calibratedAt: String = ""
|
||||||
)
|
)
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.example.hpostesting.data.model.patient
|
|
||||||
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "HBHemoCubeTest_table")
|
|
||||||
data class HBHemoCubeTestData(
|
|
||||||
@PrimaryKey
|
|
||||||
var _id: String = "",
|
|
||||||
var name: String = "",
|
|
||||||
var birthYear: String = "",
|
|
||||||
var userImageURL: String = "",
|
|
||||||
var location: UserData.Location? = null,
|
|
||||||
var reportUploadTime: String? = "",
|
|
||||||
var testType: String? = "HB EST",
|
|
||||||
var testTime: String? = "",
|
|
||||||
var testStatus: Boolean? = false,
|
|
||||||
var localFlag: Boolean = false,
|
|
||||||
var deviceId: String? = "",
|
|
||||||
var deviceSerialNumber: String = "",
|
|
||||||
var deviceType: String = "HEMOCUBE",
|
|
||||||
var kitSerial: String = "",
|
|
||||||
var resultData: String = "",
|
|
||||||
var led1Buffer: Double? = null,
|
|
||||||
var led1Sample: Double? = null,
|
|
||||||
var led1Average: Double? = null,
|
|
||||||
var hbEstimation: Double? = null
|
|
||||||
)
|
|
||||||
@@ -17,6 +17,7 @@ data class HemoCubeTestData(
|
|||||||
var testStatus: Boolean? = false,
|
var testStatus: Boolean? = false,
|
||||||
var localFlag: Boolean = false,
|
var localFlag: Boolean = false,
|
||||||
var deviceId: String? = "",
|
var deviceId: String? = "",
|
||||||
|
var appVersion:String? = "",
|
||||||
var deviceSerialNumber: String = "",
|
var deviceSerialNumber: String = "",
|
||||||
var deviceType: String = "HEMOCUBE",
|
var deviceType: String = "HEMOCUBE",
|
||||||
var kitSerial: String = "",
|
var kitSerial: String = "",
|
||||||
@@ -28,6 +29,5 @@ data class HemoCubeTestData(
|
|||||||
var led1Average: Double? = null,
|
var led1Average: Double? = null,
|
||||||
var led2Average: Double? = null,
|
var led2Average: Double? = null,
|
||||||
var deviceRatio: Double? = null,
|
var deviceRatio: Double? = null,
|
||||||
var calculatedRatio: Double? = null,
|
var calculatedRatio: Double? = null
|
||||||
var appVersion: String? = ""
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -45,12 +45,3 @@ fun UserData.toHemoCubeTestData() = HemoCubeTestData(
|
|||||||
testStatus = testStatus,
|
testStatus = testStatus,
|
||||||
location = location
|
location = location
|
||||||
)
|
)
|
||||||
|
|
||||||
fun UserData.toHBHemoCubeTestData() = HBHemoCubeTestData(
|
|
||||||
_id = _id,
|
|
||||||
name = name,
|
|
||||||
birthYear = birthYear,
|
|
||||||
userImageURL = userImageURL,
|
|
||||||
testStatus = testStatus,
|
|
||||||
location = location
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -2,6 +2,5 @@ package com.example.hpostesting.data.model.test
|
|||||||
|
|
||||||
enum class TestType {
|
enum class TestType {
|
||||||
SICKLECERT,
|
SICKLECERT,
|
||||||
SICKLEFIND,
|
SICKLEFIND
|
||||||
HB
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
package com.example.hpostesting.data.repository
|
package com.example.hpostesting.data.repository
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import androidx.room.Room
|
||||||
|
import com.example.hpostesting.data.dao.MyDatabase
|
||||||
import com.example.hpostesting.data.model.PendingUploads
|
import com.example.hpostesting.data.model.PendingUploads
|
||||||
import com.example.hpostesting.data.model.Response
|
import com.example.hpostesting.data.model.Response
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.HBHemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
|
import com.google.android.datatransport.runtime.dagger.Provides
|
||||||
import com.google.firebase.firestore.FirebaseFirestore
|
import com.google.firebase.firestore.FirebaseFirestore
|
||||||
import com.google.firebase.firestore.ktx.firestore
|
import com.google.firebase.firestore.ktx.firestore
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import com.google.firebase.storage.ktx.storage
|
import com.google.firebase.storage.ktx.storage
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.tasks.await
|
import kotlinx.coroutines.tasks.await
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
class DatabaseRepository : Repository {
|
class DatabaseRepository : Repository {
|
||||||
|
|
||||||
@@ -21,31 +27,14 @@ class DatabaseRepository : Repository {
|
|||||||
|
|
||||||
suspend fun addTestToDatabase(data: HemoCubeTestData?): Response<String> {
|
suspend fun addTestToDatabase(data: HemoCubeTestData?): Response<String> {
|
||||||
return try {
|
return try {
|
||||||
val userdata =
|
val userdata = db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
||||||
db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
|
||||||
if (userdata.documents.isNotEmpty()) {
|
if (userdata.documents.isNotEmpty()) {
|
||||||
userdata.documents.forEach {
|
userdata.documents.forEach {
|
||||||
db.collection("patientData").document(it.id).update("testStatus", true)
|
db.collection("patientData").document(it.id).update("testStatus", true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.collection("testData").add(data).await()
|
db.collection("testData").add(data!!).await()
|
||||||
Response.Success(data._id)
|
Response.Success(data!!._id)
|
||||||
} catch (e: Exception) {
|
|
||||||
Response.Error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun addTestToDatabase(data: HBHemoCubeTestData?): 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) {
|
} catch (e: Exception) {
|
||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
}
|
}
|
||||||
@@ -54,29 +43,43 @@ class DatabaseRepository : Repository {
|
|||||||
|
|
||||||
suspend fun addTestToDatabase(data: UserData?): Response<String> {
|
suspend fun addTestToDatabase(data: UserData?): Response<String> {
|
||||||
return try {
|
return try {
|
||||||
val userdata =
|
val userdata = db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
||||||
db.collection("patientData").whereEqualTo("_id", data!!._id).get().await()
|
|
||||||
if (userdata.documents.isNotEmpty()) {
|
if (userdata.documents.isNotEmpty()) {
|
||||||
userdata.documents.forEach {
|
userdata.documents.forEach {
|
||||||
db.collection("patientData").document(it.id).update("testStatus", true)
|
db.collection("patientData").document(it.id).update("testStatus", true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.collection("testData").add(data).await()
|
db.collection("testData").add(data!!).await()
|
||||||
Response.Success(data._id)
|
Response.Success(data!!._id)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean> {
|
suspend fun uploadFileToStorage(patientID: String, filePath: String): Response<Boolean> {
|
||||||
return try {
|
try {
|
||||||
|
|
||||||
val file = Uri.fromFile(File(filePath))
|
val file = Uri.fromFile(File(filePath))
|
||||||
val riversRef = storage.reference.child("$patientID/${file.lastPathSegment}")
|
val riversRef = storage.reference.child("$patientID/${file.lastPathSegment}")
|
||||||
riversRef.putFile(file).await()
|
riversRef.putFile(file).await()
|
||||||
Response.Success(true)
|
return Response.Success(true)
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
return Response.Error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun addToPendingQueue(pendingUploads: PendingUploads): Response<Boolean> {
|
||||||
|
return try {
|
||||||
|
db.collection("pendingUploads").document(pendingUploads.pendingId).set(pendingUploads)
|
||||||
|
.await()
|
||||||
|
|
||||||
|
Response.Success(true)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
Response.Error(e)
|
Response.Error(e)
|
||||||
@@ -127,4 +130,5 @@ class DatabaseRepository : Repository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@ package com.example.hpostesting.domain.di
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.example.hpostesting.data.dao.HBHemoCubeDao
|
|
||||||
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
|
||||||
import com.example.hpostesting.data.dao.UserDao
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
@@ -45,12 +44,6 @@ object AppModule {
|
|||||||
return myDatabase.hemoCubeDao()
|
return myDatabase.hemoCubeDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideMyHBHemo(myDatabase: MyDatabase): HBHemoCubeDao {
|
|
||||||
return myDatabase.hbHemoCubeDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideContext(application: Application): Context {
|
fun provideContext(application: Application): Context {
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.example.hpostesting.presentation
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import com.example.hpostesting.data.DataHolder
|
||||||
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
|
import com.example.hpostesting.presentation.testRight.TestRightActivity
|
||||||
|
import `in`.sminnovations.hpostesting.databinding.ActivityBloodCollectingMethodBinding
|
||||||
|
|
||||||
|
class BloodCollectingMethodActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityBloodCollectingMethodBinding
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = ActivityBloodCollectingMethodBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
init()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun init() {
|
||||||
|
setSupportActionBar(binding.toolbar)
|
||||||
|
binding.btnGo.setOnClickListener {
|
||||||
|
DataHolder.usbConnected.observe(this) {
|
||||||
|
if (it) {
|
||||||
|
if (binding.venousBloodRadioButton.isChecked) {
|
||||||
|
moveToNext(Constants.VENOUS_BLOOD)
|
||||||
|
} else {
|
||||||
|
moveToNext(Constants.FINGER_PRICK_BLOOD)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "No Device Connected", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun moveToNext(bloodCollectingMethod: String) {
|
||||||
|
DataHolder.deviceType.observe(this) { deviceType ->
|
||||||
|
when (deviceType) {
|
||||||
|
Constants.DEVICE_TYPE_HOMOCUBE -> {
|
||||||
|
val intent = Intent(applicationContext, HemocubeActivity::class.java)
|
||||||
|
intent.putExtra(Constants.BLOOD_COLLECTING_METHOD, bloodCollectingMethod)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
Constants.DEVICE_TYPE_TEST_RIGHT -> {
|
||||||
|
val intent = Intent(applicationContext, TestRightActivity::class.java)
|
||||||
|
intent.putExtra(Constants.BLOOD_COLLECTING_METHOD, bloodCollectingMethod)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,14 +5,14 @@ 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.util.Log
|
||||||
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeActivity
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.example.hpostesting.presentation.hemocube.hb.HBHemoCubeActivity
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightActivity
|
|
||||||
import com.journeyapps.barcodescanner.ScanContract
|
import com.journeyapps.barcodescanner.ScanContract
|
||||||
import com.journeyapps.barcodescanner.ScanIntentResult
|
import com.journeyapps.barcodescanner.ScanIntentResult
|
||||||
import com.journeyapps.barcodescanner.ScanOptions
|
import com.journeyapps.barcodescanner.ScanOptions
|
||||||
@@ -26,8 +26,6 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
|
|
||||||
private var hbTest = ""
|
|
||||||
|
|
||||||
private val barcodeLauncher = registerForActivityResult(
|
private val barcodeLauncher = registerForActivityResult(
|
||||||
ScanContract()
|
ScanContract()
|
||||||
) { result: ScanIntentResult ->
|
) { result: ScanIntentResult ->
|
||||||
@@ -50,30 +48,40 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
sharedPreference = this.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
sharedPreference = this.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
hbTest = intent.getStringExtra("Test").toString()
|
|
||||||
|
|
||||||
if (hbTest.isNotEmpty()) {
|
|
||||||
if (checkHBHemoCubeKitData()) {
|
|
||||||
val i = Intent(applicationContext, HBHemoCubeActivity::class.java)
|
|
||||||
startActivity(i)
|
|
||||||
finish()
|
|
||||||
} else {
|
|
||||||
with(sharedPreference.edit()) {
|
|
||||||
putString(Constants.HB_KIT_NUMBER, "")
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken) {
|
if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken) {
|
||||||
DataHolder.selectedTest!!.kitSerial = DataHolder.kitSerial
|
DataHolder.selectedTest!!.kitSerial = DataHolder.kitSerial
|
||||||
moveToNext()
|
moveToNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (checkHemoCubeKitData()) {
|
||||||
|
// DataHolder.selectedTest!!.kitSerial =
|
||||||
|
// sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
|
||||||
|
// moveToNext()
|
||||||
|
// } else {
|
||||||
|
// with(sharedPreference.edit()) {
|
||||||
|
// putString(Constants.KIT_NUMBER, "")
|
||||||
|
// putInt(Constants.KIT_COUNT, 0)
|
||||||
|
// putString(Constants.BUFFER_VALUE_1, "")
|
||||||
|
// putString(Constants.BUFFER_VALUE_2, "")
|
||||||
|
// apply()
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
if (checkHemoCubeKitData()) {
|
if (checkHemoCubeKitData()) {
|
||||||
|
try {
|
||||||
DataHolder.selectedTest!!.kitSerial =
|
DataHolder.selectedTest!!.kitSerial =
|
||||||
sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
|
sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
|
||||||
moveToNext()
|
moveToNext()
|
||||||
|
} catch (e: NullPointerException) {
|
||||||
|
// Handle the NullPointerException here
|
||||||
|
e.printStackTrace() // You can log the exception for debugging
|
||||||
|
FirebaseCrashlytics.getInstance().recordException(e)
|
||||||
|
val errorMessage = "An error occurred: ${e.message}"
|
||||||
|
val rootView = findViewById<View>(android.R.id.content)
|
||||||
|
Snackbar.make(rootView, errorMessage, Snackbar.LENGTH_LONG).show()
|
||||||
|
// Optionally, show a user-friendly error message to the user
|
||||||
|
// Toast.makeText(applicationContext, "An error occurred", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
with(sharedPreference.edit()) {
|
with(sharedPreference.edit()) {
|
||||||
putString(Constants.KIT_NUMBER, "")
|
putString(Constants.KIT_NUMBER, "")
|
||||||
@@ -82,6 +90,8 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
putString(Constants.BUFFER_VALUE_2, "")
|
putString(Constants.BUFFER_VALUE_2, "")
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.nameEditText.setText("SMI/SC/")
|
binding.nameEditText.setText("SMI/SC/")
|
||||||
@@ -116,11 +126,6 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
&& sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
|
&& sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkHBHemoCubeKitData(): Boolean {
|
|
||||||
return sharedPreference.getString(Constants.HB_KIT_NUMBER, "")
|
|
||||||
?.isNotBlank() == true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isSerialValid(s: String): Boolean {
|
private fun isSerialValid(s: String): Boolean {
|
||||||
if (s.length != 17) {
|
if (s.length != 17) {
|
||||||
binding.nameEditText.error = getString(R.string.invalid_kit)
|
binding.nameEditText.error = getString(R.string.invalid_kit)
|
||||||
@@ -130,32 +135,8 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun moveToNext() {
|
private fun moveToNext() {
|
||||||
|
val i = Intent(applicationContext, BloodCollectingMethodActivity::class.java)
|
||||||
if (hbTest.isNotEmpty()) {
|
|
||||||
with(sharedPreference.edit()) {
|
|
||||||
putString(Constants.HB_KIT_NUMBER, binding.nameEditText.text.toString())
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
val i = Intent(applicationContext, HBHemoCubeActivity::class.java)
|
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
DataHolder.deviceType.observe(this) { deviceType ->
|
|
||||||
when (deviceType) {
|
|
||||||
Constants.DEVICE_TYPE_HOMOCUBE -> {
|
|
||||||
val i = Intent(applicationContext, HemoCubeActivity::class.java)
|
|
||||||
startActivity(i)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
Constants.DEVICE_TYPE_TEST_RIGHT -> {
|
|
||||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
|
||||||
startActivity(i)
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startScanningNow() {
|
private fun startScanningNow() {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ 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.data.model.test.TestType
|
import com.example.hpostesting.data.model.test.TestType
|
||||||
import com.google.android.gms.location.*
|
import com.google.android.gms.location.*
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.ActivityMainBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityMainBinding
|
||||||
@@ -234,6 +236,22 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
|
||||||
|
// location?.let {
|
||||||
|
// DataHolder.selectedTest!!.location =
|
||||||
|
// UserData.Location(location.latitude, location.longitude)
|
||||||
|
// DataHolder.location =
|
||||||
|
// UserData.Location(location.latitude, location.longitude)
|
||||||
|
// } ?: run {
|
||||||
|
// requestLocationUpdates()
|
||||||
|
// }
|
||||||
|
// }.addOnFailureListener { exception: Exception ->
|
||||||
|
// exception.printStackTrace()
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
|
fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
|
||||||
location?.let {
|
location?.let {
|
||||||
DataHolder.selectedTest!!.location =
|
DataHolder.selectedTest!!.location =
|
||||||
@@ -244,8 +262,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
requestLocationUpdates()
|
requestLocationUpdates()
|
||||||
}
|
}
|
||||||
}.addOnFailureListener { exception: Exception ->
|
}.addOnFailureListener { exception: Exception ->
|
||||||
|
// Handle the exception here
|
||||||
exception.printStackTrace()
|
exception.printStackTrace()
|
||||||
|
FirebaseCrashlytics.getInstance().recordException(exception)
|
||||||
|
// Display an error message to the user using a Snackbar
|
||||||
|
val errorMessage = "An error occurred: ${exception.message}"
|
||||||
|
val rootView = findViewById<View>(android.R.id.content)
|
||||||
|
Snackbar.make(rootView, errorMessage, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestLocationUpdates() {
|
private fun requestLocationUpdates() {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class SplashActivity : AppCompatActivity() {
|
|||||||
binding = ActivitySplashBinding.inflate(layoutInflater)
|
binding = ActivitySplashBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
setupFirestoreCache()
|
// setupFirestoreCache()
|
||||||
setupStaticConstants()
|
setupStaticConstants()
|
||||||
|
|
||||||
requestPermissions()
|
requestPermissions()
|
||||||
@@ -50,12 +50,12 @@ class SplashActivity : AppCompatActivity() {
|
|||||||
Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)
|
Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupFirestoreCache() {
|
// private fun setupFirestoreCache() {
|
||||||
val settings = FirebaseFirestoreSettings.Builder()
|
// val settings = FirebaseFirestoreSettings.Builder()
|
||||||
.setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED)
|
// .setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED)
|
||||||
.build()
|
// .build()
|
||||||
Firebase.firestore.firestoreSettings = settings
|
// Firebase.firestore.firestoreSettings = settings
|
||||||
}
|
// }
|
||||||
|
|
||||||
private fun requestPermissions() {
|
private fun requestPermissions() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.example.hpostesting.presentation.adapter
|
package com.example.hpostesting.presentation.adapter
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -11,8 +10,6 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.example.hpostesting.data.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.data.model.test.TestType
|
|
||||||
import com.example.hpostesting.presentation.KitScanActivity
|
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
import com.firebase.ui.firestore.FirestoreRecyclerAdapter
|
import com.firebase.ui.firestore.FirestoreRecyclerAdapter
|
||||||
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
||||||
@@ -56,10 +53,7 @@ class UserListAdapter(
|
|||||||
).show()
|
).show()
|
||||||
} else {
|
} else {
|
||||||
DataHolder.selectedTest = model
|
DataHolder.selectedTest = model
|
||||||
DataHolder.selectedTestType = TestType.HB
|
view.findNavController().navigate(R.id.action_nav_home_to_mainActivity)
|
||||||
val intent = Intent(view.context, KitScanActivity::class.java)
|
|
||||||
intent.putExtra("Test", "HB")
|
|
||||||
view.context.startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,16 @@ class HomeFragment : Fragment() {
|
|||||||
private lateinit var sharedPreference: SharedPreferences
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
): View {
|
): View? {
|
||||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
|
// Check if _binding is null
|
||||||
|
if (_binding == null) {
|
||||||
|
// Handle the case where binding could not be initialized
|
||||||
|
// You may want to log an error or return a default view in this case
|
||||||
|
return super.onCreateView(inflater, container, savedInstanceState)
|
||||||
|
}
|
||||||
|
|
||||||
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
DataHolder.selectedTest = null
|
DataHolder.selectedTest = null
|
||||||
|
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ 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
|
||||||
import com.google.firebase.firestore.BuildConfig
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.firebase.firestore.FirebaseFirestore
|
import com.google.firebase.firestore.FirebaseFirestore
|
||||||
import com.google.firebase.firestore.ktx.firestore
|
import com.google.firebase.firestore.ktx.firestore
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
//import `in`.sminnovations.hpostesting.BuildConfig
|
import `in`.sminnovations.hpostesting.BuildConfig
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.tasks.await
|
import kotlinx.coroutines.tasks.await
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlin.math.log10
|
import kotlin.math.log10
|
||||||
|
|
||||||
class HemoCubeFragment : Fragment() {
|
class HemoCubeFragment : Fragment() {
|
||||||
@@ -42,7 +44,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private var resultData: String = ""
|
private var resultData: String = ""
|
||||||
private var isUsingExistingBuffer = false
|
private var isUsingExistingBuffer = false
|
||||||
private var isTestOngoing = false
|
private var isTestOngoing = false
|
||||||
private var bloodGroup: String = ""
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
@@ -61,19 +62,13 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
// val bloodGroupText = binding.etBloodGroup.text.toString()
|
val bloodGroupText = binding.etBloodGroup.text.toString()
|
||||||
// if (bloodGroupText.isNullOrBlank() || bloodGroupText == "Select Blood Group") {
|
if (bloodGroupText.isEmpty()) {
|
||||||
// binding.etBloodGroup.error = "Please enter your blood group"
|
binding.etBloodGroup.error = "Please enter your blood group"
|
||||||
// Toast.makeText(context, "Please enter your blood group", Toast.LENGTH_SHORT).show()
|
} else {
|
||||||
// } else {
|
|
||||||
// binding.etBloodGroup.error = null
|
|
||||||
// bloodGroup = bloodGroupText
|
|
||||||
// checkBloodGroup()
|
|
||||||
// }
|
|
||||||
it.isEnabled = false
|
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
|
||||||
fetchResult()
|
fetchResult()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (isTestOngoing) {
|
if (isTestOngoing) {
|
||||||
binding.btnKit.visibility = View.GONE
|
binding.btnKit.visibility = View.GONE
|
||||||
binding.btnKit.isEnabled = false
|
binding.btnKit.isEnabled = false
|
||||||
@@ -104,26 +99,32 @@ class HemoCubeFragment : Fragment() {
|
|||||||
resetKitCount()
|
resetKitCount()
|
||||||
val intent = Intent(context, KitScanActivity::class.java)
|
val intent = Intent(context, KitScanActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
(activity as HemoCubeActivity).finish()
|
(activity as HemocubeActivity).finish()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkBloodGroup() {
|
private suspend fun checkBloodGroup() {
|
||||||
binding.apply {
|
binding.apply {
|
||||||
// bloodGroup = etBloodGroup.text.toString()
|
val bloodGroup = etBloodGroup.text.toString()
|
||||||
|
if (bloodGroup.isEmpty()) {
|
||||||
|
etBloodGroup.error = "Please enter your blood group"
|
||||||
|
} else {
|
||||||
val db: FirebaseFirestore = Firebase.firestore
|
val db: FirebaseFirestore = Firebase.firestore
|
||||||
|
val userdata = db.collection("patientData")
|
||||||
// Launch a new coroutine scope
|
.whereEqualTo("_id", hemoCubeViewModel.testDetails?._id).get().await()
|
||||||
lifecycleScope.launch {
|
|
||||||
val userdata =
|
|
||||||
db.collection("patientData").whereEqualTo("_id", hemoCubeViewModel.testDetails?._id)
|
|
||||||
.get().await()
|
|
||||||
if (userdata.documents.isNotEmpty()) {
|
if (userdata.documents.isNotEmpty()) {
|
||||||
db.collection("patientData").document(userdata.documents[0].id)
|
db.collection("patientData").document(userdata.documents[0].id)
|
||||||
.update("bloodGroup", bloodGroup)
|
.update("bloodGroup", bloodGroup)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
val i = Intent(
|
||||||
|
requireContext().applicationContext, DashboardActivity::class.java
|
||||||
|
)
|
||||||
|
startActivity(i)
|
||||||
|
(activity as HemocubeActivity).finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +134,9 @@ class HemoCubeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
||||||
if (result == "Success") {
|
if (result == "Success") {
|
||||||
showToast("Test Results Uploaded Successfully")
|
showToast("Test Results Uploaded Successfully")
|
||||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
lifecycleScope.launch {
|
||||||
|
checkBloodGroup()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result == "Local") {
|
if (result == "Local") {
|
||||||
showToast("Internet not available, test details stored locally")
|
showToast("Internet not available, test details stored locally")
|
||||||
@@ -143,6 +146,8 @@ class HemoCubeFragment : Fragment() {
|
|||||||
binding.progressBar.visibility = View.GONE
|
binding.progressBar.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID, ""))
|
||||||
|
|
||||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
||||||
currentDeviceData = it
|
currentDeviceData = it
|
||||||
showToast(calculateRatio(0.17).toString())
|
showToast(calculateRatio(0.17).toString())
|
||||||
@@ -150,7 +155,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||||
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID,""))
|
|
||||||
isOnline = isNetworkAvailable
|
isOnline = isNetworkAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +218,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
|
||||||
val fullReadOutput = StringBuilder()
|
val fullReadOutput = StringBuilder()
|
||||||
(activity as HemoCubeActivity).mService.listenToHemoCube(object : UsbServiceListener {
|
(activity as HemocubeActivity).mService.listenToHemoCube(object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
data?.let {
|
data?.let {
|
||||||
val stringData = String(it)
|
val stringData = String(it)
|
||||||
@@ -238,8 +242,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
resultData += fullReadOutput.toString()
|
resultData += fullReadOutput.toString()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
stringData.contains("ERROR 500") -> showError500Dialog()
|
|
||||||
stringData.contains("ERROR 501") -> showError501Dialog()
|
|
||||||
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||||
stringData.contains("#Sample Completed") -> {
|
stringData.contains("#Sample Completed") -> {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
@@ -268,38 +270,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showError500Dialog() {
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
"BUFFER ERROR",
|
|
||||||
"Do you want to continue with existing buffer?",
|
|
||||||
getString(R.string.noo),
|
|
||||||
"Yes",
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
listenToHemoCube()
|
|
||||||
startBufferProcess()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showError501Dialog() {
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
"SAMPLE ERROR",
|
|
||||||
"Do you want to continue with Sample?",
|
|
||||||
getString(R.string.noo),
|
|
||||||
"Yes",
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
listenToHemoCube()
|
|
||||||
startSampleProcess()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showStartSampleDialog() {
|
private fun showStartSampleDialog() {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
UIUtils.createAlertDialog(requireContext(),
|
||||||
@@ -311,7 +281,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
override fun onClickNegativeButton() {}
|
override fun onClickNegativeButton() {}
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
override fun onClickPositiveButton() {
|
||||||
startSampleProcess()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -320,36 +290,146 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
||||||
try {
|
try {
|
||||||
val result = validString.split(" ")
|
val result = validString.split(" ")
|
||||||
if (result.size == 8) {
|
if (result.size != 8) return
|
||||||
|
|
||||||
val deviceSerialNo = result[2]
|
val deviceSerialNo = result[2]
|
||||||
val led1BufferForDevice = if (isUsingExistingBuffer) {
|
val led1BufferForDevice =
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
getLedBufferValue(isUsingExistingBuffer, Constants.BUFFER_VALUE_1, result[3])
|
||||||
} else {
|
val led2BufferForDevice =
|
||||||
result[3].toDoubleOrNull()
|
getLedBufferValue(isUsingExistingBuffer, Constants.BUFFER_VALUE_2, result[4])
|
||||||
}
|
val version = BuildConfig.VERSION_NAME
|
||||||
val led2BufferForDevice = if (isUsingExistingBuffer) {
|
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()
|
|
||||||
} else {
|
|
||||||
result[4].toDoubleOrNull()
|
|
||||||
}
|
|
||||||
val led1Sample = result[5].toDoubleOrNull()
|
val led1Sample = result[5].toDoubleOrNull()
|
||||||
val led2Sample = result[6].toDoubleOrNull()
|
val led2Sample = result[6].toDoubleOrNull()
|
||||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
|
||||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
val led1Average = calculateAverage(led1BufferForDevice, led1Sample)
|
||||||
|
val led2Average = calculateAverage(led2BufferForDevice, led2Sample)
|
||||||
val deviceRatio = led1Average / led2Average
|
val deviceRatio = led1Average / led2Average
|
||||||
val version = BuildConfig.VERSION_NAME
|
val calculatedRatio = calculateRatio(deviceRatio)
|
||||||
|
val isBufferValid = validateBuffer(led1BufferForDevice, led2BufferForDevice)
|
||||||
|
val isSampleValid =
|
||||||
|
validateSample(led1Sample, led1BufferForDevice, led2Sample, led2BufferForDevice)
|
||||||
|
val isCalculatedRatioValid = validateCalculatedRatio(deviceRatio)
|
||||||
|
|
||||||
|
when {
|
||||||
|
!isBufferValid -> showError(
|
||||||
|
"Buffer error",
|
||||||
|
"Check for Empty curved, disconnected and reconnect the device, and please retest this sample again with a new blank"
|
||||||
|
)
|
||||||
|
|
||||||
|
!isSampleValid -> showError(
|
||||||
|
"Sample error",
|
||||||
|
"Check for Empty curved, disconnected and reconnect the device, and please retest this sample again with a new blank"
|
||||||
|
)
|
||||||
|
|
||||||
|
!validateBloodVolume(led1Average, led2Average) -> {
|
||||||
|
showError(
|
||||||
|
"Low Blood Volume",
|
||||||
|
"Please retest this sample with a higher volume of blood"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
!validateHighBloodVolume(led1Average, led2Average) -> {
|
||||||
|
showError(
|
||||||
|
"High Blood Volume",
|
||||||
|
"Please retest this sample by diluting the sample in the buffer"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
!isCalculatedRatioValid -> showError(
|
||||||
|
"calculated Ratio error",
|
||||||
|
"Check for Empty curved, disconnected and reconnect the device, and please retest this sample again with a new blank"
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> processValidData(
|
||||||
|
deviceSerialNo,
|
||||||
|
led1BufferForDevice,
|
||||||
|
led2BufferForDevice,
|
||||||
|
version,
|
||||||
|
led1Sample,
|
||||||
|
led2Sample,
|
||||||
|
led1Average,
|
||||||
|
led2Average,
|
||||||
|
deviceRatio,
|
||||||
|
fullReadOutput,
|
||||||
|
calculatedRatio
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (_: Exception) {
|
||||||
|
// handle exception or log it if necessary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getLedBufferValue(
|
||||||
|
usingExistingBuffer: Boolean, bufferConstant: String, resultValue: String
|
||||||
|
): Double? {
|
||||||
|
return if (usingExistingBuffer) {
|
||||||
|
sharedPreferences.getString(bufferConstant, "")?.toDoubleOrNull()
|
||||||
|
} else {
|
||||||
|
resultValue.toDoubleOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateAverage(bufferForDevice: Double?, sample: Double?): Double {
|
||||||
|
return log10(bufferForDevice?.div(sample ?: 1.0) ?: 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateBuffer(led1Buffer: Double?, led2Buffer: Double?): Boolean {
|
||||||
|
return led1Buffer!! in 20001.0..23999.0 && led2Buffer!! in 20001.0..23999.0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateSample(
|
||||||
|
sample1: Double?, buffer1: Double?, sample2: Double?, buffer2: Double?
|
||||||
|
): Boolean {
|
||||||
|
return sample1 != null && sample1 < buffer1!! && sample1 < 24000 && sample2 != null && sample2 < buffer2!! && sample2 < 24000
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateBloodVolume(average1: Double, average2: Double): Boolean {
|
||||||
|
return average1 > 0.08 && average2 > 0.08
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateCalculatedRatio(deviceRatio: Double): Boolean {
|
||||||
|
return deviceRatio > 0.08 && deviceRatio < 0.3
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validateHighBloodVolume(average1: Double, average2: Double): Boolean {
|
||||||
|
return average1 < 1.07 && average2 < 1.07
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showError(title: String, message: String) {
|
||||||
|
customErrorDialogBox(title, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processValidData(
|
||||||
|
deviceId: String,
|
||||||
|
led1Buffer: Double?,
|
||||||
|
led2Buffer: Double?,
|
||||||
|
appVersion: String,
|
||||||
|
led1Sample: Double?,
|
||||||
|
led2Sample: Double?,
|
||||||
|
led1Average: Double,
|
||||||
|
led2Average: Double,
|
||||||
|
deviceRatio: Double,
|
||||||
|
resultData: String,
|
||||||
|
calculatedRatio: Double
|
||||||
|
) {
|
||||||
|
val threshold =
|
||||||
|
if ((activity as HemocubeActivity).bloodCollectingMethod == Constants.FINGER_PRICK_BLOOD) 0.05 else 0.06
|
||||||
|
|
||||||
|
if (led1Average > threshold) {
|
||||||
DataHolder.hemoCubeTestData?.apply {
|
DataHolder.hemoCubeTestData?.apply {
|
||||||
deviceId = deviceSerialNo
|
this.deviceId = deviceId
|
||||||
appVersion = version
|
this.led1Buffer = led1Buffer
|
||||||
led1Buffer = led1BufferForDevice
|
this.led2Buffer = led2Buffer
|
||||||
led2Buffer = led2BufferForDevice
|
this.appVersion = appVersion
|
||||||
this.led1Sample = led1Sample
|
this.led1Sample = led1Sample
|
||||||
this.led2Sample = led2Sample
|
this.led2Sample = led2Sample
|
||||||
this.led1Average = led1Average
|
this.led1Average = led1Average
|
||||||
this.led2Average = led2Average
|
this.led2Average = led2Average
|
||||||
this.deviceRatio = deviceRatio
|
this.deviceRatio = deviceRatio
|
||||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
this.calculatedRatio = calculatedRatio
|
||||||
this.resultData = fullReadOutput
|
this.resultData = resultData
|
||||||
|
|
||||||
if (!isBufferValueAvailable()) {
|
if (!isBufferValueAvailable()) {
|
||||||
with(sharedPreferences.edit()) {
|
with(sharedPreferences.edit()) {
|
||||||
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
||||||
@@ -361,12 +441,37 @@ class HemoCubeFragment : Fragment() {
|
|||||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
showError(
|
||||||
|
"Low Blood Volume",
|
||||||
|
"Please repeat the test with 10 µl of blood added to 1 ml of buffer"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e: Exception) {
|
private fun customErrorDialogBox(title: String, message: String) {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
MaterialAlertDialogBuilder(requireContext()).setTitle(title).setMessage(message)
|
||||||
|
.setPositiveButton("OK") { dialog, _ ->
|
||||||
|
if (title == "Buffer error" || title == "Sample error") {
|
||||||
|
with(sharedPreferences.edit()) {
|
||||||
|
putString(Constants.BUFFER_VALUE_1, "")
|
||||||
|
putString(Constants.BUFFER_VALUE_2, "")
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
finishTestingActivity()
|
||||||
|
} else {
|
||||||
|
finishTestingActivity()
|
||||||
|
}
|
||||||
|
dialog.dismiss()
|
||||||
|
}.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun finishTestingActivity() {
|
||||||
|
val i = Intent(requireContext().applicationContext, DashboardActivity::class.java)
|
||||||
|
startActivity(i)
|
||||||
|
(activity as HemocubeActivity).finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showToast(message: String) {
|
private fun showToast(message: String) {
|
||||||
@@ -376,8 +481,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private fun startBufferProcess() {
|
private fun startBufferProcess() {
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
|
||||||
(activity as HemoCubeActivity).mService.sendAndListenToHemoCube(
|
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
||||||
HemoCubeCommands.startBuffer,
|
|
||||||
object : UsbServiceListener {
|
object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
override fun onUsbRead(data: ByteArray?) {}
|
||||||
|
|
||||||
@@ -390,8 +494,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private fun startSampleProcess() {
|
private fun startSampleProcess() {
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
|
||||||
(activity as HemoCubeActivity).mService.sendAndListenToHemoCube(
|
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
||||||
HemoCubeCommands.startSample,
|
|
||||||
object : UsbServiceListener {
|
object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
override fun onUsbRead(data: ByteArray?) {}
|
||||||
|
|
||||||
@@ -404,8 +507,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private fun fetchResult() {
|
private fun fetchResult() {
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
|
||||||
(activity as HemoCubeActivity).mService.sendAndListenToHemoCube(
|
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.getSample,
|
||||||
HemoCubeCommands.getSample,
|
|
||||||
object : UsbServiceListener {
|
object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
override fun onUsbRead(data: ByteArray?) {}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ 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.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
@@ -70,6 +71,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addResultTestToDb() {
|
private fun addResultTestToDb() {
|
||||||
|
testDetails?.deviceRatio = DataHolder.hemocubeResult
|
||||||
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()
|
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()
|
||||||
testDetails?.location = DataHolder.location
|
testDetails?.location = DataHolder.location
|
||||||
testDetails?.testTime = SimpleDateFormat(
|
testDetails?.testTime = SimpleDateFormat(
|
||||||
@@ -98,7 +100,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
is Response.Success -> {
|
is Response.Success -> {
|
||||||
val kitCount = sharedPreference.getInt(Constants.KIT_COUNT, 0)
|
val kitCount = sharedPreference.getInt(Constants.KIT_COUNT, 0)
|
||||||
with(sharedPreference.edit()) {
|
with(sharedPreference.edit()) {
|
||||||
putInt(Constants.KIT_COUNT, kitCount.plus(1))
|
putInt(Constants.KIT_COUNT, kitCount.plus(1) ?: 0)
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||||
@@ -106,10 +108,14 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
is Response.Error -> {
|
is Response.Error -> {
|
||||||
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 -> {
|
||||||
|
Log.e("Testdb", "Unknown response from repository: $response")
|
||||||
|
fireBaseUpload.postValue("Unknown")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import `in`.sminnovations.hpostesting.R
|
|||||||
import `in`.sminnovations.hpostesting.databinding.ActivityHemocubeBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityHemocubeBinding
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class HemoCubeActivity : AppCompatActivity() {
|
class HemocubeActivity : AppCompatActivity() {
|
||||||
private lateinit var binding: ActivityHemocubeBinding
|
private lateinit var binding: ActivityHemocubeBinding
|
||||||
private val viewModel by viewModels<HemoCubeViewModel>()
|
private val viewModel by viewModels<HemoCubeViewModel>()
|
||||||
private var myMenu: Menu? = null
|
private var myMenu: Menu? = null
|
||||||
@@ -40,6 +40,8 @@ class HemoCubeActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private val TAG = "HemoCube"
|
private val TAG = "HemoCube"
|
||||||
|
|
||||||
|
var bloodCollectingMethod = ""
|
||||||
|
|
||||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
|
||||||
@@ -77,6 +79,7 @@ class HemoCubeActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityHemocubeBinding.inflate(layoutInflater)
|
binding = ActivityHemocubeBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
bloodCollectingMethod = intent.getStringExtra(Constants.BLOOD_COLLECTING_METHOD).toString()
|
||||||
setSupportActionBar(binding.myToolbar)
|
setSupportActionBar(binding.myToolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
setupListener()
|
setupListener()
|
||||||
@@ -118,10 +121,12 @@ class HemoCubeActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
|
|
||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
||||||
val mPendingIntent: PendingIntent =
|
val mPendingIntent: PendingIntent = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_MUTABLE
|
this,
|
||||||
|
0,
|
||||||
|
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
||||||
|
PendingIntent.FLAG_MUTABLE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
@@ -144,15 +149,17 @@ class HemoCubeActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun moveToNext() {
|
private fun moveToNext() {
|
||||||
if (supportFragmentManager.isDestroyed) return
|
if (supportFragmentManager.isDestroyed)
|
||||||
|
return
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction().replace(binding.fghemocube.id, HemoCubeFragment())
|
supportFragmentManager.beginTransaction()
|
||||||
.commit()
|
.replace(binding.fghemocube.id, HemoCubeFragment()).commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onErrorReported(msg: String) {
|
fun onErrorReported(msg: String) {
|
||||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
||||||
if (!isFinishing) onBackPressed()
|
if (!isFinishing)
|
||||||
|
onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
@@ -1,171 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube.hb
|
|
||||||
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.IntentFilter
|
|
||||||
import android.content.ServiceConnection
|
|
||||||
import android.hardware.usb.UsbDevice
|
|
||||||
import android.hardware.usb.UsbDeviceConnection
|
|
||||||
import android.hardware.usb.UsbManager
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.os.IBinder
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.activity.viewModels
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.core.view.get
|
|
||||||
import com.example.hpostesting.data.DataHolder
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
|
||||||
import com.example.hpostesting.presentation.testRight.UsbService
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import `in`.sminnovations.hpostesting.R
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.ActivityHemocubeBinding
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class HBHemoCubeActivity : AppCompatActivity() {
|
|
||||||
private lateinit var binding: ActivityHemocubeBinding
|
|
||||||
private val viewModel by viewModels<HBHemoCubeViewModel>()
|
|
||||||
private var myMenu: Menu? = null
|
|
||||||
|
|
||||||
private lateinit var mDriver: UsbSerialDriver
|
|
||||||
private var mConnection: UsbDeviceConnection? = null
|
|
||||||
lateinit var mService: UsbService
|
|
||||||
|
|
||||||
private val TAG = "HemoCube"
|
|
||||||
|
|
||||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
|
||||||
|
|
||||||
synchronized(this) {
|
|
||||||
val device: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
|
|
||||||
|
|
||||||
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
|
|
||||||
device?.apply {
|
|
||||||
connectUsb(true)
|
|
||||||
DataHolder.usbConnected.postValue(true)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
onErrorReported("permission denied for device")
|
|
||||||
DataHolder.usbConnected.postValue(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private val connection = object : ServiceConnection {
|
|
||||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
|
||||||
val binder = service as UsbService.UsbServiceBinder
|
|
||||||
mService = binder.getService()
|
|
||||||
viewModel.isServiceConnected = true
|
|
||||||
mConnection.let { mService.connect(mDriver, mConnection!!) }
|
|
||||||
moveToNext()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
|
||||||
viewModel.isServiceConnected = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
binding = ActivityHemocubeBinding.inflate(layoutInflater)
|
|
||||||
setContentView(binding.root)
|
|
||||||
setSupportActionBar(binding.myToolbar)
|
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
||||||
setupListener()
|
|
||||||
connectUsb(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupListener() {
|
|
||||||
DataHolder.usbConnected.observe(this) {
|
|
||||||
Log.d("USB OBSERVE", "HemoCube called -> $it")
|
|
||||||
if (it) {
|
|
||||||
myMenu?.get(0)?.icon =
|
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
|
|
||||||
} else {
|
|
||||||
myMenu?.get(0)?.icon =
|
|
||||||
ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
|
||||||
Toast.makeText(this, "Device is Disconnected", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun connectUsb(permissionGranted: Boolean) {
|
|
||||||
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
|
|
||||||
val manager = getSystemService(Context.USB_SERVICE) as UsbManager
|
|
||||||
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager)
|
|
||||||
|
|
||||||
if (availableDrivers.isEmpty()) {
|
|
||||||
onErrorReported("No Device is Connected")
|
|
||||||
} else {
|
|
||||||
mDriver = availableDrivers[0]
|
|
||||||
mConnection = manager.openDevice(mDriver.device)
|
|
||||||
|
|
||||||
if (mConnection == null) {
|
|
||||||
requestUserPermission(manager, mDriver.device)
|
|
||||||
} else {
|
|
||||||
setupService()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
|
|
||||||
val mPendingIntent: PendingIntent =
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
this, 0, Intent(Constants.HOMOCUBE_USB_PERMISSION), PendingIntent.FLAG_IMMUTABLE
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
this,
|
|
||||||
0,
|
|
||||||
Intent(Constants.HOMOCUBE_USB_PERMISSION),
|
|
||||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val filter = IntentFilter(Constants.HOMOCUBE_USB_PERMISSION)
|
|
||||||
registerReceiver(broadcastReceiver, filter)
|
|
||||||
manager.requestPermission(device, mPendingIntent)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupService() {
|
|
||||||
val intent = Intent(this, UsbService::class.java)
|
|
||||||
// startService(intent)
|
|
||||||
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun moveToNext() {
|
|
||||||
if (supportFragmentManager.isDestroyed) return
|
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.replace(binding.fghemocube.id, HBHemoCubeFragment()).commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onErrorReported(msg: String) {
|
|
||||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
|
||||||
if (!isFinishing) onBackPressed()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
|
||||||
menuInflater.inflate(R.menu.my_menu, menu)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
if (viewModel.isServiceConnected) {
|
|
||||||
mService.disconnect()
|
|
||||||
unbindService(connection)
|
|
||||||
viewModel.isServiceConnected = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,400 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube.hb
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.fragment.app.activityViewModels
|
|
||||||
import com.example.hpostesting.data.DataHolder
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
|
||||||
import com.example.hpostesting.data.model.patient.toHBHemoCubeTestData
|
|
||||||
import com.example.hpostesting.presentation.KitScanActivity
|
|
||||||
import com.example.hpostesting.presentation.UsbServiceListener
|
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
|
||||||
import com.example.hpostesting.presentation.utils.UIUtils
|
|
||||||
import `in`.sminnovations.hpostesting.R
|
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
|
||||||
import kotlin.math.log10
|
|
||||||
|
|
||||||
class HBHemoCubeFragment : Fragment() {
|
|
||||||
|
|
||||||
private lateinit var binding: FragmentHemoCubeReferenceBinding
|
|
||||||
private val hemoCubeViewModel: HBHemoCubeViewModel by activityViewModels()
|
|
||||||
private lateinit var sharedPreferences: SharedPreferences
|
|
||||||
private var isOnline = false
|
|
||||||
private var currentDeviceData: DeviceData? = null
|
|
||||||
private var resultData: String = ""
|
|
||||||
private var isUsingExistingBuffer = false
|
|
||||||
private var isTestOngoing = false
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
|
||||||
): View {
|
|
||||||
binding = FragmentHemoCubeReferenceBinding.inflate(inflater, container, false)
|
|
||||||
sharedPreferences =
|
|
||||||
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
|
||||||
return binding.root
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
initViews()
|
|
||||||
observeViewModel()
|
|
||||||
checkAndStartProcess()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initViews() {
|
|
||||||
binding.btnSubmit.setOnClickListener {
|
|
||||||
it.isEnabled = false
|
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
|
||||||
hemoCubeViewModel.uploadHBHemoCubeResultToDatabase(
|
|
||||||
isOnline, true, sharedPreferences.getString(Constants.HB_KIT_NUMBER, "")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (isTestOngoing) {
|
|
||||||
binding.btnKit.visibility = View.GONE
|
|
||||||
binding.btnKit.isEnabled = false
|
|
||||||
binding.btnKit.isClickable = false
|
|
||||||
|
|
||||||
}
|
|
||||||
binding.btnSubmit.isEnabled = false
|
|
||||||
binding.btnSubmit.isClickable = false
|
|
||||||
|
|
||||||
binding.btnKit.setOnClickListener {
|
|
||||||
if (isTestOngoing) {
|
|
||||||
val title = "WARNING"
|
|
||||||
val message = "There is a on going test, do you want to stop it"
|
|
||||||
val negativeText = getString(R.string.no)
|
|
||||||
val positiveText = "Yes"
|
|
||||||
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
negativeText,
|
|
||||||
positiveText,
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
resetKitCount()
|
|
||||||
val intent = Intent(context, KitScanActivity::class.java)
|
|
||||||
startActivity(intent)
|
|
||||||
(activity as HBHemoCubeActivity).finish()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun observeViewModel() {
|
|
||||||
hemoCubeViewModel.fireBaseUpload.observe(viewLifecycleOwner) { result ->
|
|
||||||
if (result == "Success") {
|
|
||||||
showToast("Test Results Uploaded Successfully")
|
|
||||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
|
||||||
}
|
|
||||||
if (result == "Local") {
|
|
||||||
showToast("Internet not available, test details stored locally")
|
|
||||||
startActivity(Intent(requireActivity(), DashboardActivity::class.java))
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.progressBar.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
|
||||||
currentDeviceData = it
|
|
||||||
}
|
|
||||||
|
|
||||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
|
||||||
hemoCubeViewModel.getDeviceData(sharedPreferences.getString(Constants.USER_ID, ""))
|
|
||||||
isOnline = isNetworkAvailable
|
|
||||||
}
|
|
||||||
|
|
||||||
hemoCubeViewModel.messages.observe(viewLifecycleOwner) {
|
|
||||||
binding.tvSubtitle4.text = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkAndStartProcess() {
|
|
||||||
if (isBufferValueAvailable()) {
|
|
||||||
showBufferAlertDialog()
|
|
||||||
} else {
|
|
||||||
listenToHemoCube()
|
|
||||||
startBufferProcess()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isBufferValueAvailable(): Boolean {
|
|
||||||
return if (sharedPreferences.getString(Constants.HB_BUFFER_VALUE_1, "") != "") {
|
|
||||||
sharedPreferences.getString(Constants.HB_BUFFER_VALUE_1, "")
|
|
||||||
?.toDouble()!! > 0.0
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showBufferAlertDialog() {
|
|
||||||
val title = "WARNING"
|
|
||||||
val message = "Do you want to continue with existing buffer?"
|
|
||||||
val negativeText = getString(R.string.no)
|
|
||||||
val positiveText = "Yes"
|
|
||||||
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
title,
|
|
||||||
message,
|
|
||||||
negativeText,
|
|
||||||
positiveText,
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {
|
|
||||||
listenToHemoCube()
|
|
||||||
startBufferProcess()
|
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(Constants.HB_BUFFER_VALUE_1, "")
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
listenToHemoCube()
|
|
||||||
startSampleProcess()
|
|
||||||
isUsingExistingBuffer = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun listenToHemoCube() {
|
|
||||||
if (DataHolder.HbHemoCubeTestData == null) {
|
|
||||||
DataHolder.HbHemoCubeTestData = DataHolder.selectedTest?.toHBHemoCubeTestData()
|
|
||||||
}
|
|
||||||
|
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
|
||||||
|
|
||||||
val fullReadOutput = StringBuilder()
|
|
||||||
(activity as HBHemoCubeActivity).mService.listenToHemoCube(object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
|
||||||
data?.let {
|
|
||||||
val stringData = String(it)
|
|
||||||
fullReadOutput.append(stringData)
|
|
||||||
handleUsbData(stringData, fullReadOutput)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
|
||||||
if (stringData.contains("#")) {
|
|
||||||
hemoCubeViewModel.messages.postValue(stringData)
|
|
||||||
isTestOngoing = true
|
|
||||||
}
|
|
||||||
|
|
||||||
resultData += fullReadOutput.toString()
|
|
||||||
|
|
||||||
when {
|
|
||||||
stringData.contains("ERROR 500") -> showError500Dialog()
|
|
||||||
stringData.contains("ERROR 501") -> showError501Dialog()
|
|
||||||
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
|
||||||
stringData.contains("#Sample Completed") -> {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
binding.btnSubmit.isEnabled = true
|
|
||||||
binding.btnSubmit.isClickable = true
|
|
||||||
fetchResult()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
|
||||||
var validString: String
|
|
||||||
val results: List<String>
|
|
||||||
if (stringData.contains("RESULT")) {
|
|
||||||
validString = isValidResult(stringData)
|
|
||||||
if (validString.isEmpty()) {
|
|
||||||
results = resultData.split("\n")
|
|
||||||
validString = parseResult(results)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
results = resultData.split("\n")
|
|
||||||
validString = parseResult(results)
|
|
||||||
}
|
|
||||||
if (validString.isNotEmpty()) {
|
|
||||||
handleValidResult(validString, resultData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showError500Dialog() {
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
"BUFFER ERROR",
|
|
||||||
"Do you want to continue with existing buffer?",
|
|
||||||
getString(R.string.noo),
|
|
||||||
"Yes",
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
listenToHemoCube()
|
|
||||||
startBufferProcess()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showError501Dialog() {
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
"SAMPLE ERROR",
|
|
||||||
"Do you want to continue with Sample?",
|
|
||||||
getString(R.string.noo),
|
|
||||||
"Yes",
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
listenToHemoCube()
|
|
||||||
startSampleProcess()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showStartSampleDialog() {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
"Start Sample",
|
|
||||||
"Do you want to start sample reading?",
|
|
||||||
getString(R.string.no),
|
|
||||||
"Yes",
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
startSampleProcess()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
|
||||||
try {
|
|
||||||
val result = validString.split(" ")
|
|
||||||
if (result.size == 6) {
|
|
||||||
val deviceSerialNo = result[2]
|
|
||||||
val led1BufferForDevice = if (isUsingExistingBuffer) {
|
|
||||||
sharedPreferences.getString(Constants.HB_BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
|
||||||
} else {
|
|
||||||
result[3].toDoubleOrNull()
|
|
||||||
}
|
|
||||||
val led1Sample = result[4].toDoubleOrNull()
|
|
||||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
|
||||||
|
|
||||||
binding.result.text = "HB Est. - ${((led1Average-0.0177)/0.0237).toString().substring(0, 6)}"
|
|
||||||
DataHolder.HbHemoCubeTestData?.apply {
|
|
||||||
deviceId = deviceSerialNo
|
|
||||||
led1Buffer = led1BufferForDevice
|
|
||||||
this.led1Sample = led1Sample
|
|
||||||
this.led1Average = led1Average
|
|
||||||
this.hbEstimation = ((led1Average-0.0177)/0.0237)
|
|
||||||
this.resultData = fullReadOutput
|
|
||||||
if (!isBufferValueAvailable()) {
|
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(Constants.HB_BUFFER_VALUE_1, led1Buffer.toString())
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (_: Exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showToast(message: String) {
|
|
||||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startBufferProcess() {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
|
||||||
|
|
||||||
(activity as HBHemoCubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
|
||||||
object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startSampleProcess() {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
|
||||||
|
|
||||||
(activity as HBHemoCubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
|
|
||||||
object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun fetchResult() {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
|
||||||
|
|
||||||
(activity as HBHemoCubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.getSample,
|
|
||||||
object : UsbServiceListener {
|
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
|
||||||
hemoCubeViewModel.progressBar.postValue(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun calculateRatio(ratio: Double): Double {
|
|
||||||
val coefficient1 = currentDeviceData?.hbCoefficients?.get(0) ?: 0.0
|
|
||||||
val coefficient2 = currentDeviceData?.hbCoefficients?.get(1) ?: 0.0
|
|
||||||
return coefficient1 * ratio + coefficient2
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseResult(frames: List<String>): String {
|
|
||||||
val lines = mutableListOf<String>()
|
|
||||||
for (frame in frames.reversed()) {
|
|
||||||
if (frame.contains("REND") || frame.contains("RESULT")) lines += frame
|
|
||||||
if (frame.contains("RESULT")) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val line = lines.reversed().joinToString("").trim()
|
|
||||||
if (line.contains("RESULT") && line.split(" ").size == 6) {
|
|
||||||
return line
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isValidResult(line: String): String {
|
|
||||||
return if (line.contains("RESULT") && line.split(" ").size == 6) {
|
|
||||||
line
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resetKitCount() {
|
|
||||||
with(sharedPreferences.edit()) {
|
|
||||||
putString(Constants.KIT_NUMBER, "")
|
|
||||||
putInt(Constants.KIT_COUNT, 0)
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube.hb
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import com.example.hpostesting.data.DataHolder
|
|
||||||
import com.example.hpostesting.data.NetworkStatusLiveData
|
|
||||||
import com.example.hpostesting.data.constant.Constants
|
|
||||||
import com.example.hpostesting.data.dao.HBHemoCubeDao
|
|
||||||
import com.example.hpostesting.data.model.Response
|
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
|
||||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.model.patient.toHBHemoCubeTestData
|
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Calendar
|
|
||||||
import java.util.Locale
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltViewModel
|
|
||||||
class HBHemoCubeViewModel @Inject constructor(
|
|
||||||
private val hbHemoCubeDao: HBHemoCubeDao,
|
|
||||||
private val repository: DatabaseRepository,
|
|
||||||
context: Context,
|
|
||||||
) : ViewModel() {
|
|
||||||
var isServiceConnected = false
|
|
||||||
val progressBar = MutableLiveData(false)
|
|
||||||
val testDetails = DataHolder.selectedTest?.toHBHemoCubeTestData()
|
|
||||||
val messages = MutableLiveData<String>()
|
|
||||||
private val sharedPreference: SharedPreferences =
|
|
||||||
context.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
|
||||||
|
|
||||||
// Get the device ID of the device you want to retrieve data for (e.g., the first device in the list)
|
|
||||||
|
|
||||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
|
||||||
val allUserData = hbHemoCubeDao.getAll()
|
|
||||||
val deviceData = MutableLiveData<DeviceData?>()
|
|
||||||
val networkStatusLiveData: LiveData<Boolean>
|
|
||||||
get() = _networkStatusLiveData
|
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
|
||||||
fun uploadHBHemoCubeResultToDatabase(
|
|
||||||
isOnline: Boolean, testStatus: Boolean, kitSerial: String?
|
|
||||||
) = viewModelScope.launch {
|
|
||||||
if (kitSerial != null) {
|
|
||||||
testDetails?.kitSerial = kitSerial
|
|
||||||
}
|
|
||||||
testDetails?.testStatus = testStatus
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (isOnline) {
|
|
||||||
addResultTestToDb()
|
|
||||||
} else {
|
|
||||||
testDetails?.testTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
hbHemoCubeDao.insertAll(testDetails!!)
|
|
||||||
fireBaseUpload.postValue("Local")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("Testdb", "Upload failed: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getDeviceData(deviceId: String?) = viewModelScope.launch {
|
|
||||||
deviceData.postValue(deviceId?.let { repository.getDeviceDataById(it) })
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addResultTestToDb() {
|
|
||||||
testDetails?.resultData = DataHolder.HbHemoCubeTestData?.resultData.toString()
|
|
||||||
testDetails?.location = DataHolder.location
|
|
||||||
testDetails?.testTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
|
|
||||||
testDetails?.deviceId = DataHolder.HbHemoCubeTestData?.deviceId
|
|
||||||
testDetails?.deviceSerialNumber =
|
|
||||||
sharedPreference.getString(Constants.USER_ID, "").toString()
|
|
||||||
testDetails?.kitSerial = sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
|
|
||||||
testDetails?.led1Buffer = DataHolder.HbHemoCubeTestData?.led1Buffer
|
|
||||||
testDetails?.led1Sample = DataHolder.HbHemoCubeTestData?.led1Sample
|
|
||||||
testDetails?.led1Average = DataHolder.HbHemoCubeTestData?.led1Average
|
|
||||||
testDetails?.hbEstimation = DataHolder.HbHemoCubeTestData?.hbEstimation
|
|
||||||
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
testDetails!!.reportUploadTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
|
|
||||||
when (val response = repository.addTestToDatabase(testDetails)) {
|
|
||||||
is Response.Success -> {
|
|
||||||
val kitCount = sharedPreference.getInt(Constants.KIT_COUNT, 0)
|
|
||||||
with(sharedPreference.edit()) {
|
|
||||||
putInt(Constants.KIT_COUNT, kitCount.plus(1))
|
|
||||||
apply()
|
|
||||||
}
|
|
||||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
|
||||||
fireBaseUpload.postValue("Success")
|
|
||||||
}
|
|
||||||
|
|
||||||
is Response.Error -> {
|
|
||||||
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
|
||||||
fireBaseUpload.postValue("Error")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
|
||||||
fireBaseUpload.postValue("Error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bulkAddResultTestToDb(userData: HemoCubeTestData) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
userData.reportUploadTime = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
when (repository.addTestToDatabase(userData)) {
|
|
||||||
is Response.Success -> {
|
|
||||||
fireBaseUpload.postValue("Success")
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteById(userId: String) = viewModelScope.launch {
|
|
||||||
hbHemoCubeDao.deleteById(id = userId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
74
app/src/main/res/layout/activity_blood_collecting_method.xml
Normal file
74
app/src/main/res/layout/activity_blood_collecting_method.xml
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
|
tools:context="com.example.hpostesting.presentation.BloodCollectingMethodActivity">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/app_bar_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:theme="@style/Theme.HPOS.AppBarOverlay">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
app:popupTheme="@style/Theme.HPOS.PopupOverlay" />
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_title"
|
||||||
|
style="@style/title1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/select_blood_collecting_method"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/app_bar_layout" />
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/bloodTypeRadioGroup"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tv_title">
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/venousBloodRadioButton"
|
||||||
|
style="@style/title1_1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/venous_blood" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/fingerPrickBloodRadioButton"
|
||||||
|
style="@style/title1_1"
|
||||||
|
android:checked="true"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/finger_prick_blood" />
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/btn_go"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="24dp"
|
||||||
|
android:text="@string/go"
|
||||||
|
app:cornerRadius="16dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/bloodTypeRadioGroup" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -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.KitScanActivity">
|
tools:context="com.example.hpostesting.presentation.KitScanActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/app_bar_layout"
|
android:id="@+id/app_bar_layout"
|
||||||
|
|||||||
@@ -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.GalleryFragment">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_gallery"
|
android:id="@+id/text_gallery"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="24dp"
|
android:layout_marginHorizontal="24dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:text="HB TESTING INSTRUCTIONS"
|
android:text="@string/Instructions"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
@@ -69,7 +69,30 @@
|
|||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4" />
|
app:layout_constraintTop_toBottomOf="@id/til_blood_group" />
|
||||||
|
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/til_blood_group"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tv_subtitle4">
|
||||||
|
|
||||||
|
<AutoCompleteTextView
|
||||||
|
android:id="@+id/et_blood_group"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/select_blood_group"
|
||||||
|
android:inputType="none"
|
||||||
|
android:labelFor="@id/til_blood_group"
|
||||||
|
app:simpleItems="@array/blood_group" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_kit"
|
android:id="@+id/btn_kit"
|
||||||
@@ -82,23 +105,7 @@
|
|||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
<TextView
|
<!-- <Button-->
|
||||||
android:id="@+id/result"
|
|
||||||
style="@style/title1_1"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:layout_marginHorizontal="24dp"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:gravity="center"
|
|
||||||
tools:text="HB Est. : 16.254 g/dl"
|
|
||||||
android:textColor="@color/red"
|
|
||||||
android:textSize="28sp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btn_submit" />
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <Button-->
|
|
||||||
<!-- android:id="@+id/btn_buffer"-->
|
<!-- android:id="@+id/btn_buffer"-->
|
||||||
<!-- android:layout_width="wrap_content"-->
|
<!-- android:layout_width="wrap_content"-->
|
||||||
<!-- android:layout_height="wrap_content"-->
|
<!-- android:layout_height="wrap_content"-->
|
||||||
|
|||||||
@@ -190,5 +190,8 @@
|
|||||||
<string name="test_completed">Test Completed</string>
|
<string name="test_completed">Test Completed</string>
|
||||||
<string name="select_blood_group">Select Blood Group</string>
|
<string name="select_blood_group">Select Blood Group</string>
|
||||||
<string name="all_registered_user_are_tested_successfully">All registered user are tested successfully</string>
|
<string name="all_registered_user_are_tested_successfully">All registered user are tested successfully</string>
|
||||||
|
<string name="venous_blood">Venous Blood</string>
|
||||||
|
<string name="finger_prick_blood">Finger Prick Blood</string>
|
||||||
|
<string name="select_blood_collecting_method">Select blood collecting method</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user