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

Add alternative GPS url coordinate #2719

Merged
merged 6 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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.GPS_COORDINATE_EXTENSION_URL,
null,
)
assertThat(LocationGpsCoordinateViewHolderFactory.matcher(questionnaireItem)).isTrue()
}

@Test
fun matcherShouldReturnTrueForAlternativeGpsCoordinateUrl() {
val questionnaireItem = Questionnaire.QuestionnaireItemComponent()
questionnaireItem.addExtension(
LocationGpsCoordinateViewHolderFactory.ALTERNATIVE_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 @@ -60,7 +60,10 @@ object LocationGpsCoordinateViewHolderFactory :
val gpsCoordinateExtensionValue =
questionnaireViewItem.questionnaireItem
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
.getExtensionByUrl(GPS_COORDINATE_EXTENSION_URL)
.value as StringType
?.value as? StringType
?: questionnaireViewItem.questionnaireItem
.getExtensionByUrl(ALTERNATIVE_GPS_COORDINATE_EXTENSION_URL)
.value as StringType
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
when (gpsCoordinateExtensionValue.valueAsString) {
GPS_COORDINATE_EXTENSION_VALUE_LATITUDE -> {
supportFragmentManager.setFragmentResultListener(
Expand Down Expand Up @@ -148,10 +151,13 @@ object LocationGpsCoordinateViewHolderFactory :
}

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

const val GPS_COORDINATE_EXTENSION_URL = "gps-coordinate"
const val ALTERNATIVE_GPS_COORDINATE_EXTENSION_URL =
"https://github.com/google/android-fhir/gps-coordinate"
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
sharon2719 marked this conversation as resolved.
Show resolved Hide resolved
const val GPS_COORDINATE_EXTENSION_VALUE_LATITUDE = "latitude"
const val GPS_COORDINATE_EXTENSION_VALUE_LONGITUDE = "longitude"
const val GPS_COORDINATE_EXTENSION_VALUE_ALTITUDE = "altitude"
Expand Down