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

Merge prs for releases #6

Open
wants to merge 154 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
2e57f26
Add itemImage extension support on text and group questions
ekigamba Oct 1, 2021
badcbe8
Add itemImage extension support on display questions
ekigamba Oct 4, 2021
a2575d5
Add sample implementation of itemImage extension
ekigamba Oct 4, 2021
81a2941
Add tests for Attachment#fetchBitmap extension
ekigamba Oct 5, 2021
585914b
Fix itemImage not displayed centered on group question
ekigamba Oct 5, 2021
4500c05
Fix repeating images of itemImage and cleanup code
ekigamba Oct 7, 2021
4a818db
Fix build
ekigamba Oct 8, 2021
ad89571
Merge branch 'master' into ek/item-image-support
ekigamba Oct 22, 2021
0c84423
Remove Timber dependency
ekigamba Oct 22, 2021
da1c25d
Merge branch 'master' into ek/item-image-support
ekigamba Oct 26, 2021
4a820ec
Add tests for Binary & Attachment extension funcs
ekigamba Oct 26, 2021
741107d
Merge branch 'master' into ek/item-image-support
ekigamba Nov 1, 2021
02675e3
Merge branch 'master' into ek/item-image-support
ekigamba Nov 12, 2021
30a18dc
Merge branch 'master' into ek/item-image-support
ekigamba Nov 17, 2021
d8ba75f
Publicise Binary#isImage & #getBitamp
ekigamba Nov 22, 2021
1336898
Add itemImage extension tests
ekigamba Nov 22, 2021
270fe5b
Merge branch 'master' into ek/item-image-support
ekigamba Nov 22, 2021
a7f3a46
Merge branch 'master' into ek/item-image-support
ekigamba Jan 6, 2022
8f4d122
Fix datacapture module instrumented tests
ekigamba Jan 6, 2022
b08a3a2
Fix datacapture module instrumented tests
ekigamba Jan 6, 2022
b2dba45
Merge branch 'master' into ek/item-image-support
ekigamba Jan 9, 2022
9c2fcd3
Merge branch 'master' into ek/item-image-support
ekigamba Apr 1, 2022
442fe46
Fix demo app build
ekigamba Apr 1, 2022
2e31b5e
Merge branch 'master' into ek/item-image-support
ekigamba Apr 1, 2022
5227b4d
Merge branch 'master' into ek/item-image-support
ekigamba May 10, 2022
24e3aa9
Code reformatting with spotlessApply
ekigamba May 10, 2022
7bf05ce
Implement calculated-expression extension
maimoonak May 11, 2022
b569b81
Fix form value update bug
maimoonak May 12, 2022
27aef40
Merge branch 'master' into 971_calc_exp
maimoonak May 12, 2022
d472190
Detect cyclic dependency | fix on init value loading
maimoonak May 12, 2022
c44e595
Merge branch '971_calc_exp' of https://github.com/opensrp/android-fhi…
maimoonak May 12, 2022
5536e96
Fix merge conflict
maimoonak May 12, 2022
bce9fd9
Make birthdate age dependent | Handle and fix quantity values
maimoonak May 12, 2022
777489b
Fix failing test
maimoonak May 12, 2022
1eafc31
Merge branch 'master' into 971_calc_exp
maimoonak May 12, 2022
0ee4c27
quantity viewholder delegate test covergae
maimoonak May 12, 2022
1f43305
Merge branch '971_calc_exp' of https://github.com/opensrp/android-fhi…
maimoonak May 12, 2022
3fe03fe
Test coverage for update flow
maimoonak May 13, 2022
8ae3161
spotless fix
maimoonak May 13, 2022
e56bd98
spotless fix | re-run ci
maimoonak May 13, 2022
d4d8e1f
Merge branch '971_calc_exp' of https://github.com/opensrp/android-fhi…
maimoonak May 13, 2022
1acf759
Merge branch 'master' into 971_calc_exp
maimoonak May 16, 2022
219dd9e
Test covergae for questionnaire fragment
maimoonak May 19, 2022
0fdb56b
Merge branch '971_calc_exp' of https://github.com/opensrp/android-fhi…
maimoonak May 19, 2022
b613865
Merge branch 'master' into 971_calc_exp
maimoonak May 19, 2022
5fff50d
test coverage for quantity types
maimoonak May 20, 2022
23ed2e3
questionnaire fragment test with launchInFragmentContainer
maimoonak May 20, 2022
a52078c
Move tryUnwrapContext() to utilities
FikriMilano May 21, 2022
f7958ff
Use lifeCycleScope
FikriMilano May 21, 2022
492b657
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano May 21, 2022
fef0052
Fix failing test
FikriMilano May 25, 2022
47d903f
Merge main to ek/item-image-support
FikriMilano May 25, 2022
fde21ab
Fix failing test
FikriMilano May 25, 2022
b26b103
Fix failing test
FikriMilano May 25, 2022
35e7541
Fix failing test
FikriMilano May 26, 2022
5e41ae4
Merge branch 'master' into 971_calc_exp
maimoonak May 30, 2022
1f97b8d
Update datacapture/src/main/java/com/google/android/fhir/datacapture/…
maimoonak May 30, 2022
9e31819
Move widget to LayoutList | Run Calculation after state-change
maimoonak May 31, 2022
501f4ef
Revert the run-expression after state-flow
maimoonak May 31, 2022
0c6b334
Merge branch 'master' into ek/item-image-support
FikriMilano Jun 1, 2022
b580a85
Fix testing typo
FikriMilano Jun 1, 2022
a7b8709
Merge branch 'master' into 971_calc_exp
maimoonak Jun 1, 2022
39cebfa
Merge branch 'master' into 971_calc_exp
maimoonak Jun 1, 2022
20c83d5
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Jun 2, 2022
f9c036d
Trigger CI checks
FikriMilano Jun 2, 2022
d7c5d9d
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Jun 2, 2022
8ed91d7
Merge branch 'master' into 971_calc_exp
maimoonak Jun 2, 2022
3107d7e
Trigger CI checks
FikriMilano Jun 3, 2022
37fd56d
Merge branch 'master' into 971_calc_exp
maimoonak Jun 3, 2022
2694edb
Merge branch 'master' into ek/item-image-support
dubdabasoduba Jun 6, 2022
dddfd20
Merge branch 'master' into 971_calc_exp
maimoonak Jun 6, 2022
cda1f03
Merge branch 'master' into 971_calc_exp
maimoonak Jun 6, 2022
168303c
Merge branch 'master' into ek/item-image-support
FikriMilano Jun 7, 2022
a5993ff
Merge branch 'master' into 971_calc_exp
dubdabasoduba Jun 7, 2022
b5e8352
Merge branch 'master' into 971_calc_exp
maimoonak Jun 8, 2022
aee9dd2
Add test
FikriMilano Jun 9, 2022
4287727
Update test
FikriMilano Jun 10, 2022
b2eab51
Add test
FikriMilano Jun 10, 2022
a2d3f55
Merge branch 'master' into ek/item-image-support
FikriMilano Jun 10, 2022
c48d220
Trigger CI checks
FikriMilano Jun 10, 2022
58fb48e
Merge branch 'master' into 971_calc_exp
dubdabasoduba Jun 10, 2022
b566b28
Merge branch 'master' into 971_calc_exp
dubdabasoduba Jun 15, 2022
28f0c65
Merge branch 'master' into 971_calc_exp
dubdabasoduba Jun 16, 2022
284524b
Merge branch 'master' into 971_calc_exp
maimoonak Jun 20, 2022
2ce0055
Merge branch 'master' into 971_calc_exp
maimoonak Jun 30, 2022
c8ded57
Remove commented code
FikriMilano Jul 1, 2022
bc45196
Revert orientation to horizontal
FikriMilano Jul 1, 2022
34ef1d3
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Jul 1, 2022
bf956c5
Merge branch 'master' into 971_calc_exp
maimoonak Jul 4, 2022
9b967b8
Merge branch 'master' into ek/item-image-support
FikriMilano Jul 4, 2022
3c227f2
Merge branch 'master' into 971_calc_exp
maimoonak Jul 4, 2022
0414961
remove empty line changes
maimoonak Jul 4, 2022
2406e26
Merge branch '971_calc_exp' of https://github.com/opensrp/android-fhi…
maimoonak Jul 4, 2022
bbda724
spotless fix
maimoonak Jul 4, 2022
1fd726c
Esperesso test | Fix failing test
maimoonak Jul 4, 2022
4c4f1ef
Merge branch 'master' into 971_calc_exp
maimoonak Jul 5, 2022
6748dfe
Use IO Dispatcher to fetch Bitmap
FikriMilano Jul 6, 2022
15d0808
Remove unused comment
FikriMilano Jul 6, 2022
f1d6ec3
spotlessApply
FikriMilano Jul 6, 2022
6ce8463
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Jul 6, 2022
4793baf
Merge main and resolve conflicts
maimoonak Jul 20, 2022
d402a3f
Merge branch 'master' into 971_calc_exp
maimoonak Jul 20, 2022
e738864
Remove unnessary changes
maimoonak Jul 20, 2022
4b4aaaf
Fix espresso tests
maimoonak Jul 20, 2022
f1cb2bf
Merge branch '971_calc_exp' of https://github.com/opensrp/android-fhi…
maimoonak Jul 20, 2022
be654e1
Merge branch 'master' into 971_calc_exp
maimoonak Jul 20, 2022
c6032aa
Ignore Failing tests
maimoonak Jul 20, 2022
7b2b4bd
Merge branch 'master' into 971_calc_exp
maimoonak Jul 21, 2022
2c6a86f
Merge branch 'master' into 971_calc_exp
maimoonak Jul 21, 2022
26fb54a
Merge branch 'master' into 971_calc_exp
maimoonak Jul 21, 2022
cefbb96
Merge branch 'master' into 971_calc_exp
maimoonak Jul 25, 2022
f51eb9e
Merge branch 'master' into 971_calc_exp
maimoonak Jul 26, 2022
1d2ae03
Merge branch 'master' into 971_calc_exp
maimoonak Jul 26, 2022
e12f3bc
Merge branch 'master' into 971_calc_exp
maimoonak Jul 27, 2022
7fc8ba1
Use internal tryUnwrapContext for barcode
FikriMilano Jul 27, 2022
2e719fe
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Jul 27, 2022
2f868ce
Merge branch 'master' into 971_calc_exp
maimoonak Jul 29, 2022
f2a1aec
Merge branch 'master' into 971_calc_exp
maimoonak Aug 5, 2022
9302aa0
Revert ignore test | merge main | refactor
maimoonak Aug 5, 2022
01bc73d
Merge branch 'master' into 971_calc_exp
maimoonak Aug 12, 2022
6ba5378
Fix failing build checks
FikriMilano Aug 21, 2022
3181d5e
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Aug 21, 2022
5ec6ce6
Use NotValidated in test
FikriMilano Aug 21, 2022
1a68298
spotlessApply
FikriMilano Aug 21, 2022
d136220
Add item image to multi line edit text
FikriMilano Aug 21, 2022
14c076e
Trigger checks
FikriMilano Aug 21, 2022
f711a35
Use itemMedia instead itemImage
FikriMilano Aug 21, 2022
a8484a0
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Aug 21, 2022
03d52d1
Trigger checks
FikriMilano Aug 21, 2022
8f6547c
Merge branch 'master' into ek/item-image-support
f-odhiambo Aug 22, 2022
bb2efdd
Revert unused dependency
FikriMilano Aug 23, 2022
caf5e05
Revert contentType of video to document
FikriMilano Aug 23, 2022
c63c449
Rename ID from itemImage to item_image
FikriMilano Sep 5, 2022
e1df233
Create QuestionnaireItemMediaView
FikriMilano Sep 6, 2022
b072dfe
Migrate ImageView to QuestionnaireItemMediaView
FikriMilano Sep 6, 2022
e8efc30
Add test for QuestionnaireItemEditTextMultiLineViewHolderFactory
FikriMilano Sep 6, 2022
251df9b
Merge branch 'ek/item-image-support' of github.com:opensrp/android-fh…
FikriMilano Sep 6, 2022
0349b42
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Sep 6, 2022
b579c1d
Merge branch 'master' into ek/item-image-support
f-odhiambo Sep 14, 2022
648847d
Merge branch 'master' of github.com:google/android-fhir into 971_calc…
dubdabasoduba Sep 14, 2022
21ebb11
Set display and group type questionnaire as vertical
FikriMilano Sep 21, 2022
ac69d77
Merge branch 'ek/item-image-support' of github.com:opensrp/android-fh…
FikriMilano Sep 21, 2022
58c7f39
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Sep 21, 2022
5265207
Merge branch 'master' into ek/item-image-support
ndegwamartin Sep 26, 2022
a86ffae
Remove duplicate test
FikriMilano Sep 29, 2022
2f8814e
Rename test class
FikriMilano Sep 29, 2022
67f5412
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Sep 29, 2022
84f34f4
Merge branch 'master' of github.com:google/android-fhir into ek/item-…
FikriMilano Sep 30, 2022
b62aabe
Merge branch 'ek/item-image-support' of github.com:opensrp/android-fh…
FikriMilano Sep 30, 2022
2e9c0de
Catch exception in flow
ellykits Oct 7, 2022
f9545f7
Fix flow exception violation issue
ellykits Oct 7, 2022
42fd2fc
Merge branch '971_calc_exp' into merge_prs_for_releases
dubdabasoduba Oct 9, 2022
3e8bf1d
Merge remote-tracking branch 'origin/fix-sync-state-exception-handlin…
dubdabasoduba Oct 9, 2022
2c621d3
Merge remote-tracking branch 'origin/ek/item-image-support' into merg…
dubdabasoduba Oct 9, 2022
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
36 changes: 36 additions & 0 deletions catalog/src/main/assets/calculated_expression_questionnaire.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"resourceType": "Questionnaire",
"item": [
{
"linkId": "a-birthdate",
"text": "Birth Date",
"type": "date",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.repeat(item).where(linkId='a-age-years' and answer.empty().not()).select(today() - answer.value)"
}
}
]
},
{
"linkId": "a-age-years",
"text": "Age years",
"type": "quantity",
"initial": [{
"valueQuantity": {
"unit": "years",
"system": "http://unitsofmeasure.org",
"code": "years"
}
}]
},
{
"linkId": "a-age-acknowledge",
"text": "Input age to automatically calculate birthdate until birthdate is updated manually",
"type": "display"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,10 @@ class ComponentListViewModel(application: Application, private val state: SavedS
"component_auto_complete.json",
"component_auto_complete_with_validation.json"
),
CALCULATED_EXPRESSION(
R.drawable.ic_unitoptions,
R.string.component_name_calculated_expression,
"calculated_expression_questionnaire.json"
),
}
}
3 changes: 3 additions & 0 deletions catalog/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<string name="component_name_slider">Slider</string>
<string name="component_name_dropdown">Dropdown</string>
<string name="component_name_image">Image</string>
<string
name="component_name_calculated_expression"
>Calculated Expression</string>
<string name="component_name_auto_complete">Auto Complete</string>
<string name="layout_name_default_text">Default</string>
<string name="layout_name_paginated">Paginated</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import android.view.View
import android.widget.TextView
import androidx.fragment.app.FragmentResultListener
import com.google.android.fhir.datacapture.contrib.views.barcode.mlkit.md.LiveBarcodeScanningFragment
import com.google.android.fhir.datacapture.contrib.views.barcode.mlkit.md.Utils.tryUnwrapContext
import com.google.android.fhir.datacapture.localizedPrefixSpanned
import com.google.android.fhir.datacapture.localizedTextSpanned
import com.google.android.fhir.datacapture.validation.ValidationResult
import com.google.android.fhir.datacapture.views.QuestionnaireItemViewHolderDelegate
import com.google.android.fhir.datacapture.views.QuestionnaireItemViewHolderFactory
import com.google.android.fhir.datacapture.views.QuestionnaireItemViewItem
import com.google.android.fhir.datacapture.views.tryUnwrapContext
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.hl7.fhir.r4.model.StringType

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,8 @@ import android.graphics.RectF
import android.graphics.YuvImage
import android.hardware.Camera
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.exifinterface.media.ExifInterface
import com.google.android.fhir.datacapture.contrib.views.barcode.mlkit.md.camera.CameraSizePair
import com.google.mlkit.vision.barcode.BarcodeScanning
Expand Down Expand Up @@ -224,4 +226,25 @@ object Utils {
}

fun getBarcodeScanningClient() = BarcodeScanning.getClient()

/**
* Returns the [AppCompatActivity] if there exists one wrapped inside [ContextThemeWrapper] s, or
* `null` otherwise.
*
* This function is inspired by the function with the same name in `AppCompateDelegateImpl`. See
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:appcompat/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java;l=1615
*
* TODO: find a more robust way to do this as it is not guaranteed that the activity is an
* AppCompatActivity.
*/
internal fun Context.tryUnwrapContext(): AppCompatActivity? {
var context = this
while (true) {
when (context) {
is AppCompatActivity -> return context
is ContextThemeWrapper -> context = context.baseContext
else -> return null
}
}
}
}
1 change: 1 addition & 0 deletions datacapture/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<application
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar"
android:name=".DataCaptureTestApplication"
>
<activity android:name=".TestActivity" />
</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 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.datacapture

import android.app.Application

/** Application class when you want to test the DataCaptureConfig.Provider */
internal class DataCaptureTestApplication : Application(), DataCaptureConfig.Provider {
var dataCaptureConfiguration: DataCaptureConfig? = null

override fun getDataCaptureConfig(): DataCaptureConfig {
if (dataCaptureConfiguration == null) {
dataCaptureConfiguration = DataCaptureConfig()
}

return dataCaptureConfiguration!!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2022 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.datacapture

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.Base64
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import java.nio.charset.Charset
import kotlinx.coroutines.runBlocking
import org.hl7.fhir.r4.model.Attachment
import org.hl7.fhir.r4.model.Binary
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MoreQuestionnaireItemComponentsInstrumentedTest {

@Test
fun fetchBitmap_shouldReturnNull_whenAttachmentHasDataAndIncorrectContentType() {
val attachment =
Attachment().apply {
data = "some-byte".toByteArray(Charset.forName("UTF-8"))
contentType = "document/pdf"
}
val bitmap: Bitmap?
runBlocking { bitmap = attachment.fetchBitmap(ApplicationProvider.getApplicationContext()) }
assertThat(bitmap).isNull()
}

@Test
fun fetchBitmap_shouldReturnBitmap_whenAttachmentHasDataAndCorrectContentType() {
val attachment =
Attachment().apply {
data =
Base64.decode("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", Base64.DEFAULT)
contentType = "image/png"
}
val bitmap: Bitmap?
runBlocking { bitmap = attachment.fetchBitmap(ApplicationProvider.getApplicationContext()) }
assertThat(bitmap).isNotNull()
}

@Test
fun isImage_shouldTrue_whenAttachmentContentTypeIsImage() {
val attachment = Attachment().apply { contentType = "image/png" }
assertThat(attachment.isImage).isTrue()
}

@Test
fun isImage_shouldFalseWhenAttachmentContentTypeIsNotImage() {
val attachment = Attachment().apply { contentType = "document/pdf" }
assertThat(attachment.isImage).isFalse()
}

@Test
fun fetchBitmap_shouldReturnBitmapAndCallAttachmentResolverResolveBinaryResource() {
val attachment = Attachment().apply { url = "https://hapi.fhir.org/Binary/f006" }
ApplicationProvider.getApplicationContext<DataCaptureTestApplication>()
.getDataCaptureConfig()
.attachmentResolver = TestAttachmentResolver()

val bitmap: Bitmap?
runBlocking { bitmap = attachment.fetchBitmap(ApplicationProvider.getApplicationContext()) }

assertThat(bitmap).isNotNull()
}

@Test
fun fetchBitmap_shouldReturnBitmapAndCallAttachmentResolverResolveImageUrl() {
val attachment = Attachment().apply { url = "https://some-image-server.com/images/f0006.png" }

val byteArray =
Base64.decode("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", Base64.DEFAULT)
val expectedBitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)

ApplicationProvider.getApplicationContext<DataCaptureTestApplication>()
.getDataCaptureConfig()
.attachmentResolver = TestAttachmentResolver(expectedBitmap)

val resolvedBitmap: Bitmap?
runBlocking {
resolvedBitmap = attachment.fetchBitmap(ApplicationProvider.getApplicationContext())
}

assertThat(resolvedBitmap).isEqualTo(expectedBitmap)
}

class TestAttachmentResolver(var testBitmap: Bitmap? = null) : AttachmentResolver {

override suspend fun resolveBinaryResource(uri: String): Binary? {
return if (uri == "https://hapi.fhir.org/Binary/f006") {
Binary().apply {
contentType = "image/png"
data =
Base64.decode(
"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
Base64.DEFAULT
)
}
} else null
}

override suspend fun resolveImageUrl(uri: String): Bitmap? {
return if (uri == "https://some-image-server.com/images/f0006.png") {
testBitmap
} else null
}
}
}
Loading