<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="digidot-Observation-no" />
  <url value="http://novari.no/fhir/digidot/StructureDefinition/digidot-Observation-no" />
  <version value="0.1.3" />
  <name value="digidot_Observation_no" />
  <title value="DigiDot Observation (NO)" />
  <status value="draft" />
  <date value="2025-10-31" />
  <publisher value="Novari AS – DigiDot" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Observation" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Observation" />
  <derivation value="constraint" />
  <differential>
    <element id="Observation">
      <path value="Observation" />
    </element>
    <element id="Observation.status">
      <path value="Observation.status" />
      <min value="1" />
      <max value="1" />
      <fixedCode value="final" />
    </element>
    <element id="Observation.category">
      <path value="Observation.category" />
      <min value="0" />
      <max value="*" />
      <binding>
        <strength value="preferred" />
        <valueSet value="http://terminology.hl7.org/ValueSet/observation-category" />
      </binding>
    </element>
    <element id="Observation.code">
      <path value="Observation.code" />
      <short value="Observable entity" />
      <definition value="The SNOMED CT concept describing what is being observed (observable entity)." />
      <min value="1" />
      <constraint>
        <key value="obs-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>
      <binding>
        <strength value="required" />
        <description value="SNOMED CT Observable entity" />
        <valueSet value="http://snomed.info/sct?fhir_vs=isa/363787002" />
      </binding>
    </element>
    <element id="Observation.code.coding">
      <path value="Observation.code.coding" />
      <slicing>
        <discriminator>
          <type value="profile" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="1" />
      <max value="2" />
    </element>
    <element id="Observation.code.coding:SCTpre">
      <path value="Observation.code.coding" />
      <sliceName value="SCTpre" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Coding" />
        <profile value="http://novari.no/fhir/digidot/StructureDefinition/Coding-SCTpre-no" />
      </type>
    </element>
    <element id="Observation.code.coding:SCTpost">
      <path value="Observation.code.coding" />
      <sliceName value="SCTpost" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Coding" />
        <profile value="http://novari.no/fhir/digidot/StructureDefinition/Coding-SCTpost-no" />
      </type>
    </element>
    <element id="Observation.subject">
      <path value="Observation.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="Observation.encounter">
      <path value="Observation.encounter" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://novari.no/fhir/digidot/StructureDefinition/digidot-Encounter-no" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Encounter" />
      </type>
    </element>
    <element id="Observation.effective[x]">
      <path value="Observation.effective[x]" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="dateTime" />
      </type>
    </element>
    <element id="Observation.value[x]">
      <path value="Observation.value[x]" />
      <short value="Result value" />
      <definition value="The result of the observation." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Quantity" />
      </type>
      <type>
        <code value="CodeableConcept" />
      </type>
      <type>
        <code value="string" />
      </type>
      <type>
        <code value="integer" />
      </type>
      <type>
        <code value="boolean" />
      </type>
    </element>
    <element id="Observation.interpretation">
      <path value="Observation.interpretation" />
      <min value="0" />
      <max value="*" />
    </element>
    <element id="Observation.bodySite">
      <path value="Observation.bodySite" />
      <min value="0" />
      <max value="*" />
      <constraint>
        <key value="tooth-required-if-surface" />
        <severity value="error" />
        <human value="If tooth surfaces are provided, a tooth must also be provided." />
        <expression value="coding.where($this.sliceName='surface').empty() or coding.where($this.sliceName='tooth').exists()" />
      </constraint>
    </element>
    <element id="Observation.bodySite.coding">
      <path value="Observation.bodySite.coding" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="0" />
      <max value="*" />
    </element>
    <element id="Observation.bodySite.coding.system">
      <path value="Observation.bodySite.coding.system" />
      <min value="1" />
      <fixedUri value="http://snomed.info/sct" />
    </element>
    <element id="Observation.bodySite.coding:tooth">
      <path value="Observation.bodySite.coding" />
      <sliceName value="tooth" />
      <min value="0" />
      <max value="1" />
      <binding>
        <strength value="required" />
        <valueSet value="http://novari.no/fhir/digidot/ValueSet/teeth" />
      </binding>
    </element>
    <element id="Observation.bodySite.coding:surface">
      <path value="Observation.bodySite.coding" />
      <sliceName value="surface" />
      <min value="0" />
      <max value="*" />
      <binding>
        <strength value="required" />
        <valueSet value="http://novari.no/fhir/digidot/ValueSet/tooth-surfaces" />
      </binding>
    </element>
    <element id="Observation.bodySite.coding.code">
      <path value="Observation.bodySite.coding.code" />
      <min value="1" />
    </element>
    <element id="Observation.bodySite.coding.display">
      <path value="Observation.bodySite.coding.display" />
      <min value="0" />
      <max value="1" />
    </element>
    <element id="Observation.note">
      <path value="Observation.note" />
      <min value="0" />
      <max value="*" />
    </element>
    <element id="Observation.performer">
      <path value="Observation.performer" />
      <min value="0" />
      <max value="*" />
      <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>
  </differential>
</StructureDefinition>