<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="pilot-digidot-Condition-no" />
  <url value="https://novari.no/fhir/digidot/StructureDefinition/pilot-digidot-Condition-no" />
  <version value="0.2.2" />
  <name value="PilotDigidotConditionNo" />
  <title value="Pilot DigiDOT Condition (NO)" />
  <status value="draft" />
  <date value="2025-09-17" />
  <publisher value="Novari AS - DigiDot" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Condition" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Condition" />
  <derivation value="constraint" />
  <differential>
    <element id="Condition">
      <path value="Condition" />
    </element>
    <element id="Condition.clinicalStatus">
      <path value="Condition.clinicalStatus" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Condition.code">
      <path value="Condition.code" />
      <min value="1" />
      <constraint>
        <key value="cond-sct-min1" />
        <severity value="warning" />
        <human value="At least one SNOMED CT code (pre- or postcoordinated) should be present." />
        <expression value="coding.where(system = 'http://snomed.info/sct').exists()" />
      </constraint>
    </element>
    <element id="Condition.code.coding">
      <path value="Condition.code.coding" />
      <slicing>
        <discriminator>
          <type value="profile" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="1" />
      <max value="2" />
    </element>
    <element id="Condition.code.coding:SCTpre">
      <path value="Condition.code.coding" />
      <sliceName value="SCTpre" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Coding" />
        <profile value="https://novari.no/fhir/digidot/StructureDefinition/pilot-digidot-Coding-SCTpre-no" />
      </type>
      <binding>
        <strength value="required" />
        <valueSet value="https://novari.no/fhir/digidot/ValueSet/pilot-digidot-ValueSet-conditions" />
      </binding>
    </element>
    <element id="Condition.code.coding:SCTpost">
      <path value="Condition.code.coding" />
      <sliceName value="SCTpost" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Coding" />
        <profile value="https://novari.no/fhir/digidot/StructureDefinition/pilot-digidot-Coding-SCTpost-no" />
      </type>
    </element>
    <element id="Condition.bodySite">
      <path value="Condition.bodySite" />
      <short value="Tooth, surface or other dental body site" />
      <definition value="Use bodySite to identify the relevant tooth or teeth and, when needed, tooth surface. Tooth and surface are represented as named slices on bodySite.coding, with required bindings to the DigiDOT teeth and tooth-surfaces ValueSets. If a surface coding is present, exactly one tooth coding must also be present in the same bodySite." />
      <min value="0" />
      <max value="*" />
      <constraint>
        <key value="single-tooth-required-if-surface" />
        <severity value="error" />
        <human value="If tooth surfaces are provided, exactly one tooth must also be provided in the same bodySite." />
        <expression value="coding.where(memberOf('https://novari.no/fhir/digidot/ValueSet/pilot-digidot-ValueSet-tooth-surfaces')).empty() or coding.where(memberOf('https://novari.no/fhir/digidot/ValueSet/pilot-digidot-ValueSet-teeth')).count() = 1" />
      </constraint>
    </element>
    <element id="Condition.bodySite.coding">
      <path value="Condition.bodySite.coding" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <short value="Tooth and surface codings" />
      <definition value="Open slicing of bodySite.coding. The named tooth and surface slices are identified by required ValueSet bindings, not by separate Coding profiles." />
      <min value="0" />
      <max value="*" />
    </element>
    <element id="Condition.bodySite.coding:tooth">
      <path value="Condition.bodySite.coding" />
      <sliceName value="tooth" />
      <short value="Tooth" />
      <definition value="One or more relevant teeth, coded with SNOMED CT and constrained by the DigiDOT teeth ValueSet." />
      <min value="0" />
      <max value="*" />
      <binding>
        <strength value="required" />
        <valueSet value="https://novari.no/fhir/digidot/ValueSet/pilot-digidot-ValueSet-teeth" />
      </binding>
    </element>
    <element id="Condition.bodySite.coding:tooth.system">
      <path value="Condition.bodySite.coding.system" />
      <min value="1" />
      <fixedUri value="http://snomed.info/sct" />
    </element>
    <element id="Condition.bodySite.coding:tooth.code">
      <path value="Condition.bodySite.coding.code" />
      <min value="1" />
    </element>
    <element id="Condition.bodySite.coding:surface">
      <path value="Condition.bodySite.coding" />
      <sliceName value="surface" />
      <short value="Tooth surface" />
      <definition value="One or more relevant tooth surfaces, coded with SNOMED CT and constrained by the DigiDOT tooth-surfaces ValueSet. A surface coding requires exactly one tooth coding on the same bodySite." />
      <min value="0" />
      <max value="*" />
      <binding>
        <strength value="required" />
        <valueSet value="https://novari.no/fhir/digidot/ValueSet/pilot-digidot-ValueSet-tooth-surfaces" />
      </binding>
    </element>
    <element id="Condition.bodySite.coding:surface.system">
      <path value="Condition.bodySite.coding.system" />
      <min value="1" />
      <fixedUri value="http://snomed.info/sct" />
    </element>
    <element id="Condition.bodySite.coding:surface.code">
      <path value="Condition.bodySite.coding.code" />
      <min value="1" />
    </element>
    <element id="Condition.subject">
      <path value="Condition.subject" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Patient" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Patient" />
      </type>
    </element>
    <element id="Condition.encounter">
      <path value="Condition.encounter" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://novari.no/fhir/digidot/StructureDefinition/pilot-digidot-Encounter-no" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Encounter" />
      </type>
    </element>
    <element id="Condition.asserter">
      <path value="Condition.asserter" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Practitioner" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Practitioner" />
      </type>
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-PractitionerRole" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/PractitionerRole" />
      </type>
    </element>
    <element id="Condition.note">
      <path value="Condition.note" />
      <min value="0" />
      <max value="1" />
    </element>
  </differential>
</StructureDefinition>