Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3126 refactor config registry #3249

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5b58896
wip - refactoring down sync config
AbdulWahabMemon Apr 15, 2024
1a6576a
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon Apr 15, 2024
1ad23fa
wip-assistInject
AbdulWahabMemon Apr 15, 2024
ce62746
Sync by Download Manager POC
ndegwamartin Apr 15, 2024
9ee7121
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon Apr 15, 2024
088fb9b
wip - resolve cyclic injection error,
AbdulWahabMemon Apr 17, 2024
08e91e2
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon Apr 17, 2024
a53ca0c
refactor config-registry syncing - WIP
AbdulWahabMemon Apr 22, 2024
83a2d5e
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon Apr 22, 2024
0acb800
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon Apr 29, 2024
7314bf3
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 2, 2024
629baf8
WIP - 2nd May 2024 refactoring
AbdulWahabMemon May 4, 2024
61b45e1
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 4, 2024
1dfe251
refactor configRegistry processComposition, processCompositionList, a…
AbdulWahabMemon May 6, 2024
334deda
wip
AbdulWahabMemon May 6, 2024
39838d8
wip sync last changes tested
AbdulWahabMemon May 7, 2024
7685830
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 7, 2024
3288763
resolve merge conflicts - configRegistry from main
AbdulWahabMemon May 7, 2024
855695d
resolved conflicts for new implementation after merging main
AbdulWahabMemon May 8, 2024
ad647c6
wip log updates for testing
AbdulWahabMemon May 8, 2024
7810147
fetchNonFlow fun from main to compare
AbdulWahabMemon May 8, 2024
aa5015f
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 8, 2024
70a840e
rename fun
AbdulWahabMemon May 9, 2024
c4dadbf
resolve fetching multiple binaries from compositionList
AbdulWahabMemon May 9, 2024
e482d02
refactoring
AbdulWahabMemon May 13, 2024
c7c0c8e
clear logs
AbdulWahabMemon May 13, 2024
7c6e1a8
clear logs
AbdulWahabMemon May 13, 2024
f1d34ea
clear logs and refactor imports
AbdulWahabMemon May 13, 2024
a00ef68
fixed failing injections for unit tests
AbdulWahabMemon May 13, 2024
8c38a9c
fix imports - spotlessApply
AbdulWahabMemon May 13, 2024
20fe6a9
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 14, 2024
c0efdc5
fix Tests class dependencies after main merge
AbdulWahabMemon May 14, 2024
ebd4b69
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 14, 2024
1d74003
refactor after merging main
AbdulWahabMemon May 14, 2024
6bb4306
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 14, 2024
bf4d995
rename fun and data-properties
AbdulWahabMemon May 14, 2024
aaac16a
syncParams pairs via mutableMap
AbdulWahabMemon May 14, 2024
2868a1d
renaming attribute missed in last commit
AbdulWahabMemon May 15, 2024
71735af
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 15, 2024
2cb375d
rename funs and props,
AbdulWahabMemon May 15, 2024
3bb9387
Merge branch 'main' into 3126-refactor-configRegistry
AbdulWahabMemon May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.WorkerParameters
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.sync.AcceptLocalConflictResolver
import com.google.android.fhir.sync.ConflictResolver
import com.google.android.fhir.sync.DownloadWorkManager
import com.google.android.fhir.sync.FhirSyncWorker
import com.google.android.fhir.sync.upload.UploadStrategy
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.hl7.fhir.r4.model.ResourceType

@HiltWorker
class CompListItemSyncWorker
@AssistedInject
constructor(
@Assisted appContext: Context,
@Assisted workerParams: WorkerParameters,
private val openSrpFhirEngine: FhirEngine,
private val appTimeStampContext: AppTimeStampContext,
private val syncParamSource: SyncParamSource
) : FhirSyncWorker(appContext, workerParams) {

override fun getConflictResolver(): ConflictResolver = AcceptLocalConflictResolver

override fun getDownloadWorkManager(): DownloadWorkManager =
OpenSrpDownloadManager(
syncParams = loadCompositionListParams(),
context = appTimeStampContext,
)

override fun getFhirEngine(): FhirEngine = openSrpFhirEngine

override fun getUploadStrategy(): UploadStrategy = UploadStrategy.AllChangesSquashedBundlePut

private fun loadCompositionListParams(): Map<ResourceType, Map<String, String>> {
return syncParamSource.compListItemRequestQue.pop()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.WorkerParameters
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.sync.AcceptLocalConflictResolver
import com.google.android.fhir.sync.ConflictResolver
import com.google.android.fhir.sync.DownloadWorkManager
import com.google.android.fhir.sync.FhirSyncWorker
import com.google.android.fhir.sync.upload.UploadStrategy
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.hl7.fhir.r4.model.ResourceType

@HiltWorker
class CompositionConfigSyncWorker
@AssistedInject
constructor(
@Assisted appContext: Context,
@Assisted workerParams: WorkerParameters,
private val openSrpFhirEngine: FhirEngine,
private val appTimeStampContext: AppTimeStampContext,
private val syncParamSource: SyncParamSource
) : FhirSyncWorker(appContext, workerParams) {

override fun getConflictResolver(): ConflictResolver = AcceptLocalConflictResolver

override fun getDownloadWorkManager(): DownloadWorkManager =
OpenSrpDownloadManager(
syncParams = loadCompositionConfigParams(),
context = appTimeStampContext,
)

override fun getFhirEngine(): FhirEngine = openSrpFhirEngine

override fun getUploadStrategy(): UploadStrategy = UploadStrategy.AllChangesSquashedBundlePut

private fun loadCompositionConfigParams(): Map<ResourceType, Map<String, String>> {
return syncParamSource.compConfigRequestQue.pop()
// return syncParamSource.compositionConfigSyncParameters
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.WorkerParameters
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.sync.AcceptLocalConflictResolver
import com.google.android.fhir.sync.ConflictResolver
import com.google.android.fhir.sync.DownloadWorkManager
import com.google.android.fhir.sync.FhirSyncWorker
import com.google.android.fhir.sync.upload.UploadStrategy
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.hl7.fhir.r4.model.ResourceType

@HiltWorker
class CompositionListSyncWorker
@AssistedInject
constructor(
@Assisted appContext: Context,
@Assisted workerParams: WorkerParameters,
private val openSrpFhirEngine: FhirEngine,
private val appTimeStampContext: AppTimeStampContext,
private val syncParamSource: SyncParamSource
) : FhirSyncWorker(appContext, workerParams) {

override fun getConflictResolver(): ConflictResolver = AcceptLocalConflictResolver

override fun getDownloadWorkManager(): DownloadWorkManager =
OpenSrpDownloadManager(
syncParams = loadCompositionListParams(),
context = appTimeStampContext,
)

override fun getFhirEngine(): FhirEngine = openSrpFhirEngine

override fun getUploadStrategy(): UploadStrategy = UploadStrategy.AllChangesSquashedBundlePut

private fun loadCompositionListParams(): Map<ResourceType, Map<String, String>> {
return syncParamSource.compListRequestQue.pop()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.WorkerParameters
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.sync.AcceptLocalConflictResolver
import com.google.android.fhir.sync.ConflictResolver
import com.google.android.fhir.sync.DownloadWorkManager
import com.google.android.fhir.sync.FhirSyncWorker
import com.google.android.fhir.sync.upload.UploadStrategy
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.hl7.fhir.r4.model.ResourceType

@HiltWorker
class CompositionManifestSyncWorker
@AssistedInject
constructor(
@Assisted appContext: Context,
@Assisted workerParams: WorkerParameters,
private val openSrpFhirEngine: FhirEngine,
private val appTimeStampContext: AppTimeStampContext,
private val syncParamSource: SyncParamSource
) : FhirSyncWorker(appContext, workerParams) {

override fun getConflictResolver(): ConflictResolver = AcceptLocalConflictResolver

override fun getDownloadWorkManager(): DownloadWorkManager =
OpenSrpDownloadManager(
syncParams = loadCompositionManifestParams(),
context = appTimeStampContext,
)

override fun getFhirEngine(): FhirEngine = openSrpFhirEngine

override fun getUploadStrategy(): UploadStrategy = UploadStrategy.AllChangesSquashedBundlePut

private fun loadCompositionManifestParams(): Map<ResourceType, Map<String, String>> {
return syncParamSource.compositionManifestSyncPairs
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.WorkerParameters
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.sync.AcceptLocalConflictResolver
import com.google.android.fhir.sync.ConflictResolver
import com.google.android.fhir.sync.DownloadWorkManager
import com.google.android.fhir.sync.FhirSyncWorker
import com.google.android.fhir.sync.upload.UploadStrategy
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.hl7.fhir.r4.model.Composition
import org.hl7.fhir.r4.model.ResourceType
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import timber.log.Timber

@HiltWorker
class CompositionSyncWorker
@AssistedInject
constructor(
@Assisted appContext: Context,
@Assisted workerParams: WorkerParameters,
private val openSrpFhirEngine: FhirEngine,
private val appTimeStampContext: AppTimeStampContext,
val sharedPreferencesHelper: SharedPreferencesHelper,
private val syncParamSource: SyncParamSource
) : FhirSyncWorker(appContext, workerParams) {

override fun getConflictResolver(): ConflictResolver = AcceptLocalConflictResolver

override fun getDownloadWorkManager(): DownloadWorkManager =
OpenSrpDownloadManager(
syncParams = loadConfigSyncParams(),
context = appTimeStampContext,
)

override fun getFhirEngine(): FhirEngine = openSrpFhirEngine

override fun getUploadStrategy(): UploadStrategy = UploadStrategy.AllChangesSquashedBundlePut

private fun loadConfigSyncParams(): Map<ResourceType, Map<String, String>> {

Timber.d("Composition loadConfigSyncParams")
val pairs = mutableListOf<Pair<ResourceType, Map<String, String>>>()
// val urlPath =
// "${ResourceType.Composition.name}?${Composition.SP_IDENTIFIER}=$appId&_count=${ConfigurationRegistry.DEFAULT_COUNT}"
sharedPreferencesHelper.read(SharedPreferenceKey.APP_ID.name, null)?.let { appId ->
val parsedAppId = appId.substringBefore(ConfigurationRegistry.TYPE_REFERENCE_DELIMITER).trim()
pairs.add(
Pair(
ResourceType.Composition,
mapOf(Composition.SP_IDENTIFIER to parsedAppId),
),
)
pairs.add(
Pair(
ResourceType.Composition,
mapOf("_count" to ConfigurationRegistry.DEFAULT_COUNT.toString()),
),
)
}
// GET /StructureMap?_count=37
return mapOf(*pairs.toTypedArray())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import com.google.android.fhir.sync.DownloadWorkManager
import com.google.android.fhir.sync.download.DownloadRequest
import com.google.android.fhir.sync.download.ResourceParamsBasedDownloadWorkManager
import com.google.android.fhir.sync.download.ResourceSearchParams
import org.hl7.fhir.r4.model.Resource
import org.hl7.fhir.r4.model.ResourceType
import org.smartregister.fhircore.engine.util.extension.updateLastUpdated

class ConfigDownloadManager(
syncParams: ResourceSearchParams,
val context: ResourceParamsBasedDownloadWorkManager.TimestampContext
) : DownloadWorkManager {

private val downloadWorkManager = ResourceParamsBasedDownloadWorkManager(syncParams, context)

override suspend fun getNextRequest(): DownloadRequest? = downloadWorkManager.getNextRequest()

override suspend fun getSummaryRequestUrls(): Map<ResourceType, String> =
downloadWorkManager.getSummaryRequestUrls()

override suspend fun processResponse(response: Resource): Collection<Resource> {
return downloadWorkManager.processResponse(response).onEach { it.updateLastUpdated() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.sync

import org.hl7.fhir.r4.model.ResourceType

data class ResTypeId(val type: ResourceType, var id: String)
Loading
Loading