<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="67329733-af3b-40f1-95f8-a83812dc0a43" />
  <url value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
  <name value="ExtensionProvenanceAgent" />
  <version value="1.0.1" />
  <status value="draft" />
  <date value="2024-08-14T13:51:00+00:00" />
  <fhirVersion value="4.0.1" />
  <mapping>
    <identity value="rim" />
    <uri value="http://hl7.org/v3" />
    <name value="RIM Mapping" />
  </mapping>
  <kind value="complex-type" />
  <abstract value="false" />
  <context>
    <type value="element" />
    <expression value="Task" />
  </context>
  <context>
    <type value="element" />
    <expression value="Claim" />
  </context>
  <context>
    <type value="element" />
    <expression value="Appointment" />
  </context>
  <type value="Extension" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Extension" />
  <derivation value="constraint" />
  <differential>
    <element id="Extension.url">
      <path value="Extension.url" />
      <fixedUri value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
    </element>
    <element id="Extension.value[x]">
      <path value="Extension.value[x]" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-PractitionerRole" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Practitioner" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-HealthcareService" />
      </type>
      <constraint>
        <key value="usercode-reference" />
        <severity value="error" />
        <human value="An identifier reference or resource reference must be provided" />
        <expression value="(reference.exists() or identifier.exists())" />
        <source value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
      </constraint>
      <constraint>
        <key value="usercode-nmc" />
        <severity value="error" />
        <human value="NMC must be of the format NNANNNNA" />
        <expression value="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 value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
      </constraint>
      <constraint>
        <key value="usercode-gmp" />
        <severity value="error" />
        <human value="GMP must be of the format GNNNNNNN and not be a spurious code (starts with G6 or G7)" />
        <expression value="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 value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
      </constraint>
      <constraint>
        <key value="usercode-gmc" />
        <severity value="error" />
        <human value="GMC must be of the format CNNNNNNN" />
        <expression value="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 value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
      </constraint>
      <constraint>
        <key value="usercode-gphc" />
        <severity value="error" />
        <human value="GPHC must be of the format NNNNNNN" />
        <expression value="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 value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
      </constraint>
      <constraint>
        <key value="usercode-hcpc" />
        <severity value="error" />
        <human value="HCPC must be of the format AANNNNNN" />
        <expression value="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 value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
      </constraint>
      <constraint>
        <key value="usercode-din" />
        <severity value="error" />
        <human value="DIN format must be NNNNNN" />
        <expression value="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 value="https://fhir.nhs.uk/StructureDefinition/Extension-Provenance-agent" />
      </constraint>
      <constraint>
        <key value="role-sds-role-profile" />
        <severity value="error" />
        <human value="SDS Role Profile Id must be 12 digits" />
        <expression value="identifier.where(system='https://fhir.nhs.uk/Id/sds-role-profile-id').exists().not() or (identifier.where(system='https://fhir.nhs.uk/Id/sds-role-profile-id').exists()  and identifier.where(system='https://fhir.nhs.uk/Id/sds-role-profile-id').value.matches('^[0-9]{12}$'))" />
      </constraint>
    </element>
    <element id="Extension.value[x].identifier">
      <path value="Extension.value[x].identifier" />
      <min value="1" />
    </element>
    <element id="Extension.value[x].identifier.system">
      <path value="Extension.value[x].identifier.system" />
      <min value="1" />
    </element>
    <element id="Extension.value[x].identifier.value">
      <path value="Extension.value[x].identifier.value" />
      <min value="1" />
    </element>
  </differential>
</StructureDefinition>