<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="19354975-cb99-492c-b469-798ed7534b51" />
  <url value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-DocumentReference" />
  <name value="NHSDigitalDocumentReference" />
  <status value="draft" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="DocumentReference" />
  <baseDefinition value="https://fhir.hl7.org.uk/StructureDefinition/UKCore-DocumentReference" />
  <derivation value="constraint" />
  <differential>
    <element id="DocumentReference.identifier">
      <path value="DocumentReference.identifier" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.status">
      <path value="DocumentReference.status" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.type">
      <path value="DocumentReference.type" />
      <definition value="Specifies the particular kind of document referenced  (e.g. History and Physical, Discharge Summary, Progress Note). This usually equates to the purpose of making the document referenced.&#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;&quot;type&quot;: {&#xD;&#xA;        &quot;coding&quot;:  [&#xD;&#xA;            {&#xD;&#xA;                &quot;system&quot;: &quot;http://snomed.info/sct&quot;,&#xD;&#xA;                &quot;code&quot;: &quot;736253002&quot;,&#xD;&#xA;                &quot;display&quot;: &quot;Mental health crisis plan&quot;&#xD;&#xA;            }&#xD;&#xA;        ]&#xD;&#xA;    }&#xD;&#xA;```" />
      <mustSupport value="true" />
      <binding>
        <strength value="extensible" />
        <valueSet value="https://fhir.nhs.uk/ValueSet/NHSDigital-DocumentType" />
      </binding>
    </element>
    <element id="DocumentReference.type.coding">
      <path value="DocumentReference.type.coding" />
      <min value="1" />
    </element>
    <element id="DocumentReference.type.coding.system">
      <path value="DocumentReference.type.coding.system" />
      <min value="1" />
    </element>
    <element id="DocumentReference.type.coding.code">
      <path value="DocumentReference.type.coding.code" />
      <min value="1" />
    </element>
    <element id="DocumentReference.type.coding.display">
      <path value="DocumentReference.type.coding.display" />
      <min value="1" />
    </element>
    <element id="DocumentReference.category">
      <path value="DocumentReference.category" />
      <definition value="A categorization for the type of document referenced - helps for indexing and searching. This may be implied by or derived from the code specified in the DocumentReference.type.&#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;&quot;category&quot;:  [&#xD;&#xA;        {&#xD;&#xA;            &quot;coding&quot;:  [&#xD;&#xA;                {&#xD;&#xA;                    &quot;system&quot;: &quot;http://snomed.info/sct&quot;,&#xD;&#xA;                    &quot;code&quot;: &quot;734163000&quot;,&#xD;&#xA;                    &quot;display&quot;: &quot;Care plan&quot;&#xD;&#xA;                }&#xD;&#xA;            ]&#xD;&#xA;        }&#xD;&#xA;    ]&#xD;&#xA;```" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.subject">
      <path value="DocumentReference.subject" />
      <definition value="A reference to a [NHSDigital-Patient](https://simplifier.net/resolve?target=simplifier&amp;scope=uk.nhsdigital.r4&amp;canonical=https://fhir.nhs.uk/StructureDefinition/NHSDigital-Patient) and/or an identifier reference using NHSNumber. Only traced NHS Numbers may be used. &#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;&#xD;&#xA;    &quot;subject&quot;: {&#xD;&#xA;        &quot;reference&quot;: &quot;urn:uuid:edea022a-2d81-11eb-adc1-0242ac120002&quot;,&#xD;&#xA;        &quot;identifier&quot;: [&#xD;&#xA;            {&#xD;&#xA;                &quot;system&quot;: &quot;https://fhir.nhs.uk/Id/nhs-number&quot;,&#xD;&#xA;                &quot;value&quot;: &quot;9912003888&quot;&#xD;&#xA;            }&#xD;&#xA;        ]&#xD;&#xA;    },&#xD;&#xA;&#xD;&#xA;```&#xD;&#xA;&#xD;&#xA;Preference is for a reference to a Patient resource, however current document flows may only support limited metadata." />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Group" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Device" />
        <targetProfile value="https://fhir.hl7.org.uk/StructureDefinition/UKCore-Practitioner" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Patient" />
      </type>
      <constraint>
        <key value="patient-reference" />
        <severity value="warning" />
        <human value="subject - An identifier reference or resource reference must be provided" />
        <expression value="(reference.exists() or (identifier.exists()))" />
        <source value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-DocumentReference" />
      </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-DocumentReference" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.subject.identifier.system">
      <path value="DocumentReference.subject.identifier.system" />
      <min value="1" />
    </element>
    <element id="DocumentReference.subject.identifier.value">
      <path value="DocumentReference.subject.identifier.value" />
      <min value="1" />
    </element>
    <element id="DocumentReference.date">
      <path value="DocumentReference.date" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.author">
      <path value="DocumentReference.author" />
      <definition value="A resource reference to a contained [NHSDigital-PractitionerRole](https://simplifier.net/resolve?target=simplifier&amp;scope=uk.nhsdigital.r4&amp;canonical=https://fhir.nhs.uk/StructureDefinition/NHSDigital-PractitionerRole)&#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;&#xD;&#xA;    &quot;author&quot;: [&#xD;&#xA;        {&#xD;&#xA;          &quot;reference&quot; : &quot;#author&quot;,&#xD;&#xA;        }&#xD;&#xA;    ]&#xD;&#xA;```&#xD;&#xA;&#xD;&#xA;The contained resource: &#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;{&#xD;&#xA;  &quot;resourceType&quot;: &quot;DocumentReference&quot;,&#xD;&#xA;  &quot;id&quot;: &quot;a9b9f0f4-cc37-4ea3-bd4b-16d15ddbe63b&quot;,&#xD;&#xA;  &quot;contained&quot;: [&#xD;&#xA;    {&#xD;&#xA;      &quot;resourceType&quot;: &quot;PractitionerRole&quot;,&#xD;&#xA;      &quot;id&quot;: &quot;author&quot;,&#xD;&#xA;      &quot;practitioner&quot;: {&#xD;&#xA;        &quot;identifier&quot;: {&#xD;&#xA;          &quot;system&quot;: &quot;https://fhir.nhs.uk/Id/sds-user-id&quot;,&#xD;&#xA;          &quot;value&quot;: &quot;0987654321&quot;&#xD;&#xA;        }&#xD;&#xA;      },&#xD;&#xA;      &quot;organization&quot;: {&#xD;&#xA;        &quot;identifier&quot;: {&#xD;&#xA;          &quot;system&quot;: &quot;https://fhir.nhs.uk/Id/ods-organization-code&quot;,&#xD;&#xA;          &quot;value&quot;: &quot;RR8&quot;&#xD;&#xA;        },&#xD;&#xA;        &quot;display&quot;: &quot;LEEDS TEACHING HOSPITALS NHS TRUST&quot;&#xD;&#xA;      }&#xD;&#xA;    }&#xD;&#xA;  ],&#xD;&#xA;```" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Organization" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Device" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Patient" />
        <targetProfile value="https://fhir.hl7.org.uk/StructureDefinition/UKCore-RelatedPerson" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-PractitionerRole" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.custodian">
      <path value="DocumentReference.custodian" />
      <definition value="An identifier reference to an ODS Organisation. &#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;&#xD;&#xA;        &quot;custodian&quot;: {&#xD;&#xA;                &quot;identifier&quot;: {&#xD;&#xA;                    &quot;system&quot;: &quot;https://fhir.nhs.uk/Id/ods-organization-code&quot;,&#xD;&#xA;                    &quot;value&quot;: &quot;VNE51&quot;&#xD;&#xA;                },&#xD;&#xA;                &quot;display&quot;: &quot;The Pharmacy System&quot;&#xD;&#xA;        }&#xD;&#xA;```" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Organization" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.content">
      <path value="DocumentReference.content" />
      <definition value="The document and format referenced. There may be multiple content element repetitions, each with a different format.&#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;&quot;content&quot;: [&#xD;&#xA;        {&#xD;&#xA;            &quot;attachment&quot;: {&#xD;&#xA;                &quot;extension&quot;: [&#xD;&#xA;                    {&#xD;&#xA;                        &quot;url&quot;: &quot;https://fhir.nhs.uk/STU3/StructureDefinition/Extension-eRS-AttachedBy&quot;,&#xD;&#xA;                        &quot;valueReference&quot;: {&#xD;&#xA;                            &quot;identifier&quot;: {&#xD;&#xA;                                &quot;system&quot;: &quot;https://fhir.nhs.uk/Id/sds-user-id&quot;,&#xD;&#xA;                                &quot;value&quot;: &quot;987654321&quot;&#xD;&#xA;                            }&#xD;&#xA;                        }&#xD;&#xA;                    }&#xD;&#xA;                ],&#xD;&#xA;                &quot;contentType&quot;: &quot;application/pdf&quot;,&#xD;&#xA;                &quot;url&quot;: &quot;Binary/att-70001-70002&quot;,&#xD;&#xA;                &quot;size&quot;: 18592,&#xD;&#xA;                &quot;title&quot;: &quot;upload.png&quot;,&#xD;&#xA;                &quot;creation&quot;: &quot;2022-01-31&quot;&#xD;&#xA;            }&#xD;&#xA;        }&#xD;&#xA;    ]&#xD;&#xA;```" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.content.attachment">
      <path value="DocumentReference.content.attachment" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.content.attachment.contentType">
      <path value="DocumentReference.content.attachment.contentType" />
      <definition value="A listed of supported document types (mime types) should be provided, this is likely to include:&#xD;&#xA;&#xD;&#xA;- FHIR Documents&#xD;&#xA;- PDF&#xD;&#xA;- html&#xD;&#xA;- jpeg/jpg&#xD;&#xA;- png" />
    </element>
    <element id="DocumentReference.content.attachment.data">
      <path value="DocumentReference.content.attachment.data" />
      <definition value="**SHOULD** not be used. Use url to link to the actual document" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.content.attachment.url">
      <path value="DocumentReference.content.attachment.url" />
      <definition value="For REST interactions this **MUST** be a url to the actual document. For messaging interactions this must be an internal resource reference to the actual document." />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.context">
      <path value="DocumentReference.context" />
      <definition value="The clinical context in which the document was prepared.&#xD;&#xA;&#xD;&#xA;```json&#xD;&#xA;&quot;context&quot;: {&#xD;&#xA;        &quot;related&quot; : [&#xD;&#xA;            {&#xD;&#xA;                &quot;type&quot;: &quot;ServiceRequest&quot;,&#xD;&#xA;                &quot;reference&quot;: &quot;ServiceRequest/be735573-9f24-42e1-ae98-af89d632e4bf&quot;&#xD;&#xA;            },&#xD;&#xA;            {&#xD;&#xA;                &quot;type&quot;: &quot;Task&quot;,&#xD;&#xA;                &quot;reference&quot;: &quot;Task/f66e4cd7-207c-4b7d-9ac9-80630c451125&quot;&#xD;&#xA;            }&#xD;&#xA;        ]&#xD;&#xA;    }&#xD;&#xA;```" />
      <mustSupport value="true" />
    </element>
    <element id="DocumentReference.context.practiceSetting">
      <path value="DocumentReference.context.practiceSetting" />
      <definition value="It is recommended a care setting code should be provided" />
      <mustSupport value="true" />
      <binding>
        <strength value="extensible" />
        <valueSet value="https://fhir.nhs.uk/ValueSet/NHSDigital-CareSettingType" />
      </binding>
    </element>
    <element id="DocumentReference.context.related">
      <path value="DocumentReference.context.related" />
      <definition value="Related identifiers or resources associated with the DocumentReference.&#xD;&#xA;&#xD;&#xA;In eRS this is used to link a DocumentReference (i.e. a document) to a ServiceRequest and/or Task." />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-ServiceRequest" />
        <targetProfile value="https://fhir.nhs.uk/StructureDefinition/NHSDigital-Task" />
      </type>
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>