StanfordBDHG / ResearchKitOnFHIR

HL7 FHIR Structured Data Capture with ResearchKit on iOS
https://swiftpackageindex.com/StanfordBDHG/ResearchKitOnFHIR/documentation
MIT License
13 stars 2 forks source link

🐛 Bug report: Error when using `enableWhen` #69

Closed iadereggalternova closed 7 months ago

iadereggalternova commented 8 months ago

Description

On certain occasions, some questions that should be displayed based on the answers to previous questions within a questionnaire are inadvertently omitted. This means that while they should appear in the questionnaire flow based on previous answers, these questions are not presented as expected.

This suggests some kind of issue with the navigation logic, probably in the translation of the attributes of the ResearchKit navigation rules.

To verify the situation, UI tests were developed, which were executed in a multi-run test plan obtaining the following results:

  1. In a first scenario, a JSON in FHIR format was used with a question that has two conditions that depend on the answer to a previous question, obtaining a 9.1% error. Example of running 100 tests, meeting only one of the conditions. For example, nine times out of 100 executions the question with dependency was not shown, following the same flow.

image

This shows that in nine out of every hundred executions, the dependent question was not displayed, even following the same flow.

  1. In a second scenario, two tests are run, one for each possible condition, but this time the dependent question is duplicated by arranging each question with a single enableWhen attribute. The following results are obtained:
  2. image

Although the error rate decreased in this scenario, failures still occurred.

Reproduction

The questionnaire in JSON FHIR format used for the above tests, and with which the incident is being presented, is as follows:

{
  "resourceType": "Questionnaire",
  "language": "en-US",
  "title": "Report on tests",
  "status": "draft",
  "publisher": "Tester",
  "meta": {
    "profile": [
      "http://spezi.health/fhir/StructureDefinition/sdf-Questionnaire"
    ],
    "tag": [
      { "system": "urn:ietf:bcp:47", "code": "en-US", "display": "English" }
    ]
  },
  "useContext": [
    {
      "code": {
        "system": "http://hl7.org/fhir/ValueSet/usage-context-type",
        "code": "focus",
        "display": "Clinical Focus"
      },
      "valueCodeableConcept": {
        "coding": [
          {
            "system": "urn:oid:2.16.578.1.12.4.1.1.8655",
            "display": "Untitled"
          }
        ]
      }
    }
  ],
  "contact": [{ "name": "http://testing.test" }],
  "subjectType": ["Patient"],
  "url": "http://testing.test",
  "item": [
    {
      "linkId": "1.1",
      "type": "choice",
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit?",
      "required": true,
      "answerOption": [
        {
          "valueCoding": {
            "code": "very-severe",
            "system": "urn:uuid:b8ef0384-7163-44fa-e977-d5c64bce8cb8",
            "display": "Very severe"
          }
        },
        {
          "valueCoding": {
            "code": "severe",
            "system": "urn:uuid:b8ef0384-7163-44fa-e977-d5c64bce8cb8",
            "display": "Severe"
          }
        },
        {
          "valueCoding": {
            "code": "moderate",
            "system": "urn:uuid:b8ef0384-7163-44fa-e977-d5c64bce8cb8",
            "display": "Moderate"
          }
        },
        {
          "valueCoding": {
            "code": "mild",
            "system": "urn:uuid:b8ef0384-7163-44fa-e977-d5c64bce8cb8",
            "display": "Mild"
          }
        },
        {
          "valueCoding": {
            "code": "none",
            "system": "urn:uuid:b8ef0384-7163-44fa-e977-d5c64bce8cb8",
            "display": "None"
          }
        }
      ]
    },
    {
      "linkId": "1.2",
      "type": "choice",
      "required": true,
      "answerOption": [
        {
          "valueCoding": {
            "code": "yes",
            "system": "urn:uuid:2ab65962-d3f0-48d4-8c27-d042bfffafc3",
            "display": "Yes"
          }
        },
        {
          "valueCoding": {
            "code": "no",
            "system": "urn:uuid:2ab65962-d3f0-48d4-8c27-d042bfffafc3",
            "display": "No"
          }
        }
      ],
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit??",
      "enableBehavior": "any",
      "enableWhen": [
        {
          "question": "1.1",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:b8ef0384-7163-44fa-e977-d5c64bce8cb8",
            "code": "very-severe"
          }
        },
        {
          "question": "1.1",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:b8ef0384-7163-44fa-e977-d5c64bce8cb8",
            "code": "severe"
          }
        }
      ]
    },
    {
      "linkId": "1.3",
      "type": "choice",
      "required": true,
      "answerOption": [
        {
          "valueCoding": {
            "code": "severe-abdominal-pain",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Severe abdominal pain"
          }
        },
        {
          "valueCoding": {
            "id": "05a9c9ec-1781-479f-e302-6283a66474ef",
            "code": "havent-passed-gas",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Haven't passed gas from my bottom (or ostomy)"
          }
        },
        {
          "valueCoding": {
            "id": "4446b2d6-c19f-4e33-e536-f4ef3cb0aa90",
            "code": "vomiting",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Vomiting"
          }
        }
      ],
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
          "valueCodeableConcept": {
            "coding": [
              {
                "system": "http://hl7.org/fhir/questionnaire-item-control",
                "code": "check-box",
                "display": "Checkbox"
              }
            ],
            "text": "Checkbox"
          }
        }
      ],
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing.",
      "enableWhen": [
        {
          "question": "1.2",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:2ab65962-d3f0-48d4-8c27-d042bfffafc3",
            "code": "yes"
          }
        }
      ],
      "item": [
        {
          "extension": [
            {
              "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "http://hl7.org/fhir/questionnaire-display-category",
                    "code": "instructions"
                  }
                ]
              }
            }
          ],
          "linkId": "1-select-one",
          "text": "Select all that apply",
          "type": "display"
        }
      ]
    },
    {
      "linkId": "1.4.1",
      "type": "dateTime",
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit?",
      "required": true,
      "enableBehavior": "any"
    },
    {
      "linkId": "1.4.2",
      "type": "choice",
      "required": true,
      "answerOption": [
        {
          "valueCoding": {
            "code": "very-large",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Very large"
          }
        },
        {
          "valueCoding": {
            "code": "large",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Large"
          }
        },
        {
          "valueCoding": {
            "code": "medium",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Medium"
          }
        },
        {
          "valueCoding": {
            "code": "small",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Small"
          }
        },
        {
          "valueCoding": {
            "code": "very-small",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Very small"
          }
        }
      ],
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit?"
    },
    {
      "linkId": "1.5",
      "type": "dateTime",
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit?",
      "required": true,
      "enableBehavior": "any",
      "enableWhen": [
        {
          "question": "1.4.2",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "code": "small"
          }
        },
        {
          "question": "1.4.2",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "code": "very-small"
          }
        }
      ]
    },
    {
      "linkId": "1.6",
      "type": "choice",
      "required": true,
      "answerOption": [
        {
          "valueCoding": {
            "code": "hard-or-lumpy",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Hard or lumpy"
          }
        },
        {
          "valueCoding": {
            "code": "soft-or-unformed",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Soft or unformed"
          }
        },
        {
          "valueCoding": {
            "code": "loose-or-watery",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Loose or watery"
          }
        },
        {
          "valueCoding": {
            "code": "unfinished",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Unfinished"
          }
        },
        {
          "valueCoding": {
            "code": "difficult-to-get-out",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Difficult to get out"
          }
        },
        {
          "valueCoding": {
            "code": "painful",
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "display": "Painful"
          }
        }
      ],
      "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit?",
      "enableBehavior": "any",
      "enableWhen": [
        {
          "question": "1.4.2",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "code": "very-large"
          }
        },
        {
          "question": "1.4.2",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "code": "large"
          }
        },
        {
          "question": "1.4.2",
          "operator": "=",
          "answerCoding": {
            "system": "urn:uuid:190d3b6e-015f-415e-9325-48f7b6275108",
            "code": "medium"
          }
        },
        { "question": "1.5", "operator": "exists", "answerBoolean": true }
      ]
    }
  ]
}

Expected behavior

It is expected that question 1.2 will be activated whenever the 'very severe' or 'severe' option is selected.

Additional context

No response

Code of Conduct

vishnuravi commented 8 months ago

Hi @iadereggalternova, thanks for reporting this issue. We believe it should be resolved with the latest release: https://github.com/StanfordBDHG/ResearchKitOnFHIR/releases/tag/1.1.2