duplicate data coming issue got resolved for molbio and firebase
This commit is contained in:
@@ -19,8 +19,8 @@ android {
|
||||
applicationId "in.sminnovations.hpostesting.dev"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 112
|
||||
versionName "2.1.112"
|
||||
versionCode 113
|
||||
versionName "2.1.113"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -123,10 +123,11 @@
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.MONKEY"/>
|
||||
<category android:name="android.intent.category.LAUNCHER_APP" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<!-- <category android:name="android.intent.category.HOME" />-->
|
||||
<!-- <category android:name="android.intent.category.DEFAULT" />-->
|
||||
<!-- <category android:name="android.intent.category.MONKEY"/>-->
|
||||
<!-- <category android:name="android.intent.category.LAUNCHER_APP" />-->
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
|
||||
@@ -144,45 +144,54 @@ class HomeFragment : Fragment() {
|
||||
checkForTokenAndUpdate()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { originalUserDataList ->
|
||||
// Ensure the list does not contain duplicates based on _id
|
||||
val userDataList = originalUserDataList.distinctBy { it._id }
|
||||
|
||||
// Initialize the resultList outside of the loop to avoid duplicates
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf())
|
||||
val processedUserIds = mutableSetOf<String>() // To track processed users based on _id
|
||||
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time),
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time),
|
||||
collectionTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time),
|
||||
expiryTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
// Ensure we process each user only once
|
||||
if (!processedUserIds.contains(userData._id)) {
|
||||
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(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = currentTimeFormatted,
|
||||
analysisStatus = userData.classificationResult ?: "defaultStatus", // Handle possible nulls
|
||||
thresholds = bufferIntensityThreshold,
|
||||
interpretation = userData.classificationResult ?: "defaultInterpretation", // Handle possible nulls
|
||||
testId = userData._id,
|
||||
testTime = currentTimeFormatted,
|
||||
collectionTime = currentTimeFormatted,
|
||||
expiryTime = currentTimeFormatted
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
// Mark this userData as processed to avoid re-processing
|
||||
processedUserIds.add(userData._id)
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
// Mark the userData for localFlag update, this will be handled in bulk after the loop
|
||||
if (!userData.localFlag) {
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
userData.localFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Perform bulk operations after the loop
|
||||
// Set localFlag to true for all usersToUpdate and perform bulk database upd
|
||||
|
||||
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
||||
if (resultList.results?.isNotEmpty() == true) {
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -832,39 +841,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = "2024-02-08 16:33:56", //userData.reportUploadTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { kitDataList ->
|
||||
kitDataList.forEach { userData ->
|
||||
if (!userData.localFlag) {
|
||||
@@ -875,36 +851,6 @@ class HomeFragment : Fragment() {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = "2024-02-08 16:33:56",//userData.testTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
||||
)
|
||||
)
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||
|
||||
Reference in New Issue
Block a user