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

Support for custom headers in the download http requests and use ETags for upload #2009

Merged
merged 8 commits into from
Jun 11, 2023
Prev Previous commit
Added separate tests for if-Match header in bundle
  • Loading branch information
aditya-07 committed Jun 9, 2023
commit 89c06cf0bb1e584c8f4340487971225945e890b8
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal abstract class HttpVerbBasedBundleEntryComponentGenerator(
UriType("${localChange.resourceType}/${localChange.resourceId}")
)
.apply {
if (useETagForUpload) {
if (useETagForUpload && !localChange.versionId.isNullOrEmpty()) {
// FHIR supports weak Etag, See ETag section https://hl7.org/fhir/http.html#Http-Headers
when (localChange.type) {
LocalChange.Type.UPDATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,48 +232,74 @@ class TransactionBundleGeneratorTest {
@Test
fun `generate() should return Bundle Entry without if-match when useETagForUpload is false`() =
aditya-07 marked this conversation as resolved.
Show resolved Hide resolved
runBlocking {
val jsonParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser()
val changes =
listOf(
LocalChangeEntity(
id = 1,
resourceType = ResourceType.Patient.name,
resourceId = "Patient-002",
type = Type.UPDATE,
payload =
LocalChangeUtils.diff(
jsonParser,
Patient().apply {
id = "Patient-002"
addName(
HumanName().apply {
addGiven("Jane")
family = "Doe"
}
)
},
Patient().apply {
id = "Patient-002"
addName(
HumanName().apply {
addGiven("Janet")
family = "Doe"
}
)
}
)
.toString(),
versionId = "v-p002-01"
payload = "[]",
versionId = "patient-002-version-1"
)
.toLocalChange()
.apply { LocalChangeToken(listOf(2)) }
)
val generator = TransactionBundleGenerator.Factory.getDefault(useETagForUpload = false)
val result = generator.generate(changes.chunked(1))

assertThat(result).hasSize(1)
assertThat(result.first().first.type).isEqualTo(Bundle.BundleType.TRANSACTION)
assertThat(result.first().first.entry.first().request.method).isEqualTo(Bundle.HTTPVerb.PATCH)
assertThat(result.first().first.entry.first().request.ifMatch).isNull()
}

@Test
fun `generate() should return Bundle Entry with if-match when useETagForUpload is true`() =
runBlocking {
val changes =
listOf(
LocalChangeEntity(
id = 1,
resourceType = ResourceType.Patient.name,
resourceId = "Patient-002",
type = Type.UPDATE,
payload = "[]",
versionId = "patient-002-version-1"
)
.toLocalChange()
)
val generator = TransactionBundleGenerator.Factory.getDefault(useETagForUpload = true)
val result = generator.generate(changes.chunked(1))

assertThat(result.first().first.entry.first().request.ifMatch)
.isEqualTo("W/\"patient-002-version-1\"")
}

@Test
fun `generate() should return Bundle Entry without if-match when the LocalChangeEntity has no versionId`() =
runBlocking {
val changes =
listOf(
LocalChangeEntity(
id = 1,
resourceType = ResourceType.Patient.name,
resourceId = "Patient-002",
type = Type.UPDATE,
payload = "[]",
versionId = ""
)
.toLocalChange(),
LocalChangeEntity(
id = 1,
resourceType = ResourceType.Patient.name,
resourceId = "Patient-003",
type = Type.UPDATE,
payload = "[]",
versionId = null
)
.toLocalChange()
)
val generator = TransactionBundleGenerator.Factory.getDefault(useETagForUpload = true)
val result = generator.generate(changes.chunked(2))

assertThat(result.first().first.entry[0].request.ifMatch).isNull()
assertThat(result.first().first.entry[1].request.ifMatch).isNull()
}
}
Loading