<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="DataStandardsWales-PSOM-MessageHeader" />
  <url value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-PSOM-MessageHeader" />
  <name value="DataStandardsWalesPSOMMessageHeader" />
  <title value="Data Standards Wales PSOM MessageHeader" />
  <status value="active" />
  <publisher value="NHS Wales" />
  <contact>
    <name value="Data Standards" />
    <telecom>
      <system value="email" />
      <value value="data.standards@wales.nhs.uk" />
      <use value="work" />
    </telecom>
  </contact>
  <description value="A profile that defines a MessageHeader structure used for PSOM messaging." />
  <copyright value="© 2023 NHS Wales." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="MessageHeader" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/MessageHeader" />
  <derivation value="constraint" />
  <differential>
    <element id="MessageHeader">
      <path value="MessageHeader" />
      <constraint>
        <key value="PSOM-MessageHeader-01" />
        <severity value="error" />
        <human value="All exception response messages must include a fully specified response (including an OperationOutcome that contains the issue details)." />
        <expression value="event.code = 'exception-response' implies (response.details.exists())" />
      </constraint>
    </element>
    <element id="MessageHeader.event[x]">
      <path value="MessageHeader.event[x]" />
      <type>
        <code value="Coding" />
      </type>
      <condition value="PSOM-MessageHeader-01" />
      <binding>
        <strength value="required" />
        <description value="PSOM message events" />
        <valueSet value="https://fhir.nhs.wales/ValueSet/DataStandardsWales-PSOM-MessageEvent" />
      </binding>
    </element>
    <element id="MessageHeader.response">
      <path value="MessageHeader.response" />
      <condition value="PSOM-MessageHeader-01" />
    </element>
    <element id="MessageHeader.response.identifier">
      <path value="MessageHeader.response.identifier" />
      <comment value="This value should be the `MessageHeader.id` of the original message, i.e. a business identifier. See http://hl7.org/fhir/R4/messageheader-definitions.html#MessageHeader.response.identifier for more information." />
    </element>
    <element id="MessageHeader.response.details">
      <path value="MessageHeader.response.details" />
      <condition value="PSOM-MessageHeader-01" />
    </element>
    <element id="MessageHeader.focus">
      <path value="MessageHeader.focus" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-PSOM-CarePlan" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-PSOM-Task" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-Patient" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-PSOM-QuestionnaireResponse" />
      </type>
    </element>
    <element id="MessageHeader.definition">
      <path value="MessageHeader.definition" />
      <type>
        <code value="canonical" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-PSOM-MessageDefinition" />
      </type>
    </element>
  </differential>
</StructureDefinition>