{
  "resourceType": "StructureDefinition",
  "url": "https://fhir.nhs.wales/StructureDefinition/CDR-MessageHeader",
  "name": "CDRMessageHeader",
  "status": "draft",
  "description": "Defines the CDR MessageHeader profile, derived from the Data Standards Wales MessageHeader profile, for use in CDR FHIR messages. This profile constrains the message source endpoint to an NHS Wales Application Instance Identifier (AII) OID URN and requires the message event code to be drawn from the CDR Message Events value set.",
  "purpose": "The purpose of this profile is to standardise message-level metadata for all messages submitted to the CDR so that the sending system can be reliably identified and the business event can be consistently interpreted. By enforcing a valid AII endpoint and a required CDR event code, this profile supports safe message routing, validation, processing and traceability across CDR integrations.",
  "fhirVersion": "4.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "MessageHeader",
  "baseDefinition": "https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-MessageHeader",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "MessageHeader.event[x].code",
        "path": "MessageHeader.event[x].code",
        "binding": {
          "strength": "required",
          "description": "A value set containing all event codes for FHIR messages events handled by the CDR.",
          "valueSet": "https://fhir.nhs.wales/ValueSet/CDR-MessageEvents"
        }
      },
      {
        "id": "MessageHeader.source.endpoint",
        "path": "MessageHeader.source.endpoint",
        "constraint": [
          {
            "key": "cdr-messageheader-1",
            "severity": "error",
            "human": "The source endpoint SHALL contain the Application Instance Identifier (AII) allocated to the sending system by the Data Standards Wales team. The identifier is issued as an NHS Wales OID and SHALL use the namespace 2.16.840.1.113883.2.1.8.1.5, expressed as a URN, with a mandatory three-digit system identifier and an optional additional numeric sub-identifier.",
            "expression": "matches('^urn:oid:2[.]16[.]840[.]1[.]113883[.]2[.]1[.]8[.]1[.]5[.][0-9]{3}([.](0|[1-9][0-9]*))?$')"
          }
        ]
      }
    ]
  }
}