<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="641d2bce-32f0-415d-903b-c3905e4c2483" />
  <url value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Encounter" />
  <name value="NHSDigitalEncounter" />
  <status value="draft" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Encounter" />
  <baseDefinition value="https://fhir.hl7.org.uk/StructureDefinition/UKCore-Encounter" />
  <derivation value="constraint" />
  <differential>
    <element id="Encounter.identifier">
      <path value="Encounter.identifier" />
      <definition value="In ITK HL7v2 this is PV1.19 Visit Number .&#xD;&#xA;&#xD;&#xA;Identifier(s) by which this encounter is known." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Encounter.identifier.system">
      <path value="Encounter.identifier.system" />
      <min value="1" />
    </element>
    <element id="Encounter.identifier.value">
      <path value="Encounter.identifier.value" />
      <min value="1" />
    </element>
    <element id="Encounter.class">
      <path value="Encounter.class" />
      <definition value="In ITK HL7v2 PV1.2 Patient Class&#xD;&#xA;&#xD;&#xA;Concepts representing classification of patient encounter such as ambulatory (outpatient), inpatient, emergency, home health or others due to local variations." />
    </element>
    <element id="Encounter.type">
      <path value="Encounter.type" />
      <definition value="In ITK HL7v2 PV1.4 Admission Type&#xD;&#xA;&#xD;&#xA;Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation)." />
    </element>
    <element id="Encounter.serviceType">
      <path value="Encounter.serviceType" />
      <definition value="In HL7v2 ITK PV1.10 Hospital Service – specialty&#xD;&#xA;&#xD;&#xA;Broad categorization of the service that is to be provided (e.g. cardiology)." />
      <binding>
        <strength value="extensible" />
        <description value="NHS Data Dictionary Treatment Function Code" />
        <valueSet value="https://fhir.nhs.uk/ValueSet/NHSDataModelAndDictionary-treatment-function" />
      </binding>
    </element>
    <element id="Encounter.subject">
      <path value="Encounter.subject" />
      <constraint>
        <key value="patient-reference" />
        <severity value="warning" />
        <human value="subject - An identifier reference plus a display name or resource reference must be provided" />
        <expression value="(reference.exists() or (identifier.exists() and display.exists()))" />
        <source value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Encounter" />
      </constraint>
      <constraint>
        <key value="patient-nhs" />
        <severity value="error" />
        <human value="Supplied NHS Number is outside the English and Welsh NHS Number range or length of the number is wrong." />
        <expression value="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 value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Encounter" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Encounter.subject.identifier.system">
      <path value="Encounter.subject.identifier.system" />
      <min value="1" />
    </element>
    <element id="Encounter.subject.identifier.value">
      <path value="Encounter.subject.identifier.value" />
      <min value="1" />
    </element>
    <element id="Encounter.episodeOfCare">
      <path value="Encounter.episodeOfCare" />
      <definition value="In ITK HL7v2 this may be PV1.50 Alternate Visit ID (if this is a Stay or Episode identifier)&#xD;&#xA;&#xD;&#xA;Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years)." />
    </element>
    <element id="Encounter.episodeOfCare.identifier.system">
      <path value="Encounter.episodeOfCare.identifier.system" />
      <min value="1" />
    </element>
    <element id="Encounter.episodeOfCare.identifier.value">
      <path value="Encounter.episodeOfCare.identifier.value" />
      <min value="1" />
    </element>
    <element id="Encounter.basedOn">
      <path value="Encounter.basedOn" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-ServiceRequest" />
      </type>
    </element>
    <element id="Encounter.basedOn.identifier.system">
      <path value="Encounter.basedOn.identifier.system" />
      <min value="1" />
    </element>
    <element id="Encounter.basedOn.identifier.value">
      <path value="Encounter.basedOn.identifier.value" />
      <min value="1" />
    </element>
    <element id="Encounter.participant">
      <path value="Encounter.participant" />
      <definition value="In HL7v2 this is PV1.7 Attending Doctor, PV1.8 Referring Doctor and PV1.9 Consulting Doctoer&#xD;&#xA;&#xD;&#xA;The list of people responsible for providing the service." />
      <mustSupport value="true" />
    </element>
    <element id="Encounter.participant.individual">
      <path value="Encounter.participant.individual" />
      <mustSupport value="true" />
    </element>
    <element id="Encounter.participant.individual.identifier.system">
      <path value="Encounter.participant.individual.identifier.system" />
      <min value="1" />
    </element>
    <element id="Encounter.participant.individual.identifier.value">
      <path value="Encounter.participant.individual.identifier.value" />
      <min value="1" />
    </element>
    <element id="Encounter.appointment">
      <path value="Encounter.appointment" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Appointment" />
      </type>
    </element>
    <element id="Encounter.period">
      <path value="Encounter.period" />
      <definition value="ITK Hl7v2 PV1.44 Admit Date/Time PV1.45 Discharge Date/Time&#xD;&#xA;&#xD;&#xA;The start and end time of the encounter." />
    </element>
    <element id="Encounter.reasonCode">
      <path value="Encounter.reasonCode" />
      <mustSupport value="true" />
    </element>
    <element id="Encounter.hospitalization.dischargeDisposition">
      <path value="Encounter.hospitalization.dischargeDisposition" />
      <definition value="ITK Hl7v2 PV1.36 Discharge Disposition&#xD;&#xA;&#xD;&#xA;Category or kind of location after discharge." />
    </element>
    <element id="Encounter.location">
      <path value="Encounter.location" />
      <definition value="ITK HL7v2 PV1.4 Assigned Patient Location&#xD;&#xA;&#xD;&#xA;List of locations where  the patient has been during this encounter." />
    </element>
    <element id="Encounter.partOf">
      <path value="Encounter.partOf" />
      <definition value="In ITK HL7v2 this may be PV1.50 Alternate Visit ID (if this is an Encounter identifier)&#xD;&#xA;&#xD;&#xA;Another Encounter of which this encounter is a part of (administratively or in time)." />
    </element>
  </differential>
</StructureDefinition>