google/android-fhir

Async process for getQuestionnairePages

FikriMilano opened this issue · 7 comments

Is your feature request related to a problem? Please describe.
getQuestionnairePages delays the UI update for ~2 seconds after changing an answer, when we have a lot of skip logic (that applies to pages).

private suspend fun getQuestionnaireState(): QuestionnaireState {
val questionnaireItemList = questionnaire.item
val questionnaireResponseItemList = questionnaireResponse.item
// Only display items on the current page while editing a paginated questionnaire, otherwise,
// display all items.
val questionnaireItemViewItems =
if (!isReadOnly && !isInReviewModeFlow.value && questionnaire.isPaginated) {
pages = getQuestionnairePages()
if (currentPageIndexFlow.value == null) {
currentPageIndexFlow.value = pages!!.first { it.enabled && !it.hidden }.index
}

Describe the solution you'd like

  1. Process the getQuestionnairePages right after changing an answer
  2. Add a progress bar on the next page, to prevent user to go to the next page until getQuestionnairePages finishes. If not, user can potentially open a blank page. The progress bar shall only be shown if the item that has it's answer changed, is going to affect pages with skip logic

Describe alternatives you've considered
Open to it

Additional context
Video of the progress bar:

Screen_recording_20240807_093625.webm
Screen_recording_20240802_145126.1.webm

Would you like to work on the issue?
Yes

@FikriMilano

UI refreshing takes time after the answer is updated, and this is an issue, right?
And basically, you are making this operation asynchronous and triggering it much earlier than it used to be, right?
Also, we are showing a circular progress bar while the operation is running, which prevents the user from clicking the 'Next' button to navigate to the next page. right?

can you share the questionnaire or ui profiling result? really curious why it takes 2 seconds

@jingtang10 I've shared the 2 questionnaires to your email

@FikriMilano Is the 2 seconds constant or it depends on the action being undertaken?

Depends how many enable when expression that the questionnaire has.

In this case where it's taking 2 seconds, it's processing around ~25 enable when expressions.