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 configurable confirmation dialog on form submission #3619

Merged
merged 8 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2. Introduced a new class (HtmlPopulator) to populate HTML templates with data from a Questionnaire Response
3. Implemented functionality to launch PDF generation using a configuration setup
- Added Save draft MVP functionality
- Add configurable confirmation dialog on form submission

## [1.1.0] - 2024-02-15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ data class QuestionnaireConfig(
val uniqueIdAssignment: UniqueIdAssignmentConfig? = null,
val linkIds: List<LinkIdConfig>? = null,
val showSubmitAnywayButton: String = "false",
val showSubmissionConfirmationDialog: String = "false",
FikriMilano marked this conversation as resolved.
Show resolved Hide resolved
) : java.io.Serializable, Parcelable {

fun interpolate(computedValuesMap: Map<String, Any>) =
Expand Down Expand Up @@ -102,6 +103,8 @@ data class QuestionnaireConfig(
linkIds = linkIds?.onEach { it.linkId.interpolate(computedValuesMap) },
saveButtonText = saveButtonText?.interpolate(computedValuesMap),
showSubmitAnywayButton = showSubmitAnywayButton.interpolate(computedValuesMap),
showSubmissionConfirmationDialog =
showSubmissionConfirmationDialog.interpolate(computedValuesMap),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.isReadOnly
import org.smartregister.fhircore.engine.domain.model.isSummary
import org.smartregister.fhircore.engine.ui.base.AlertDialogue
import org.smartregister.fhircore.engine.ui.base.AlertIntent
import org.smartregister.fhircore.engine.ui.base.BaseMultiLanguageActivity
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.extension.encodeResourceToString
Expand Down Expand Up @@ -303,44 +304,61 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {
QuestionnaireFragment.SUBMIT_REQUEST_KEY,
this,
) { _, _ ->
lifecycleScope.launch {
val questionnaireResponse = retrieveQuestionnaireResponse()
if (questionnaireConfig.showSubmissionConfirmationDialog.toBooleanStrict()) {
AlertDialogue.showAlert(
context = this,
alertIntent = AlertIntent.CONFIRM,
message = getString(R.string.questionnaire_submission_confirmation_message),
title = getString(R.string.questionnaire_submission_confirmation_title),
confirmButtonListener = { processSubmission() },
confirmButtonText = R.string.yes,
neutralButtonListener = { dialog -> dialog.dismiss() },
neutralButtonText = R.string.no,
)
} else {
processSubmission()
}
}
}

// Close questionnaire if opened in read only mode or if experimental
if (questionnaireConfig.isReadOnly() || questionnaire?.experimental == true) {
finish()
}
if (questionnaireResponse != null && questionnaire != null) {
viewModel.run {
setProgressState(QuestionnaireProgressState.ExtractionInProgress(true))

if (currentLocation != null) {
questionnaireResponse.contained.add(
ResourceUtils.createFhirLocationFromGpsLocation(gpsLocation = currentLocation!!),
)
}
private fun processSubmission() {
lifecycleScope.launch {
val questionnaireResponse = retrieveQuestionnaireResponse()

handleQuestionnaireSubmission(
questionnaire = questionnaire!!,
currentQuestionnaireResponse = questionnaireResponse,
questionnaireConfig = questionnaireConfig,
actionParameters = actionParameters,
context = this@QuestionnaireActivity,
) { idTypes, questionnaireResponse ->
// Dismiss progress indicator dialog, submit result then finish activity
// TODO Ensure this dialog is dismissed even when an exception is encountered
setProgressState(QuestionnaireProgressState.ExtractionInProgress(false))
setResult(
Activity.RESULT_OK,
Intent().apply {
putExtra(QUESTIONNAIRE_RESPONSE, questionnaireResponse as Serializable)
putExtra(QUESTIONNAIRE_SUBMISSION_EXTRACTED_RESOURCE_IDS, idTypes as Serializable)
putExtra(QUESTIONNAIRE_CONFIG, questionnaireConfig as Parcelable)
putExtra(ON_RESULT_TYPE, ActivityOnResultType.QUESTIONNAIRE.name)
},
)
finish()
}
// Close questionnaire if opened in read only mode or if experimental
if (questionnaireConfig.isReadOnly() || questionnaire?.experimental == true) {
finish()
}
if (questionnaireResponse != null && questionnaire != null) {
viewModel.run {
setProgressState(QuestionnaireProgressState.ExtractionInProgress(true))

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

handleQuestionnaireSubmission(
questionnaire = questionnaire!!,
currentQuestionnaireResponse = questionnaireResponse,
questionnaireConfig = questionnaireConfig,
actionParameters = actionParameters,
context = this@QuestionnaireActivity,
) { idTypes, questionnaireResponse ->
// Dismiss progress indicator dialog, submit result then finish activity
// TODO Ensure this dialog is dismissed even when an exception is encountered
setProgressState(QuestionnaireProgressState.ExtractionInProgress(false))
setResult(
Activity.RESULT_OK,
Intent().apply {
putExtra(QUESTIONNAIRE_RESPONSE, questionnaireResponse as Serializable)
putExtra(QUESTIONNAIRE_SUBMISSION_EXTRACTED_RESOURCE_IDS, idTypes as Serializable)
putExtra(QUESTIONNAIRE_CONFIG, questionnaireConfig as Parcelable)
putExtra(ON_RESULT_TYPE, ActivityOnResultType.QUESTIONNAIRE.name)
},
)
finish()
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions android/quest/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@
<string name="all_locations_rendered"><b>All</b> the locations rendered successfully"</string>
<string name="all_matching_locations_rendered"><b>%1$d </b> matching location(s) rendered successfully"</string>
<string name="on_cancel_adding_location">Cancel adding location</string>
<string name="questionnaire_submission_confirmation_message">Are you sure you want to submit?</string>
<string name="questionnaire_submission_confirmation_title">You are about to submit</string>
</resources>
Loading