<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="ddd7eac3-0f9e-4b96-9638-92f30392ff9c" />
  <meta>
    <lastUpdated value="2022-06-09T10:17:59.5125235+00:00" />
  </meta>
  <url value="http://nhn.no/kj/fhir/StructureDefinition/KjAllergyIntolerance" />
  <name value="KjAllergyIntolerance" />
  <status value="active" />
  <date value="2022-06-09T10:19:04.3111016+00:00" />
  <fhirVersion value="4.0.1" />
  <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" />
      <definition value="Risk of harmful or undesirable, physiological response which is unique to an individual and associated with exposure to a substance.s" />
      <condition value="kj-ait-7" />
      <constraint>
        <key value="kj-ait-7" />
        <severity value="error" />
        <human value="Category must be medication if code.coding is not OtherAllergen. If code.coding is OtherAllergen, category cannot be medication." />
        <expression value="(category='medication' and (code.coding.where(system='http://nhn.no/kj/fhir/CodeSystem/OtherAllergen').exists().not())) or (category!='medication' and (code.coding.where(system='http://nhn.no/kj/fhir/CodeSystem/OtherAllergen').exists()))" />
        <source value="http://nhn.no/kj/fhir/StructureDefinition/KjAllergyIntolerance" />
      </constraint>
    </element>
    <element id="AllergyIntolerance.extension">
      <path value="AllergyIntolerance.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="1" />
    </element>
    <element id="AllergyIntolerance.extension:updatedDateTime">
      <path value="AllergyIntolerance.extension" />
      <sliceName value="updatedDateTime" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://nhn.no/kj/fhir/StructureDefinition/KjUpdatedDateTime" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.extension:updatedDateTime.value[x]">
      <path value="AllergyIntolerance.extension.value[x]" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="AllergyIntolerance.extension:updater">
      <path value="AllergyIntolerance.extension" />
      <sliceName value="updater" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://nhn.no/kj/fhir/StructureDefinition/KjUpdater" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.extension:updater.value[x]">
      <path value="AllergyIntolerance.extension.value[x]" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="AllergyIntolerance.extension:sourceOfInformation">
      <path value="AllergyIntolerance.extension" />
      <sliceName value="sourceOfInformation" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://nhn.no/kj/fhir/StructureDefinition/KjSourceOfInformation" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.identifier">
      <path value="AllergyIntolerance.identifier" />
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.clinicalStatus">
      <path value="AllergyIntolerance.clinicalStatus" />
      <short value="active | inactive" />
      <definition value="Should use inactive if refuted or entered-in-error, otherwise use active. Resolved should not be used." />
      <comment value="Should use inactive if refuted or entered-in-error, otherwise use active. Resolved should not be used." />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://nhn.no/kj/fhir/ValueSet/AllergyIntoleranceClinicalStatus" />
      </binding>
    </element>
    <element id="AllergyIntolerance.verificationStatus">
      <path value="AllergyIntolerance.verificationStatus" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.verificationStatus.extension">
      <path value="AllergyIntolerance.verificationStatus.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="0" />
    </element>
    <element id="AllergyIntolerance.verificationStatus.extension:Presumed">
      <path value="AllergyIntolerance.verificationStatus.extension" />
      <sliceName value="Presumed" />
      <min value="0" />
      <type>
        <code value="Extension" />
        <profile value="http://nhn.no/kj/fhir/StructureDefinition/KjPresumed" />
      </type>
    </element>
    <element id="AllergyIntolerance.category">
      <path value="AllergyIntolerance.category" />
      <comment value="Should support all types, but in GUI: Medication is &quot;Legemiddel&quot; and all other are &quot;Annet&quot;" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.criticality">
      <path value="AllergyIntolerance.criticality" />
      <min value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://hl7.org/fhir/ValueSet/allergy-intolerance-criticality" />
      </binding>
    </element>
    <element id="AllergyIntolerance.code">
      <path value="AllergyIntolerance.code" />
      <short value="Different code systems allowed here" />
      <min value="1" />
      <condition value="kj-ait-4" />
      <condition value="kj-ait-6" />
      <constraint>
        <key value="kj-ait-4" />
        <severity value="error" />
        <human value="If code.coding:OtherAllergen.code has value 15 (Annen viktig allergi), then code.text must be present" />
        <expression value="(coding.where(system='http://nhn.no/kj/fhir/CodeSystem/OtherAllergen' and code = '15').exists() and text.exists()) or (coding.where(system='http://nhn.no/kj/fhir/CodeSystem/OtherAllergen' and code = '15').exists().not() and text.empty())" />
        <source value="http://nhn.no/kj/fhir/StructureDefinition/KjAllergyIntolerance" />
      </constraint>
      <constraint>
        <key value="kj-ait-6" />
        <severity value="error" />
        <human value="InactiveIngredient can only be set when coding is DrugTradeName" />
        <expression value="coding.where(system='http://nhn.no/kj/fhir/CodeSystem/DrugTradeName').exists() or extension.where(url='http://nhn.no/kj/fhir/StructureDefinition/KjInactiveIngredient').exists().not()" />
        <source value="http://nhn.no/kj/fhir/StructureDefinition/KjAllergyIntolerance" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.code.extension">
      <path value="AllergyIntolerance.code.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="0" />
    </element>
    <element id="AllergyIntolerance.code.extension:inactiveIngredient">
      <path value="AllergyIntolerance.code.extension" />
      <sliceName value="inactiveIngredient" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://nhn.no/kj/fhir/StructureDefinition/KjInactiveIngredient" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.code.coding">
      <path value="AllergyIntolerance.code.coding" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="closed" />
      </slicing>
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.code.coding:ATC">
      <path value="AllergyIntolerance.code.coding" />
      <sliceName value="ATC" />
      <short value="This is the codesystem for ATC - urn:oid:2.16.578.1.12.4.1.1.7180" />
      <max value="1" />
    </element>
    <element id="AllergyIntolerance.code.coding:ATC.system">
      <path value="AllergyIntolerance.code.coding.system" />
      <fixedUri value="http://nhn.no/kj/fhir/CodeSystem/ATC" />
    </element>
    <element id="AllergyIntolerance.code.coding:ActiveSubstance">
      <path value="AllergyIntolerance.code.coding" />
      <sliceName value="ActiveSubstance" />
      <short value="This is the codesystem for 'Virkestoff' from FEST" />
      <max value="1" />
    </element>
    <element id="AllergyIntolerance.code.coding:ActiveSubstance.system">
      <path value="AllergyIntolerance.code.coding.system" />
      <fixedUri value="http://nhn.no/kj/fhir/CodeSystem/ActiveSubstance" />
    </element>
    <element id="AllergyIntolerance.code.coding:OtherAllergen">
      <path value="AllergyIntolerance.code.coding" />
      <sliceName value="OtherAllergen" />
      <short value="This is the codesystem for defining allergens - urn:oid:2.16.578.1.12.4.1.1.7514" />
      <max value="1" />
    </element>
    <element id="AllergyIntolerance.code.coding:OtherAllergen.system">
      <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status">
        <valueCode value="normative" />
      </extension>
      <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-normative-version">
        <valueCode value="4.0.0" />
      </extension>
      <path value="AllergyIntolerance.code.coding.system" />
      <fixedUri value="http://nhn.no/kj/fhir/CodeSystem/OtherAllergen" />
    </element>
    <element id="AllergyIntolerance.code.coding:DrugTradeName">
      <path value="AllergyIntolerance.code.coding" />
      <sliceName value="DrugTradeName" />
      <short value="This is the codesystem for 'Merkevare' from FEST" />
      <max value="1" />
    </element>
    <element id="AllergyIntolerance.code.coding:DrugTradeName.system">
      <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status">
        <valueCode value="normative" />
      </extension>
      <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-normative-version">
        <valueCode value="4.0.0" />
      </extension>
      <path value="AllergyIntolerance.code.coding.system" />
      <fixedUri value="http://nhn.no/kj/fhir/CodeSystem/DrugTradeName" />
    </element>
    <element id="AllergyIntolerance.code.text">
      <path value="AllergyIntolerance.code.text" />
      <short value="Other allergy if no proper code is found" />
      <definition value="Use this element if no proper code is found." />
      <condition value="kj-ait-5" />
      <constraint>
        <key value="kj-ait-5" />
        <severity value="error" />
        <human value="Text can be maximum 80 characters" />
        <expression value="value.length() &lt;= 80" />
        <source value="http://nhn.no/kj/fhir/StructureDefinition/KjAllergyIntolerance" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.patient">
      <path value="AllergyIntolerance.patient" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Patient" />
        <aggregation value="referenced" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.onset[x]">
      <path value="AllergyIntolerance.onset[x]" />
      <type>
        <code value="dateTime" />
      </type>
      <type>
        <code value="Age" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.recordedDate">
      <path value="AllergyIntolerance.recordedDate" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.recorder">
      <path value="AllergyIntolerance.recorder" />
      <definition value="Who recorded the insensitivity. Should use PractitionerRole for registrate both Practitioner and the Organization the recorder worked at when the registration was performed." />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://nhn.no/kj/fhir/StructureDefinition/KjPractitionerRole" />
        <aggregation value="contained" />
        <aggregation value="bundled" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.note">
      <path value="AllergyIntolerance.note" />
      <max value="1" />
      <condition value="kj-ait-3" />
      <constraint>
        <key value="kj-ait-3" />
        <severity value="error" />
        <human value="If note is present, then text must be between 0 and 500 characters." />
        <expression value="empty() or (first().text.value.length() &gt;=0 and first().text.value.length() &lt;= 500)" />
        <source value="http://nhn.no/kj/fhir/StructureDefinition/KjAllergyIntolerance" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.reaction">
      <path value="AllergyIntolerance.reaction" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="AllergyIntolerance.reaction.manifestation">
      <path value="AllergyIntolerance.reaction.manifestation" />
      <max value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="preferred" />
        <valueSet value="http://nhn.no/kj/fhir/ValueSet/TypeOfReaction" />
      </binding>
    </element>
    <element id="AllergyIntolerance.reaction.manifestation.coding">
      <path value="AllergyIntolerance.reaction.manifestation.coding" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="AllergyIntolerance.reaction.manifestation.coding:TypeOfReaction">
      <path value="AllergyIntolerance.reaction.manifestation.coding" />
      <sliceName value="TypeOfReaction" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://nhn.no/kj/fhir/ValueSet/TypeOfReaction" />
      </binding>
    </element>
    <element id="AllergyIntolerance.reaction.manifestation.coding:TypeOfReaction.system">
      <path value="AllergyIntolerance.reaction.manifestation.coding.system" />
      <fixedUri value="http://nhn.no/kj/fhir/CodeSystem/TypeOfReaction" />
    </element>
  </differential>
</StructureDefinition>