android-fhir icon indicating copy to clipboard operation
android-fhir copied to clipboard

Paginated Questionnaires: Validate before going to the next page

Open Aleem92 opened this issue 1 year ago • 3 comments

Describe the bug In a paginated questionnaire where the first item on the first page is autofilled and the second item on this page fetches data from the database using a query, users can proceed from the first screen to the second screen without filling out all required fields on the first screen. This results in an error message appearing when submitting the form on the second screen.

Component SDC library

To Reproduce Steps to reproduce the behavior:

  1. Open the sample questionnaire
  2. Clicking on the next button without filling in the required fields will move to the next page without validating the current page.

Expected behavior Display an error message to block users from proceeding to the next page if the current form is incomplete or incorrect.

Screenshots Screenshot_1722204951 Screenshot_1722204976

Additional context The questionnaire has the following extension:

 {
      "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-entryMode",
      "valueCode": "prior-edit"
 }

But it does not validate the required fields when the first item on the page has initial values and the second item fetches data from the database. In the sample questionnaire, there is an item with the link Id visit-date, which is a date type containing today's date as a value. The next item has the link Id medicine and is a reference type that fetches medicines from the database.

        {
          "extension": [
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
              "valueExpression": {
                "language": "text/fhirpath",
                "expression": "today()"
              }
            }
          ],
          "linkId": "visit-date",
          "text": "Visit date",
          "type": "date",
          "required": false,
          "item": [
            {
              "linkId": "visit-date-hint",
              "text": "Visit date",
              "type": "display",
              "extension": [
                {
                  "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
                  "valueCodeableConcept": {
                    "coding": [
                      {
                        "system": "http://hl7.org/fhir/questionnaire-item-control",
                        "code": "flyover",
                        "display": "Fly-over"
                      }
                    ],
                    "text": "Flyover"
                  }
                }
              ]
            }
          ]
        },
        {
          "linkId": "medicine",
          "type": "reference",
          "required": true,
          "item": [
            {
              "linkId": "medicine-hint",
              "text": "Medicine",
              "type": "display",
              "extension": [
                {
                  "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
                  "valueCodeableConcept": {
                    "coding": [
                      {
                        "system": "http://hl7.org/fhir/questionnaire-item-control",
                        "code": "flyover",
                        "display": "Fly-over"
                      }
                    ],
                    "text": "Flyover"
                  }
                }
              ]
            }
          ],
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/questionnaire-item-control",
                    "code": "drop-down",
                    "display": "Drop down"
                  }
                ],
                "text": "Drop down"
              }
            },
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression",
              "valueExpression": {
                "expression": "Medication",
                "language": "application/x-fhir-query"
              }
            },
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn",
              "extension": [
                {
                  "url": "path",
                  "valueString": "Medication.code.coding.display"
                },
                {
                  "url": "forDisplay",
                  "valueBoolean": true
                }
              ]
            }
          ]
        },

It has been observed that when the following extensions are removed from the item medicine, it does not move to the next page if the required fields are not filled, and it shows the validation errors.

            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression",
              "valueExpression": {
                "expression": "Medication",
                "language": "application/x-fhir-query"
              }
            },
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn",
              "extension": [
                {
                  "url": "path",
                  "valueString": "Medication.code.coding.display"
                },
                {
                  "url": "forDisplay",
                  "valueBoolean": true
                }
              ]
            }

Sample Questionnaire

Would you like to work on the issue? Yes

Aleem92 avatar Jul 28 '24 22:07 Aleem92

Thanks for catching the bug @Aleem92. Are you working on this ?

MJ1998 avatar Jul 30 '24 15:07 MJ1998

@Aleem92 Can you try adding entryMode extension at questionnaire top level and set code to prior-edit. This will enforce validation.

MJ1998 avatar Aug 05 '24 16:08 MJ1998

@Aleem92 Can you try adding entryMode extension at questionnaire top level and set code to prior-edit. This will enforce validation.

As mentioned above, I am already using the entryMode extension. You can refer to the sample questionnaire for reference.

Aleem92 avatar Aug 12 '24 14:08 Aleem92

is this still a valid issue?

pld avatar Oct 22 '24 14:10 pld

Apk Version - opensrp-dc-v0.1.5-release.apk Device - BLUG60 Android version - 9

This issue has been addressed in all the questionnaires/forms. A user can't proceed to the next page before filling in the mandatory fields. All the mandatory fields get highlighted in red when the Next/Save button is tapped before filling them.

faith-mutua avatar Oct 22 '24 14:10 faith-mutua

Seems to be re-occuring, and validation fails for a repeated-group item do not prevent proceeding to the next page

LZRS avatar Dec 05 '24 16:12 LZRS