google / android-fhir

The Android FHIR SDK is a set of Kotlin libraries for building offline-capable, mobile-first healthcare applications using the HL7® FHIR® standard on Android.
https://google.github.io/android-fhir/
Apache License 2.0
481 stars 257 forks source link

Paginated Questionnaires: Validate before going to the next page #2646

Open Aleem92 opened 1 month ago

Aleem92 commented 1 month ago

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

MJ1998 commented 1 month ago

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

MJ1998 commented 1 month ago

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

Aleem92 commented 1 month ago

@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.