<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="digidot-Procedure-no" />
  <url value="http://novari.no/fhir/digidot/StructureDefinition/digidot-Procedure-no" />
  <version value="0.1.5" />
  <name value="digidot_Procedure_no" />
  <title value="DigiDot Procedure (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="Procedure" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Procedure" />
  <derivation value="constraint" />
  <differential>
    <element id="Procedure.code">
      <path value="Procedure.code" />
      <min value="1" />
      <constraint>
        <key value="proc-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="Procedure.code.coding">
      <path value="Procedure.code.coding" />
      <slicing>
        <discriminator>
          <type value="profile" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="1" />
      <max value="2" />
    </element>
    <element id="Procedure.code.coding:SCTpre">
      <path value="Procedure.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>
      <binding>
        <strength value="extensible" />
        <description value="For EHR implementations using this profile for storage of clinical data the code-element can contain relevant concepts from SNOMED CT beyond those of the reference set. For national reporting or information exchange to other systems codes are restricted to those included by the reference set." />
        <valueSet value="http://novari.no/fhir/digidot/ValueSet/dental-procedures" />
      </binding>
    </element>
    <element id="Procedure.code.coding:SCTpost">
      <path value="Procedure.code.coding" />
      <sliceName value="SCTpost" />
      <max value="1" />
      <type>
        <code value="Coding" />
        <profile value="http://novari.no/fhir/digidot/StructureDefinition/Coding-SCTpost-no" />
      </type>
    </element>
    <element id="Procedure.subject">
      <path value="Procedure.subject" />
      <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="Procedure.encounter">
      <path value="Procedure.encounter" />
      <min 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="Procedure.performer.actor">
      <path value="Procedure.performer.actor" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Practitioner" />
      </type>
    </element>
    <element id="Procedure.location">
      <path value="Procedure.location" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Location" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Location" />
      </type>
    </element>
    <element id="Procedure.reasonReference">
      <path value="Procedure.reasonReference" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://novari.no/fhir/digidot/StructureDefinition/digidot-Condition-no" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Condition" />
      </type>
    </element>
    <element id="Procedure.bodySite">
      <path value="Procedure.bodySite" />
      <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="Procedure.bodySite.coding">
      <path value="Procedure.bodySite.coding" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="Procedure.bodySite.coding.system">
      <path value="Procedure.bodySite.coding.system" />
      <min value="1" />
      <fixedUri value="http://snomed.info/sct" />
    </element>
    <element id="Procedure.bodySite.coding:tooth">
      <path value="Procedure.bodySite.coding" />
      <sliceName value="tooth" />
      <max value="1" />
      <binding>
        <strength value="required" />
        <valueSet value="http://novari.no/fhir/digidot/ValueSet/teeth" />
      </binding>
    </element>
    <element id="Procedure.bodySite.coding:surface">
      <path value="Procedure.bodySite.coding" />
      <sliceName value="surface" />
      <binding>
        <strength value="required" />
        <valueSet value="http://novari.no/fhir/digidot/ValueSet/tooth-surfaces" />
      </binding>
    </element>
    <element id="Procedure.bodySite.coding:surface.code">
      <path value="Procedure.bodySite.coding.code" />
      <min value="1" />
    </element>
  </differential>
</StructureDefinition>