<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="profile-allergyintolerance" />
  <url value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-allergyintolerance" />
  <version value="1.0.1" />
  <name value="AllergyIntoleranceProfile" />
  <title value="AllergyIntolerance Profile" />
  <status value="draft" />
  <date value="2026-01-09" />
  <publisher value="HL7 Canada - FHIR Implementation Work Group" />
  <contact>
    <telecom>
      <system value="url" />
      <value value="https://infocentral.infoway-inforoute.ca/en/collaboration/wg/fhir-implementations" />
    </telecom>
  </contact>
  <description value="Proposed constraints and extensions on the AllergyIntolerance Resource" />
  <jurisdiction>
    <coding>
      <system value="urn:iso:std:iso:3166" />
      <code value="CA" />
    </coding>
  </jurisdiction>
  <fhirVersion value="4.0.1" />
  <mapping>
    <identity value="rim" />
    <uri value="http://hl7.org/v3" />
    <name value="RIM Mapping" />
  </mapping>
  <mapping>
    <identity value="w5" />
    <uri value="http://hl7.org/fhir/fivews" />
    <name value="FiveWs Pattern Mapping" />
  </mapping>
  <mapping>
    <identity value="v2" />
    <uri value="http://hl7.org/v2" />
    <name value="HL7 v2 Mapping" />
  </mapping>
  <kind value="resource" />
  <abstract value="false" />
  <type value="AllergyIntolerance" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/AllergyIntolerance" />
  <derivation value="constraint" />
  <differential>
    <element id="AllergyIntolerance">
      <path value="AllergyIntolerance" />
      <short value="AllergyIntolerance Profile" />
      <definition value="The AllergyIntolerance Profile is based upon the core FHIR AllergyIntolerance Resource" />
      <constraint>
        <key value="ca-baseline-allergy" />
        <severity value="error" />
        <human value="AllergyIntolerance.verificationStatus SHALL be present if AllergyIntolerance.code represents NullFlavor concept" />
        <expression value="code.coding.where(system = 'http://terminology.hl7.org/CodeSystem/v3-NullFlavor').exists() implies verificationStatus.exists()" />
        <xpath value="f:code/f:coding/f:system/@value='https://fhir.infoway-inforoute.ca/ValueSet/nullflavor' implies exists(f:verificationStatus)" />
      </constraint>
      <constraint>
        <key value="ca-baseline-allergy-notasked" />
        <severity value="error" />
        <human value="if AllergyIntolerance.code is a NullFlavor value, then AllergyIntolerance.clinicalStatus, AllergyIntolerance.type, AllergyIntolerance.category, AllergyIntolerance.criticality SHALL NOT be present" />
        <expression value="code.coding.where(system = 'http://terminology.hl7.org/CodeSystem/v3-NullFlavor').exists() implies type.exists().not() and category.exists().not() and criticality.exists().not()" />
        <xpath value="f:code/f:coding/f:system/@value='http://terminology.hl7.org/CodeSystem/v3-NullFlavor' and exists(f:type).not() and exists(f:category).not() and exists(f:criticality).not()" />
      </constraint>
      <constraint>
        <key value="ca-baseline-allergy-noallergy" />
        <severity value="error" />
        <human value="if AllergyIntolerance.code is '716186003' No known allergy, then AllergyIntolerance.verificationStatus SHALL be one of the following: confirmed | refuted | entered-in-error" />
        <expression value="code.coding.where(system = 'http://snomed.info/sct' and code = '716186003').exists() and verificationStatus.coding.where(code = 'unconfirmed').empty()" />
        <xpath value="f:code/f:coding/f:system/@value='http://snomed.info/sct' and exists(f:verificationStatus/f:coding/f:code/@value='unconfirmed').not()" />
      </constraint>
    </element>
    <element id="AllergyIntolerance.extension">
      <path value="AllergyIntolerance.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
    </element>
    <element id="AllergyIntolerance.extension:abatement">
      <path value="AllergyIntolerance.extension" />
      <sliceName value="abatement" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://hl7.org/fhir/StructureDefinition/allergyintolerance-abatement" />
      </type>
    </element>
    <element id="AllergyIntolerance.identifier">
      <path value="AllergyIntolerance.identifier" />
    </element>
    <element id="AllergyIntolerance.clinicalStatus">
      <path value="AllergyIntolerance.clinicalStatus" />
      <isModifier value="true" />
      <isModifierReason value="This element is labeled as a modifier because the status contains the codes refuted and entered-in-error that mark the AllergyIntolerance as not currently valid." />
    </element>
    <element id="AllergyIntolerance.verificationStatus">
      <path value="AllergyIntolerance.verificationStatus" />
      <isModifier value="true" />
      <isModifierReason value="This element is labeled as a modifier because the status contains the codes refuted and entered-in-error that mark the AllergyIntolerance as not currently valid." />
    </element>
    <element id="AllergyIntolerance.category">
      <path value="AllergyIntolerance.category" />
      <comment value="Some implementers may utilize value sets where category is readily distinguishable while others may not, and those that do not use those value sets should consider making category MS in their profiles" />
    </element>
    <element id="AllergyIntolerance.code">
      <path value="AllergyIntolerance.code" />
      <binding>
        <strength value="preferred" />
        <valueSet value="https://fhir.infoway-inforoute.ca/ValueSet/pharmaceuticalbiologicproductandsubstancecode" />
      </binding>
    </element>
    <element id="AllergyIntolerance.patient">
      <path value="AllergyIntolerance.patient" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-patient" />
      </type>
    </element>
    <element id="AllergyIntolerance.encounter">
      <path value="AllergyIntolerance.encounter" />
      <short value="Encounter when the allergy or intolerance was asserted" />
      <definition value="The encounter when the allergy or intolerance was asserted." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-encounter" />
      </type>
    </element>
    <element id="AllergyIntolerance.onsetDateTime:onsetDateTime">
      <path value="AllergyIntolerance.onsetDateTime" />
      <sliceName value="onsetDateTime" />
      <comment value="This slice was initially flagged as Must Support, and is considered MS in a handful of Canadian FHIR Implementation Guides. However, while clinically desireable it is not broadly considered MS across all IGuides reviewed during the Due Dilligence Review." />
      <min value="0" />
      <type>
        <code value="dateTime" />
      </type>
    </element>
    <element id="AllergyIntolerance.recorder">
      <path value="AllergyIntolerance.recorder" />
      <short value="Who recorded the sensitivity" />
      <definition value="Individual who recorded the record and takes responsibility for its content." />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-practitioner" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-practitionerrole" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-patient" />
      </type>
    </element>
    <element id="AllergyIntolerance.asserter">
      <path value="AllergyIntolerance.asserter" />
      <short value="Source of the information about the allergy" />
      <definition value="The source of the information about the allergy that is recorded." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-patient" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-practitioner" />
        <targetProfile value="http://hl7.org/fhir/ca/baseline/StructureDefinition/profile-practitionerrole" />
      </type>
    </element>
    <element id="AllergyIntolerance.reaction.substance">
      <path value="AllergyIntolerance.reaction.substance" />
      <short value="Specific substance or pharmaceutical product considered to be responsible for event" />
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding">
      <path value="AllergyIntolerance.reaction.substance.coding" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="closed" />
      </slicing>
      <comment value="This slice was initially identified with a 1..* cardinality, and has similar constraints in a handful of Canadian FHIR Implementation Guides. However, while clinically desireable to include coding, it was not constrained consistently across all IGuides reviewed during the Due Dilligence Review." />
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding:NonDrugAllergen">
      <path value="AllergyIntolerance.reaction.substance.coding" />
      <sliceName value="NonDrugAllergen" />
      <short value="Code for the specific non-drug allergen" />
      <definition value="Code for the specific non-drug allergen or other agent/substance to which the Client has an allergic reaction." />
      <comment value="The binding strength of this element is [Preferred](https://www.hl7.org/fhir/terminologies.html#strength), meaning that codes are encouraged to draw from the NonDrugAllergenCode value set for interoperability purposes but are not required to do so to be considered conformant." />
      <type>
        <code value="Coding" />
      </type>
      <binding>
        <strength value="preferred" />
        <description value="Represents the specific non-drug allergen or other agent/substance to which the Client has an allergic reaction." />
        <valueSet value="https://fhir.infoway-inforoute.ca/ValueSet/nondrugallergencode" />
      </binding>
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding:NonDrugAllergen.system">
      <path value="AllergyIntolerance.reaction.substance.coding.system" />
      <min value="1" />
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding:NonDrugAllergen.code">
      <path value="AllergyIntolerance.reaction.substance.coding.code" />
      <min value="1" />
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding:CCDD">
      <path value="AllergyIntolerance.reaction.substance.coding" />
      <sliceName value="CCDD" />
      <short value="Medicinal products for prescribing" />
      <definition value="The subset of codes with commonly used medicinal products that are available for prescribing and dispensing in Canada." />
      <comment value="The binding strength of this element is [Preferred](https://www.hl7.org/fhir/terminologies.html#strength), meaning that codes are encouraged to draw from the PrescriptionMedicinalProduct value set for interoperability purposes but are not required to do so to be considered conformant." />
      <type>
        <code value="Coding" />
      </type>
      <binding>
        <strength value="preferred" />
        <description value="Represents subset of codes with commonly used medicinal products that are available for prescribing and dispensing in Canada." />
        <valueSet value="https://fhir.infoway-inforoute.ca/ValueSet/prescriptionmedicinalproduct" />
      </binding>
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding:CCDD.system">
      <path value="AllergyIntolerance.reaction.substance.coding.system" />
      <min value="1" />
      <patternUri value="https://fhir.infoway-inforoute.ca/CodeSystem/canadianclinicaldrugdataset" />
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding:CCDD.code">
      <path value="AllergyIntolerance.reaction.substance.coding.code" />
      <min value="1" />
    </element>
    <element id="AllergyIntolerance.reaction.substance.coding:@default">
      <path value="AllergyIntolerance.reaction.substance.coding" />
      <sliceName value="@default" />
      <short value="Specific substance or pharmaceutical product considered to be responsible for event" />
      <definition value="Identification of the specific substance (or pharmaceutical product) considered to be responsible for the Adverse Reaction event." />
      <comment value="The binding strength of this element is [Example](https://hl7.org/fhir/R4/terminologies.html#example), meaning that codes are not expected or even encouraged to draw from the specified value set to be conformant" />
      <type>
        <code value="Coding" />
      </type>
      <binding>
        <extension url="http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName">
          <valueString value="SubstanceCode" />
        </extension>
        <strength value="example" />
        <description value="Codes defining the type of the substance (including pharmaceutical products)." />
        <valueSet value="http://hl7.org/fhir/ValueSet/substance-code" />
      </binding>
    </element>
    <element id="AllergyIntolerance.reaction.exposureRoute">
      <path value="AllergyIntolerance.reaction.exposureRoute" />
      <short value="How the subject was exposed to the substance" />
      <definition value="Identification of the route by which the subject was exposed to the substance." />
      <comment value="The binding strength of this element is [Preferred](https://www.hl7.org/fhir/terminologies.html#strength), meaning that codes are encouraged to draw from the RouteOfAdministration value set for interoperability purposes but are not required to do so to be considered conformant." />
      <type>
        <code value="CodeableConcept" />
      </type>
      <binding>
        <strength value="preferred" />
        <description value="A coded concept describing the route or physiological path of administration of a therapeutic agent into or onto the body of a subject." />
        <valueSet value="https://fhir.infoway-inforoute.ca/ValueSet/routeofadministration" />
      </binding>
    </element>
  </differential>
</StructureDefinition>