Skip to content

Commit

Permalink
Merge branch 'harmonize-sync-status' of github.com:opensrp/fhircore i…
Browse files Browse the repository at this point in the history
…nto harmonize-sync-status
  • Loading branch information
dubdabasoduba committed Jan 31, 2025
2 parents a1edb38 + e1574c3 commit f7642cc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,23 @@ constructor(
return Pair(customResourceSearchParams, fhirResourceSearchParams)
}

/**
* This function returns either '1' or '2' depending on whether there are custom resources (not
* included in ResourceType enum) in the sync configuration. The custom resources are configured
* in the sync configuration JSON file as valid FHIR SearchParameter of type 'special'. If there
* are custom resources to be synced with the data, the application will first download the custom
* resources then the rest of the app data.
*/
fun retrieveTotalSyncCount(): Int {
val totalSyncCount = sharedPreferencesHelper.read(SharedPreferenceKey.TOTAL_SYNC_COUNT.name, "")
return if (totalSyncCount.isNullOrBlank()) {
retrieveResourceConfiguration<Parameters>(ConfigType.Sync)
.parameter
.map { it.resource as SearchParameter }
.count { it.hasType() && it.type == Enumerations.SearchParamType.SPECIAL }
} else totalSyncCount.toInt()
}

companion object {
const val BASE_CONFIG_PATH = "configs/%s"
const val COMPOSITION_CONFIG_PATH = "configs/%s/composition_config.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ constructor(
}
onSyncListener.onSync(
SyncState(
counter = SYNC_COUNTER_2,
counter = configurationRegistry.retrieveTotalSyncCount(),
currentSyncJobStatus = currentSyncJobStatus,
),
)
Expand All @@ -137,7 +137,7 @@ constructor(
syncListenerManager.onSyncListeners.forEach { onSyncListener ->
onSyncListener.onSync(
SyncState(
counter = SYNC_COUNTER_2,
counter = configurationRegistry.retrieveTotalSyncCount(),
currentSyncJobStatus = currentSyncJobStatus,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ package org.smartregister.fhircore.engine.sync
import com.google.android.fhir.sync.CurrentSyncJobStatus

const val SYNC_COUNTER_1 = 1
const val SYNC_COUNTER_2 = 2

data class SyncState(val counter: Int, val currentSyncJobStatus: CurrentSyncJobStatus)
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import kotlin.time.Duration
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.hl7.fhir.r4.model.Parameters
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.hl7.fhir.r4.model.Task
import org.smartregister.fhircore.engine.R
Expand Down Expand Up @@ -408,7 +407,7 @@ constructor(
AppDrawerUIState(
isSyncUpload = isSyncUpload,
syncCounter = syncCounter,
totalSyncCount = retrieveTotalSyncCount(),
totalSyncCount = configurationRegistry.retrieveTotalSyncCount(),
currentSyncJobStatus = currentSyncJobStatus,
percentageProgress = percentageProgress,
)
Expand Down Expand Up @@ -487,23 +486,6 @@ constructor(
}
}

/**
* This function returns either '1' or '2' depending on whether there are custom resources (not
* included in ResourceType enum) in the sync configuration. The custom resources are configured
* in the sync configuration JSON file as valid FHIR SearchParameter of type 'special'. If there
* are custom resources to be synced with the data, the application will first download the custom
* resources then the rest of the app data.
*/
private fun retrieveTotalSyncCount(): Int {
val totalSyncCount = sharedPreferencesHelper.read(SharedPreferenceKey.TOTAL_SYNC_COUNT.name, "")
return if (totalSyncCount.isNullOrBlank()) {
configurationRegistry
.retrieveResourceConfiguration<Parameters>(ConfigType.Sync)
.parameter
.count { it.hasType() }
} else totalSyncCount.toInt()
}

companion object {
private const val INITIAL_DELAY = 15L
const val SYNC_TIMESTAMP_INPUT_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"
Expand Down

0 comments on commit f7642cc

Please sign in to comment.