{
  "resourceType": "StructureDefinition",
  "id": "BundleABeOrderLab",
  "url": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
  "version": "1.1.0",
  "name": "BundleABeOrderLab",
  "title": "Bundle (AB:eOrder-Lab)",
  "status": "draft",
  "description": "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": "4.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "Bundle",
  "baseDefinition": "http://fhir.infoway-inforoute.ca/io/CA-eReC/StructureDefinition/CA-eReC-Bundle",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Bundle",
        "path": "Bundle",
        "constraint": [
          {
            "key": "abeorderlab-bdl-1",
            "human": "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",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab') implies \nBundle.entry.resource.where(contained.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-dcr-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following DocumentReference details SHALL NOT be present: authenticator, custodian, relatesTo. context.encounter",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies \nBundle.entry.where(resource is DocumentReference).resource.where(authenticator.exists()).exists().not() and \nBundle.entry.where(resource is DocumentReference).resource.where(custodian.exists()).exists().not() and \nBundle.entry.where(resource is DocumentReference).resource.where(relatesTo.exists()).exists().not() and \nBundle.entry.where(resource is DocumentReference).resource.where(context.encounter.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-hcs-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following HealthcareService details SHALL NOT be present: photo",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies Bundle.entry.where(resource is HealthcareService).resource.where(photo.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-loc-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following Location details SHALL NOT be present: telecom.use, and address.use, managingOrganization",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies \nBundle.entry.where(resource is Location).resource.where(telecom.use.exists()).exists().not() and \nBundle.entry.where(resource is Location).resource.where(address.use.exists()).exists().not() and \nBundle.entry.where(resource is Location).resource.where(managingOrganization.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-pat-1",
            "human": "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",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies \nBundle.entry.where(resource is Patient).resource.where(text.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(active.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(address.text.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(maritalStatus.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(multipleBirth.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(photo.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(contact.gender.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(contact.organization.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(contact.period.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(generalPractitioner.exists()).exists().not() and \nBundle.entry.where(resource is Patient).resource.where(managingOrganization.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-prc-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following Practitioner details SHALL NOT be present: photo, qualification, birthDate",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies \nBundle.entry.where(resource is Practitioner).resource.where(photo.exists()).exists().not() and \nBundle.entry.where(resource is Practitioner).resource.where(qualification.exists()).exists().not() and \nBundle.entry.where(resource is Practitioner).resource.where(birthDate.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-prl-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following PractitionerRole details SHALL NOT be present: healtcareService",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies \nBundle.entry.where(resource is PractitionerRole).resource.where(healthcareService.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-srq-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the following ServiceRequest details SHALL NOT be present: replaces, reasonReference, relevantHistory",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies \nBundle.entry.where(resource is ServiceRequest).resource.where(replaces.exists()).exists().not() and\nBundle.entry.where(resource is ServiceRequest).resource.where(encounter.exists()).exists().not() and \nBundle.entry.where(resource is ServiceRequest).resource.where(reasonReference.exists()).exists().not() and \nBundle.entry.where(resource is ServiceRequest).resource.where(insurance.exists()).exists().not() and \nBundle.entry.where(resource is ServiceRequest).resource.where(relevantHistory.exists()).exists().not()"
          },
          {
            "key": "abeorderlab-bdl-srq-2",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eOrder-Lab', then the ServiceRequest.identifier.value (aka placer order number) must be unique within the Bundle",
            "source": "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/BundleABeOrderLab",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eOrder-Lab').exists() implies \nBundle.entry.resource.ofType(ServiceRequest).identifier.where(system = 'https://fhir.alberta.ca/NamingSystem/ca-ab-order-lab-placer-order-id').value.isDistinct()"
          }
        ]
      },
      {
        "id": "Bundle.meta.extension",
        "path": "Bundle.meta.extension",
        "min": 1
      },
      {
        "id": "Bundle.meta.extension:submissionMetadata",
        "path": "Bundle.meta.extension",
        "sliceName": "submissionMetadata",
        "min": 1,
        "max": "*",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "https://www.alberta.ca/fhir/psab/StructureDefinition/ext-EntityIdentifierAndName"
            ]
          }
        ],
        "mustSupport": true
      },
      {
        "id": "Bundle.meta.security",
        "path": "Bundle.meta.security",
        "mustSupport": true,
        "binding": {
          "strength": "extensible",
          "valueSet": "https://www.alberta.ca/fhir/ValueSet/security-label"
        }
      },
      {
        "id": "Bundle.identifier",
        "path": "Bundle.identifier",
        "min": 1
      },
      {
        "id": "Bundle.entry:Message",
        "path": "Bundle.entry",
        "sliceName": "Message"
      },
      {
        "id": "Bundle.entry:Message.resource",
        "path": "Bundle.entry.resource",
        "type": [
          {
            "code": "MessageHeader",
            "profile": [
              "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/MessageHeaderABeOrderLab"
            ]
          }
        ]
      },
      {
        "id": "Bundle.entry:Focus",
        "path": "Bundle.entry",
        "sliceName": "Focus"
      },
      {
        "id": "Bundle.entry:Focus.resource",
        "path": "Bundle.entry.resource",
        "type": [
          {
            "code": "ServiceRequest",
            "profile": [
              "https://www.alberta.ca/fhir/ab-eorder-lab/StructureDefinition/ServiceRequestABeOrderLab"
            ]
          }
        ]
      }
    ]
  }
}