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.

Note

A Questionnaire defined with eHealth profile ehealth-questionnaire (see https://docs.ehealth.sundhed.dk/latest-released/ig/StructureDefinition-ehealth-questionnaire.html) cannot contain expressions nor variables.

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:

...

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)

An example of a variable evaluating to an ordinal value 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": "BreathingDifficulty",
    "language": "text/fhirpath",
    "expression": "iif(QuestionnaireResponse.repeat(item).where(linkId='1.2.208.176.1.5.1,6e6bb131-debd-4675-803b-7d783a75acc6,Sundhedsdatastyrelsen').answer.valueString = 'Severe', 2,
                   iif(QuestionnaireResponse.repeat(item).where(linkId='1.2.208.176.1.5.1,6e6bb131-debd-4675-803b-7d783a75acc6,Sundhedsdatastyrelsen').answer.valueString = 'Normal', 1, {}))"
  }
}

The expression above relies on the definer to ensure consistency between the actual answer values (in Questionnaire.item.answerOption.answer[x]) and ordinal values possibly assigned in Questionnaire.item.answerOption.ordinalValue.

Defining a Calculation Expression

...

  • language - the expression language. The supported language is a subset of FHIRPath described below. The expression language is specified as "text/fhirpath".

  • expression - the expression

...

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

Expression Language

The supported expression language is the following subset of FHIRPath:

  • Arithmetic: multiplication, division, addition & subtraction only

  • Parentheses ‘(' and ')'

  • Constants

  • The equals operation (=) for primitive types

  • The iif function

Releasing a Questionnaire

...