From f84505412bd4d49a5609bb3359943924e481e246 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:59:53 +0530 Subject: [PATCH 01/12] refactoring for upload request generator --- .../TimestampBasedDownloadWorkManagerImpl.kt | 2 +- .../fhir/benchmark/FhirSyncWorkerBenchmark.kt | 2 +- .../google/android/fhir/sync/DataSource.kt | 2 + .../android/fhir/sync/DownloadWorkManager.kt | 1 + .../DownloadRequest.kt} | 31 +----------- .../fhir/sync/download/DownloaderImpl.kt | 3 -- .../ResourceParamsBasedDownloadWorkManager.kt | 1 - .../fhir/sync/remote/FhirHttpDataSource.kt | 12 ++--- .../SquashedChangesUploadWorkManager.kt | 2 +- .../fhir/sync/upload/UploadWorkManager.kt | 2 +- .../request/TransactionBundleGenerator.kt | 26 ++++------ .../fhir/sync/upload/request/UploadRequest.kt | 48 +++++++++++++++++++ .../upload/request/UploadRequestGenerator.kt | 15 +++++- .../request/UploadRequestGeneratorMode.kt | 32 +++++++++++++ ...estGenerator.kt => UrlRequestGenerator.kt} | 21 ++++---- .../google/android/fhir/testing/Utilities.kt | 10 ++-- .../fhir/sync/download/DownloaderImplTest.kt | 5 +- ...ourceParamsBasedDownloadWorkManagerTest.kt | 1 - .../sync/remote/FhirHttpDataSourceTest.kt | 2 +- .../upload/request/IndividualGeneratorTest.kt | 12 ++--- 20 files changed, 140 insertions(+), 90 deletions(-) rename engine/src/main/java/com/google/android/fhir/sync/{Request.kt => download/DownloadRequest.kt} (75%) create mode 100644 engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt create mode 100644 engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt rename engine/src/main/java/com/google/android/fhir/sync/upload/request/{IndividualRequestGenerator.kt => UrlRequestGenerator.kt} (82%) diff --git a/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt b/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt index 144f11162c..29913bdd36 100644 --- a/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt +++ b/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt @@ -17,7 +17,7 @@ package com.google.android.fhir.demo.data import com.google.android.fhir.demo.DemoDataStore -import com.google.android.fhir.sync.DownloadRequest +import com.google.android.fhir.sync.download.DownloadRequest import com.google.android.fhir.sync.DownloadWorkManager import com.google.android.fhir.sync.SyncDataParams import java.time.ZoneId diff --git a/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt b/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt index 50b17a2cda..dc9a6fa682 100644 --- a/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt +++ b/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt @@ -32,9 +32,9 @@ import com.google.android.fhir.FhirEngineConfiguration import com.google.android.fhir.FhirEngineProvider import com.google.android.fhir.ServerConfiguration import com.google.android.fhir.sync.AcceptRemoteConflictResolver -import com.google.android.fhir.sync.DownloadRequest import com.google.android.fhir.sync.DownloadWorkManager import com.google.android.fhir.sync.FhirSyncWorker +import com.google.android.fhir.sync.download.DownloadRequest import com.google.common.truth.Truth.assertThat import java.math.BigDecimal import java.util.LinkedList diff --git a/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt b/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt index 34a8600fd2..dbcaa00965 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt @@ -16,6 +16,8 @@ package com.google.android.fhir.sync +import com.google.android.fhir.sync.download.DownloadRequest +import com.google.android.fhir.sync.upload.request.UploadRequest import org.hl7.fhir.r4.model.Bundle import org.hl7.fhir.r4.model.Bundle.BundleType import org.hl7.fhir.r4.model.OperationOutcome diff --git a/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt b/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt index ff7dc64a77..e950b20611 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt @@ -16,6 +16,7 @@ package com.google.android.fhir.sync +import com.google.android.fhir.sync.download.DownloadRequest import org.hl7.fhir.r4.model.Resource import org.hl7.fhir.r4.model.ResourceType diff --git a/engine/src/main/java/com/google/android/fhir/sync/Request.kt b/engine/src/main/java/com/google/android/fhir/sync/download/DownloadRequest.kt similarity index 75% rename from engine/src/main/java/com/google/android/fhir/sync/Request.kt rename to engine/src/main/java/com/google/android/fhir/sync/download/DownloadRequest.kt index 7cc693ecd2..2aca2849d9 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/Request.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/download/DownloadRequest.kt @@ -14,11 +14,9 @@ * limitations under the License. */ -package com.google.android.fhir.sync +package com.google.android.fhir.sync.download import org.hl7.fhir.r4.model.Bundle -import org.hl7.fhir.r4.model.Resource -import org.hl7.fhir.r4.model.codesystems.HttpVerb /** * Structure represents a request that can be made to download resources from the FHIR server. The @@ -84,30 +82,3 @@ internal constructor(val url: String, override val headers: Map data class BundleDownloadRequest internal constructor(val bundle: Bundle, override val headers: Map = emptyMap()) : DownloadRequest(headers) - -/** - * Structure represents a request that can be made to upload resources/resource modifications to the - * FHIR server. - */ -sealed class UploadRequest( - open val url: String, - open val headers: Map = emptyMap(), - open val resource: Resource, -) - -/** - * A FHIR [Bundle] based request for uploads. Multiple resources/resource modifications can be - * uploaded as a single request using this. - */ -data class BundleUploadRequest( - override val headers: Map = emptyMap(), - override val resource: Bundle, -) : UploadRequest(".", headers, resource) - -/** A [url] based FHIR request to upload resources to the server. */ -data class UrlUploadRequest( - val httpVerb: HttpVerb, - override val url: String, - override val resource: Resource, - override val headers: Map = emptyMap() -) : UploadRequest(url, headers, resource) diff --git a/engine/src/main/java/com/google/android/fhir/sync/download/DownloaderImpl.kt b/engine/src/main/java/com/google/android/fhir/sync/download/DownloaderImpl.kt index 9efb3c73cd..b8c667629b 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/download/DownloaderImpl.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/download/DownloaderImpl.kt @@ -16,14 +16,11 @@ package com.google.android.fhir.sync.download -import com.google.android.fhir.sync.BundleDownloadRequest import com.google.android.fhir.sync.DataSource -import com.google.android.fhir.sync.DownloadRequest import com.google.android.fhir.sync.DownloadState import com.google.android.fhir.sync.DownloadWorkManager import com.google.android.fhir.sync.Downloader import com.google.android.fhir.sync.ResourceSyncException -import com.google.android.fhir.sync.UrlDownloadRequest import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import org.hl7.fhir.r4.model.Bundle diff --git a/engine/src/main/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManager.kt b/engine/src/main/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManager.kt index de7052104f..25e93ed48f 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManager.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManager.kt @@ -16,7 +16,6 @@ package com.google.android.fhir.sync.download -import com.google.android.fhir.sync.DownloadRequest import com.google.android.fhir.sync.DownloadWorkManager import com.google.android.fhir.sync.GREATER_THAN_PREFIX import com.google.android.fhir.sync.ParamMap diff --git a/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt b/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt index bd969c7c7d..a5a30f2ec7 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt @@ -18,13 +18,13 @@ package com.google.android.fhir.sync.remote import com.fasterxml.jackson.databind.ObjectMapper import com.github.fge.jsonpatch.JsonPatch -import com.google.android.fhir.sync.BundleDownloadRequest -import com.google.android.fhir.sync.BundleUploadRequest import com.google.android.fhir.sync.DataSource -import com.google.android.fhir.sync.DownloadRequest -import com.google.android.fhir.sync.UploadRequest -import com.google.android.fhir.sync.UrlDownloadRequest -import com.google.android.fhir.sync.UrlUploadRequest +import com.google.android.fhir.sync.download.BundleDownloadRequest +import com.google.android.fhir.sync.download.DownloadRequest +import com.google.android.fhir.sync.download.UrlDownloadRequest +import com.google.android.fhir.sync.upload.request.BundleUploadRequest +import com.google.android.fhir.sync.upload.request.UploadRequest +import com.google.android.fhir.sync.upload.request.UrlUploadRequest import org.hl7.fhir.r4.model.Binary import org.hl7.fhir.r4.model.Resource import org.hl7.fhir.r4.model.codesystems.HttpVerb diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/SquashedChangesUploadWorkManager.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/SquashedChangesUploadWorkManager.kt index 9705c56a85..eac24a11cd 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/SquashedChangesUploadWorkManager.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/SquashedChangesUploadWorkManager.kt @@ -17,10 +17,10 @@ package com.google.android.fhir.sync.upload import com.google.android.fhir.LocalChange -import com.google.android.fhir.sync.UploadRequest import com.google.android.fhir.sync.upload.patch.Patch import com.google.android.fhir.sync.upload.patch.PerResourcePatchGenerator import com.google.android.fhir.sync.upload.request.TransactionBundleGenerator +import com.google.android.fhir.sync.upload.request.UploadRequest /** * [UploadWorkManager] implementation to squash all the changes at a resource level into one change diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/UploadWorkManager.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadWorkManager.kt index 88c1994a2f..2d8ca54feb 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/UploadWorkManager.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadWorkManager.kt @@ -17,8 +17,8 @@ package com.google.android.fhir.sync.upload import com.google.android.fhir.LocalChange -import com.google.android.fhir.sync.UploadRequest import com.google.android.fhir.sync.upload.patch.Patch +import com.google.android.fhir.sync.upload.request.UploadRequest /** * Manager that pre-processes the local FHIR changes and handles how to upload them to the server. diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt index 2f4a698b5f..14af20e05f 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt @@ -16,20 +16,15 @@ package com.google.android.fhir.sync.upload.request -import com.google.android.fhir.LocalChangeToken -import com.google.android.fhir.sync.BundleUploadRequest import com.google.android.fhir.sync.upload.patch.Patch import org.hl7.fhir.r4.model.Bundle -/** - * Generates list of [BundleUploadRequest] with Transaction [Bundle] and [LocalChangeToken]s - * associated with the resources present in the transaction bundle. - */ -class TransactionBundleGenerator( +/** Generates list of [BundleUploadRequest] of type Transaction [Bundle] from the [Patch]es */ +internal class TransactionBundleGenerator( private val generatedBundleSize: Int, private val useETagForUpload: Boolean, - private val getBundleEntryComponentGeneratorForLocalChangeType: - (type: Patch.Type, useETagForUpload: Boolean) -> BundleEntryComponentGenerator + private val getBundleEntryComponentGeneratorForPatch: + (patch: Patch, useETagForUpload: Boolean) -> BundleEntryComponentGenerator ) : UploadRequestGenerator { override fun generateUploadRequests(patches: List): List { @@ -41,10 +36,7 @@ class TransactionBundleGenerator( Bundle().apply { type = Bundle.BundleType.TRANSACTION patches.forEach { - this.addEntry( - getBundleEntryComponentGeneratorForLocalChangeType(it.type, useETagForUpload) - .getEntry(it) - ) + this.addEntry(getBundleEntryComponentGeneratorForPatch(it, useETagForUpload).getEntry(it)) } } return BundleUploadRequest( @@ -75,8 +67,8 @@ class TransactionBundleGenerator( fun getGenerator( httpVerbToUseForCreate: Bundle.HTTPVerb, httpVerbToUseForUpdate: Bundle.HTTPVerb, - generatedBundleSize: Int, - useETagForUpload: Boolean + generatedBundleSize: Int = 500, + useETagForUpload: Boolean = true ): TransactionBundleGenerator { val createFunction = @@ -91,8 +83,8 @@ class TransactionBundleGenerator( "Update using $httpVerbToUseForUpdate is not supported." ) - return TransactionBundleGenerator(generatedBundleSize, useETagForUpload) { type, useETag -> - when (type) { + return TransactionBundleGenerator(generatedBundleSize, useETagForUpload) { patch, useETag -> + when (patch.type) { Patch.Type.INSERT -> createFunction(useETag) Patch.Type.UPDATE -> updateFunction(useETag) Patch.Type.DELETE -> HttpDeleteEntryComponentGenerator(useETag) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt new file mode 100644 index 0000000000..3bada4334a --- /dev/null +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2023 Google LLC + * + * 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 com.google.android.fhir.sync.upload.request + +import org.hl7.fhir.r4.model.Bundle +import org.hl7.fhir.r4.model.Resource +import org.hl7.fhir.r4.model.codesystems.HttpVerb + +/** + * Structure represents a request that can be made to upload resources/resource modifications to the + * FHIR server. + */ +sealed class UploadRequest( + open val url: String, + open val headers: Map = emptyMap(), + open val resource: Resource, +) + +/** + * A FHIR [Bundle] based request for uploads. Multiple resources/resource modifications can be + * uploaded as a single request using this. + */ +data class BundleUploadRequest( + override val headers: Map = emptyMap(), + override val resource: Bundle, +) : UploadRequest(".", headers, resource) + +/** A [url] based FHIR request to upload resources to the server. */ +data class UrlUploadRequest( + val httpVerb: HttpVerb, + override val url: String, + override val resource: Resource, + override val headers: Map = emptyMap() +) : UploadRequest(url, headers, resource) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt index 5cad87079e..eb42220a62 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt @@ -16,11 +16,24 @@ package com.google.android.fhir.sync.upload.request -import com.google.android.fhir.sync.UploadRequest import com.google.android.fhir.sync.upload.patch.Patch /** Generator that generates [UploadRequest]s from the [Patch]es */ internal interface UploadRequestGenerator { /** Generates a list of [UploadRequest] from the [Patch]es */ fun generateUploadRequests(patches: List): List + + companion object { + internal fun byMode(mode: UploadRequestGeneratorMode): UploadRequestGenerator { + return when (mode) { + is UploadRequestGeneratorMode.UrlRequest -> + UrlRequestGenerator.getGenerator(mode.httpVerbToUseForCreate, mode.httpVerbToUseForUpdate) + is UploadRequestGeneratorMode.BundleRequest -> + TransactionBundleGenerator.getGenerator( + mode.httpVerbToUseForCreate, + mode.httpVerbToUseForUpdate + ) + } + } + } } diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt new file mode 100644 index 0000000000..bff772c6da --- /dev/null +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2023 Google LLC + * + * 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 com.google.android.fhir.sync.upload.request + +import org.hl7.fhir.r4.model.Bundle +import org.hl7.fhir.r4.model.codesystems.HttpVerb + +/** Mode to decide the type of [UploadRequest] that needs to be generated */ +sealed class UploadRequestGeneratorMode { + data class UrlRequest( + val httpVerbToUseForCreate: HttpVerb, + val httpVerbToUseForUpdate: HttpVerb + ) : UploadRequestGeneratorMode() + data class BundleRequest( + val httpVerbToUseForCreate: Bundle.HTTPVerb, + val httpVerbToUseForUpdate: Bundle.HTTPVerb + ) : UploadRequestGeneratorMode() +} diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/IndividualRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt similarity index 82% rename from engine/src/main/java/com/google/android/fhir/sync/upload/request/IndividualRequestGenerator.kt rename to engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt index b0e4b22e24..6d8bb64ed0 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/IndividualRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt @@ -19,19 +19,18 @@ package com.google.android.fhir.sync.upload.request import ca.uhn.fhir.context.FhirContext import ca.uhn.fhir.context.FhirVersionEnum import com.google.android.fhir.ContentTypes -import com.google.android.fhir.sync.UrlUploadRequest import com.google.android.fhir.sync.upload.patch.Patch import org.hl7.fhir.r4.model.Binary import org.hl7.fhir.r4.model.Resource import org.hl7.fhir.r4.model.codesystems.HttpVerb -/** Generates list of [UrlUploadRequest]s with for each [Patch] given. */ -class IndividualRequestGenerator( - private val getIndividualRequestForPatchType: (type: Patch.Type, patch: Patch) -> UrlUploadRequest +/** Generates list of [UrlUploadRequest]s for a list of [Patch]es. */ +internal class UrlRequestGenerator( + private val getUrlRequestForPatch: (patch: Patch) -> UrlUploadRequest ) : UploadRequestGenerator { override fun generateUploadRequests(patches: List): List = - patches.map { getIndividualRequestForPatchType(it.type, it) } + patches.map { getUrlRequestForPatch(it) } companion object Factory { @@ -51,14 +50,14 @@ class IndividualRequestGenerator( fun getDefault() = getGenerator(HttpVerb.PUT, HttpVerb.PATCH) /** - * Returns a [IndividualRequestGenerator] based on the provided [HttpVerb]s for creating and - * updating resources. The function may throw an [IllegalArgumentException] if the provided - * [HttpVerb]s are not supported. + * Returns a [UrlRequestGenerator] based on the provided [HttpVerb]s for creating and updating + * resources. The function may throw an [IllegalArgumentException] if the provided [HttpVerb]s + * are not supported. */ fun getGenerator( httpVerbToUseForCreate: HttpVerb, httpVerbToUseForUpdate: HttpVerb - ): IndividualRequestGenerator { + ): UrlRequestGenerator { val createFunction = createMapping[httpVerbToUseForCreate] @@ -72,8 +71,8 @@ class IndividualRequestGenerator( "Update using $httpVerbToUseForUpdate is not supported." ) - return IndividualRequestGenerator { type, patch -> - when (type) { + return UrlRequestGenerator { patch -> + when (patch.type) { Patch.Type.INSERT -> createFunction(patch) Patch.Type.UPDATE -> updateFunction(patch) Patch.Type.DELETE -> deleteFunction(patch) diff --git a/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt b/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt index 6b7a27ae57..b98b129ab9 100644 --- a/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt +++ b/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt @@ -25,14 +25,14 @@ import com.google.android.fhir.LocalChange import com.google.android.fhir.LocalChangeToken import com.google.android.fhir.SearchResult import com.google.android.fhir.search.Search -import com.google.android.fhir.sync.BundleDownloadRequest -import com.google.android.fhir.sync.BundleUploadRequest import com.google.android.fhir.sync.ConflictResolver import com.google.android.fhir.sync.DataSource -import com.google.android.fhir.sync.DownloadRequest import com.google.android.fhir.sync.DownloadWorkManager -import com.google.android.fhir.sync.UploadRequest -import com.google.android.fhir.sync.UrlDownloadRequest +import com.google.android.fhir.sync.download.BundleDownloadRequest +import com.google.android.fhir.sync.download.DownloadRequest +import com.google.android.fhir.sync.download.UrlDownloadRequest +import com.google.android.fhir.sync.upload.request.BundleUploadRequest +import com.google.android.fhir.sync.upload.request.UploadRequest import com.google.common.truth.Truth.assertThat import java.net.SocketTimeoutException import java.time.Instant diff --git a/engine/src/test/java/com/google/android/fhir/sync/download/DownloaderImplTest.kt b/engine/src/test/java/com/google/android/fhir/sync/download/DownloaderImplTest.kt index 2a3a7d9a01..1e5424f075 100644 --- a/engine/src/test/java/com/google/android/fhir/sync/download/DownloaderImplTest.kt +++ b/engine/src/test/java/com/google/android/fhir/sync/download/DownloaderImplTest.kt @@ -17,13 +17,10 @@ package com.google.android.fhir.sync.download import com.google.android.fhir.logicalId -import com.google.android.fhir.sync.BundleDownloadRequest import com.google.android.fhir.sync.DataSource -import com.google.android.fhir.sync.DownloadRequest import com.google.android.fhir.sync.DownloadState import com.google.android.fhir.sync.DownloadWorkManager -import com.google.android.fhir.sync.UploadRequest -import com.google.android.fhir.sync.UrlDownloadRequest +import com.google.android.fhir.sync.upload.request.UploadRequest import com.google.common.truth.Truth.assertThat import java.util.LinkedList import java.util.Queue diff --git a/engine/src/test/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManagerTest.kt b/engine/src/test/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManagerTest.kt index 53dd0d79d2..89a5e92228 100644 --- a/engine/src/test/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManagerTest.kt +++ b/engine/src/test/java/com/google/android/fhir/sync/download/ResourceParamsBasedDownloadWorkManagerTest.kt @@ -18,7 +18,6 @@ package com.google.android.fhir.sync.download import com.google.android.fhir.logicalId import com.google.android.fhir.sync.SyncDataParams -import com.google.android.fhir.sync.UrlDownloadRequest import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runBlockingTest import org.hl7.fhir.exceptions.FHIRException diff --git a/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt b/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt index 053da3c6df..8a2d2ef321 100644 --- a/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt +++ b/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt @@ -17,9 +17,9 @@ import ca.uhn.fhir.context.FhirContext import com.google.android.fhir.ContentTypes import com.google.android.fhir.NetworkConfiguration -import com.google.android.fhir.sync.UrlUploadRequest import com.google.android.fhir.sync.remote.FhirHttpDataSource import com.google.android.fhir.sync.remote.RetrofitHttpService +import com.google.android.fhir.sync.upload.request.UrlUploadRequest import com.google.android.fhir.testing.assertResourceEquals import com.google.common.truth.Truth.assertThat import java.net.HttpURLConnection diff --git a/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt b/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt index 211fdb4da0..23d2c1c09f 100644 --- a/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt +++ b/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt @@ -38,14 +38,14 @@ class IndividualGeneratorTest { @Test fun `should return empty list if there are no local changes`() = runTest { - val generator = IndividualRequestGenerator.getDefault() + val generator = UrlRequestGenerator.getDefault() val requests = generator.generateUploadRequests(listOf()) assertThat(requests).isEmpty() } @Test fun `should create a POST request for insert`() = runTest { - val generator = IndividualRequestGenerator.getGenerator(HttpVerb.POST, HttpVerb.PATCH) + val generator = UrlRequestGenerator.getGenerator(HttpVerb.POST, HttpVerb.PATCH) val requests = generator.generateUploadRequests( listOf( @@ -78,7 +78,7 @@ class IndividualGeneratorTest { @Test fun `should create a PUT request for insert`() = runTest { - val generator = IndividualRequestGenerator.getDefault() + val generator = UrlRequestGenerator.getDefault() val requests = generator.generateUploadRequests( listOf( @@ -122,7 +122,7 @@ class IndividualGeneratorTest { timestamp = Instant.now() ), ) - val generator = IndividualRequestGenerator.Factory.getDefault() + val generator = UrlRequestGenerator.Factory.getDefault() val requests = generator.generateUploadRequests(patches) with(requests.single()) { assertThat(requests.size).isEqualTo(1) @@ -158,7 +158,7 @@ class IndividualGeneratorTest { timestamp = Instant.now() ), ) - val generator = IndividualRequestGenerator.Factory.getDefault() + val generator = UrlRequestGenerator.Factory.getDefault() val requests = generator.generateUploadRequests(patches) with(requests.single()) { assertThat(httpVerb).isEqualTo(HttpVerb.DELETE) @@ -215,7 +215,7 @@ class IndividualGeneratorTest { timestamp = Instant.now() ), ) - val generator = IndividualRequestGenerator.Factory.getDefault() + val generator = UrlRequestGenerator.Factory.getDefault() val result = generator.generateUploadRequests(patches) assertThat(result).hasSize(3) assertThat(result.map { it.httpVerb }) From 48ae6c3979afb9ff06fcf672c268ef140f097367 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:26:48 +0530 Subject: [PATCH 02/12] spotless application --- .../fhir/benchmark/FhirSyncWorkerBenchmark.kt | 63 +++++++++++-------- .../google/android/fhir/sync/DataSource.kt | 4 +- .../android/fhir/sync/DownloadWorkManager.kt | 2 +- .../fhir/sync/download/DownloadRequest.kt | 2 + .../fhir/sync/remote/FhirHttpDataSource.kt | 1 + .../request/TransactionBundleGenerator.kt | 4 +- .../fhir/sync/upload/request/UploadRequest.kt | 2 +- .../upload/request/UploadRequestGenerator.kt | 2 +- .../request/UploadRequestGeneratorMode.kt | 5 +- .../upload/request/UrlRequestGenerator.kt | 11 ++-- .../google/android/fhir/testing/Utilities.kt | 11 ++-- .../sync/remote/FhirHttpDataSourceTest.kt | 11 ++-- .../upload/request/IndividualGeneratorTest.kt | 40 ++++++------ 13 files changed, 86 insertions(+), 72 deletions(-) diff --git a/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt b/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt index dc9a6fa682..e74dd7028a 100644 --- a/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt +++ b/engine/benchmark/src/androidTest/java/com/google/android/fhir/benchmark/FhirSyncWorkerBenchmark.kt @@ -77,13 +77,15 @@ class FhirSyncWorkerBenchmark { class BenchmarkTestOneTimeSyncWorker( private val appContext: Context, - workerParams: WorkerParameters + workerParams: WorkerParameters, ) : FhirSyncWorker(appContext, workerParams) { override fun getFhirEngine(): FhirEngine { return FhirEngineProvider.getInstance(appContext) } + override fun getDownloadWorkManager(): DownloadWorkManager = BenchmarkTestDownloadManagerImpl() + override fun getConflictResolver() = AcceptRemoteConflictResolver } @@ -92,6 +94,7 @@ class FhirSyncWorkerBenchmark { private val urls = LinkedList(queries) override suspend fun getNextRequest() = urls.poll()?.let { DownloadRequest.of(it) } + override suspend fun getSummaryRequestUrls(): Map { return emptyMap() } @@ -142,7 +145,7 @@ class FhirSyncWorkerBenchmark { private fun setupMockServerDispatcher( numberPatients: Int, numberObservations: Int, - numberEncounters: Int + numberEncounters: Int, ) { mockWebServer.dispatcher = object : Dispatcher() { @@ -209,14 +212,17 @@ class FhirSyncWorkerBenchmark { return Patient().apply { id = patientId gender = - if (patientId.last().isDigit()) Enumerations.AdministrativeGender.FEMALE - else Enumerations.AdministrativeGender.MALE + if (patientId.last().isDigit()) { + Enumerations.AdministrativeGender.FEMALE + } else { + Enumerations.AdministrativeGender.MALE + } name = listOf( HumanName().apply { given = listOf(StringType("Test patient Name $patientId")) family = "Patient Family" - } + }, ) address = listOf( @@ -227,7 +233,7 @@ class FhirSyncWorkerBenchmark { state = "Vic" postalCode = "postalCode" line = listOf(StringType("534 Erewhon St")) - } + }, ) contact = listOf( @@ -242,11 +248,14 @@ class FhirSyncWorkerBenchmark { family = "Patient Family" } gender = - if (patientId.last().isDigit()) Enumerations.AdministrativeGender.MALE - else Enumerations.AdministrativeGender.FEMALE - } + if (patientId.last().isDigit()) { + Enumerations.AdministrativeGender.MALE + } else { + Enumerations.AdministrativeGender.FEMALE + } + }, ) - } + }, ) telecom = listOf( @@ -259,7 +268,7 @@ class FhirSyncWorkerBenchmark { system = ContactPoint.ContactPointSystem.PHONE value = "(03) 3410 5613" use = ContactPoint.ContactPointUse.WORK - } + }, ) } } @@ -298,7 +307,7 @@ class FhirSyncWorkerBenchmark { code = "kPa" system = "http://unitsofmeasure.org" } - } + }, ) interpretation = listOf( @@ -306,9 +315,9 @@ class FhirSyncWorkerBenchmark { Coding( "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation", "H", - "high" - ) - ) + "high", + ), + ), ) } } @@ -328,7 +337,7 @@ class FhirSyncWorkerBenchmark { CodeableConcept().apply { coding = listOf(Coding("http://snomed.info/sct", "183807002", "Inpatient stay for nine days")) - } + }, ) subject = Reference("Patient/$patientId") episodeOfCare = listOf(Reference("Episode/${UUID.randomUUID()}")) @@ -345,12 +354,12 @@ class FhirSyncWorkerBenchmark { Coding( "http://terminology.hl7.org/CodeSystem/v3-ParticipationType", "PART", - "Participant" - ) + "Participant", + ), ) - } + }, ) - } + }, ) diagnosis = listOf( @@ -363,8 +372,8 @@ class FhirSyncWorkerBenchmark { Coding( "http://terminology.hl7.org/CodeSystem/diagnosis-role", "AD", - "Admission diagnosis" - ) + "Admission diagnosis", + ), ) } }, @@ -377,11 +386,11 @@ class FhirSyncWorkerBenchmark { Coding( "http://terminology.hl7.org/CodeSystem/diagnosis-role", "DD", - "Discharge diagnosis" - ) + "Discharge diagnosis", + ), ) } - } + }, ) } } @@ -397,8 +406,8 @@ class FhirSyncWorkerBenchmark { FhirEngineProvider.init( FhirEngineConfiguration( serverConfiguration = ServerConfiguration("http://127.0.0.1:$mockServerPort/fhir/"), - testMode = true - ) + testMode = true, + ), ) mockWebServer.start(mockServerPort) } diff --git a/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt b/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt index dbcaa00965..e324bcd9e0 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/DataSource.kt @@ -30,8 +30,8 @@ internal interface DataSource { /** * @return [Bundle] of type [BundleType.TRANSACTIONRESPONSE] for a successful operation, - * [OperationOutcome] otherwise. Call this api with the [Bundle] that needs to be uploaded to the - * server. + * [OperationOutcome] otherwise. Call this api with the [Bundle] that needs to be uploaded to + * the server. */ suspend fun upload(request: UploadRequest): Resource } diff --git a/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt b/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt index e950b20611..6571a4f586 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/DownloadWorkManager.kt @@ -24,7 +24,7 @@ import org.hl7.fhir.r4.model.ResourceType * Manager that generates the FHIR requests and handles the FHIR responses of a download job. * * TODO(jingtang10): What happens after the end of a download job. Should a new download work - * manager be created or should there be an API to restart a new download job. + * manager be created or should there be an API to restart a new download job. */ interface DownloadWorkManager { /** diff --git a/engine/src/main/java/com/google/android/fhir/sync/download/DownloadRequest.kt b/engine/src/main/java/com/google/android/fhir/sync/download/DownloadRequest.kt index 2aca2849d9..cdaecba39a 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/download/DownloadRequest.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/download/DownloadRequest.kt @@ -30,9 +30,11 @@ import org.hl7.fhir.r4.model.Bundle * * The application developer may use a request like below to get an update on Patient/123 since it * was last downloaded. + * * ``` * Request.of("/Patient/123", mapOf("If-Modified-Since" to "knownLastUpdatedOfPatient123")) * ``` + * * **BundleRequest** * * The application developer may use a request like below to download multiple resources in a single diff --git a/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt b/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt index a5a30f2ec7..9d2d9727ba 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/remote/FhirHttpDataSource.kt @@ -31,6 +31,7 @@ import org.hl7.fhir.r4.model.codesystems.HttpVerb /** * Implementation of [DataSource] to sync data with the FHIR server using HTTP method calls. + * * @param fhirHttpService Http service to make requests to the server. */ internal class FhirHttpDataSource(private val fhirHttpService: FhirHttpService) : DataSource { diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt index cd05336127..8753aad164 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/TransactionBundleGenerator.kt @@ -24,7 +24,7 @@ internal class TransactionBundleGenerator( private val generatedBundleSize: Int, private val useETagForUpload: Boolean, private val getBundleEntryComponentGeneratorForPatch: - (patch: Patch, useETagForUpload: Boolean) -> BundleEntryComponentGenerator + (patch: Patch, useETagForUpload: Boolean) -> BundleEntryComponentGenerator, ) : UploadRequestGenerator { override fun generateUploadRequests(patches: List): List { @@ -68,7 +68,7 @@ internal class TransactionBundleGenerator( httpVerbToUseForCreate: Bundle.HTTPVerb, httpVerbToUseForUpdate: Bundle.HTTPVerb, generatedBundleSize: Int = 500, - useETagForUpload: Boolean = true + useETagForUpload: Boolean = true, ): TransactionBundleGenerator { val createFunction = createMapping[httpVerbToUseForCreate] diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt index 3bada4334a..9d9270de17 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequest.kt @@ -44,5 +44,5 @@ data class UrlUploadRequest( val httpVerb: HttpVerb, override val url: String, override val resource: Resource, - override val headers: Map = emptyMap() + override val headers: Map = emptyMap(), ) : UploadRequest(url, headers, resource) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt index eb42220a62..61010f569a 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt @@ -31,7 +31,7 @@ internal interface UploadRequestGenerator { is UploadRequestGeneratorMode.BundleRequest -> TransactionBundleGenerator.getGenerator( mode.httpVerbToUseForCreate, - mode.httpVerbToUseForUpdate + mode.httpVerbToUseForUpdate, ) } } diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt index bff772c6da..60f5296baa 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt @@ -23,10 +23,11 @@ import org.hl7.fhir.r4.model.codesystems.HttpVerb sealed class UploadRequestGeneratorMode { data class UrlRequest( val httpVerbToUseForCreate: HttpVerb, - val httpVerbToUseForUpdate: HttpVerb + val httpVerbToUseForUpdate: HttpVerb, ) : UploadRequestGeneratorMode() + data class BundleRequest( val httpVerbToUseForCreate: Bundle.HTTPVerb, - val httpVerbToUseForUpdate: Bundle.HTTPVerb + val httpVerbToUseForUpdate: Bundle.HTTPVerb, ) : UploadRequestGeneratorMode() } diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt index 6d8bb64ed0..7898207b24 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UrlRequestGenerator.kt @@ -26,7 +26,7 @@ import org.hl7.fhir.r4.model.codesystems.HttpVerb /** Generates list of [UrlUploadRequest]s for a list of [Patch]es. */ internal class UrlRequestGenerator( - private val getUrlRequestForPatch: (patch: Patch) -> UrlUploadRequest + private val getUrlRequestForPatch: (patch: Patch) -> UrlUploadRequest, ) : UploadRequestGenerator { override fun generateUploadRequests(patches: List): List = @@ -56,19 +56,18 @@ internal class UrlRequestGenerator( */ fun getGenerator( httpVerbToUseForCreate: HttpVerb, - httpVerbToUseForUpdate: HttpVerb + httpVerbToUseForUpdate: HttpVerb, ): UrlRequestGenerator { - val createFunction = createMapping[httpVerbToUseForCreate] ?: throw IllegalArgumentException( - "Creation using $httpVerbToUseForCreate is not supported." + "Creation using $httpVerbToUseForCreate is not supported.", ) val updateFunction = updateMapping[httpVerbToUseForUpdate] ?: throw IllegalArgumentException( - "Update using $httpVerbToUseForUpdate is not supported." + "Update using $httpVerbToUseForUpdate is not supported.", ) return UrlRequestGenerator { patch -> @@ -106,7 +105,7 @@ internal class UrlRequestGenerator( httpVerb = HttpVerb.PATCH, url = "${patch.resourceType}/${patch.resourceId}", resource = Binary().apply { data = patch.payload.toByteArray() }, - headers = mapOf("Content-Type" to ContentTypes.APPLICATION_JSON_PATCH) + headers = mapOf("Content-Type" to ContentTypes.APPLICATION_JSON_PATCH), ) } } diff --git a/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt b/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt index b98b129ab9..20458c0f4b 100644 --- a/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt +++ b/engine/src/main/java/com/google/android/fhir/testing/Utilities.kt @@ -111,7 +111,7 @@ object TestDataSourceImpl : DataSource { } open class TestDownloadManagerImpl( - private val queries: List = listOf("Patient?address-city=NAIROBI") + private val queries: List = listOf("Patient?address-city=NAIROBI"), ) : DownloadWorkManager { private val urls = LinkedList(queries) @@ -147,17 +147,18 @@ object TestFhirEngineImpl : FhirEngine { } override suspend fun syncUpload( - upload: suspend (List) -> Flow> + upload: suspend (List) -> Flow>, ) { upload(getLocalChanges(ResourceType.Patient, "123")).collect() } override suspend fun syncDownload( conflictResolver: ConflictResolver, - download: suspend () -> Flow> + download: suspend () -> Flow>, ) { download().collect() } + override suspend fun count(search: Search): Long { return 0 } @@ -176,8 +177,8 @@ object TestFhirEngineImpl : FhirEngine { payload = "{ 'resourceType' : 'Patient', 'id' : '123' }", token = LocalChangeToken(listOf()), type = LocalChange.Type.INSERT, - timestamp = Instant.now() - ) + timestamp = Instant.now(), + ), ) } diff --git a/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt b/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt index 8a2d2ef321..ee8c19d6dd 100644 --- a/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt +++ b/engine/src/test/java/com/google/android/fhir/sync/remote/FhirHttpDataSourceTest.kt @@ -55,8 +55,8 @@ internal class FhirHttpDataSourceTest { Bundle().apply { id = "transaction-response-1" type = Bundle.BundleType.TRANSACTIONRESPONSE - } - ) + }, + ), ) } @@ -82,7 +82,7 @@ internal class FhirHttpDataSourceTest { HumanName().apply { addGiven("John") family = "Doe" - } + }, ) } val request = UrlUploadRequest(HttpVerb.POST, "Patient", patient, emptyMap()) @@ -104,7 +104,7 @@ internal class FhirHttpDataSourceTest { HumanName().apply { addGiven("John") family = "Doe" - } + }, ) } val request = @@ -128,7 +128,8 @@ internal class FhirHttpDataSourceTest { val patchToApply = Binary().apply { data = - "[{\"op\":\"replace\",\"path\":\"\\/name\\/0\\/given\\/0\",\"value\":\"Janet\"}]".toByteArray() + "[{\"op\":\"replace\",\"path\":\"\\/name\\/0\\/given\\/0\",\"value\":\"Janet\"}]" + .toByteArray() } val request = diff --git a/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt b/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt index 23d2c1c09f..37d5baf49f 100644 --- a/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt +++ b/engine/src/test/java/com/google/android/fhir/sync/upload/request/IndividualGeneratorTest.kt @@ -61,13 +61,13 @@ class IndividualGeneratorTest { HumanName().apply { addGiven("John") family = "Doe" - } + }, ) - } + }, ), - timestamp = Instant.now() + timestamp = Instant.now(), ), - ) + ), ) with(requests.single()) { @@ -94,13 +94,13 @@ class IndividualGeneratorTest { HumanName().apply { addGiven("John") family = "Doe" - } + }, ) - } + }, ), - timestamp = Instant.now() + timestamp = Instant.now(), ), - ) + ), ) with(requests.single()) { @@ -119,7 +119,7 @@ class IndividualGeneratorTest { type = Patch.Type.UPDATE, payload = "[{\"op\":\"replace\",\"path\":\"\\/name\\/0\\/given\\/0\",\"value\":\"Janet\"}]", - timestamp = Instant.now() + timestamp = Instant.now(), ), ) val generator = UrlRequestGenerator.Factory.getDefault() @@ -130,7 +130,7 @@ class IndividualGeneratorTest { assertThat(url).isEqualTo("Patient/Patient-002") assertThat((resource as Binary).data.toString(Charsets.UTF_8)) .isEqualTo( - "[{\"op\":\"replace\",\"path\":\"\\/name\\/0\\/given\\/0\",\"value\":\"Janet\"}]" + "[{\"op\":\"replace\",\"path\":\"\\/name\\/0\\/given\\/0\",\"value\":\"Janet\"}]", ) } } @@ -151,11 +151,11 @@ class IndividualGeneratorTest { HumanName().apply { addGiven("John") family = "Doe" - } + }, ) - } + }, ), - timestamp = Instant.now() + timestamp = Instant.now(), ), ) val generator = UrlRequestGenerator.Factory.getDefault() @@ -182,11 +182,11 @@ class IndividualGeneratorTest { HumanName().apply { addGiven("John") family = "Doe" - } + }, ) - } + }, ), - timestamp = Instant.now() + timestamp = Instant.now(), ), Patch( resourceType = ResourceType.Patient.name, @@ -194,7 +194,7 @@ class IndividualGeneratorTest { type = Patch.Type.UPDATE, payload = "[{\"op\":\"replace\",\"path\":\"\\/name\\/0\\/given\\/0\",\"value\":\"Janet\"}]", - timestamp = Instant.now() + timestamp = Instant.now(), ), Patch( resourceType = ResourceType.Patient.name, @@ -208,11 +208,11 @@ class IndividualGeneratorTest { HumanName().apply { addGiven("John") family = "Roe" - } + }, ) - } + }, ), - timestamp = Instant.now() + timestamp = Instant.now(), ), ) val generator = UrlRequestGenerator.Factory.getDefault() From 4b34c2d65932a5fe823feb245779bc9dd223879b Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:34:23 +0530 Subject: [PATCH 03/12] spotless application --- .../demo/data/TimestampBasedDownloadWorkManagerImpl.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt b/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt index 29913bdd36..62ac55348b 100644 --- a/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt +++ b/demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt @@ -17,9 +17,9 @@ package com.google.android.fhir.demo.data import com.google.android.fhir.demo.DemoDataStore -import com.google.android.fhir.sync.download.DownloadRequest import com.google.android.fhir.sync.DownloadWorkManager import com.google.android.fhir.sync.SyncDataParams +import com.google.android.fhir.sync.download.DownloadRequest import java.time.ZoneId import java.time.format.DateTimeFormatter import java.util.Date @@ -98,14 +98,15 @@ class TimestampBasedDownloadWorkManagerImpl(private val dataStore: DemoDataStore } private suspend fun extractAndSaveLastUpdateTimestampToFetchFutureUpdates( - resources: List + resources: List, ) { resources .groupBy { it.resourceType } - .entries.map { map -> + .entries + .map { map -> dataStore.saveLastUpdatedTimestamp( map.key, - map.value.maxOfOrNull { it.meta.lastUpdated }?.toTimeZoneString() ?: "" + map.value.maxOfOrNull { it.meta.lastUpdated }?.toTimeZoneString() ?: "", ) } } From 6ec60bdd9ec86bdffaaf1c169e2d19152b6dce03 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:56:48 +0530 Subject: [PATCH 04/12] added UploadRequestGeneratorFactory --- .../sync/upload/request/UploadRequestGenerator.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt index 61010f569a..1f20bcd8b7 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt @@ -37,3 +37,18 @@ internal interface UploadRequestGenerator { } } } + +internal object UploadRequestGeneratorFactory { + fun byMode( + mode: UploadRequestGeneratorMode, + ): UploadRequestGenerator = + when (mode) { + is UploadRequestGeneratorMode.UrlRequest -> + UrlRequestGenerator.getGenerator(mode.httpVerbToUseForCreate, mode.httpVerbToUseForUpdate) + is UploadRequestGeneratorMode.BundleRequest -> + TransactionBundleGenerator.getGenerator( + mode.httpVerbToUseForCreate, + mode.httpVerbToUseForUpdate, + ) + } +} From b2f3bec33e6e4dcc04c6409c9af03e9a0e68d78f Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:57:12 +0530 Subject: [PATCH 05/12] Spotless applications --- .../sync/upload/request/UploadRequestGenerator.kt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt index 1f20bcd8b7..cb8fda4293 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt @@ -22,20 +22,6 @@ import com.google.android.fhir.sync.upload.patch.Patch internal interface UploadRequestGenerator { /** Generates a list of [UploadRequest] from the [Patch]es */ fun generateUploadRequests(patches: List): List - - companion object { - internal fun byMode(mode: UploadRequestGeneratorMode): UploadRequestGenerator { - return when (mode) { - is UploadRequestGeneratorMode.UrlRequest -> - UrlRequestGenerator.getGenerator(mode.httpVerbToUseForCreate, mode.httpVerbToUseForUpdate) - is UploadRequestGeneratorMode.BundleRequest -> - TransactionBundleGenerator.getGenerator( - mode.httpVerbToUseForCreate, - mode.httpVerbToUseForUpdate, - ) - } - } - } } internal object UploadRequestGeneratorFactory { From 28244f204bb2c970588df10f2c8868c4c8d467f6 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Fri, 15 Sep 2023 16:09:06 +0530 Subject: [PATCH 06/12] review comments --- .../upload/request/UploadRequestGenerator.kt | 15 +++++++++ .../request/UploadRequestGeneratorMode.kt | 33 ------------------- 2 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt index cb8fda4293..d5c344d338 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGenerator.kt @@ -17,6 +17,8 @@ package com.google.android.fhir.sync.upload.request import com.google.android.fhir.sync.upload.patch.Patch +import org.hl7.fhir.r4.model.Bundle +import org.hl7.fhir.r4.model.codesystems.HttpVerb /** Generator that generates [UploadRequest]s from the [Patch]es */ internal interface UploadRequestGenerator { @@ -24,6 +26,19 @@ internal interface UploadRequestGenerator { fun generateUploadRequests(patches: List): List } +/** Mode to decide the type of [UploadRequest] that needs to be generated */ +internal sealed class UploadRequestGeneratorMode { + data class UrlRequest( + val httpVerbToUseForCreate: HttpVerb, + val httpVerbToUseForUpdate: HttpVerb, + ) : UploadRequestGeneratorMode() + + data class BundleRequest( + val httpVerbToUseForCreate: Bundle.HTTPVerb, + val httpVerbToUseForUpdate: Bundle.HTTPVerb, + ) : UploadRequestGeneratorMode() +} + internal object UploadRequestGeneratorFactory { fun byMode( mode: UploadRequestGeneratorMode, diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt deleted file mode 100644 index f893673452..0000000000 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/request/UploadRequestGeneratorMode.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * 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 com.google.android.fhir.sync.upload.request - -import org.hl7.fhir.r4.model.Bundle -import org.hl7.fhir.r4.model.codesystems.HttpVerb - -/** Mode to decide the type of [UploadRequest] that needs to be generated */ -internal sealed class UploadRequestGeneratorMode { - data class UrlRequest( - val httpVerbToUseForCreate: HttpVerb, - val httpVerbToUseForUpdate: HttpVerb, - ) : UploadRequestGeneratorMode() - - data class BundleRequest( - val httpVerbToUseForCreate: Bundle.HTTPVerb, - val httpVerbToUseForUpdate: Bundle.HTTPVerb, - ) : UploadRequestGeneratorMode() -} From 11d3bb3acf3829e8c0e627ba60c646ca08dbbae1 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:42:49 +0530 Subject: [PATCH 07/12] Upload Strategy --- .../fhir/sync/upload/LocalChangeFetcher.kt | 2 +- .../fhir/sync/upload/UploadStrategy.kt | 83 +++++++++++++++++++ .../fhir/sync/upload/patch/PatchGenerator.kt | 9 ++ .../sync/upload/patch/PatchGeneratorMode.kt | 23 +++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt create mode 100644 engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt index 34f8eee4d4..be84f9a071 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt @@ -70,7 +70,7 @@ internal class AllChangesLocalChangeFetcher( } /** Represents the mode in which local changes should be fetched. */ -sealed class LocalChangesFetchMode { +internal sealed class LocalChangesFetchMode { object AllChanges : LocalChangesFetchMode() object PerResource : LocalChangesFetchMode() diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt new file mode 100644 index 0000000000..1e8ea12259 --- /dev/null +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt @@ -0,0 +1,83 @@ +/* + * Copyright 2023 Google LLC + * + * 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 com.google.android.fhir.sync.upload + +import com.google.android.fhir.sync.upload.patch.PatchGeneratorMode +import com.google.android.fhir.sync.upload.request.UploadRequestGeneratorMode +import org.hl7.fhir.r4.model.codesystems.HttpVerb + +sealed class UploadStrategy( + internal val localChangesFetchMode: LocalChangesFetchMode, + internal val patchGeneratorMode: PatchGeneratorMode, + internal val requestGeneratorMode: UploadRequestGeneratorMode, +) { + object SingleChangePut : + UploadStrategy( + LocalChangesFetchMode.EarliestChange, + PatchGeneratorMode.PerChange, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), + ) + + object SingleChangePost : + UploadStrategy( + LocalChangesFetchMode.EarliestChange, + PatchGeneratorMode.PerChange, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), + ) + + object SingleResourcePut : + UploadStrategy( + LocalChangesFetchMode.PerResource, + PatchGeneratorMode.PerResource, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), + ) + + object SingleResourcePost : + UploadStrategy( + LocalChangesFetchMode.PerResource, + PatchGeneratorMode.PerResource, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), + ) + + object AllChangesBundlePut : + UploadStrategy( + LocalChangesFetchMode.AllChanges, + PatchGeneratorMode.PerChange, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), + ) + + object AllChangesBundlePost : + UploadStrategy( + LocalChangesFetchMode.AllChanges, + PatchGeneratorMode.PerChange, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), + ) + + object AllChangesSquashedBundlePut : + UploadStrategy( + LocalChangesFetchMode.AllChanges, + PatchGeneratorMode.PerResource, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), + ) + + object AllChangesSquashedBundlePost : + UploadStrategy( + LocalChangesFetchMode.AllChanges, + PatchGeneratorMode.PerResource, + UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), + ) +} diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt index f0ff53f7ce..c0ecd39af0 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt @@ -34,4 +34,13 @@ internal interface PatchGenerator { * certain numbers of [Patch]es. */ fun generate(localChanges: List): List + + companion object { + internal fun byMode(mode: PatchGeneratorMode): PatchGenerator { + return when (mode) { + is PatchGeneratorMode.PerChange -> PerChangePatchGenerator + is PatchGeneratorMode.PerResource -> PerResourcePatchGenerator + } + } + } } diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt new file mode 100644 index 0000000000..678b5e0e97 --- /dev/null +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2023 Google LLC + * + * 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 com.google.android.fhir.sync.upload.patch + +internal sealed class PatchGeneratorMode { + object PerResource : PatchGeneratorMode() + + object PerChange : PatchGeneratorMode() +} From 894247990dcf9163118add1d69177852057bcb4e Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Fri, 15 Sep 2023 09:54:19 +0530 Subject: [PATCH 08/12] Adding factories --- .../fhir/sync/upload/patch/PatchGenerator.kt | 15 ++++++++------- .../fhir/sync/upload/patch/PatchGeneratorMode.kt | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt index c0ecd39af0..2aa4cb823c 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt @@ -34,13 +34,14 @@ internal interface PatchGenerator { * certain numbers of [Patch]es. */ fun generate(localChanges: List): List +} - companion object { - internal fun byMode(mode: PatchGeneratorMode): PatchGenerator { - return when (mode) { - is PatchGeneratorMode.PerChange -> PerChangePatchGenerator - is PatchGeneratorMode.PerResource -> PerResourcePatchGenerator - } +internal object PatchGeneratorFactory { + fun byMode( + mode: PatchGeneratorMode, + ): PatchGenerator = + when (mode) { + is PatchGeneratorMode.PerChange -> PerChangePatchGenerator + is PatchGeneratorMode.PerResource -> PerResourcePatchGenerator } - } } diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt index 678b5e0e97..1c37f8921a 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt @@ -16,6 +16,9 @@ package com.google.android.fhir.sync.upload.patch +/** + * Mode to decide the type of [PatchGenerator] that needs to be used to upload the [LocalChange]s + */ internal sealed class PatchGeneratorMode { object PerResource : PatchGeneratorMode() From f488c9eeb1991b711714832ba39971ceb6563185 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:28:51 +0530 Subject: [PATCH 09/12] patch generator mode in same class as patch generator --- .../fhir/sync/upload/patch/PatchGenerator.kt | 9 +++++++ .../sync/upload/patch/PatchGeneratorMode.kt | 26 ------------------- 2 files changed, 9 insertions(+), 26 deletions(-) delete mode 100644 engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt index 2aa4cb823c..090e85e2b7 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGenerator.kt @@ -45,3 +45,12 @@ internal object PatchGeneratorFactory { is PatchGeneratorMode.PerResource -> PerResourcePatchGenerator } } + +/** + * Mode to decide the type of [PatchGenerator] that needs to be used to upload the [LocalChange]s + */ +internal sealed class PatchGeneratorMode { + object PerResource : PatchGeneratorMode() + + object PerChange : PatchGeneratorMode() +} diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt deleted file mode 100644 index 1c37f8921a..0000000000 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchGeneratorMode.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * 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 com.google.android.fhir.sync.upload.patch - -/** - * Mode to decide the type of [PatchGenerator] that needs to be used to upload the [LocalChange]s - */ -internal sealed class PatchGeneratorMode { - object PerResource : PatchGeneratorMode() - - object PerChange : PatchGeneratorMode() -} From 277966818cf64c523437915b8a0b1ba86c2a4367 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:45:56 +0530 Subject: [PATCH 10/12] making local fetch mode not internal --- .../com/google/android/fhir/sync/upload/LocalChangeFetcher.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt index be84f9a071..34f8eee4d4 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/LocalChangeFetcher.kt @@ -70,7 +70,7 @@ internal class AllChangesLocalChangeFetcher( } /** Represents the mode in which local changes should be fetched. */ -internal sealed class LocalChangesFetchMode { +sealed class LocalChangesFetchMode { object AllChanges : LocalChangesFetchMode() object PerResource : LocalChangesFetchMode() From 6b98818f67be27197baab746a20dd0da801ea9a8 Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Thu, 21 Sep 2023 12:06:23 +0530 Subject: [PATCH 11/12] addressed review comments --- .../google/android/fhir/sync/upload/UploadStrategy.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt index 1e8ea12259..dfa96ad3f6 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt @@ -20,7 +20,16 @@ import com.google.android.fhir.sync.upload.patch.PatchGeneratorMode import com.google.android.fhir.sync.upload.request.UploadRequestGeneratorMode import org.hl7.fhir.r4.model.codesystems.HttpVerb -sealed class UploadStrategy( +/** + * Strategy to define how to upload the [LocalChange]s to the FHIR server. + * + * Each strategy comprises of deciding appropriate modes for [LocalChangeFetcher], + * [PatchGeneratorMode], [UploadRequestGeneratorMode]. The strategies mentioned here are exhaustive + * as the different modes for the components mentioned above can only be used together in some + * specific ways. + */ +sealed class UploadStrategy +private constructor( internal val localChangesFetchMode: LocalChangesFetchMode, internal val patchGeneratorMode: PatchGeneratorMode, internal val requestGeneratorMode: UploadRequestGeneratorMode, From acd28fba0fb9480930674327600013969bac9beb Mon Sep 17 00:00:00 2001 From: anchita-g <109063673+anchita-g@users.noreply.github.com> Date: Thu, 21 Sep 2023 13:42:12 +0530 Subject: [PATCH 12/12] using bundle request --- .../google/android/fhir/sync/upload/UploadStrategy.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt index dfa96ad3f6..ef082becc3 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt @@ -18,6 +18,7 @@ package com.google.android.fhir.sync.upload import com.google.android.fhir.sync.upload.patch.PatchGeneratorMode import com.google.android.fhir.sync.upload.request.UploadRequestGeneratorMode +import org.hl7.fhir.r4.model.Bundle import org.hl7.fhir.r4.model.codesystems.HttpVerb /** @@ -66,27 +67,27 @@ private constructor( UploadStrategy( LocalChangesFetchMode.AllChanges, PatchGeneratorMode.PerChange, - UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), + UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.PUT, Bundle.HTTPVerb.PATCH), ) object AllChangesBundlePost : UploadStrategy( LocalChangesFetchMode.AllChanges, PatchGeneratorMode.PerChange, - UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), + UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.POST, Bundle.HTTPVerb.PATCH), ) object AllChangesSquashedBundlePut : UploadStrategy( LocalChangesFetchMode.AllChanges, PatchGeneratorMode.PerResource, - UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), + UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.PUT, Bundle.HTTPVerb.PATCH), ) object AllChangesSquashedBundlePost : UploadStrategy( LocalChangesFetchMode.AllChanges, PatchGeneratorMode.PerResource, - UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), + UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.POST, Bundle.HTTPVerb.PATCH), ) }