Skip to content

Commit 9b1cb4f

Browse files
authored
Fixed demo app crash by appropriately handing ResourceNotFoundException. (google#2152)
1 parent 4681561 commit 9b1cb4f

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

demo/src/main/assets/screener-questionnaire.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,16 +1144,7 @@
11441144
{
11451145
"text": "Add instructions for capturing temperature",
11461146
"type": "display",
1147-
"linkId": "5.1.0",
1148-
"extension": [
1149-
{
1150-
"url" : "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemMedia",
1151-
"valueAttachment" : {
1152-
"contentType": "image/png",
1153-
"url": "https://hapi.fhir.org/baseR4/Binary/android-fhir-thermometer-image"
1154-
}
1155-
}
1156-
]
1147+
"linkId": "5.1.0"
11571148
},
11581149
{
11591150
"linkId": "5.2.0",

demo/src/main/java/com/google/android/fhir/demo/ReferenceUrlResolver.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Google LLC
2+
* Copyright 2022-2023 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,16 +20,23 @@ import android.content.Context
2020
import android.graphics.Bitmap
2121
import android.graphics.BitmapFactory
2222
import com.google.android.fhir.datacapture.UrlResolver
23+
import com.google.android.fhir.db.ResourceNotFoundException
2324
import com.google.android.fhir.get
2425
import org.hl7.fhir.r4.model.Binary
2526
import org.hl7.fhir.r4.model.ResourceType
27+
import timber.log.Timber
2628

2729
class ReferenceUrlResolver(val context: Context) : UrlResolver {
2830

2931
override suspend fun resolveBitmapUrl(url: String): Bitmap? {
3032
val logicalId = getLogicalIdFromFhirUrl(url, ResourceType.Binary)
31-
val binary = FhirApplication.fhirEngine(context).get<Binary>(logicalId)
32-
return BitmapFactory.decodeByteArray(binary.data, 0, binary.data.size)
33+
return try {
34+
val binary = FhirApplication.fhirEngine(context).get<Binary>(logicalId)
35+
BitmapFactory.decodeByteArray(binary.data, 0, binary.data.size)
36+
} catch (e: ResourceNotFoundException) {
37+
Timber.e(e)
38+
null
39+
}
3340
}
3441
}
3542

demo/src/main/java/com/google/android/fhir/demo/data/TimestampBasedDownloadWorkManagerImpl.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,7 @@ import org.hl7.fhir.r4.model.ResourceType
3636
class TimestampBasedDownloadWorkManagerImpl(private val dataStore: DemoDataStore) :
3737
DownloadWorkManager {
3838
private val resourceTypeList = ResourceType.values().map { it.name }
39-
private val urls =
40-
LinkedList(
41-
listOf(
42-
"Patient?address-city=NAIROBI&_sort=_lastUpdated",
43-
"Binary?_id=android-fhir-thermometer-image"
44-
)
45-
)
39+
private val urls = LinkedList(listOf("Patient?address-city=NAIROBI&_sort=_lastUpdated"))
4640

4741
override suspend fun getNextRequest(): DownloadRequest? {
4842
var url = urls.poll() ?: return null

0 commit comments

Comments
 (0)