Skip to content

Commit

Permalink
Fixed demo app crash by appropriately handing ResourceNotFoundExcepti…
Browse files Browse the repository at this point in the history
…on. (#2152)
  • Loading branch information
aditya-07 committed Sep 7, 2023
1 parent 4681561 commit 9b1cb4f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
11 changes: 1 addition & 10 deletions demo/src/main/assets/screener-questionnaire.json
Original file line number Diff line number Diff line change
Expand Up @@ -1144,16 +1144,7 @@
{
"text": "Add instructions for capturing temperature",
"type": "display",
"linkId": "5.1.0",
"extension": [
{
"url" : "http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemMedia",
"valueAttachment" : {
"contentType": "image/png",
"url": "https://hapi.fhir.org/baseR4/Binary/android-fhir-thermometer-image"
}
}
]
"linkId": "5.1.0"
},
{
"linkId": "5.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2022-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.
Expand All @@ -20,16 +20,23 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.google.android.fhir.datacapture.UrlResolver
import com.google.android.fhir.db.ResourceNotFoundException
import com.google.android.fhir.get
import org.hl7.fhir.r4.model.Binary
import org.hl7.fhir.r4.model.ResourceType
import timber.log.Timber

class ReferenceUrlResolver(val context: Context) : UrlResolver {

override suspend fun resolveBitmapUrl(url: String): Bitmap? {
val logicalId = getLogicalIdFromFhirUrl(url, ResourceType.Binary)
val binary = FhirApplication.fhirEngine(context).get<Binary>(logicalId)
return BitmapFactory.decodeByteArray(binary.data, 0, binary.data.size)
return try {
val binary = FhirApplication.fhirEngine(context).get<Binary>(logicalId)
BitmapFactory.decodeByteArray(binary.data, 0, binary.data.size)
} catch (e: ResourceNotFoundException) {
Timber.e(e)
null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ import org.hl7.fhir.r4.model.ResourceType
class TimestampBasedDownloadWorkManagerImpl(private val dataStore: DemoDataStore) :
DownloadWorkManager {
private val resourceTypeList = ResourceType.values().map { it.name }
private val urls =
LinkedList(
listOf(
"Patient?address-city=NAIROBI&_sort=_lastUpdated",
"Binary?_id=android-fhir-thermometer-image"
)
)
private val urls = LinkedList(listOf("Patient?address-city=NAIROBI&_sort=_lastUpdated"))

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

0 comments on commit 9b1cb4f

Please sign in to comment.