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"
|
applicationId "in.sminnovations.hpostesting.dev"
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 112
|
versionCode 113
|
||||||
versionName "2.1.112"
|
versionName "2.1.113"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,10 +123,11 @@
|
|||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.HOME" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<!-- <category android:name="android.intent.category.HOME" />-->
|
||||||
<category android:name="android.intent.category.MONKEY"/>
|
<!-- <category android:name="android.intent.category.DEFAULT" />-->
|
||||||
<category android:name="android.intent.category.LAUNCHER_APP" />
|
<!-- <category android:name="android.intent.category.MONKEY"/>-->
|
||||||
|
<!-- <category android:name="android.intent.category.LAUNCHER_APP" />-->
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
|
|||||||
@@ -144,45 +144,54 @@ class HomeFragment : Fragment() {
|
|||||||
checkForTokenAndUpdate()
|
checkForTokenAndUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { originalUserDataList ->
|
||||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
// 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 ->
|
userDataList.forEach { userData ->
|
||||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
// Ensure we process each user only once
|
||||||
resultList.results?.add(
|
if (!processedUserIds.contains(userData._id)) {
|
||||||
MolbioV2Result(
|
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||||
rawData = userData,
|
val currentTimeFormatted = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()).format(Calendar.getInstance().time)
|
||||||
analysisId = userData._id,
|
val bufferIntensityThreshold = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId]?.toString() ?: "defaultThreshold" // Handle possible nulls safely
|
||||||
analysisDate = SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
resultList.results?.add(
|
||||||
).format(Calendar.getInstance().time),
|
MolbioV2Result(
|
||||||
analysisStatus = userData.classificationResult,
|
rawData = userData,
|
||||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
analysisId = userData._id,
|
||||||
interpretation = userData.classificationResult,
|
analysisDate = currentTimeFormatted,
|
||||||
testId = userData._id,
|
analysisStatus = userData.classificationResult ?: "defaultStatus", // Handle possible nulls
|
||||||
testTime = SimpleDateFormat(
|
thresholds = bufferIntensityThreshold,
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
interpretation = userData.classificationResult ?: "defaultInterpretation", // Handle possible nulls
|
||||||
).format(Calendar.getInstance().time),
|
testId = userData._id,
|
||||||
collectionTime = SimpleDateFormat(
|
testTime = currentTimeFormatted,
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
collectionTime = currentTimeFormatted,
|
||||||
).format(Calendar.getInstance().time),
|
expiryTime = currentTimeFormatted
|
||||||
expiryTime = SimpleDateFormat(
|
)
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.getDefault()
|
|
||||||
).format(Calendar.getInstance().time)
|
|
||||||
)
|
)
|
||||||
)
|
// Mark this userData as processed to avoid re-processing
|
||||||
}
|
processedUserIds.add(userData._id)
|
||||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
}
|
||||||
userData.molbioFlag = true
|
|
||||||
hemoCubeViewModel.uploadResult(resultList)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!userData.localFlag) {
|
// Mark the userData for localFlag update, this will be handled in bulk after the loop
|
||||||
userData.localFlag = true
|
if (!userData.localFlag) {
|
||||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
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 {
|
} 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 ->
|
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { kitDataList ->
|
||||||
kitDataList.forEach { userData ->
|
kitDataList.forEach { userData ->
|
||||||
if (!userData.localFlag) {
|
if (!userData.localFlag) {
|
||||||
@@ -875,36 +851,6 @@ class HomeFragment : Fragment() {
|
|||||||
dialog.dismiss()
|
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) {
|
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||||
|
|||||||
Reference in New Issue
Block a user