opensrp / fhircore

FHIR Core / OpenSRP 2 is a Kotlin application for delivering offline-capable, mobile-first healthcare project implementations from local community to national and international scale using FHIR and WHO Smart Guidelines on Android.
https://smartregister.org
Apache License 2.0
50 stars 39 forks source link

Saving a questionnaire with nested repeatedGroup items fails with crash #3245

Closed LZRS closed 5 days ago

LZRS commented 1 month ago

To Reproduce Steps to reproduce the behavior:

  1. Open a questionnaire with a repeated group item
  2. Repeatedly fill the group to at least 3 or more times
  3. Submit the questionnaire and it crashes

Additional context Add any other context about the problem here.

java.lang.IllegalArgumentException: Missing questionnaire item for questionnaire response item blood-pressure-repeating-group
                                                                                                        at com.google.android.fhir.datacapture.validation.QuestionnaireResponseValidator.validateQuestionnaireResponseItems(QuestionnaireResponseValidator.kt:120)
                                                                                                        at com.google.android.fhir.datacapture.validation.QuestionnaireResponseValidator.validateQuestionnaireResponseItem(QuestionnaireResponseValidator.kt:160)
                                                                                                        at com.google.android.fhir.datacapture.validation.QuestionnaireResponseValidator.validateQuestionnaireResponseItems(QuestionnaireResponseValidator.kt:133)
                                                                                                        at com.google.android.fhir.datacapture.validation.QuestionnaireResponseValidator.validateQuestionnaireResponse(QuestionnaireResponseValidator.kt:93)
                                                                                                        at com.google.android.fhir.datacapture.validation.QuestionnaireResponseValidator.validateQuestionnaireResponse$default(QuestionnaireResponseValidator.kt:57)
                                                                                                        at org.smartregister.fhircore.quest.ui.questionnaire.QuestionnaireViewModel.validateQuestionnaireResponse(QuestionnaireViewModel.kt:731)
                                                                                                        at org.smartregister.fhircore.quest.ui.questionnaire.QuestionnaireViewModel$handleQuestionnaireSubmission$1.invokeSuspend(QuestionnaireViewModel.kt:242)

experienced in WDF

pld commented 1 month ago

is this an Android FHIR SDK error?

LZRS commented 1 month ago

is this an Android FHIR SDK error?

Yeah the error seems to be coming from the sdk's side. The QuestionnaireResponse we get from the sdk has the repeated groups unpacked here, which is what causes validation to fails here. An example

{
  "resourceType": "QuestionnaireResponse",
  "item": [
    {
      "linkId": "page-1",
      "item": [
        {
          "linkId": "blood-pressure-repeating-group",
          "item": [
            {
              "linkId": "systolic-bp",
              "answer": [
                {
                  "valueInteger": 124
                }
              ]
            }
          ]
        },
        {
          "linkId": "blood-pressure-repeating-group",
          "item": [
            {
              "linkId": "systolic-bp",
              "answer": [
                {
                  "valueInteger": 125
                }
              ]
            }
          ]
        },
        {
          "linkId": "blood-pressure-repeating-group",
          "item": [
            {
              "linkId": "systolic-bp",
              "answer": [
                {
                  "valueInteger": 126
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Also, the sdk does it's own validation here on submit, and it uses its own internal representation of QuestionnaireResponse (which has the repeated groups packed together) and passes validation. Example

{
  "resourceType": "QuestionnaireResponse",
  "item": [
    {
      "linkId": "page-1",
      "item": [
        {
          "linkId": "blood-pressure-repeating-group",
          "answer": [
            {
              "item": [
                {
                  "linkId": "systolic-bp",
                  "answer": [
                    {
                      "valueInteger": 124
                    }
                  ]
                }
              ]
            },
            {
              "item": [
                {
                  "linkId": "systolic-bp",
                  "answer": [
                    {
                      "valueInteger": 125
                    }
                  ]
                }
              ]
            },
            {
              "item": [
                {
                  "linkId": "systolic-bp",
                  "answer": [
                    {
                      "valueInteger": 126
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

The validation from the sdk's side happens just before our fragment result listener is called. Maybe one way to resolve the error might be to remove the validation from our side and trust that sdk's alright.