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

Nested questions behave strangely #652

Closed
jingtang10 opened this issue Jul 15, 2021 · 4 comments · Fixed by #660, #661 or #662
Closed

Nested questions behave strangely #652

jingtang10 opened this issue Jul 15, 2021 · 4 comments · Fixed by #660, #661 or #662
Assignees
Labels
type:bug Something isn't working

Comments

@jingtang10
Copy link
Collaborator

jingtang10 commented Jul 15, 2021

Originally reported by @joiskash

Describe the bug

  • questionnaireResponseChangedCallback not called in drop-down after selecting an answer
  • Clear answer items if enableWhen condition is false. This happens when you select an answer, the conditional logic is true, and then you deselect. Not clearing the answer corrupts the questionnaire response. Because the questionnaire response will now have both answers,even though it should actually have the last edit.
  • enableWhen bug questionnaireResponseItem.answer.any instead of questionnaireResponseItem.contains
  • Handle nested items in answers for linkIdMapsQuestionnaireResponseMap

Component
SDC lib

To Reproduce
Use the following questionnaire in the gallery app.

Expected behavior
Behaves normally

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

Smartphone (please complete the following information):

  • Device: Pixel4a

Additional context
questionnaire:

{
  "meta": {
    "profile": [
      "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire|2.7"
    ],
    "tag": [
      {
        "code": "lformsVersion: 29.0.3"
      }
    ]
  },
  "version": "1",
  "status": "draft",
  "experimental": true,
  "publisher": "IPRD",
  "name": "Malaria net distribution",
  "title": "Malaria Net Survey",
  "resourceType": "Questionnaire",
  "item": [
    {
      "type": "choice",
      "code": [
        {
          "code": "lga-codes",
          "display": "LGA",
          "system": "https://www.oyo.com/codes"
        }
      ],
      "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"
          }
        }
      ],
      "required": true,
      "linkId": "1",
      "text": "LGA",
      "answerOption": [
        {
          "valueCoding": {
            "code": "oluyole",
            "display": "OLUYOLE",
            "system": "https://www.oyo.com/codes/lga"
          }
        },
        {
          "valueCoding": {
            "code": "akinyele",
            "display": "AKINYELE",
            "system": "https://www.oyo.com/codes/lga"
          }
        }
      ],
      "item": [
        {
          "type": "choice",
          "code": [],
          "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"
              }
            }
          ],
          "required": false,
          "linkId": "ward-akinyele",
          "text": "Ward",
          "enableWhen": [
            {
              "answerCoding": {
                "code": "akinyele",
                "system": "https://www.oyo.com/codes/lga"
              },
              "question": "1",
              "operator": "="
            }
          ],
          "answerOption": [
            {
              "valueCoding": {
                "code": "ikereku",
                "display": "Ikereku",
                "system": "https://www.oyo.com/codes/wards"
              }
            },
            {
              "valueCoding": {
                "code": "iroko",
                "display": "Iroko",
                "system": "https://www.oyo.com/codes/wards"
              }
            }
          ],
          "item": [
            {
              "type": "choice",
              "code": [
                {
                  "code": "ward-Iroko",
                  "display": "Net distribution",
                  "system": "https://www.oyo.com/codes"
                }
              ],
              "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"
                  }
                }
              ],
              "required": false,
              "linkId": "ward-Iroko",
              "text": "Net distribution",
              "enableWhen": [
                {
                  "answerCoding": {
                    "code": "iroko",
                    "system": "https://www.oyo.com/codes/wards"
                  },
                  "question": "ward-akinyele",
                  "operator": "="
                },
                {
                  "answerCoding": {
                    "code": "akinyele",
                    "system": "https://www.oyo.com/codes/lga"
                  },
                  "question": "1",
                  "operator": "="
                }
              ],
              "enableBehavior": "all",
              "answerOption": [
                {
                  "valueCoding": {
                    "code": "hla-primary-school",
                    "display": "HLA Primary School",
                    "system": "https://www.oyo.com/codes/distributionCenter"
                  }
                },
                {
                  "valueCoding": {
                    "code": "christ-apostolic-church",
                    "display": "Christ Apostolic Church",
                    "system": "https://www.oyo.com/codes/distributionCenter"
                  }
                }
              ]
            },
            {
              "type": "choice",
              "code": [
                {
                  "code": "ward-ikereku",
                  "display": "Net distribution",
                  "system": "https://www.oyo.com/codes"
                }
              ],
              "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"
                  }
                }
              ],
              "required": false,
              "linkId": "ward-ikereku",
              "text": "Net distribution",
              "enableWhen": [
                {
                  "answerCoding": {
                    "code": "ikereku",
                    "system": "https://www.oyo.com/codes/wards"
                  },
                  "question": "ward-akinyele",
                  "operator": "="
                }
              ],
              "answerOption": [
                {
                  "valueCoding": {
                    "code": "ogun-state-water-corporation",
                    "display": "Ogun state water corporation Arakanga",
                    "system": "https://www.oyo.com/codes/distributionCenter"
                  }
                },
                {
                  "valueCoding": {
                    "code": "iberekodo-central-mosque",
                    "display": "Iberekodo Central Mosque",
                    "system": "https://www.oyo.com/codes/distributionCenter"
                  }
                }
              ]
            }
          ]
        },
        {
          "type": "choice",
          "code": [
            {
              "code": "ward-oluyole",
              "display": "Ward oluyole",
              "system": "https://www.oyo.com/codes"
            },
            {
              "code": "ward-codes",
              "display": "Ward",
              "system": "https://www.oyo.com/codes"
            }
          ],
          "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"
              }
            }
          ],
          "required": false,
          "linkId": "ward-oluyole",
          "text": "Ward",
          "enableWhen": [
            {
              "answerCoding": {
                "code": "oluyole",
                "system": "https://www.oyo.com/codes/lga"
              },
              "question": "1",
              "operator": "="
            }
          ],
          "answerOption": [
            {
              "valueCoding": {
                "code": "okanhinde",
                "display": "Okanhinde",
                "system": "https://www.oyo.com/codes/wards"
              }
            },
            {
              "valueCoding": {
                "code": "ayegun",
                "display": "Ayegun",
                "system": "https://www.oyo.com/codes/wards"
              }
            }
          ],
          "item": [
            {
              "type": "choice",
              "code": [
                {
                  "code": "ward-okanhinde",
                  "display": "Net distribution",
                  "system": "https://www.oyo.com/codes"
                }
              ],
              "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"
                  }
                }
              ],
              "required": false,
              "linkId": "ward-okanhinde",
              "text": "Net distribution",
              "enableWhen": [
                {
                  "answerCoding": {
                    "code": "okanhinde",
                    "system": "https://www.oyo.com/codes/wards"
                  },
                  "question": "ward-oluyole",
                  "operator": "="
                },
                {
                  "answerCoding": {
                    "code": "oluyole",
                    "system": "https://www.oyo.com/codes/lga"
                  },
                  "question": "1",
                  "operator": "="
                }
              ],
              "enableBehavior": "all",
              "answerOption": [
                {
                  "valueCoding": {
                    "code": "olojuoro-school",
                    "display": "Olojuoro Pry. Sch.",
                    "system": "https://www.oyo.com/codes/distributionCenter"
                  }
                },
                {
                  "valueCoding": {
                    "code": "agbeja-school",
                    "display": "Agbeja N. P. Sch",
                    "system": "https://www.oyo.com/codes/distributionCenter"
                  }
                }
              ]
            },
            {
              "type": "choice",
              "code": [
                {
                  "code": "ward-ayegun",
                  "display": "Net distribution",
                  "system": "https://www.oyo.com/codes"
                }
              ],
              "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://lhcforms.nlm.nih.gov/fhirExt/dataControl",
                  "valueString": "[]"
                }
              ],
              "required": false,
              "linkId": "ward-ayegun",
              "text": "Net distribution",
              "enableWhen": [
                {
                  "answerCoding": {
                    "code": "ayegun",
                    "system": "https://www.oyo.com/codes/wards"
                  },
                  "question": "ward-oluyole",
                  "operator": "="
                }
              ],
              "answerOption": [
                {
                  "valueCoding": {
                    "code": "aspen-arena",
                    "display": "ASPEN ARENA",
                    "system": "https://www.oyo.com/codes/distributionCenter"
                  }
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "integer",
      "code": [
        {
          "code": "number-nets",
          "display": "Number of nets",
          "system": "https://www.oyo.com/codes"
        }
      ],
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/maxValue",
          "valueInteger": 5
        }
      ],
      "required": true,
      "linkId": "number-nets",
      "text": "Number of nets"
    },
    {
      "type": "string",
      "code": [],
      "required": true,
      "linkId": "head-of-household",
      "text": "Initials of the Head of the Household"
    },
    {
      "type": "boolean",
      "code": [
        {
          "code": "phone-number-permission",
          "display": "Does Head of household agree to provide phone number for healthcare use?"
        }
      ],
      "required": true,
      "linkId": "phone-number-permission",
      "text": "Does Head of household agree to provide phone number for healthcare use?",
      "initial": [
        {
          "valueBoolean": "false"
        }
      ],
      "item": [
        {
          "type": "choice",
          "code": [
            {
              "code": "country-code",
              "display": "Country code",
              "system": "https://countrycode.com/countryCodes"
            }
          ],
          "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"
              }
            }
          ],
          "required": false,
          "linkId": "country-code",
          "text": "Country code",
          "enableWhen": [
            {
              "answerBoolean": true,
              "question": "phone-number-permission",
              "operator": "="
            }
          ],
          "enableBehavior": "all",
          "answerOption": [
            {
              "valueCoding": {
                "code": "nigeria",
                "display": "+234",
                "system": "https://countrycode.com/countryCodes"
              }
            },
            {
              "valueCoding": {
                "code": "india",
                "display": "+91",
                "system": "https://countrycode.com/countryCodes"
              }
            },
            {
              "valueCoding": {
                "code": "usa",
                "display": "+1",
                "system": "https://countrycode.com/countryCodes"
              }
            },
            {
              "valueCoding": {
                "code": "south-africa",
                "display": "+27",
                "system": "https://countrycode.com/countryCodes"
              }
            }
          ]
        },
        {
          "type": "string",
          "code": [
            {
              "code": "phone-number",
              "display": "Phone number",
              "system": "https://countrycode.com/countryCodes"
            }
          ],
          "required": false,
          "linkId": "phone-number",
          "text": "Phone number",
          "enableWhen": [
            {
              "answerBoolean": true,
              "question": "country-code",
              "operator": "exists"
            }
          ],
          "enableBehavior": "all"
        }
      ]
    }
  ]
}

Would you like to work on the issue?
Yes

@jingtang10 jingtang10 added the type:bug Something isn't working label Jul 15, 2021
@jingtang10 jingtang10 added this to To do in Data capture library via automation Jul 15, 2021
@jingtang10
Copy link
Collaborator Author

@joiskash about "Clear answer items if enableWhen condition is false" how do you reproduce it in your questionnaire?

@joiskash
Copy link
Collaborator

  1. Select answers for the first 3 questions i.e. LGA, ward, distribution center
  2. Then press submit you will see the correct items in the questionnaire response
  3. Now select a new LGA, new ward and new distribution center note that the ward also has to be different/new.
  4. Then press submit, you will see the answers selected at step 1 and step 3 in the questionnaire response

@jingtang10
Copy link
Collaborator Author

@joiskash can you please verify that your questionnaire works with the fixes here? thanks

Data capture library automation moved this from To do to Done Jul 22, 2021
@jingtang10 jingtang10 reopened this Jul 22, 2021
Data capture library automation moved this from Done to To do Jul 22, 2021
@joiskash
Copy link
Collaborator

joiskash commented Jul 22, 2021

Yes i just tried a build from the master branch with an updated version of my questionnaire with more answer options. It works fine! Thanks! @jingtang10

Data capture library automation moved this from To do to Done Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment