Make some changes token changes and added feature for multi result upload
This commit is contained in:
@@ -16,7 +16,7 @@ android {
|
||||
|
||||
// prod - production, preprod - preproduction, quality - qc, dev - development
|
||||
defaultConfig {
|
||||
applicationId "in.sminnovations.hpostesting.preprod"
|
||||
applicationId "in.sminnovations.hpostesting.dev"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 91
|
||||
|
||||
@@ -79,7 +79,7 @@ object Constants {
|
||||
"HC-V1-018",
|
||||
"HC-V1-019",
|
||||
"HC-V1-020",
|
||||
"HCV-000-3001",
|
||||
"HCV-000-1015",
|
||||
"HCV-000-3002",
|
||||
"HCV-000-3003",
|
||||
"HCV-000-3004",
|
||||
@@ -283,7 +283,7 @@ object Constants {
|
||||
listOf(0.2304, -0.0145), // LED3, 555nm
|
||||
listOf(1.0, 0.0) // LED4
|
||||
),
|
||||
"HCV-000-3019" to listOf(
|
||||
"HCV-000-1015" to listOf(
|
||||
listOf(1.7272, -1.1977), // LED1, 435nm
|
||||
listOf(0.581462456, -0.58502), // LED2, 415nm
|
||||
listOf(0.2304, -0.0145), // LED3, 555nm
|
||||
@@ -796,7 +796,7 @@ object Constants {
|
||||
listOf(0.1964, 0.011565), // LED3, 555nm
|
||||
listOf(1.0, 0.0) // LED4
|
||||
),
|
||||
"HCV-000-3024" to listOf(
|
||||
"HCV-000-1015" to listOf(
|
||||
listOf(1.7272, -1.1977), // LED1, 435nm
|
||||
listOf(0.581462456, -0.58502), // LED2, 415nm
|
||||
listOf(0.2304, -0.0145), // LED3, 555nm
|
||||
@@ -1222,7 +1222,7 @@ object Constants {
|
||||
listOf(24500, 26250),
|
||||
listOf(24500, 26250),
|
||||
),
|
||||
"HCV-000-3013" to listOf(
|
||||
"HCV-000-1015" to listOf(
|
||||
listOf(24500, 26250),
|
||||
listOf(24500, 26250),
|
||||
listOf(24500, 26250),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.example.hpostesting.data.model.molbioresult
|
||||
|
||||
data class MolbioV2ResultRequest(
|
||||
val results: List<MolbioV2Result>? = listOf()
|
||||
val results: MutableList<MolbioV2Result>? = mutableListOf()
|
||||
)
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.hpostesting.presentation.dashboard
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
@@ -30,6 +31,7 @@ class GalleryFragment : Fragment() {
|
||||
|
||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.login.LoginRequest
|
||||
import com.example.hpostesting.data.model.login.LoginResponse
|
||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2Result
|
||||
import com.example.hpostesting.data.model.molbioresult.MolbioV2ResultRequest
|
||||
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||
import com.example.hpostesting.data.model.patient.UserData
|
||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
||||
@@ -56,6 +58,7 @@ class HomeFragment : Fragment() {
|
||||
0 // Initialize with a default value, or obtain the actual battery level
|
||||
private lateinit var adapter: OfflineUserListAdapter
|
||||
|
||||
private var isTokenAvailable = false
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
@@ -142,18 +145,16 @@ class HomeFragment : Fragment() {
|
||||
|
||||
private fun checkForTokenAndUpdate() {
|
||||
val accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||
val natsToken = sharedPreference.getString(Constants.NATS_TOKEN, "").toString()
|
||||
val natsTokenExpireDate =
|
||||
sharedPreference.getString(Constants.NATS_TOKEN_EXPIRE_DATE, "").toString()
|
||||
val password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||
val userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||
if (userID.isNotEmpty() && password.isNotEmpty()) {
|
||||
if (accessToken.isEmpty() && natsToken.isEmpty()) {
|
||||
if (accessToken.isEmpty()) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
if (isTokenExpired(accessToken)) {
|
||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||
} else {
|
||||
isTokenAvailable = true
|
||||
hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
@@ -174,8 +175,9 @@ class HomeFragment : Fragment() {
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred in login: $message", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
Toast.makeText(
|
||||
activity, "An error occurred in login: $message", Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,8 +200,9 @@ class HomeFragment : Fragment() {
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred check update: $message", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
Toast.makeText(
|
||||
activity, "An error occurred check update: $message", Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,8 +226,11 @@ class HomeFragment : Fragment() {
|
||||
|
||||
is Result.Error -> {
|
||||
response.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred in uploading logs: $message", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
Toast.makeText(
|
||||
activity,
|
||||
"An error occurred in uploading logs: $message",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,6 +241,31 @@ class HomeFragment : Fragment() {
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
it.data.data?.forEach { id ->
|
||||
id.rawData?.let { it1 ->
|
||||
hemoCubeViewModel.updateMolbioFlag(
|
||||
it1._id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
//Remove this line of code while deploying to IOCL
|
||||
it.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isTokenExpired(token: String): Boolean {
|
||||
@@ -253,11 +284,11 @@ class HomeFragment : Fragment() {
|
||||
putString(Constants.ACCESS_TOKEN, response.data.data?.accessToken)
|
||||
putString(Constants.NATS_TOKEN, response.data.data?.deviceUser?.natsToken)
|
||||
putString(
|
||||
Constants.NATS_TOKEN_EXPIRE_DATE,
|
||||
response.data.data?.deviceUser?.natsTokenExpiry
|
||||
Constants.NATS_TOKEN_EXPIRE_DATE, response.data.data?.deviceUser?.natsTokenExpiry
|
||||
)
|
||||
apply()
|
||||
}
|
||||
isTokenAvailable = true
|
||||
}
|
||||
|
||||
private fun createLoginRequestData(userID: String, password: String): LoginRequest {
|
||||
@@ -266,10 +297,7 @@ class HomeFragment : Fragment() {
|
||||
)
|
||||
val version = pInfo.versionName
|
||||
return LoginRequest(
|
||||
password = password,
|
||||
serialNumber = userID,
|
||||
username = userID,
|
||||
version = version
|
||||
password = password, serialNumber = userID, username = userID, version = version
|
||||
)
|
||||
}
|
||||
|
||||
@@ -469,7 +497,7 @@ class HomeFragment : Fragment() {
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val uploadDataVisibility =
|
||||
if (userDataList.any { !it.localFlag && it.testStatus == true }) View.VISIBLE else View.GONE
|
||||
if (userDataList.any { !it.localFlag && !it.molbioFlag && it.testStatus == true }) View.VISIBLE else View.GONE
|
||||
binding.uploadData.visibility = uploadDataVisibility
|
||||
}
|
||||
|
||||
@@ -514,12 +542,32 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
if (!userData.molbioFlag && isTokenAvailable) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = userData.testTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = userData.testTime,
|
||||
collectionTime = userData.testTime,
|
||||
expiryTime = userData.testTime,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isTokenAvailable) {
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
|
||||
@@ -149,11 +149,11 @@ class DeviceProvisionFragment : Fragment() {
|
||||
private fun handleUsbData() {
|
||||
when {
|
||||
resultData.contains("SNE") -> {
|
||||
val pattern = Regex("HPP1-\\d{4}-\\d{4}")
|
||||
val pattern = Regex("HCV-\\d{3}-\\d{4}")
|
||||
val matchResult = pattern.find(resultData)
|
||||
val hardwareId = matchResult?.value
|
||||
|
||||
if (hardwareId.toString().length == 14) {
|
||||
if (hardwareId.toString().length == 12) {
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.DEVICE_ID, hardwareId)
|
||||
apply()
|
||||
|
||||
@@ -302,7 +302,7 @@ class HemoCubeViewModel @Inject constructor(
|
||||
testDetails.localFlag = true
|
||||
uploadResult(
|
||||
MolbioV2ResultRequest(
|
||||
listOf(
|
||||
mutableListOf(
|
||||
MolbioV2Result(
|
||||
rawData = testDetails,
|
||||
analysisId = testDetails._id,
|
||||
|
||||
Reference in New Issue
Block a user