{
  "resourceType": "StructureDefinition",
  "id": "2b02f97f-e0db-48c9-af27-0fc391677dc4",
  "url": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse",
  "name": "NHSDigitalQuestionnaireResponse",
  "status": "draft",
  "fhirVersion": "4.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "QuestionnaireResponse",
  "baseDefinition": "https://fhir.hl7.org.uk/StructureDefinition/UKCore-QuestionnaireResponse",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "QuestionnaireResponse.identifier",
        "path": "QuestionnaireResponse.identifier",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.questionnaire",
        "path": "QuestionnaireResponse.questionnaire",
        "definition": "The Questionnaire that defines and organizes the questions for which answers are being provided.\r\n\r\n```json\r\n\"questionnaire\": \"https://fhir.nhs.uk/Questionnaire/COVIDVaccinationMedicalExemption\",\r\n```",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.status",
        "path": "QuestionnaireResponse.status",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.subject",
        "path": "QuestionnaireResponse.subject",
        "definition": "The subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.\r\n\r\n```json\r\n\"subject\": {\r\n        \"identifier\": [\r\n            {\r\n                \"system\": \"https://fhir.nhs.uk/Id/nhs-number\",\r\n                \"value\": \"9912003888\"\r\n            }\r\n        ],\r\n        \"display\": \"Ivor Fritagelse\"\r\n    },\r\n```",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://fhir.nhs.uk/StructureDefinition/NHSDigital-Patient"
            ]
          }
        ],
        "constraint": [
          {
            "key": "patient-reference",
            "severity": "error",
            "human": "An identifier reference or resource reference must be provided",
            "expression": "(reference.exists() or (identifier.exists()))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          },
          {
            "key": "patient-nhs",
            "severity": "error",
            "human": "Supplied NHS Number is outside the English and Welsh NHS Number range or length of the number is wrong.",
            "expression": "identifier.where(system='https://fhir.nhs.uk/Id/nhs-number').exists().not() or (identifier.where(system='https://fhir.nhs.uk/Id/nhs-number').exists()  and identifier.where(system='https://fhir.nhs.uk/Id/nhs-number').value.matches('^([456789]{1}[0-9]{9})$'))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-Claim"
          }
        ],
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.subject.identifier.system",
        "path": "QuestionnaireResponse.subject.identifier.system",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.subject.identifier.value",
        "path": "QuestionnaireResponse.subject.identifier.value",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.subject.display",
        "path": "QuestionnaireResponse.subject.display",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.authored",
        "path": "QuestionnaireResponse.authored",
        "definition": "The date and/or time that this set of answers were last changed.\r\n\r\n```json\r\n\"authored\": \"2021-09-09T08:32:00+00:00\",\r\n```",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.author",
        "path": "QuestionnaireResponse.author",
        "definition": "Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.\r\n\r\n```json\r\n\"author\": {\r\n        \"identifier\": {\r\n            \"system\": \"https://fhir.nhs.uk/Id/ods-organization-code\",\r\n            \"value\": \"B81001\"\r\n        },\r\n        \"display\": \"Austhorpe Springs Practice\"\r\n    },\r\n```",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://fhir.nhs.uk/StructureDefinition/NHSDigital-Organization",
              "https://fhir.nhs.uk/StructureDefinition/NHSDigital-PractitionerRole-Minimal"
            ],
            "aggregation": [
              "contained"
            ]
          }
        ],
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.author.identifier.system",
        "path": "QuestionnaireResponse.author.identifier.system",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.author.identifier.value",
        "path": "QuestionnaireResponse.author.identifier.value",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.author.display",
        "path": "QuestionnaireResponse.author.display",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.source",
        "path": "QuestionnaireResponse.source",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://fhir.nhs.uk/StructureDefinition/NHSDigital-PractitionerRole"
            ],
            "aggregation": [
              "contained"
            ]
          }
        ],
        "constraint": [
          {
            "key": "usercode-reference",
            "severity": "warning",
            "human": "An identifier reference or resource reference must be provided",
            "expression": "(reference.exists() or (identifier.exists()))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          },
          {
            "key": "usercode-nmc",
            "severity": "error",
            "human": "NMC must be of the format NNANNNNA",
            "expression": "identifier.exists().not() or identifier.where(system='https://fhir.hl7.org.uk/Id/nmc-number').exists().not() or (identifier.where(system='https://fhir.hl7.org.uk/Id/nmc-number').exists()  and identifier.where(system='https://fhir.hl7.org.uk/Id/nmc-number').value.matches('^[0-9]{2}[A-Z]{1}[0-9]{4}[A-Z]{1}$'))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          },
          {
            "key": "usercodee-gmp",
            "severity": "error",
            "human": "GMP must be of the format GNNNNNNN and not be a spurious code (starts with G6 or G7)",
            "expression": "identifier.exists().not() or identifier.where(system='https://fhir.hl7.org.uk/Id/gmp-number').exists().not() or (identifier.where(system='https://fhir.hl7.org.uk/Id/gmp-number').exists()  and identifier.where(system='https://fhir.hl7.org.uk/Id/gmp-number').value.matches('^[G]{1}[01234589]{1}[0-9]{6}$'))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          },
          {
            "key": "usercode-gmc",
            "severity": "error",
            "human": "GMC must be of the format CNNNNNNN",
            "expression": "identifier.exists().not() or identifier.where(system='https://fhir.hl7.org.uk/Id/gmc-number').exists().not() or (identifier.where(system='https://fhir.hl7.org.uk/Id/gmc-number').exists()  and identifier.where(system='https://fhir.hl7.org.uk/Id/gmc-number').value.matches('^[C]{1}[0-9]{7}$'))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          },
          {
            "key": "usercode-gphc",
            "severity": "error",
            "human": "GPHC must be of the format NNNNNNN",
            "expression": "identifier.exists().not() or identifier.where(system='https://fhir.hl7.org.uk/Id/gphc-number').exists().not() or (identifier.where(system='https://fhir.hl7.org.uk/Id/gphc-number').exists()  and identifier.where(system='https://fhir.hl7.org.uk/Id/gphc-number').value.matches('^[0-9]{7}$'))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          },
          {
            "key": "usercode-hcpc",
            "severity": "error",
            "human": "HCPC must be of the format AANNNNNN",
            "expression": "identifier.exists().not() or identifier.where(system='https://fhir.hl7.org.uk/Id/hcpc-number').exists().not() or (identifier.where(system='https://fhir.hl7.org.uk/Id/hcpc-number').exists()  and identifier.where(system='https://fhir.hl7.org.uk/Id/hcpc-number').value.matches('^[A-Z]{2}[0-9]{6}$'))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          },
          {
            "key": "usercode-din",
            "severity": "error",
            "human": "DIN format must be NNNNNN",
            "expression": "identifier.exists().not() or identifier.where(system='https://fhir.hl7.org.uk/Id/din-number').exists().not() or (identifier.where(system='https://fhir.hl7.org.uk/Id/din-number').exists()  and identifier.where(system='https://fhir.hl7.org.uk/Id/din-number').value.matches('^[0-9]{6}$'))",
            "source": "https://fhir.nhs.uk/StructureDefinition/NHSDigital-QuestionnaireResponse"
          }
        ],
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.source.identifier",
        "path": "QuestionnaireResponse.source.identifier",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.source.identifier.value",
        "path": "QuestionnaireResponse.source.identifier.value",
        "min": 1
      },
      {
        "id": "QuestionnaireResponse.source.display",
        "path": "QuestionnaireResponse.source.display",
        "mustSupport": true
      },
      {
        "id": "QuestionnaireResponse.item",
        "path": "QuestionnaireResponse.item",
        "definition": "A group or question item from the original questionnaire for which answers are provided.\r\n\r\n```json\r\n \"item\": [\r\n        {\r\n            \"linkId\": \"exemptionStatus\",\r\n            \"answer\": [\r\n                {\r\n                    \"valueCoding\": {\r\n                        \"system\": \"https://fhir.nhs.uk/CodeSystem/covid-vaccination-medical-exemption\",\r\n                        \"code\": \"4\",\r\n                        \"display\": \"Rejected: Exemption from COVID vaccination and testing\"\r\n                    }\r\n                }\r\n            ]\r\n        }\r\n   ]\r\n```",
        "min": 1,
        "mustSupport": true
      }
    ]
  }
}