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 Location co-ordinates on questionnaire submission #2997

Merged
merged 77 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
563fca0
Add location permissions to get location details on submission
DebbieArita Jan 18, 2024
6c52152
Edit current location
DebbieArita Jan 18, 2024
dcfbe3c
Append precise and approximate location to the questionnaireResponse
DebbieArita Jan 22, 2024
6a9307e
Merge branch 'main' into questionnaire-location
DebbieArita Jan 22, 2024
093138c
Add application config checker
DebbieArita Jan 23, 2024
cf61cc8
Add logQuestionnaireLocation config to toggle functionality
DebbieArita Jan 23, 2024
ca395b2
Merge branch 'main' into questionnaire-location
DebbieArita Jan 23, 2024
eabd1be
Run SpotlessApply
DebbieArita Jan 23, 2024
13c170d
Merge branch 'main' into questionnaire-location
DebbieArita Feb 1, 2024
2427914
Run location calculation in background and add user checks
DebbieArita Feb 1, 2024
d2dd2f0
Update build gradle
DebbieArita Feb 2, 2024
e7babb2
Code refactors
qiarie Feb 6, 2024
57ee61e
Code cleanup
qiarie Feb 6, 2024
6d0a310
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Feb 6, 2024
16285f7
Refactor location implementation
qiarie Feb 6, 2024
ba0fc6f
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Feb 6, 2024
8d8df47
Rename location setup
qiarie Feb 6, 2024
66ec65f
Fix crash on opening location service settings after permissions
qiarie Feb 6, 2024
a910980
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Feb 6, 2024
06c6e7c
Merge branch 'main' into questionnaire-location
brandyodhiambo Feb 8, 2024
52bea17
Resolve merge conflict
brandyodhiambo Feb 8, 2024
c59f335
Add tests
DebbieArita Feb 9, 2024
8431a58
Allow location picking when location service & permissions are alread…
qiarie Feb 9, 2024
4c39e81
add service location test on QuestionnaireActivityTest
brandyodhiambo Feb 13, 2024
ae10339
Merge branch 'main' into questionnaire-location
brandyodhiambo Feb 13, 2024
7cbbac0
Merge remote-tracking branch 'origin/questionnaire-location' into que…
brandyodhiambo Feb 13, 2024
642542d
Merge branch 'main' into questionnaire-location
DebbieArita Feb 19, 2024
a686ce0
Add tests and Run SpotlessApply
DebbieArita Feb 19, 2024
1a8e82c
Merge remote-tracking branch 'origin/questionnaire-location' into que…
DebbieArita Feb 19, 2024
94a01e0
Merge branch 'main' into questionnaire-location
DebbieArita Feb 19, 2024
150c64f
Empty commit
DebbieArita Feb 19, 2024
3b46ada
Update RegisterCardList tests
DebbieArita Feb 20, 2024
7493e33
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Feb 21, 2024
2f47f93
Resolve merge conflicts and WIP questionnaire improvements
DebbieArita Feb 22, 2024
1a9ed26
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Feb 23, 2024
a06ae76
Log GPS location fetch failure
qiarie Feb 23, 2024
4e12927
Update QuestionnaireActivityTests
DebbieArita Feb 23, 2024
baae9b3
Merge branch 'main' into questionnaire-location
DebbieArita Feb 23, 2024
5e4dee6
Merge branch 'main' into questionnaire-location
DebbieArita Feb 23, 2024
2423fc5
Merge remote-tracking branch 'origin/questionnaire-location' into que…
DebbieArita Feb 23, 2024
516f484
Remove comments
DebbieArita Feb 23, 2024
8f63da1
Merge branch 'main' into questionnaire-location
Lentumunai-Mark Feb 26, 2024
554eb83
Update tests WIP
DebbieArita Feb 26, 2024
fe035a6
Merge branch 'main' into questionnaire-location
dubdabasoduba Feb 26, 2024
066d1b9
Merge branch 'main' into questionnaire-location
DebbieArita Feb 27, 2024
a107cc5
Merge branch 'main' into questionnaire-location
DebbieArita Feb 28, 2024
1797620
Update LocationUtils tests
DebbieArita Feb 28, 2024
d30b3bf
Run spotlessApply
DebbieArita Feb 28, 2024
5d2d057
Refactor PermissionsUtilsTest
DebbieArita Feb 28, 2024
4b054df
Refactor ResourceUtilsTest
DebbieArita Feb 28, 2024
56c26b3
Run SpotlessApply
DebbieArita Feb 28, 2024
14e18fe
Merge branch 'main' into questionnaire-location
pld Mar 4, 2024
1210019
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Mar 5, 2024
5623799
Update ApplicationConfiguration docs
qiarie Mar 5, 2024
da25d8d
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Mar 7, 2024
e3719a6
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Mar 7, 2024
b148c88
Merge branch 'main' into questionnaire-location
DebbieArita Mar 7, 2024
ed31f2d
Merge branch 'main' into questionnaire-location
dubdabasoduba Mar 8, 2024
e2857a2
Make logGpsLocations config a list in ApplicationConfiguration
qiarie Mar 11, 2024
cc8727a
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Mar 11, 2024
02e818b
Merge branch 'questionnaire-location' of github.com:opensrp/fhircore …
qiarie Mar 11, 2024
7f8a65c
Update tests
qiarie Mar 11, 2024
aebe8cf
Update test configs
qiarie Mar 11, 2024
76908ef
Merge branch 'main' into questionnaire-location
DebbieArita Mar 12, 2024
ebdd7bb
Update docs on logGpsLocation config option
qiarie Mar 12, 2024
e5577fe
Merge branch 'questionnaire-location' of github.com:opensrp/fhircore …
qiarie Mar 12, 2024
a6587f8
Merge remote-tracking branch 'origin/main' into questionnaire-location
qiarie Mar 12, 2024
1b4aaa4
Merge branch 'main' into questionnaire-location
dubdabasoduba Mar 12, 2024
f5a9f1a
Update android/quest/src/main/java/org/smartregister/fhircore/quest/u…
qiarie Mar 13, 2024
8568ea7
Merge branch 'main' into questionnaire-location
DebbieArita Mar 13, 2024
b4a0513
Run SpotlessApply
DebbieArita Mar 13, 2024
9cc8d0c
Update fhir Location from GPS and remove null safety
DebbieArita Mar 14, 2024
e5d3a9f
Run SpotlessApply
DebbieArita Mar 14, 2024
eeee521
Update test
DebbieArita Mar 14, 2024
6b009f2
Merge branch 'main' into questionnaire-location
dubdabasoduba Mar 15, 2024
34fffda
Update application config docs
DebbieArita Mar 15, 2024
ac82739
Update location permission denied string
DebbieArita Mar 15, 2024
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
2 changes: 1 addition & 1 deletion android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ dependencies {
api(libs.jjwt)
api(libs.fhir.common.utils) { exclude(group = "org.slf4j", module = "jcl-over-slf4j") }
api(libs.runtime.livedata)
// api(libs.material3)
// api(libs.material3)
DebbieArita marked this conversation as resolved.
Show resolved Hide resolved
api(libs.foundation)
api(libs.fhir.common.utils)
api(libs.kotlinx.serialization.json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ data class ApplicationConfiguration(
val showLogo: Boolean = true,
val taskBackgroundWorkerBatchSize: Int = 500,
val eventWorkflows: List<EventWorkflow> = emptyList(),
val logGpsLocation: List<LocationLogOptions> = emptyList(),
) : Configuration()

enum class LocationLogOptions {
QUESTIONNAIRE,
}
8 changes: 6 additions & 2 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ okhttp = "4.12.0"
okhttp-logging-interceptor = "4.11.0"
orchestrator = "1.4.2"
p2p-lib = "0.6.9-SNAPSHOT"
paging-compose = "3.2.0"
paging-runtime-ktx = "3.2.0"
playServicesLocation = "21.0.1"
paging = "3.2.1"
preference-ktx = "1.2.1"
prettytime = "5.0.2.Final"
Expand Down Expand Up @@ -164,8 +167,9 @@ okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhtt
okhttp-logging-interceptor = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp-logging-interceptor" }
orchestrator = { group = "androidx.test", name = "orchestrator", version.ref = "orchestrator" }
p2p-lib = { group = "org.smartregister", name = "p2p-lib", version.ref = "p2p-lib" }
paging-compose = { group = "androidx.paging", name = "paging-compose", version.ref = "paging" }
paging-runtime-ktx = { group = "androidx.paging", name = "paging-runtime-ktx", version.ref = "paging" }
paging-compose = { group = "androidx.paging", name = "paging-compose", version.ref = "paging-compose" }
paging-runtime-ktx = { group = "androidx.paging", name = "paging-runtime-ktx", version.ref = "paging-runtime-ktx" }
play-services-location = { module = "com.google.android.gms:play-services-location", version.ref = "playServicesLocation" }
preference-ktx = { group = "androidx.preference", name = "preference-ktx", version.ref = "preference-ktx" }
prettytime = { group = "org.ocpsoft.prettytime", name = "prettytime", version.ref = "prettytime" }
retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
Expand Down
1 change: 1 addition & 0 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ dependencies {
implementation(libs.material)
implementation(libs.dagger.hilt.android)
implementation(libs.hilt.work)
implementation(libs.play.services.location)

// Annotation processors
kapt(libs.hilt.compiler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RegisterCardListTest {
)
}

composeTestRule.onNodeWithTag(REGISTER_CARD_LIST_TEST_TAG).onChildren().assertCountEquals(2)
composeTestRule.onNodeWithTag(REGISTER_CARD_LIST_TEST_TAG).onChildren().assertCountEquals(3)

composeTestRule
.onNodeWithTag(REGISTER_CARD_LIST_TEST_TAG)
Expand Down Expand Up @@ -119,7 +119,7 @@ class RegisterCardListTest {
)
}

composeTestRule.onNodeWithTag(REGISTER_CARD_LIST_TEST_TAG).onChildren().assertCountEquals(3)
composeTestRule.onNodeWithTag(REGISTER_CARD_LIST_TEST_TAG).onChildren().assertCountEquals(4)

composeTestRule
.onNodeWithTag(REGISTER_CARD_LIST_TEST_TAG)
Expand Down
3 changes: 3 additions & 0 deletions android/quest/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@
android:resource="@xml/file_paths" />
</provider>
</application>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@
}
]
}
],
"logGpsLocation": [
"QUESTIONNAIRE"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,74 @@

package org.smartregister.fhircore.quest.ui.questionnaire

import android.Manifest
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.location.Location
import android.os.Bundle
import android.os.Parcelable
import android.provider.Settings
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.viewModels
import androidx.core.os.bundleOf
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
import com.google.android.fhir.datacapture.QuestionnaireFragment
import com.google.android.fhir.logicalId
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import dagger.hilt.android.AndroidEntryPoint
import java.io.Serializable
import java.util.LinkedList
import javax.inject.Inject
import kotlinx.coroutines.launch
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.hl7.fhir.r4.model.Resource
import org.hl7.fhir.r4.model.ResourceType
import org.smartregister.fhircore.engine.configuration.QuestionnaireConfig
import org.smartregister.fhircore.engine.configuration.app.LocationLogOptions
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
import org.smartregister.fhircore.engine.domain.model.isEditable
import org.smartregister.fhircore.engine.domain.model.isReadOnly
import org.smartregister.fhircore.engine.ui.base.AlertDialogue
import org.smartregister.fhircore.engine.ui.base.BaseMultiLanguageActivity
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.extension.clearText
import org.smartregister.fhircore.engine.util.extension.encodeResourceToString
import org.smartregister.fhircore.engine.util.extension.parcelable
import org.smartregister.fhircore.engine.util.extension.parcelableArrayList
import org.smartregister.fhircore.engine.util.extension.showToast
import org.smartregister.fhircore.quest.R
import org.smartregister.fhircore.quest.databinding.QuestionnaireActivityBinding
import org.smartregister.fhircore.quest.util.LocationUtils
import org.smartregister.fhircore.quest.util.PermissionUtils
import org.smartregister.fhircore.quest.util.ResourceUtils
import timber.log.Timber

@AndroidEntryPoint
class QuestionnaireActivity : BaseMultiLanguageActivity() {

@Inject lateinit var dispatcherProvider: DispatcherProvider
val viewModel by viewModels<QuestionnaireViewModel>()
private lateinit var questionnaireConfig: QuestionnaireConfig
private lateinit var actionParameters: ArrayList<ActionParameter>
private lateinit var viewBinding: QuestionnaireActivityBinding
private var questionnaire: Questionnaire? = null
private var alertDialog: AlertDialog? = null
private lateinit var fusedLocationClient: FusedLocationProviderClient
var currentLocation: Location? = null

Check warning on line 80 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L80

Added line #L80 was not covered by tests
private lateinit var locationPermissionLauncher: ActivityResultLauncher<Array<String>>
private lateinit var activityResultLauncher: ActivityResultLauncher<Intent>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setTheme(org.smartregister.fhircore.engine.R.style.AppTheme_Questionnaire)
viewBinding = QuestionnaireActivityBinding.inflate(layoutInflater)
setContentView(viewBinding.root)
Expand Down Expand Up @@ -97,6 +116,8 @@

if (savedInstanceState == null) renderQuestionnaire()

setupLocationServices()

Check warning on line 119 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L119

Added line #L119 was not covered by tests

this.onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(true) {
Expand All @@ -107,6 +128,103 @@
)
}

fun setupLocationServices() {
if (
viewModel.applicationConfiguration.logGpsLocation.contains(LocationLogOptions.QUESTIONNAIRE)
) {
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)

Check warning on line 135 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L135

Added line #L135 was not covered by tests

if (!LocationUtils.isLocationEnabled(this)) {
openLocationServicesSettings()

Check warning on line 138 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L138

Added line #L138 was not covered by tests
}

if (!hasLocationPermissions()) {
launchLocationPermissionsDialog()

Check warning on line 142 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L142

Added line #L142 was not covered by tests
}

if (LocationUtils.isLocationEnabled(this) && hasLocationPermissions()) {
fetchLocation(true)

Check warning on line 146 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L146

Added line #L146 was not covered by tests
}
}
}

fun hasLocationPermissions(): Boolean {
return PermissionUtils.checkPermissions(
this,
listOf(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,

Check warning on line 156 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L152-L156

Added lines #L152 - L156 were not covered by tests
),
)
}

fun openLocationServicesSettings() {
activityResultLauncher =
PermissionUtils.getStartActivityForResultLauncher(this) { resultCode, _ ->

Check warning on line 163 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L162-L163

Added lines #L162 - L163 were not covered by tests
if (resultCode == RESULT_OK || hasLocationPermissions()) {
fetchLocation()

Check warning on line 165 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L165

Added line #L165 was not covered by tests
}
}

val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
showLocationSettingsDialog(intent)

Check warning on line 170 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L169-L170

Added lines #L169 - L170 were not covered by tests
}

private fun showLocationSettingsDialog(intent: Intent) {
viewModel.setProgressState(QuestionnaireProgressState.QuestionnaireLaunch(false))
AlertDialog.Builder(this)
.setMessage(getString(R.string.location_services_disabled))
.setCancelable(true)

Check warning on line 177 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L174-L177

Added lines #L174 - L177 were not covered by tests
.setPositiveButton(getString(R.string.yes)) { _, _ -> activityResultLauncher.launch(intent) }
.setNegativeButton(getString(R.string.no)) { dialog, _ -> dialog.cancel() }
.show()

Check warning on line 180 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L179-L180

Added lines #L179 - L180 were not covered by tests
}

fun launchLocationPermissionsDialog() {
locationPermissionLauncher =
PermissionUtils.getLocationPermissionLauncher(
this,
onFineLocationPermissionGranted = { fetchLocation(true) },
onCoarseLocationPermissionGranted = { fetchLocation(false) },

Check warning on line 188 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L184-L188

Added lines #L184 - L188 were not covered by tests
onLocationPermissionDenied = {
Toast.makeText(
this,
getString(R.string.location_permissions_denied),
Toast.LENGTH_SHORT,

Check warning on line 193 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L190-L193

Added lines #L190 - L193 were not covered by tests
)
.show()
Timber.e("Location permissions denied")
},

Check warning on line 197 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L195-L197

Added lines #L195 - L197 were not covered by tests
)

locationPermissionLauncher.launch(
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,

Check warning on line 203 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L202-L203

Added lines #L202 - L203 were not covered by tests
),
)
}

fun fetchLocation(highAccuracy: Boolean = true) {
lifecycleScope.launch {
try {

Check warning on line 210 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L208-L210

Added lines #L208 - L210 were not covered by tests
if (highAccuracy) {
currentLocation =

Check warning on line 212 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L212

Added line #L212 was not covered by tests
LocationUtils.getAccurateLocation(fusedLocationClient, dispatcherProvider.io())
} else {
currentLocation =

Check warning on line 215 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L215

Added line #L215 was not covered by tests
LocationUtils.getApproximateLocation(fusedLocationClient, dispatcherProvider.io())
}
} catch (e: Exception) {

Check warning on line 218 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L218

Added line #L218 was not covered by tests
Timber.e(e, "Failed to get GPS location for questionnaire: ${questionnaireConfig.id}")
} finally {
if (currentLocation == null) {
this@QuestionnaireActivity.showToast("Failed to get GPS location", Toast.LENGTH_LONG)

Check warning on line 222 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L222

Added line #L222 was not covered by tests
}
}
}
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.clear()
Expand Down Expand Up @@ -238,6 +356,13 @@
if (questionnaireResponse != null && questionnaire != null) {
viewModel.run {
setProgressState(QuestionnaireProgressState.ExtractionInProgress(true))

if (currentLocation != null) {
questionnaireResponse.contained.add(
ResourceUtils.createLocationResource(gpsLocation = currentLocation),

Check warning on line 362 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt#L361-L362

Added lines #L361 - L362 were not covered by tests
)
}

handleQuestionnaireSubmission(
questionnaire = questionnaire!!,
currentQuestionnaireResponse = questionnaireResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@
import org.hl7.fhir.r4.model.ResourceType
import org.hl7.fhir.r4.model.StringType
import org.smartregister.fhircore.engine.BuildConfig
import org.smartregister.fhircore.engine.configuration.ConfigType
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.GroupResourceConfig
import org.smartregister.fhircore.engine.configuration.LinkIdType
import org.smartregister.fhircore.engine.configuration.QuestionnaireConfig
import org.smartregister.fhircore.engine.configuration.app.ApplicationConfiguration
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
Expand Down Expand Up @@ -104,6 +107,7 @@
val sharedPreferencesHelper: SharedPreferencesHelper,
val fhirOperator: FhirOperator,
val fhirPathDataExtractor: FhirPathDataExtractor,
val configurationRegistry: ConfigurationRegistry,

Check warning on line 110 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt#L110

Added line #L110 was not covered by tests
) : ViewModel() {
private val parser = FhirContext.forR4Cached().newJsonParser()

Expand All @@ -121,6 +125,10 @@
val questionnaireProgressStateLiveData: LiveData<QuestionnaireProgressState?>
get() = _questionnaireProgressStateLiveData

val applicationConfiguration: ApplicationConfiguration by lazy {

Check warning on line 128 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt#L128

Added line #L128 was not covered by tests
configurationRegistry.retrieveConfiguration(ConfigType.Application)
}

/**
* This function retrieves the [Questionnaire] as configured via the [QuestionnaireConfig]. The
* retrieved [Questionnaire] can be pre-populated with computed values from the Rules engine.
Expand Down
Loading
Loading