Skip to content

Commit

Permalink
Merge branch 'main' into enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
dubdabasoduba authored Dec 9, 2024
2 parents b0672b7 + aef0fdc commit d52a45f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3. Implemented functionality to launch PDF generation using a configuration setup
- Added Save draft MVP functionality
- Added Delete saved draft feature
- 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",
) : 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 @@ -52,6 +52,7 @@ import org.smartregister.fhircore.engine.domain.model.isReadOnly
import org.smartregister.fhircore.engine.domain.model.isSummary
import org.smartregister.fhircore.engine.ui.base.AlertDialogButton
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 @@ -304,44 +305,66 @@ 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),
confirmButton =
AlertDialogButton(
listener = { processSubmission() },
),
neutralButton =
AlertDialogButton(
text = R.string.no,
listener = { it.dismiss() },
),
)
} 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 @@ -142,4 +142,6 @@
<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="error_rendering_profile">Error rendering profile</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>
2 changes: 2 additions & 0 deletions docs/engineering/app/configuring/forms/forms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ These are used when generating other tasks, CarePlans and related resources.See
| onSubmitActions | Configurations for actions invoked post Questionnaire submission | no | null |
| extractedResourceUniquePropertyExpressions | Configurations for unique properties used to identify resources during Questionnaire edit | no | null |
| uniqueIdAssignment | Configuration for unique identifier assignment | no | null |
| showSubmitAnywayButton | When a form submission detects a validation error, the app will display a validation error dialog that prevents the user from submitting the form. Enabling this property will show a button in the validation error dialog. When pressed, the form will be submitted regardless of the validation error. | no | false |
| showSubmissionConfirmationDialog | Display a submission confirmation dialog once the submit button is pressed | no | false |

## Dynamic data pass between Profiles and Questionnaires

Expand Down

0 comments on commit d52a45f

Please sign in to comment.