Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A Questionnaire defined with the eHealth profile ehealth-questionnaire-advanced (see https://docs.ehealth.sundhed.dk/latest-released/ig/StructureDefinition-ehealth-questionnaire-advanced.html) can contain zero, one or more expressions performing a calculation based on answers to questions in the Questionnaire. The expression can make use of zero, one or more variables which identify the particular question/answers more concisely.

Defining a Variable

...

A variable intended for use in an expression (see below) is defined using the extension variable. An example of a variable is shown below as an excerpt of a Questionnaire (in profile ehealth-questionnaire-advanced) in JSON:

Code Block
languagejson
 {
  "url": "http://hl7.org/fhir/StructureDefinition/variable",
  "valueExpression": {
    "name": "Count",
    "language": "text/fhirpath",
    "expression": "QuestionnaireResponse.repeat(item).where(linkId='1.2.208.176.1.5.1,7a481674-9016-46bb-8dd8-2ee49f5bbd53,Sundhedsdatastyrelsen').answer.valueInteger"
  }
}

The variable here is defined at Questionnaire root level referencing a particular question through its Questionnaire.item.linkId. On evaluation in a QuestionnaireResponse, the variable will hold the integer value of the answer (presumably, the referenced Questionnaire.item has integer answer type).

Info

A variable is supported for a question with answer type choice, integer and decimal provided that:

  • the question is not a calculated expression

  • a question of type choice is single-choice only

  • all answer options for question of type choice have an ordinalValue (see ordinalValue)

Defining a Calculation Expression

An expression is defined in a separate Questionnaire.item (or recursively, Questionnaire.item.item) which shall have:

...

The expression itself is defined in the extension sdc-questionnaire-calculatedExpression (see calculatedExpression) which is an Expression FHIR element type containing:

  • language - the expression language. The supported language is FHIRPath.

  • expression - the expression

An example calculation expression is shown below as an excerpt of a Questionnaire (in profile ehealth-questionnaire-advanced) in JSON:

Code Block
languagejson
  "extension": [
    {
      "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
      "valueExpression": {
        "language": "text/fhirpath",
        "expression": "%Animal * %Count"
      }
    },
    "linkId": "1.2.208.176.1.5.1,25d40dde-f91c-4f11-9477-c6cca71d4178,Sundhedsdatastyrelsen",
    "text": "Total",
    "type": "decimal",
    "required": false,
    "readOnly": true
}
Info

The following runtime behavior is not performed when maintaining the Questionnaire but provides background. On evaluation in a QuestionnaireResponse, the QuestionnaireResponse.item corresponding to the Questionnaire.item above shall contain the calculated value in its QuestionnaireResponse.item.answer.valueDecimal. Provided that values are available in the variables Count and Animal (in the evaluation context of the QuestionnaireResponse), the calculated result can be determined.

Info

In case the expression is defined using one or more Questionnaire.item that are not guaranteed to be present in a well-formed QuestionnaireResponse, it should be defined as not required.

A Questionnaire.item is not guaranteed to be present when either:

  • it is not required

  • it depends on other answer(s) (with Questionnaire.item.enableWhen)

  • it is placed in a group nesting structure which has enableWhen itself

Releasing a Questionnaire

...