Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching of the correct pair of qItem and qrItem fails for repeated groups #2655

Closed
allan-on opened this issue Aug 13, 2024 · 5 comments · Fixed by #2657
Closed

Matching of the correct pair of qItem and qrItem fails for repeated groups #2655

allan-on opened this issue Aug 13, 2024 · 5 comments · Fixed by #2657

Comments

@allan-on
Copy link
Contributor

allan-on commented Aug 13, 2024

Describe the bug

This newly introduced requirement through #2618, fails and throws a java.lang.IllegalArgumentException: Failed requirement when loading a Questionnaire that has repeated groups, and populating it with values from the latest QuestionnaireResponse.

The exception is thrown because when matching qItem and qrItem, the number of questionnaire items isn't equal to the number of questionnaire response items.

For repeated groups this observed in the following scenarios:

a. If a Questionnaire has a repeated group with one set of repeated items/fields:
If a field didn't have an answer because it was optional or it was hidden by an enableWhen expression then it is excluded from the Questionnaire response resulting in the QR with less items

b. If a Questionnaire has a repeated group with several repeated items/fields:
The repeated group items are put in the answerItems in the QR and when iterating and pairing the qItems will have a size of the number of fields in the group while it appears in the iteration, the repeated group qrItems aren't being correctly retrieved

Component
SDC library

To Reproduce
Steps to reproduce the behavior:
See additional context in comments below

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: [e.g. Pixel4a emulator]
  • Android version: [e.g. Settings -> About phone -> Android version]
  • Build number: [e.g. Settings -> About phone -> Build number]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Would you like to work on the issue?
Please state if this issue should be assigned to you or who you think could help to solve this issue.

@FikriMilano
Copy link
Collaborator

@allan-on could you share the questionnaire, questionnaire response, and the exception to the ticket?

@allan-on allan-on changed the title Matching of the correct pair of qItem and qrItem is backwards incompatible for repeated groups Matching of the correct pair of qItem and qrItem is fails for repeated groups Aug 14, 2024
@allan-on
Copy link
Contributor Author

allan-on commented Aug 14, 2024

Here's additional context for the bug observed:

Exception Stack trace

java.lang.IllegalArgumentException: Failed requirement.
	at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:202)
	at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:226)
	at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:217)
	at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:190)
	at com.google.android.fhir.datacapture.QuestionnaireViewModel.initializeCalculatedExpressions(QuestionnaireViewModel.kt:630)
	at com.google.android.fhir.datacapture.QuestionnaireViewModel.access$initializeCalculatedExpressions(QuestionnaireViewModel.kt:90)
	at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$2.invokeSuspend(QuestionnaireViewModel.kt:609)
	at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$2.invoke(Unknown Source:8)
	at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$2.invoke(Unknown Source:4)

Questionnaire used

{
  "resourceType": "Questionnaire",
  "language": "en-GB",
  "id": "dc-clinic-medicines",
  "name": "DC Clinic Medicines",
  "title": "Medicines",
  "description": "Patient medicines",
  "version": "0.0.1",
  "status": "active",
  "publisher": "ONA",
  "contact": [
    {
      "name": "http://www.smartregister.org/"
    }
  ],
  "subjectType": [
    "Patient"
  ],
  "extension": [
    {
      "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap",
      "valueCanonical": "https://smartregister.org/fhir/StructureMap/dc-patient-medicines-sm"
    },
    {
      "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-entryMode",
      "valueCode": "prior-edit"
    }
  ],
  "item": [
    {
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
          "valueCodeableConcept": {
            "coding": [
              {
                "system": "http://hl7.org/fhir/questionnaire-item-control",
                "code": "page",
                "display": "Page 1"
              }
            ],
            "text": "Page 1"
          }
        }
      ],
      "linkId": "page-1",
      "type": "group",
      "item": [
        {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden",
              "valueBoolean": true
            }
          ],
          "linkId": "has-hypertension",
          "type": "boolean",
          "readOnly": true,
          "required": false
        },
        {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden",
              "valueBoolean": true
            }
          ],
          "linkId": "has-diabetes",
          "type": "boolean",
          "readOnly": true,
          "required": false
        },
        {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
              "valueString": "d/M/yy"
            },
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
              "valueExpression": {
                "language": "text/fhirpath",
                "expression": "today()"
              }
            },
            {
              "url": "http://hl7.org/fhir/StructureDefinition/maxValue",
              "valueDate": {
                "extension": [
                  {
                    "url": "http://hl7.org/fhir/StructureDefinition/cqf-calculatedValue",
                    "valueExpression": {
                      "language": "text/fhirpath",
                      "expression": "today()"
                    }
                  }
                ]
              }
            }
          ],
          "linkId": "visit-date",
          "text": "Visit date",
          "type": "date",
          "required": true,
          "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": "medicines-repeated-group",
          "type": "group",
          "text": "Medicine",
          "item": [
            {
              "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
                    }
                  ]
                }
              ]
            },
            {
              "linkId": "dosage",
              "type": "choice",
              "required": true,
              "item": [
                {
                  "linkId": "dosage-hint",
                  "text": "Dosage (mg)",
                  "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"
                  }
                }
              ],
              "answerOption": [
                {
                  "valueCoding": {
                    "id": "3_mg",
                    "system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
                    "code": "3_mg",
                    "display": "3 mg"
                  }
                },
                {
                  "valueCoding": {
                    "id": "3_5_mg",
                    "system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
                    "code": "3_5_mg",
                    "display": "3.5 mg"
                  }
                }
              ],
              "enableWhen": [
                {
                  "question": "medicine",
                  "operator": "=",
                  "answerReference": {
                    "reference": "Medication/dc-med-00206501"
                  }
                },
                {
                  "question": "medicine",
                  "operator": "=",
                  "answerReference": {
                    "reference": "Medication/dc-med-00202901"
                  }
                }
              ],
              "enableBehavior": "any"
            },
            {
              "linkId": "insulin-dosage",
              "type": "integer",
              "required": true,
              "extension": [
                {
                  "url": "http://hl7.org/fhir/StructureDefinition/minValue",
                  "valueInteger": 1
                },
                {
                  "url": "http://hl7.org/fhir/StructureDefinition/maxValue",
                  "valueInteger": 500
                }
              ],
              "item": [
                {
                  "linkId": "insulin-dosage-hint",
                  "text": "Dosage (IU)",
                  "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"
                      }
                    }
                  ]
                }
              ],
              "enableWhen": [
                {
                  "question": "medicine",
                  "operator": "=",
                  "answerReference": {
                    "reference": "Medication/dc-med-00700701"
                  }
                },
                {
                  "question": "medicine",
                  "operator": "=",
                  "answerReference": {
                    "reference": "Medication/dc-med-00700801"
                  }
                },
                {
                  "question": "medicine",
                  "operator": "=",
                  "answerReference": {
                    "reference": "Medication/dc-med-00700601"
                  }
                }
              ],
              "enableBehavior": "any"
            },
            {
              "linkId": "frequency",
              "type": "choice",
              "required": true,
              "item": [
                {
                  "linkId": "frequency-hint",
                  "text": "Frequency",
                  "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"
                  }
                }
              ],
              "answerOption": [
                {
                  "valueCoding": {
                    "id": "od_mane",
                    "code": "od_mane",
                    "system": "http://smartregister.org/",
                    "display": "OD Mane"
                  }
                },
                {
                  "valueCoding": {
                    "id": "od_nocte",
                    "code": "od_nocte",
                    "system": "http://smartregister.org/",
                    "display": "OD Nocte"
                  }
                }
              ]
            },
            {
              "linkId": "notes",
              "type": "string",
              "required": false,
              "item": [
                {
                  "linkId": "notes-hint",
                  "text": "Notes",
                  "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"
                      }
                    }
                  ]
                }
              ]
            }
          ],
          "repeats": true
        }
      ]
    },
    {
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
          "valueCodeableConcept": {
            "coding": [
              {
                "system": "http://hl7.org/fhir/questionnaire-item-control",
                "code": "page",
                "display": "Page 2"
              }
            ],
            "text": "Page 2"
          }
        },
        {
          "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
          "valueExpression": {
            "language": "text/fhirpath",
            "expression": "(%resource.descendants().where(linkId='has-hypertension').answer.value.exists() and %resource.descendants().where(linkId='has-hypertension').answer.value = false) or (%resource.descendants().where(linkId='has-diabetes').answer.value.exists() and %resource.descendants().where(linkId='has-diabetes').answer.value = false) or (%resource.descendants().where(linkId='has-hypertension').answer.exists().not()) or (%resource.descendants().where(linkId='has-diabetes').answer.exists().not())"
          }
        }
      ],
      "linkId": "page-2",
      "type": "group",
      "item": [
        {
          "linkId": "hypertension-diagnosis",
          "type": "choice",
          "text": "Add diagnosis for hypertension?",
          "required": true,
          "answerOption": [
            {
              "valueCoding": {
                "id": "hypertension-choice",
                "code": "hypertension",
                "system": "http://smartregister.org/",
                "display": "Hypertension"
              }
            },
            {
              "valueCoding": {
                "id": "no-diagnosis",
                "code": "no-diagnosis",
                "system": "http://smartregister.org/",
                "display": "No diagnosis"
              }
            }
          ],
          "extension": [
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
              "valueExpression": {
                "language": "text/fhirpath",
                "expression": "(%resource.descendants().where(linkId='has-hypertension').answer.value.exists() and %resource.descendants().where(linkId='has-hypertension').answer.value = false) or (%resource.descendants().where(linkId='has-hypertension').answer.exists().not())"
              }
            },
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/ValueSet/questionnaire-item-control",
                    "code": "radio-button"
                  }
                ]
              }
            }
          ]
        },
        {
          "linkId": "diabetes-diagnosis",
          "type": "choice",
          "text": "Add diagnosis for diabetes?",
          "required": true,
          "answerOption": [
            {
              "valueCoding": {
                "id": "diabetes-type-1-choice",
                "system": "http://smartregister.org/",
                "code": "diabetes-type-1",
                "display": "Diabetes Type 1"
              }
            },
            {
              "valueCoding": {
                "id": "diabetes-type-2-choice",
                "system": "http://smartregister.org/",
                "code": "diabetes-type-2",
                "display": "Diabetes Type 2"
              }
            },
            {
              "valueCoding": {
                "id": "no-diagnosis",
                "code": "no-diagnosis",
                "system": "http://smartregister.org/",
                "display": "No diagnosis"
              }
            }
          ],
          "extension": [
            {
              "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
              "valueExpression": {
                "language": "text/fhirpath",
                "expression": "(%resource.descendants().where(linkId='has-diabetes').answer.value.exists() and %resource.descendants().where(linkId='has-diabetes').answer.value = false) or (%resource.descendants().where(linkId='has-diabetes').answer.exists().not())"
              }
            },
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/ValueSet/questionnaire-item-control",
                    "code": "radio-button"
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  ]
}

a. QuestionnaireResponse where a Questionnaire has a repeated group with one set of repeated items/fields

The "linkId": "insulin-dosage" field wasn't included in the QR

{
    "resourceType": "QuestionnaireResponse",
    "id": "41664149-90b7-4cce-a874-2120bae9ca24",
    "meta": {
        "lastUpdated": "2024-08-13T12:10:37.965+03:00"
    },
    "questionnaire": "Questionnaire/dc-clinic-medicines",
    "status": "completed",
    "subject": {
        "reference": "Patient/f5f86091-0ccf-47c1-89a3-15547740a967"
    },
    "authored": "2024-08-13T12:10:35+03:00",
    "author": {
        "reference": "Practitioner/a21decb7-ac90-43e1-926a-0579a46816ed"
    },
    "item": [
        {
            "linkId": "page-1",
            "item": [
                {
                    "linkId": "has-hypertension",
                    "answer": [
                        {
                            "valueBoolean": false
                        }
                    ]
                },
                {
                    "linkId": "has-diabetes",
                    "answer": [
                        {
                            "valueString": "false"
                        }
                    ]
                },
                {
                    "linkId": "visit-date",
                    "text": "Visit date",
                    "answer": [
                        {
                            "valueDate": "2024-08-13",
                            "item": [
                                {
                                    "linkId": "visit-date-hint",
                                    "text": "Visit date"
                                }
                            ]
                        }
                    ]
                },
                {
                    "linkId": "medicines-repeated-group",
                    "text": "Medicine",
                    "item": [
                        {
                            "linkId": "medicine",
                            "answer": [
                                {
                                    "valueReference": {
                                        "reference": "Medication/dc-med-00202901",
                                        "display": "Losartan"
                                    },
                                    "item": [
                                        {
                                            "linkId": "medicine-hint",
                                            "text": "Medicine"
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "linkId": "dosage",
                            "answer": [
                                {
                                    "valueCoding": {
                                        "id": "20_mg",
                                        "system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
                                        "code": "20_mg",
                                        "display": "20 mg"
                                    },
                                    "item": [
                                        {
                                            "linkId": "dosage-hint",
                                            "text": "Dosage (mg)"
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "linkId": "frequency",
                            "answer": [
                                {
                                    "valueCoding": {
                                        "id": "eod",
                                        "system": "http://smartregister.org/",
                                        "code": "eod",
                                        "display": "EOD"
                                    },
                                    "item": [
                                        {
                                            "linkId": "frequency-hint",
                                            "text": "Frequency"
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "linkId": "notes",
                            "answer": [
                                {
                                    "valueString": "To be followed upon",
                                    "item": [
                                        {
                                            "linkId": "notes-hint",
                                            "text": "Notes"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "linkId": "page-2",
            "item": [
                {
                    "linkId": "hypertension-diagnosis",
                    "text": "Add diagnosis for hypertension?",
                    "answer": [
                        {
                            "valueCoding": {
                                "id": "hypertension-choice",
                                "system": "http://smartregister.org/",
                                "code": "hypertension",
                                "display": "Hypertension"
                            }
                        }
                    ]
                },
                {
                    "linkId": "diabetes-diagnosis",
                    "text": "Add diagnosis for diabetes?",
                    "answer": [
                        {
                            "valueCoding": {
                                "id": "diabetes-type-2-choice",
                                "system": "http://smartregister.org/",
                                "code": "diabetes-type-2",
                                "display": "Diabetes Type 2"
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

b. QuestionnaireResponse where a Questionnaire has a repeated group with several repeated items/fields

The qItems were seen to be 4 while the qrItems were 0 (zero) when iterating through the "linkId": "medicines-repeated-group" item

{
    "resourceType": "QuestionnaireResponse",
    "id": "63f318a9-e10b-434d-b7c9-1e8137433042",
    "meta": {
        "lastUpdated": "2024-08-14T09:48:07.815+03:00"
    },
    "questionnaire": "Questionnaire/dc-clinic-medicines",
    "status": "completed",
    "subject": {
        "reference": "Patient/5a88dce4-38f7-41a9-bd39-eb41142ae98e"
    },
    "authored": "2024-08-14T09:48:07+03:00",
    "author": {
        "reference": "Practitioner/a21decb7-ac90-43e1-926a-0579a46816ed"
    },
    "item": [
        {
            "linkId": "page-1",
            "item": [
                {
                    "linkId": "has-hypertension",
                    "answer": [
                        {
                            "valueBoolean": false
                        }
                    ]
                },
                {
                    "linkId": "has-diabetes",
                    "answer": [
                        {
                            "valueBoolean": false
                        }
                    ]
                },
                {
                    "linkId": "visit-date",
                    "text": "Visit date",
                    "answer": [
                        {
                            "valueDate": "2024-08-14",
                            "item": [
                                {
                                    "linkId": "visit-date-hint",
                                    "text": "Visit date"
                                }
                            ]
                        }
                    ]
                },
                {
                    "linkId": "medicines-repeated-group",
                    "answer": [
                        {
                            "item": [
                                {
                                    "linkId": "medicine",
                                    "answer": [
                                        {
                                            "valueReference": {
                                                "reference": "Medication/dc-med-00202901",
                                                "display": "Losartan"
                                            },
                                            "item": [
                                                {
                                                    "linkId": "medicine-hint",
                                                    "text": "Medicine"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "linkId": "dosage",
                                    "answer": [
                                        {
                                            "valueCoding": {
                                                "id": "10_mg",
                                                "system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
                                                "code": "10_mg",
                                                "display": "10 mg"
                                            },
                                            "item": [
                                                {
                                                    "linkId": "dosage-hint",
                                                    "text": "Dosage (mg)"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "linkId": "frequency",
                                    "answer": [
                                        {
                                            "valueCoding": {
                                                "id": "tds",
                                                "system": "http://smartregister.org/",
                                                "code": "tds",
                                                "display": "TDS"
                                            },
                                            "item": [
                                                {
                                                    "linkId": "frequency-hint",
                                                    "text": "Frequency"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "linkId": "notes"
                                }
                            ]
                        },
                        {
                            "item": [
                                {
                                    "linkId": "medicine",
                                    "answer": [
                                        {
                                            "valueReference": {
                                                "reference": "Medication/dc-med-00700601",
                                                "display": "Mixtard insulin"
                                            },
                                            "item": [
                                                {
                                                    "linkId": "medicine-hint",
                                                    "text": "Medicine"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "linkId": "insulin-dosage",
                                    "answer": [
                                        {
                                            "valueInteger": 280,
                                            "item": [
                                                {
                                                    "linkId": "insulin-dosage-hint",
                                                    "text": "Dosage (IU)"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "linkId": "frequency",
                                    "answer": [
                                        {
                                            "valueCoding": {
                                                "id": "bd",
                                                "system": "http://smartregister.org/",
                                                "code": "bd",
                                                "display": "BD"
                                            },
                                            "item": [
                                                {
                                                    "linkId": "frequency-hint",
                                                    "text": "Frequency"
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "linkId": "notes"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "linkId": "page-2",
            "item": [
                {
                    "linkId": "hypertension-diagnosis",
                    "text": "Add diagnosis for hypertension?",
                    "answer": [
                        {
                            "valueCoding": {
                                "id": "no-diagnosis",
                                "system": "http://smartregister.org/",
                                "code": "no-diagnosis",
                                "display": "No diagnosis"
                            }
                        }
                    ]
                },
                {
                    "linkId": "diabetes-diagnosis",
                    "text": "Add diagnosis for diabetes?",
                    "answer": [
                        {
                            "valueCoding": {
                                "id": "diabetes-type-1-choice",
                                "system": "http://smartregister.org/",
                                "code": "diabetes-type-1",
                                "display": "Diabetes Type 1"
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

cc @FikriMilano @jingtang10

@allan-on allan-on changed the title Matching of the correct pair of qItem and qrItem is fails for repeated groups Matching of the correct pair of qItem and qrItem fails for repeated groups Aug 14, 2024
@FikriMilano
Copy link
Collaborator

FikriMilano commented Aug 15, 2024

@jingtang10 @allan-on
There is a bug with addMissingResponseItems function.

What that function does is, if a response item is missing (because it's disabled by skip logic) the function should add an empty response item to ensure that the questionnaire item has it's corresponding response item.

This function is executed when the questionnaire response is initially passed to the QuestionnaireViewModel.

That way the above exception should not happen.

https://github.com/google/android-fhir/blob/603792f4e865ba3c736565d40672eda3a587ad97/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireViewModel.kt#L425C15-L452

@FikriMilano
Copy link
Collaborator

FikriMilano commented Aug 16, 2024

@jingtang10 @MJ1998 implementers shouldn't be able to get the QR with packed repeated groups right(?) See QR example in point 2.

I checked the latest code, it's not possible. It will always unpack.

suspend fun getQuestionnaireResponse(): QuestionnaireResponse {
return questionnaireResponse.copy().apply {
// Use the view model's questionnaire and questionnaire response for calculating enabled items
// because the calculation relies on references to the questionnaire response items.
item =
getEnabledResponseItems(
this@QuestionnaireViewModel.questionnaire.item,
questionnaireResponse.item,
)
.map { it.copy() }
unpackRepeatedGroups(this@QuestionnaireViewModel.questionnaire)
}

@allan-on I'm not sure how you get a packed response, I'd say it's a malformed response.

packed = nested items are in the answer property of the repeated group
unpacked = nested items are in the item property of the repeated group

@FikriMilano
Copy link
Collaborator

FikriMilano commented Aug 19, 2024

The second issue is a bug on the OpenSRP side, and it has been fixed
opensrp/fhircore#3455

@github-project-automation github-project-automation bot moved this from New to Complete in Android FHIR SDK Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.

2 participants