added code related offline bulkupload
This commit is contained in:
@@ -135,37 +135,59 @@ class HomeFragment : Fragment() {
|
|||||||
checkForTokenAndUpdate()
|
checkForTokenAndUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { originalUserDataList ->
|
||||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
|
||||||
userDataList.forEach { userData ->
|
Log.d("LOCAL_DB OBSERVE", "OBSERVE CALLED")
|
||||||
|
|
||||||
|
val resultList = MolbioV2ResultRequest(mutableListOf())
|
||||||
|
originalUserDataList.forEach { userData ->
|
||||||
|
Log.d(
|
||||||
|
": USER DATA",
|
||||||
|
originalUserDataList.count().toString() + " : " + userData._id
|
||||||
|
)
|
||||||
|
|
||||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||||
|
val currentTimeFormatted = SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
|
Locale.getDefault()
|
||||||
|
).format(Calendar.getInstance().time)
|
||||||
|
val bufferIntensityThreshold =
|
||||||
|
Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId]?.toString()
|
||||||
|
?: "defaultThreshold" // Handle possible nulls safely
|
||||||
resultList.results?.add(
|
resultList.results?.add(
|
||||||
MolbioV2Result(
|
MolbioV2Result(
|
||||||
rawData = userData,
|
rawData = userData,
|
||||||
analysisId = userData._id,
|
analysisId = userData._id,
|
||||||
analysisDate = "2024-02-08 16:33:56",//userData.testTime,
|
analysisDate = currentTimeFormatted,
|
||||||
analysisStatus = userData.classificationResult,
|
analysisStatus = userData.classificationResult
|
||||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
?: "defaultStatus", // Handle possible nulls
|
||||||
interpretation = userData.classificationResult,
|
thresholds = bufferIntensityThreshold,
|
||||||
|
interpretation = userData.classificationResult
|
||||||
|
?: "defaultInterpretation", // Handle possible nulls
|
||||||
testId = userData._id,
|
testId = userData._id,
|
||||||
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
testTime = currentTimeFormatted,
|
||||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
collectionTime = currentTimeFormatted,
|
||||||
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
expiryTime = currentTimeFormatted
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
|
||||||
userData.molbioFlag = true
|
|
||||||
hemoCubeViewModel.uploadResult(resultList)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!userData.localFlag) {
|
|
||||||
userData.localFlag = true
|
|
||||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Log.d("USER DATA LIST SIZE", resultList.results?.count().toString())
|
||||||
|
|
||||||
|
resultList.results?.forEach { result ->
|
||||||
|
val userData = result.rawData
|
||||||
|
Log.d("UserData", userData.toString())
|
||||||
|
if (userData != null) {
|
||||||
|
if (!userData.localFlag) {
|
||||||
|
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||||
|
userData.localFlag = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
||||||
|
if (resultList.results?.isNotEmpty() == true) {
|
||||||
|
hemoCubeViewModel.uploadResult(resultList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user