Skip to content

Commit

Permalink
Add support to be able to configure FHIR Urls, user/pwd and query
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-fdeniger committed Mar 12, 2024
1 parent cf6446c commit 4804f0d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ This repository also contains the following demo apps:

**These applications are provided for demo purposes only. Do NOT use in production.**

By default the FHIS Engine Demo App use the server hapi.fhir.org and the query `Patient?address-city=NAIROBI&_sort=_lastUpdated`.
It's possible to change this default server by adding these properties in the file `local.properties`:

```dotenv
#language= URL to the FHIR APP. For openmrs
# default value is https://hapi.fhir.org/baseR4/. For OpenMRS:
fhir_url=https://<yourServer>/openmrs/ws/fhir2/R4/
fhir_user=....
fhir_pwd=....
# default value is Patient?address-city=NAIROBI&_sort=_lastUpdated
# To have last updated patients for all addresses use:
fhir_query=Patient?&_sort=_lastUpdated
```

## Contributing

The development of the SDK began as a collaborative effort between Google, [The World Health Organization](https://www.who.int/), and [Ona](https://ona.io/). Since then, a consortium of application developers have been contributing to the project.
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object Plugins {
const val kotlin = "kotlin"
const val kotlinAndroid = "kotlin-android"
const val kotlinKapt = "kotlin-kapt"
const val kotlinKsp = "com.google.devtools.ksp"
const val mavenPublish = "maven-publish"
const val fladle = "com.osacky.fladle"
const val navSafeArgs = "androidx.navigation.safeargs.kotlin"
Expand All @@ -47,5 +48,6 @@ object Plugins {
const val androidGradlePlugin = "8.0.2"
const val benchmarkPlugin = "1.1.0"
const val dokka = "1.7.20"
const val ksp = "1.9.21-1.0.16"
}
}
3 changes: 2 additions & 1 deletion demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
/gradle.properties
13 changes: 13 additions & 0 deletions demo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.io.FileInputStream
import java.util.Properties

plugins {
id(Plugins.BuildPlugins.application)
id(Plugins.BuildPlugins.kotlinAndroid)
Expand All @@ -10,13 +13,21 @@ configureRuler()
android {
namespace = "com.google.android.fhir.demo"
compileSdk = Sdk.compileSdk
val properties=Properties()
if (project.rootProject.file("local.properties").exists()){
properties.load(FileInputStream(rootProject.file("local.properties")))
}
defaultConfig {
applicationId = Releases.Demo.applicationId
minSdk = Sdk.minSdk
targetSdk = Sdk.targetSdk
versionCode = Releases.Demo.versionCode
versionName = Releases.Demo.versionName
testInstrumentationRunner = Dependencies.androidJunitRunner
resValue("string","fhir_url",properties.getProperty("fhir_url", ""))
resValue("string","fhir_user",properties.getProperty("fhir_user", ""))
resValue("string","fhir_pwd",properties.getProperty("fhir_pwd", ""))
resValue("string","fhir_query",properties.getProperty("fhir_query", ""))
}
buildTypes {
release {
Expand All @@ -34,6 +45,8 @@ android {
isCoreLibraryDesugaringEnabled = true
}



packaging { resources.excludes.addAll(listOf("META-INF/ASL-2.0.txt", "META-INF/LGPL-3.0.txt")) }
kotlin { jvmToolchain(11) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class DemoDataStore(private val context: Context) {
context.dataStorage.edit { pref -> pref[stringPreferencesKey(resourceType.name)] = timestamp }
}

fun getFhirQuery():String{
return context.getString(R.string.fhir_query).ifBlank { "Patient?address-city=NAIROBI&_sort=_lastUpdated" }
}

suspend fun getLasUpdateTimestamp(resourceType: ResourceType): String? {
return context.dataStorage.data.first()[stringPreferencesKey(resourceType.name)]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ 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.search.search
import com.google.android.fhir.sync.HttpAuthenticationMethod
import com.google.android.fhir.sync.HttpAuthenticator
import com.google.android.fhir.sync.remote.HttpLogger
import timber.log.Timber

Expand All @@ -43,12 +45,19 @@ class FhirApplication : Application(), DataCaptureConfig.Provider {
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
val baseUrl=resources.getString(R.string.fhir_url).ifBlank { "https://hapi.fhir.org/baseR4/" }
var httpAuthenticator : HttpAuthenticator?=null
val fhirUser=resources.getString(R.string.fhir_user)
if(fhirUser.isNotBlank()){
httpAuthenticator= HttpAuthenticator { HttpAuthenticationMethod.Basic(fhirUser,resources.getString(R.string.fhir_pwd) ) }
}

FhirEngineProvider.init(
FhirEngineConfiguration(
enableEncryptionIfSupported = true,
RECREATE_AT_OPEN,
ServerConfiguration(
"https://hapi.fhir.org/baseR4/",
baseUrl,
httpLogger =
HttpLogger(
HttpLogger.Configuration(
Expand All @@ -58,6 +67,8 @@ class FhirApplication : Application(), DataCaptureConfig.Provider {
Timber.tag("App-HttpLog").d(it)
},
networkConfiguration = NetworkConfiguration(uploadWithGzip = false),
// password hardcoded as available on https://openmrs.org/demo/
authenticator = httpAuthenticator
),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +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"))
private val urls = LinkedList(listOf(dataStore.getFhirQuery()))

override suspend fun getNextRequest(): DownloadRequest? {
var url = urls.poll() ?: return null
Expand Down
2 changes: 1 addition & 1 deletion engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id(Plugins.BuildPlugins.androidLib)
id(Plugins.BuildPlugins.kotlinAndroid)
//id(Plugins.BuildPlugins.kotlinKapt)
id("com.google.devtools.ksp").version("1.9.21-1.0.16")
id(Plugins.BuildPlugins.kotlinKsp).version(Plugins.Versions.ksp)
id(Plugins.BuildPlugins.mavenPublish)
jacoco
id(Plugins.BuildPlugins.dokka).version(Plugins.Versions.dokka)
Expand Down

0 comments on commit 4804f0d

Please sign in to comment.