{
  "resourceType": "StructureDefinition",
  "id": "profile-Bundle",
  "url": "http://ontariohealth.ca/fhir/StructureDefinition/ca-on-mha-profile-bundle",
  "version": "2.0.0",
  "name": "Bundle",
  "title": "MHA Bundle Profile",
  "status": "active",
  "date": "2025-05-17T20:17:06.3613088+00:00",
  "fhirVersion": "4.0.1",
  "mapping": [
    {
      "identity": "MHA-PDS-Mapping",
      "name": "MHA PDS Mapping"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "Bundle",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Bundle",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Bundle",
        "path": "Bundle",
        "constraint": [
          {
            "key": "mha-pds-bundle-inv-1",
            "severity": "error",
            "human": "Must contain exactly one patient resource in the bundle",
            "expression": "entry.resource.ofType(Patient).count() = 1"
          },
          {
            "key": "mha-pds-bundle-inv-2",
            "severity": "error",
            "human": "Must contain exactly one organization resource in the bundle",
            "expression": "entry.resource.ofType(Organization).count() = 1"
          },
          {
            "key": "mha-pds-bundle-inv-3",
            "severity": "error",
            "human": "Must contain exactly one location resource in the bundle",
            "expression": "entry.resource.ofType(Location).count() = 1"
          },
          {
            "key": "mha-bundle-rule-1",
            "severity": "error",
            "human": "Service First Contact Date in EpisodeOfCare must be on or after Referral Received Date in ServiceRequest",
            "expression": "(entry.resource.where($this is EpisodeOfCare).extension('https://ontariohealth.ca/fhir/StructureDefinition/ca-on-mha-ext-FirstContactDate').exists() and entry.resource.where($this is EpisodeOfCare).referralRequest.resolve().extension('http://ontariohealth.ca/fhir/StructureDefinition/ca-on-mha-ext-ServiceRequestReceivedDate').exists()) implies entry.resource.where($this is EpisodeOfCare).extension('https://ontariohealth.ca/fhir/StructureDefinition/ca-on-mha-ext-FirstContactDate').value.toString().substring(0,10) >= entry.resource.where($this is EpisodeOfCare).referralRequest.resolve().extension('http://ontariohealth.ca/fhir/StructureDefinition/ca-on-mha-ext-ServiceRequestReceivedDate').value.toString().substring(0,10)"
          },
          {
            "key": "mha-bundle-rule-2",
            "severity": "warning",
            "human": "If EpisodeOfCare status is 'planned', referral received date SHALL be present",
            "expression": "entry.resource.where($this is EpisodeOfCare).status='planned' implies entry.resource.where($this is EpisodeOfCare).referralRequest.resolve().extension('http://ontariohealth.ca/fhir/StructureDefinition/ca-on-mha-ext-ServiceRequestReceivedDate').exists()"
          },
          {
            "key": "mha-bundle-inv-4",
            "severity": "error",
            "human": "Bundle must contain EpisodeOfCare and HealthcareService resource",
            "expression": "entry.resource.where($this is EpisodeOfCare).exists() and entry.resource.where($this is HealthcareService).exists()"
          }
        ]
      },
      {
        "id": "Bundle.meta",
        "path": "Bundle.meta",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "Bundle.meta.lastUpdated",
        "path": "Bundle.meta.lastUpdated",
        "mustSupport": true
      },
      {
        "id": "Bundle.meta.profile",
        "path": "Bundle.meta.profile",
        "min": 1,
        "max": "1",
        "fixedCanonical": "http://ontariohealth.ca/fhir/StructureDefinition/ca-on-mha-profile-bundle",
        "mustSupport": true
      },
      {
        "id": "Bundle.identifier",
        "path": "Bundle.identifier",
        "mustSupport": true
      },
      {
        "id": "Bundle.type",
        "path": "Bundle.type",
        "fixedCode": "collection",
        "mustSupport": true
      },
      {
        "id": "Bundle.timestamp",
        "path": "Bundle.timestamp",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "Bundle.entry",
        "path": "Bundle.entry",
        "mustSupport": true
      },
      {
        "id": "Bundle.entry.fullUrl",
        "path": "Bundle.entry.fullUrl",
        "mustSupport": true
      },
      {
        "id": "Bundle.entry.resource",
        "path": "Bundle.entry.resource",
        "mustSupport": true
      }
    ]
  }
}