Skip to content

Commit

Permalink
Add alternative GPS url coordinate (google#2719)
Browse files Browse the repository at this point in the history
* Add alternitive GPS url coordinate

* Add documentation and resolve changes

* Update docs/use/extensions.md

Co-authored-by: Nitin Sabale <[email protected]>

* Update contrib/locationwidget/src/main/java/com/google/android/fhir/datacapture/contrib/views/locationwidget/LocationGpsCoordinateViewHolderFactory.kt

Co-authored-by: Nitin Sabale <[email protected]>

---------

Co-authored-by: Benjamin Mwalimu <[email protected]>
Co-authored-by: Nitin Sabale <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent 4814123 commit 507e89c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
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
4 changes: 4 additions & 0 deletions docs/use/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ This page lists [FHIR Extensions](http://hl7.org/fhir/extensibility.html) define
* Dialog extension (https://github.com/google/android-fhir/StructureDefinition/dialog)

This extension can only be used if the questionnaire item type is `choice` and has an item-control of type `check-box` or `radio-button`.

* GPS Coordinate URL extension (https://github.com/google/android-fhir/StructureDefinition/gps-coordinate)

This URL extension can only be used if the questionnaire item type is `decimal` and has a valueString `latitude` or `longitude` .

0 comments on commit 507e89c

Please sign in to comment.