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

Fixed demo app crash by appropriately handing ResourceNotFoundException. #2152

Merged
merged 6 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Fixed demo app crash by appropriately handing ResourceNotFoundException.
  • Loading branch information
aditya-07 committed Sep 1, 2023
commit c9e82a7931f7d0ea1db0629711daec230446a21c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.google.android.fhir.NetworkConfiguration
import com.google.android.fhir.ServerConfiguration
import com.google.android.fhir.datacapture.DataCaptureConfig
import com.google.android.fhir.datacapture.XFhirQueryResolver
import com.google.android.fhir.db.ResourceNotFoundException
import com.google.android.fhir.search.search
import com.google.android.fhir.sync.remote.HttpLogger
import timber.log.Timber
Expand Down Expand Up @@ -63,7 +64,14 @@ class FhirApplication : Application(), DataCaptureConfig.Provider {
dataCaptureConfig =
DataCaptureConfig().apply {
urlResolver = ReferenceUrlResolver(this@FhirApplication as Context)
xFhirQueryResolver = XFhirQueryResolver { fhirEngine.search(it).map { it.resource } }
xFhirQueryResolver = XFhirQueryResolver {
try {
fhirEngine.search(it).map { it.resource }
} catch (e: ResourceNotFoundException) {
Timber.e(e)
emptyList()
}
}
}
}

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
Loading