Skip to content

Commit

Permalink
Merge branch 'master' into sp/date_parsing_in_demo
Browse files Browse the repository at this point in the history
  • Loading branch information
santosh-pingle authored Dec 11, 2024
2 parents 0b032dc + 17029eb commit 1b0141b
Show file tree
Hide file tree
Showing 86 changed files with 3,536 additions and 186 deletions.
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ object Dependencies {
const val mockWebServer = "com.squareup.okhttp3:mockwebserver:${Versions.http}"

const val jsonToolsPatch = "com.github.java-json-tools:json-patch:${Versions.jsonToolsPatch}"
const val material = "com.google.android.material:material:${Versions.material}"
const val sqlcipher = "net.zetetic:android-database-sqlcipher:${Versions.sqlcipher}"
const val timber = "com.jakewharton.timber:timber:${Versions.timber}"
const val woodstox = "com.fasterxml.woodstox:woodstox-core:${Versions.woodstox}"
Expand Down Expand Up @@ -143,7 +142,6 @@ object Dependencies {

const val jsonToolsPatch = "1.13"
const val jsonAssert = "1.5.1"
const val material = "1.9.0"
const val retrofit = "2.9.0"
const val gsonConverter = "2.1.0"
const val sqlcipher = "4.5.4"
Expand Down
8 changes: 7 additions & 1 deletion buildSrc/src/main/kotlin/Releases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object Releases {

object Engine : LibraryArtifact {
override val artifactId = "engine"
override val version = "1.0.0"
override val version = "1.1.0"
override val name = "Android FHIR Engine Library"
}

Expand Down Expand Up @@ -98,6 +98,12 @@ object Releases {
const val versionCode = 1
const val versionName = "1.0"
}

object WorkflowDemo {
const val applicationId = "com.google.android.fhir.workflow.demo"
const val versionCode = 1
const val versionName = "1.0"
}
}

fun Project.publishArtifact(artifact: LibraryArtifact) {
Expand Down
2 changes: 1 addition & 1 deletion catalog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ dependencies {

coreLibraryDesugaring(Dependencies.desugarJdkLibs)

implementation(Dependencies.material)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.core)
implementation(libs.androidx.fragment)
implementation(libs.androidx.navigation.fragment)
implementation(libs.androidx.navigation.ui)
implementation(libs.kotlin.stdlib)
implementation(libs.material)

implementation(project(path = ":datacapture"))
implementation(project(path = ":engine"))
Expand Down
20 changes: 10 additions & 10 deletions codelabs/datacapture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ of the `app/build.gradle.kts` file of your project:
dependencies {
// ...

implementation("com.google.android.fhir:data-capture:1.0.0")
implementation("androidx.fragment:fragment-ktx:1.5.5")
implementation("com.google.android.fhir:data-capture:1.2.0")
implementation("androidx.fragment:fragment-ktx:1.6.0")
}
```

Expand Down Expand Up @@ -150,11 +150,11 @@ Open `MainActivity.kt` and add the following code to the `MainActivity` class:

```kotlin
// Step 2: Configure a QuestionnaireFragment
val questionnaireJsonString = getStringFromAssets("questionnaire.json")
questionnaireJsonString = getStringFromAssets("questionnaire.json")

val questionnaireFragment =
QuestionnaireFragment.builder().setQuestionnaire(questionnaireJsonString!!).build()

val questionnaireParams = bundleOf(
QuestionnaireFragment.EXTRA_QUESTIONNAIRE_JSON_STRING to questionnaireJsonString
)
```

### Step 3: Add the QuestionnaireFragment to the FragmentContainerView
Expand All @@ -168,10 +168,10 @@ Add the following code to the `MainActivity` class:
```kotlin
// Step 3: Add the QuestionnaireFragment to the FragmentContainerView
if (savedInstanceState == null) {
supportFragmentManager.commit {
setReorderingAllowed(true)
add<QuestionnaireFragment>(R.id.fragment_container_view, args = questionnaireParams)
}
supportFragmentManager.commit {
setReorderingAllowed(true)
add(R.id.fragment_container_view, questionnaireFragment)
}
}
// Submit button callback
supportFragmentManager.setFragmentResultListener(
Expand Down
10 changes: 8 additions & 2 deletions codelabs/engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ file of your project:
dependencies {
// ...
implementation("com.google.android.fhir:engine:1.0.0")
implementation("com.google.android.fhir:engine:1.1.0")
}
```
Expand Down Expand Up @@ -257,7 +257,13 @@ outlined below will guide you through the process.
override fun getFhirEngine() = FhirApplication.fhirEngine(applicationContext)
override fun getUploadStrategy() = UploadStrategy.AllChangesSquashedBundlePut
override fun getUploadStrategy() =
UploadStrategy.forBundleRequest(
methodForCreate = HttpCreateMethod.PUT,
methodForUpdate = HttpUpdateMethod.PATCH,
squash = true,
bundleSize = 500,
)
}
```
Expand Down
2 changes: 1 addition & 1 deletion codelabs/engine/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ dependencies {
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")

implementation("com.google.android.fhir:engine:1.0.0")
implementation("com.google.android.fhir:engine:1.1.0")
implementation("androidx.fragment:fragment-ktx:1.8.3")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 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 @@ -30,8 +30,10 @@ class PatientItemViewHolder(binding: PatientListItemViewBinding) :

fun bind(patientItem: Patient) {
nameTextView.text =
patientItem.name.first().let { it.given.joinToString(separator = " ") + " " + it.family }
genderTextView.text = patientItem.gender.display
patientItem.name.firstOrNull()?.let {
it.given.joinToString(separator = " ") + " " + it.family
}
genderTextView.text = patientItem.gender?.display
cityTextView.text = patientItem.address.singleOrNull()?.city
}
}
2 changes: 1 addition & 1 deletion contrib/barcode/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ dependencies {
implementation(Dependencies.Mlkit.barcodeScanning)
implementation(Dependencies.Mlkit.objectDetection)
implementation(Dependencies.Mlkit.objectDetectionCustom)
implementation(Dependencies.material)
implementation(Dependencies.timber)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core)
implementation(libs.androidx.fragment)
implementation(libs.material)

testImplementation(Dependencies.mockitoInline)
testImplementation(Dependencies.mockitoKotlin)
Expand Down
2 changes: 1 addition & 1 deletion contrib/locationwidget/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ dependencies {

implementation(project(":datacapture"))
implementation(Dependencies.playServicesLocation)
implementation(Dependencies.material)
implementation(Dependencies.timber)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core)
implementation(libs.androidx.fragment)
implementation(libs.kotlinx.coroutines.playservices)
implementation(libs.material)

coreLibraryDesugaring(Dependencies.desugarJdkLibs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.core.view.isVisible
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth.assertThat
import org.hl7.fhir.r4.model.Questionnaire
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -55,4 +56,30 @@ class LocationGpsCoordinateViewHolderFactoryInstrumentedTest {
)
.isEqualTo(InputType.TYPE_NULL)
}

@Test
fun matcherShouldReturnTrueForOriginalGpsCoordinateUrl() {
val questionnaireItem = Questionnaire.QuestionnaireItemComponent()
questionnaireItem.addExtension(
LocationGpsCoordinateViewHolderFactory.PRIMARY_GPS_COORDINATE_EXTENSION_URL,
null,
)
assertThat(LocationGpsCoordinateViewHolderFactory.matcher(questionnaireItem)).isTrue()
}

@Test
fun matcherShouldReturnTrueForOldGpsCoordinateUrl() {
val questionnaireItem = Questionnaire.QuestionnaireItemComponent()
questionnaireItem.addExtension(
LocationGpsCoordinateViewHolderFactory.GPS_COORDINATE_EXTENSION_URL,
null,
)
assertThat(LocationGpsCoordinateViewHolderFactory.matcher(questionnaireItem)).isTrue()
}

@Test
fun matcherShouldReturnFalseForNoGpsCoordinateUrl() {
val questionnaireItem = Questionnaire.QuestionnaireItemComponent()
assertThat(LocationGpsCoordinateViewHolderFactory.matcher(questionnaireItem)).isFalse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ object LocationGpsCoordinateViewHolderFactory :
header.context.tryUnwrapContext()?.apply {
val gpsCoordinateExtensionValue =
questionnaireViewItem.questionnaireItem
.getExtensionByUrl(GPS_COORDINATE_EXTENSION_URL)
.value as StringType
.getExtensionByUrl(PRIMARY_GPS_COORDINATE_EXTENSION_URL)
?.value as? StringType
?: questionnaireViewItem.questionnaireItem
.getExtensionByUrl(GPS_COORDINATE_EXTENSION_URL)
.value as StringType
when (gpsCoordinateExtensionValue.valueAsString) {
GPS_COORDINATE_EXTENSION_VALUE_LATITUDE -> {
supportFragmentManager.setFragmentResultListener(
Expand Down Expand Up @@ -148,9 +151,12 @@ object LocationGpsCoordinateViewHolderFactory :
}

fun matcher(questionnaireItem: Questionnaire.QuestionnaireItemComponent): Boolean {
return questionnaireItem.hasExtension(GPS_COORDINATE_EXTENSION_URL)
return questionnaireItem.hasExtension(PRIMARY_GPS_COORDINATE_EXTENSION_URL) ||
questionnaireItem.hasExtension(GPS_COORDINATE_EXTENSION_URL)
}

const val PRIMARY_GPS_COORDINATE_EXTENSION_URL =
"https://github.com/google/android-fhir/StructureDefinition/gps-coordinate"
const val GPS_COORDINATE_EXTENSION_URL = "gps-coordinate"
const val GPS_COORDINATE_EXTENSION_VALUE_LATITUDE = "latitude"
const val GPS_COORDINATE_EXTENSION_VALUE_LONGITUDE = "longitude"
Expand Down
2 changes: 1 addition & 1 deletion datacapture/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ dependencies {
exclude(module = "commons-logging")
exclude(module = "httpclient")
}
implementation(Dependencies.material)
implementation(Dependencies.timber)
implementation(libs.android.fhir.common)
implementation(libs.androidx.appcompat)
Expand All @@ -101,6 +100,7 @@ dependencies {
implementation(libs.glide)
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.material)

testImplementation(Dependencies.mockitoInline)
testImplementation(Dependencies.mockitoKotlin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.google.android.fhir.datacapture.extensions.isHelpCode
import com.google.android.fhir.datacapture.extensions.isHidden
import com.google.android.fhir.datacapture.extensions.isPaginated
import com.google.android.fhir.datacapture.extensions.isRepeatedGroup
import com.google.android.fhir.datacapture.extensions.launchTimestamp
import com.google.android.fhir.datacapture.extensions.localizedTextSpanned
import com.google.android.fhir.datacapture.extensions.maxValue
import com.google.android.fhir.datacapture.extensions.maxValueCqfCalculatedValueExpression
Expand All @@ -64,6 +65,7 @@ import com.google.android.fhir.datacapture.validation.Valid
import com.google.android.fhir.datacapture.validation.ValidationResult
import com.google.android.fhir.datacapture.views.QuestionTextConfiguration
import com.google.android.fhir.datacapture.views.QuestionnaireViewItem
import java.util.Date
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -74,6 +76,7 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.flow.withIndex
import kotlinx.coroutines.launch
import org.hl7.fhir.r4.model.DateTimeType
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent
import org.hl7.fhir.r4.model.QuestionnaireResponse
Expand Down Expand Up @@ -160,6 +163,8 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
.forEach { questionnaireResponse.addItem(it.createQuestionnaireResponseItem()) }
}
}
// Add extension for questionnaire launch time stamp
questionnaireResponse.launchTimestamp = DateTimeType(Date())
questionnaireResponse.packRepeatedGroups(questionnaire)
}

Expand Down Expand Up @@ -475,6 +480,8 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
)
.map { it.copy() }
unpackRepeatedGroups(this@QuestionnaireViewModel.questionnaire)
// Use authored as a submission time stamp
authored = Date()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.google.android.fhir.datacapture.extensions
import android.content.Context
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.method.LinkMovementMethod
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.Button
Expand Down Expand Up @@ -82,7 +83,10 @@ fun initHelpViews(
}
}
}
helpTextView.updateTextAndVisibility(questionnaireItem.localizedHelpSpanned)
helpTextView.apply {
updateTextAndVisibility(questionnaireItem.localizedHelpSpanned)
movementMethod = LinkMovementMethod.getInstance()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@

package com.google.android.fhir.datacapture.extensions

import org.hl7.fhir.r4.model.DateTimeType
import org.hl7.fhir.r4.model.Extension
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.QuestionnaireResponse

internal const val EXTENSION_LAST_LAUNCHED_TIMESTAMP: String =
"http://github.com/google-android/questionnaire-lastLaunched-timestamp"

/** Pre-order list of all questionnaire response items in the questionnaire. */
val QuestionnaireResponse.allItems: List<QuestionnaireResponse.QuestionnaireResponseItemComponent>
get() = item.flatMap { it.descendant }
Expand Down Expand Up @@ -146,3 +151,20 @@ private fun unpackRepeatedGroups(
listOf(questionnaireResponseItem)
}
}

/**
* Adds a launch timestamp extension to the Questionnaire Response. If the extension @see
* EXTENSION_LAUNCH_TIMESTAMP already exists, it updates its value; otherwise, it adds a new one.
*/
internal var QuestionnaireResponse.launchTimestamp: DateTimeType?
get() {
val extension = this.extension.firstOrNull { it.url == EXTENSION_LAST_LAUNCHED_TIMESTAMP }
return extension?.value as? DateTimeType
}
set(value) {
extension.find { it.url == EXTENSION_LAST_LAUNCHED_TIMESTAMP }?.setValue(value)
?: run {
// Add a new extension if none exists
extension.add(Extension(EXTENSION_LAST_LAUNCHED_TIMESTAMP, value))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.android.fhir.datacapture.views

import android.content.Context
import android.text.method.LinkMovementMethod
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
Expand Down Expand Up @@ -55,11 +56,17 @@ class GroupHeaderView(context: Context, attrs: AttributeSet?) : LinearLayout(con
helpCardStateChangedCallback = questionnaireViewItem.helpCardStateChangedCallback,
)
prefix.updateTextAndVisibility(questionnaireViewItem.questionnaireItem.localizedPrefixSpanned)
// CQF expression takes precedence over static question text
question.updateTextAndVisibility(questionnaireViewItem.questionText)
hint.updateTextAndVisibility(
questionnaireViewItem.enabledDisplayItems.getLocalizedInstructionsSpanned(),
)
question.apply {
// CQF expression takes precedence over static question text
updateTextAndVisibility(questionnaireViewItem.questionText)
movementMethod = LinkMovementMethod.getInstance()
}
hint.apply {
updateTextAndVisibility(
questionnaireViewItem.enabledDisplayItems.getLocalizedInstructionsSpanned(),
)
movementMethod = LinkMovementMethod.getInstance()
}
visibility = getHeaderViewVisibility(prefix, question, hint)
applyCustomOrDefaultStyle(
questionnaireViewItem.questionnaireItem,
Expand Down
Loading

0 comments on commit 1b0141b

Please sign in to comment.