{
  "resourceType": "StructureDefinition",
  "id": "BundleABeReC",
  "url": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
  "version": "1.1.0",
  "name": "BundleABeReC",
  "title": "Bundle (AB:eReC)",
  "status": "draft",
  "description": "This profile defines a set of constraints to the FHIR Bundle resource for use in Alberta eReferral and eConsult (AB:eReC). It re-profiles the CA-eReC Bundle profile and it includes constraints applied to the Bundle resource by the AB:eReC project to include hard constraints (invariants) than enforce what sections and resource elements are allowed to be present in an Alberta eReferral and/or eConsult. 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 eReferral and/or eConsult 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": "aberec-bdl-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', 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/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.resource.where(contained.exists()).exists().not()"
          },
          {
            "key": "aberec-bdl-app-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following Appointment details SHALL NOT be present: reasonReference, supportingInformation, slot",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.where(resource is Appointment).resource.where(reasonReference.exists()).exists().not() and \nBundle.entry.where(resource is Appointment).resource.where(supportingInformation.exists()).exists().not() and \nBundle.entry.where(resource is Appointment).resource.where(slot.exists()).exists().not()"
          },
          {
            "key": "aberec-bdl-com-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following Communication details SHALL NOT be present: partOf, about, encounter, reasonReference.",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.where(resource is Communication).resource.where(partOf.exists()).exists().not() and\nBundle.entry.where(resource is Communication).resource.where(about.exists()).exists().not() and\nBundle.entry.where(resource is Communication).resource.where(encounter.exists()).exists().not() and \nBundle.entry.where(resource is Communication).resource.where(reasonReference.exists()).exists().not()"
          },
          {
            "key": "aberec-bdl-dcr-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following DocumentReference details SHALL NOT be present: authenticator, custodian, relatesTo. context.encounter",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').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": "aberec-bdl-hcs-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following HealthcareService details SHALL NOT be present: photo",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.where(resource is HealthcareService).resource.where(photo.exists()).exists().not()"
          },
          {
            "key": "aberec-bdl-loc-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following Location details SHALL NOT be present: telecom.use, and address.use, managingOrganization",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').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": "aberec-bdl-pat-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', 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/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').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": "aberec-bdl-pat-2",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following Patient details SHALL be present: telecom:Phone",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.resource.ofType(Patient).all(telecom.where(system = 'phone').exists())"
          },
          {
            "key": "aberec-bdl-prc-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following Practitioner details SHALL NOT be present: photo, qualification, birthDate",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').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": "aberec-bdl-prl-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following PractitionerRole details SHALL NOT be present: healtcareService",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.where(resource is PractitionerRole).resource.where(healthcareService.exists()).exists().not()"
          },
          {
            "key": "aberec-bdl-prl-2",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following PractitionerRole details SHALL be present: specialty.coding.code",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.where(resource is PractitionerRole).resource.where(specialty.coding.code.exists()).exists()"
          },
          {
            "key": "aberec-bdl-srq-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following ServiceRequest details SHALL NOT be present: replaces, encounter, reasonReference, insurance, specimen, relevantHistory",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \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(specimen.exists()).exists().not() and \nBundle.entry.where(resource is ServiceRequest).resource.where(relevantHistory.exists()).exists().not()"
          },
          {
            "key": "aberec-bdl-tsk-1",
            "human": "If Bundle.meta.extension.extension.valueString = 'AB:eReC', then the following Task details SHALL NOT be present: for, encounter, insurance, relevantHistory, restriction.recipient, input",
            "source": "https://www.alberta.ca/fhir/aberec/StructureDefinition/BundleABeReC",
            "severity": "error",
            "expression": "Bundle.meta.extension.extension.where(valueString = 'AB:eReC').exists() implies \nBundle.entry.where(resource is Task).resource.where(for.exists()).exists().not() and \nBundle.entry.where(resource is Task).resource.where(encounter.exists()).exists().not() and \nBundle.entry.where(resource is Task).resource.where(insurance.exists()).exists().not() and \nBundle.entry.where(resource is Task).resource.where(relevantHistory.exists()).exists().not() and \nBundle.entry.where(resource is Task).resource.where(restriction.recipient.exists()).exists().not() and \nBundle.entry.where(resource is Task).resource.where(input.exists()).exists().not()"
          }
        ]
      },
      {
        "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": "Resource",
            "profile": [
              "https://www.alberta.ca/fhir/aberec/StructureDefinition/MessageHeaderABeReC"
            ]
          }
        ]
      },
      {
        "id": "Bundle.entry:Focus",
        "path": "Bundle.entry",
        "sliceName": "Focus"
      },
      {
        "id": "Bundle.entry:Focus.resource",
        "path": "Bundle.entry.resource",
        "type": [
          {
            "code": "Resource",
            "profile": [
              "https://www.alberta.ca/fhir/aberec/StructureDefinition/AppointmentABeReC",
              "https://www.alberta.ca/fhir/aberec/StructureDefinition/CommunicationABeReC",
              "https://www.alberta.ca/fhir/aberec/StructureDefinition/ServiceRequestABeReC",
              "https://www.alberta.ca/fhir/aberec/StructureDefinition/TaskABeReC"
            ]
          }
        ]
      }
    ]
  }
}