# OHH Encrypted QuestionnaireResponse - Open Health Hub FHIR Implementation Guide v0.1.0

* [**Table of Contents**](toc.md)
* [**Artifacts Summary**](artifacts.md)
* **OHH Encrypted QuestionnaireResponse**

## Resource Profile: OHH Encrypted QuestionnaireResponse 

| | |
| :--- | :--- |
| *Official URL*:https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/EncryptedQuestionnaireResponse | *Version*:0.1.0 |
| Active as of 2025-12-03 | *Computable Name*:EncryptedQuestionnaireResponse |

 
A QuestionnaireResponse that contains encrypted answers. 

## Scope and Usage 

All answers in our QuestionnaireResponse are encrypted, so they can’t be read unless you have the correct private key to decrypt the responses.

**Usages:**

* Examples for this Profile: [QuestionnaireResponse/f443939b-439e-4fa9-a243-de27d1544b69](QuestionnaireResponse-f443939b-439e-4fa9-a243-de27d1544b69.md)
* CapabilityStatements using this Profile: [OHH FHIR API](CapabilityStatement-ohh-capability-statement.md)

You can also check for [usages in the FHIR IG Statistics](https://packages2.fhir.org/xig/ohh-fhir|current/StructureDefinition/encrypted-questionnaire-response)

### Formal Views of Profile Content

 [Description of Profiles, Differentials, Snapshots and how the different presentations work](http://build.fhir.org/ig/FHIR/ig-guidance/readingIgs.html#structure-definitions). 

 

Other representations of profile: [CSV](StructureDefinition-encrypted-questionnaire-response.csv), [Excel](StructureDefinition-encrypted-questionnaire-response.xlsx), [Schematron](StructureDefinition-encrypted-questionnaire-response.sch) 

### Notes:

## Encrypting QuestionnaireResponse 

Encrypting QuestionnaireResponses can be done in 2 separate ways:

### Using our javascript SDK

To help you with creating an encrypted QuestionnaireResponse we offer a npm package with a single function which inputs the QuestionnaireResponse and a list of Practitioners and which will output a Bundle that can be posted to our Bundle endpoint.

The following fields should already be set before passing the response through the encrypt function:

* `identifier` should be set to the identifier as set in the QuestionnaireResponse in the `CarePlan.activity` this response fulfills.
* `basedOn` should be set to a CarePlan reference with the correct ID (e.g. `CarePlan/123`).
* `source` should reference the Patient (as contained resource). The patient should have one identifier with system `urn:ietf:rfc:3986`. ( can be taken from the originating CarePlan)

The practitioners can be retrieved as [part of the CarePlan](CapabilityStatement-ohh-capability-statement.md#resourcesCap1), as [part of a CareTeam](StructureDefinition-ohh-care-team.md), or as a list of [Practitioners](StructureDefinition-practitioner-with-key.md) in a CareTeam.

### Encrypting answers yourself

If you want to handle the encryption yourself

Every answer should be encrypted in the item -> answer field, using an extension with the prefix `http://openhealthhub.com/fhir/StructureDefinition/encrypted-` followed by the type of the answer (e.g. `decimalType`, `stringType`, `attachment`).

Because decrypting all answers one-by-one can have a big impact on performance, we also want all answers in an encrypted JSON object. This should be added as an extension at the top level of the QuestionnaireResponse with url `http://openhealthhub.com/StructureDefinition/encryptedAnswers`.

All answers should be encrypted as a JSON object. The format of this object is as follows:

```
```json
{
    "value": "Raspberry",
    "codes": [{
        "code": "7658-8",
        "system": "https://fhir.loinc.org/CodeSystem/loinc",
        "display": "Raspberry BasoBnd Ab Qn",
        "version": "2.71"
    }],
    "text": "Raspberry label"
}
```

```

Field explanation:

* The `value` property contains a single value of the answer.
* `codes`: If the answer has codes linked to it (as entered in Improve Designer), they should be put in the `codes` array.
* The `text` field holds a text representation of the answer if available (e.g. for ‘choice’ type questions).

If the answer has multiple values (e.g. in case of a multiple select question) there should be multiple answer objects. Most questionnaire items should have a one-to-one match between their linkIds and the ids for the answer value objects. For result questionnaire items `result_<result_index>_formula_<formula_index>` should be created to indicate first which item (`result_<result_index>`) and second (`formula_<formula_index>`) which result sub-item the answer is for. Finally, all formula results should also be emitted as `formula_<formula_id>`.

The JSON object with all the combined answers should be an object, with a property for every question with key the `linkId` of the question. The value should be an array of answer objects as described above (also in case of single answer).

For a complete example please have a look at the **[JavaScript FHIR QuestionnaireResponse Client Example](https://github.com/openhealthhub/FhirClients/blob/main/javascript/js/questionnaire-response-encrypt.js)**

## Decrypting QuestionnaireResponse 

All answers in our QuestionnaireResponse are encrypted, so they can’t be read unless you have the correct private key to decrypt the responses. The answers are encrypted in 2 separate ways.

Every answer is encrypted in the `item.answer` field, using an extension with the prefix `https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-` followed by the type of the answer (e.g. `decimalType`, `stringType`, `attachment`). Refer to the example JSON of the implementation guide for a complete example.

Because decrypting all answers one-by-one can have a big impact on performance, we also emit all answers in an encrypted JSON object. This is emitted in an extension at the top level of the QuestionnaireResponse with url `https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encryptedAnswers`.

All answers are emitted as a JSON object with a `value` property that contains the actual value of the answer. If the answer has codes linked to it (as entered in the Form Designer), they will be put in a `codes` array. Most questionnaire items will have a one-to-one match between their linkids and the ids for the answer value objects. For result questionnaire items `result_<result_index>_formula_<formula_index>` will be created to indicate first which item (`result_<result_index>`) and second (`formula_<formula_index>`) which result sub-item the answer is for. Finally, all formula results will also be emitted as `formula_<formula_id>`.

For a complete example on how to decrypt the answers, refer to our [FhirClient example respository](https://github.com/openhealthhub/FhirClients/tree/main) where examples can be found for several popular programming languages.



## Resource Content

```json
{
  "resourceType" : "StructureDefinition",
  "id" : "encrypted-questionnaire-response",
  "url" : "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/EncryptedQuestionnaireResponse",
  "version" : "0.1.0",
  "name" : "EncryptedQuestionnaireResponse",
  "title" : "Encrypted Questionnaire Response Profile",
  "status" : "active",
  "date" : "2025-12-03T12:00:57+00:00",
  "publisher" : "Open Health Hub",
  "contact" : [
    {
      "name" : "Open Health Hub",
      "telecom" : [
        {
          "system" : "url",
          "value" : "https://www.openhealthhub.com"
        },
        {
          "system" : "email",
          "value" : "support@openhealthhub.com"
        }
      ]
    }
  ],
  "description" : "A QuestionnaireResponse that contains encrypted answers.",
  "fhirVersion" : "4.0.1",
  "mapping" : [
    {
      "identity" : "workflow",
      "uri" : "http://hl7.org/fhir/workflow",
      "name" : "Workflow Pattern"
    },
    {
      "identity" : "rim",
      "uri" : "http://hl7.org/v3",
      "name" : "RIM Mapping"
    },
    {
      "identity" : "w5",
      "uri" : "http://hl7.org/fhir/fivews",
      "name" : "FiveWs Pattern Mapping"
    }
  ],
  "kind" : "resource",
  "abstract" : false,
  "type" : "QuestionnaireResponse",
  "baseDefinition" : "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaireresponse",
  "derivation" : "constraint",
  "differential" : {
    "element" : [
      {
        "id" : "QuestionnaireResponse",
        "path" : "QuestionnaireResponse"
      },
      {
        "id" : "QuestionnaireResponse.contained",
        "path" : "QuestionnaireResponse.contained",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Patient",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/ohh-patient"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.extension",
        "path" : "QuestionnaireResponse.extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "ordered" : false,
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.extension:encryptedAnswers",
        "path" : "QuestionnaireResponse.extension",
        "sliceName" : "encryptedAnswers",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encryptedAnswers"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.identifier",
        "path" : "QuestionnaireResponse.identifier",
        "definition" : "Should be set to the identifier as set in the QuestionnaireResponse in the CarePlan.activity this response fulfills.",
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.identifier.value",
        "path" : "QuestionnaireResponse.identifier.value",
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.basedOn",
        "path" : "QuestionnaireResponse.basedOn",
        "max" : "1",
        "type" : [
          {
            "code" : "Reference",
            "targetProfile" : ["http://hl7.org/fhir/StructureDefinition/CarePlan"]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.questionnaire",
        "path" : "QuestionnaireResponse.questionnaire",
        "type" : [
          {
            "code" : "canonical",
            "targetProfile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/ohh-questionnaire"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.status",
        "path" : "QuestionnaireResponse.status",
        "fixedCode" : "completed"
      },
      {
        "id" : "QuestionnaireResponse.subject",
        "path" : "QuestionnaireResponse.subject",
        "min" : 1,
        "type" : [
          {
            "code" : "Reference",
            "targetProfile" : ["http://hl7.org/fhir/StructureDefinition/Patient"]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.subject.reference",
        "path" : "QuestionnaireResponse.subject.reference",
        "patternString" : "#patient"
      },
      {
        "id" : "QuestionnaireResponse.source",
        "path" : "QuestionnaireResponse.source",
        "min" : 1,
        "type" : [
          {
            "code" : "Reference",
            "targetProfile" : [
              "http://hl7.org/fhir/StructureDefinition/Patient",
              "http://hl7.org/fhir/StructureDefinition/Practitioner"
            ]
          }
        ],
        "constraint" : [
          {
            "key" : "source-reference-pattern",
            "severity" : "error",
            "human" : "Source reference must be either #patient or start with Practitioner/<respondentUuid>",
            "expression" : "reference.matches('^(#patient|Practitioner/.+)$')",
            "source" : "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/EncryptedQuestionnaireResponse"
          }
        ],
        "mustSupport" : true
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "type",
              "path" : "$this"
            }
          ],
          "ordered" : false,
          "rules" : "open"
        }
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueString",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueString",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "string"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueString.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "rules" : "closed"
        },
        "constraint" : [
          {
            "key" : "answer-string-extension-slice",
            "severity" : "error",
            "human" : "Must have either encrypted-stringType or encrypted-openChoiceType extension, but not both",
            "expression" : "url.exists() and (url.matches('https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-stringType') or url.matches('https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-openChoiceType'))",
            "source" : "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/EncryptedQuestionnaireResponse"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueString.extension:encrypted-stringType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-stringType",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-stringType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueString.extension:encrypted-openChoiceType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-openChoiceType",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-openChoiceType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueInteger",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueInteger",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "integer"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueInteger.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueInteger.extension:encrypted-integerType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-integerType",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-integerType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDecimal",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueDecimal",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "decimal"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDecimal.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDecimal.extension:encrypted-decimalType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-decimalType",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-decimalType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDate",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueDate",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "date"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDate.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDate.extension:encrypted-dateType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-dateType",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-dateType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDateTime",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueDateTime",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "dateTime"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDateTime.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueDateTime.extension:encrypted-dateTimeType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-dateTimeType",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-dateTimeType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueTime",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueTime",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "time"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueTime.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueTime.extension:encrypted-timeType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-timeType",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-timeType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueAttachment",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueAttachment",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "Attachment"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueAttachment.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "description" : "Extensions are always sliced by (at least) url",
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueAttachment.extension:encrypted-attachment",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-attachment",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-attachment"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueBoolean",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueBoolean",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "boolean"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueBoolean.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueBoolean.extension:encrypted-booleanType",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-booleanType",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-booleanType"
            ]
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueCoding",
        "path" : "QuestionnaireResponse.item.answer.value[x]",
        "sliceName" : "valueCoding",
        "min" : 0,
        "max" : "1",
        "type" : [
          {
            "code" : "Coding"
          }
        ]
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueCoding.extension",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "slicing" : {
          "discriminator" : [
            {
              "type" : "value",
              "path" : "url"
            }
          ],
          "description" : "Extensions are always sliced by (at least) url",
          "rules" : "closed"
        },
        "min" : 1
      },
      {
        "id" : "QuestionnaireResponse.item.answer.value[x]:valueCoding.extension:encrypted-coding",
        "path" : "QuestionnaireResponse.item.answer.value[x].extension",
        "sliceName" : "encrypted-coding",
        "min" : 1,
        "max" : "1",
        "type" : [
          {
            "code" : "Extension",
            "profile" : [
              "https://api.openhealthhub.com/OpenHealthhub/fhir/4/StructureDefinition/encrypted-coding"
            ]
          }
        ]
      }
    ]
  }
}

```
