<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="BundleABeOrderLab" />
  <url value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
  <version value="1.1.0" />
  <name value="BundleABeOrderLab" />
  <title value="Bundle (AB:eOrder-Lab)" />
  <status value="draft" />
  <description value="This profile defines a set of constraints to the FHIR Bundle resource for use in Alberta eOrder Laboratory (AB:eOrder-Lab). It re-profiles the CA-eReC Bundle profile and it includes constraints applied to the Bundle resource by the AB:eOrder-Lab project to include hard constraints (invariants) than enforce what sections and resource elements are allowed to be present in an Alberta eOrder Laboratory. These have been applied at the Bundle level as an alternative to forbidding elements through 0..0 cardinality - to balance the need for mechanical validation on eOrder Laboratory against the re-use of clinical FHIR profiles under different contexts." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Bundle" />
  <baseDefinition value="http://fhir.infoway-inforoute.ca/io/CA-eReC/StructureDefinition/CA-eReC-Bundle" />
  <derivation value="constraint" />
  <differential>
    <element id="Bundle">
      <path value="Bundle" />
      <constraint>
        <key value="abeorderlab-bdl-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following details SHALL NOT be present in all resources within the bundle instance except the bundle itself: contained" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab') implies &#xA;Bundle.entry.resource.where(contained.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-dcr-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following DocumentReference details SHALL NOT be present: authenticator, custodian, relatesTo. context.encounter" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies &#xA;Bundle.entry.where(resource is DocumentReference).resource.where(authenticator.exists()).exists().not() and &#xA;Bundle.entry.where(resource is DocumentReference).resource.where(custodian.exists()).exists().not() and &#xA;Bundle.entry.where(resource is DocumentReference).resource.where(relatesTo.exists()).exists().not() and &#xA;Bundle.entry.where(resource is DocumentReference).resource.where(context.encounter.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-hcs-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following HealthcareService details SHALL NOT be present: photo" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies Bundle.entry.where(resource is HealthcareService).resource.where(photo.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-loc-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following Location details SHALL NOT be present: telecom.use, and address.use, managingOrganization" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies &#xA;Bundle.entry.where(resource is Location).resource.where(telecom.use.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Location).resource.where(address.use.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Location).resource.where(managingOrganization.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-pat-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following Patient details SHALL NOT be present: text, active, address.text, maritalStatus, multipleBirth, photo,  contact.gender, contact.organization, contact.period, generalPractitioner, managingOrganization" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies &#xA;Bundle.entry.where(resource is Patient).resource.where(text.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(active.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(address.text.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(maritalStatus.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(multipleBirth.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(photo.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(contact.gender.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(contact.organization.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(contact.period.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(generalPractitioner.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Patient).resource.where(managingOrganization.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-prc-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following Practitioner details SHALL NOT be present: photo, qualification, birthDate" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies &#xA;Bundle.entry.where(resource is Practitioner).resource.where(photo.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Practitioner).resource.where(qualification.exists()).exists().not() and &#xA;Bundle.entry.where(resource is Practitioner).resource.where(birthDate.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-prl-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following PractitionerRole details SHALL NOT be present: healtcareService" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies &#xA;Bundle.entry.where(resource is PractitionerRole).resource.where(healthcareService.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-srq-1" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following ServiceRequest details SHALL NOT be present: replaces, reasonReference, relevantHistory" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies &#xA;Bundle.entry.where(resource is ServiceRequest).resource.where(replaces.exists()).exists().not() and&#xA;Bundle.entry.where(resource is ServiceRequest).resource.where(encounter.exists()).exists().not() and &#xA;Bundle.entry.where(resource is ServiceRequest).resource.where(reasonReference.exists()).exists().not() and &#xA;Bundle.entry.where(resource is ServiceRequest).resource.where(insurance.exists()).exists().not() and &#xA;Bundle.entry.where(resource is ServiceRequest).resource.where(relevantHistory.exists()).exists().not()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
      <constraint>
        <key value="abeorderlab-bdl-srq-2" />
        <severity value="error" />
        <human value="If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the ServiceRequest.identifier.value (aka placer order number) must be unique within the Bundle" />
        <expression value="Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies &#xA;Bundle.entry.resource.ofType(ServiceRequest).identifier.where(system = 'https://fhir.alberta.ca/NamingSystem/ca-ab-order-lab-placer-order-id').value.isDistinct()" />
        <source value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab" />
      </constraint>
    </element>
    <element id="Bundle.meta.extension">
      <path value="Bundle.meta.extension" />
      <min value="1" />
    </element>
    <element id="Bundle.meta.extension:submissionMetadata">
      <path value="Bundle.meta.extension" />
      <sliceName value="submissionMetadata" />
      <min value="1" />
      <max value="*" />
      <type>
        <code value="Extension" />
        <profile value="https://www.alberta.ca/fhir/psab/StructureDefinition/ext-EntityIdentifierAndName" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Bundle.meta.security">
      <path value="Bundle.meta.security" />
      <mustSupport value="true" />
      <binding>
        <strength value="extensible" />
        <valueSet value="https://www.alberta.ca/fhir/ValueSet/security-label" />
      </binding>
    </element>
    <element id="Bundle.identifier">
      <path value="Bundle.identifier" />
      <min value="1" />
    </element>
    <element id="Bundle.entry:Message">
      <path value="Bundle.entry" />
      <sliceName value="Message" />
    </element>
    <element id="Bundle.entry:Message.resource">
      <path value="Bundle.entry.resource" />
      <type>
        <code value="MessageHeader" />
        <profile value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/MessageHeaderABeOrderLab" />
      </type>
    </element>
    <element id="Bundle.entry:Focus">
      <path value="Bundle.entry" />
      <sliceName value="Focus" />
    </element>
    <element id="Bundle.entry:Focus.resource">
      <path value="Bundle.entry.resource" />
      <type>
        <code value="ServiceRequest" />
        <profile value="https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/ServiceRequestABeOrderLab" />
      </type>
    </element>
  </differential>
</StructureDefinition>