Merge remote-tracking branch 'origin/dev-tmp' into dev
This commit is contained in:
@@ -84,7 +84,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",
|
||||
@@ -301,7 +301,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
|
||||
@@ -820,7 +820,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
|
||||
@@ -1246,7 +1246,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()
|
||||
)
|
||||
@@ -22,6 +22,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
|
||||
@@ -58,6 +60,9 @@ class HomeFragment : Fragment() {
|
||||
0 // Initialize with a default value, or obtain the actual battery level
|
||||
private lateinit var adapter: OfflineUserListAdapter
|
||||
private val homeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
|
||||
private var isTokenAvailable = false
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
@@ -185,18 +190,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()
|
||||
@@ -290,6 +293,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 {
|
||||
@@ -308,11 +336,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 {
|
||||
@@ -321,10 +349,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
|
||||
)
|
||||
}
|
||||
|
||||
@@ -524,7 +549,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
|
||||
}
|
||||
|
||||
@@ -594,12 +619,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()
|
||||
|
||||
@@ -316,7 +316,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