<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="hn-basis-appointment" />
  <url value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
  <version value="2.5.5" />
  <name value="HnBasisAppointment" />
  <title value="hn-basis-appointment" />
  <status value="active" />
  <description value="Base profile for Helsenorge Appointment information. Defined by Helsenorge based on national profile." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Appointment" />
  <baseDefinition value="http://hl7.no/fhir/StructureDefinition/no-basis-Appointment" />
  <derivation value="constraint" />
  <differential>
    <element id="Appointment">
      <path value="Appointment" />
      <constraint>
        <key value="hn-app-availability-status" />
        <severity value="error" />
        <human value="Proposed appointments with serviceCategory 7 shall have availabilityStatus. All other appointments shall not have availabilityStatus." />
        <expression value="(&#xA;  status = 'proposed' and&#xA;  serviceCategory.coding.code = '7'&#xA;)&#xA;=&#xA;extension('http://helsenorge.no/fhir/StructureDefinition/hn-availability-status').exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="cancelationReason-inv" />
        <severity value="error" />
        <human value="Cancellation reason MUST be set when status=cancelled and the appointment is not partOf another appointment" />
        <expression value="(status = 'cancelled' and extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').empty()) implies cancelationReason.exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="contained-location-must-have-managingorganization" />
        <severity value="error" />
        <human value="When serviceCategory is 27 or 30, every contained Location must have managingOrganization." />
        <expression value="serviceCategory.coding.where(code = '27' or code = '30').empty() or contained.ofType(Location).all(managingOrganization.exists())" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-primary-2" />
        <severity value="error" />
        <human value="If basedOn is present, serviceCategory must be 27 or 30" />
        <expression value="basedOn.empty() or serviceCategory.coding.code.where($this = '27' or $this = '30').exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="start-required-inv" />
        <severity value="error" />
        <human value="start is required unless the appointment uses requestedPeriod and status is proposed, cancelled, or entered-in-error." />
        <expression value="start.exists() or (requestedPeriod.exists() and (status = 'proposed' or status = 'cancelled' or status = 'entered-in-error'))" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-reqperiod-1" />
        <severity value="error" />
        <human value="If status is proposed, requestedPeriod must exist. If requestedPeriod is present, each requestedPeriod must have both start and end." />
        <expression value="(status != 'proposed' or requestedPeriod.exists()) and (requestedPeriod.empty() or requestedPeriod.all(start.exists() and end.exists()))" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-reqperiod-2" />
        <severity value="error" />
        <human value="If requestedPeriod is present, status must be proposed, cancelled, or entered-in-error." />
        <expression value="requestedPeriod.empty() or (status = 'proposed' or status = 'cancelled' or status = 'entered-in-error')" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-primary-4" />
        <severity value="error" />
        <human value="partOf is only allowed when serviceCategory is 27 or 30" />
        <expression value="extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').empty() or serviceCategory.coding.where(code = '27' or code = '30').exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-primary-5" />
        <severity value="error" />
        <human value="postponementReason is only allowed when serviceCategory is 27 or 30" />
        <expression value="postponementReason.empty() or serviceCategory.coding.where(code = '27' or code = '30').exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="serviceCategory-location-type" />
        <severity value="error" />
        <human value="For serviceCategory 27 or 30, every contained Location must have type HU or HOSP, and at least one HU and one HOSP Location must be present. The rule does not apply when Appointment.partOf is populated." />
        <expression value="extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').exists() or&#xA;serviceCategory.coding.where(code = '27' or code = '30').empty() or&#xA;(&#xA;  contained.ofType(Location).where(&#xA;    type.coding.where(&#xA;      system = 'http://terminology.hl7.org/CodeSystem/v3-RoleCode' and&#xA;      code = 'HU'&#xA;    ).exists()&#xA;  ).exists()&#xA;  and&#xA;  contained.ofType(Location).where(&#xA;    type.coding.where(&#xA;      system = 'http://terminology.hl7.org/CodeSystem/v3-RoleCode' and&#xA;      code = 'HOSP'&#xA;    ).exists()&#xA;  ).exists()&#xA;)" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="community-services-location-requires-ptres-or-of" />
        <severity value="error" />
        <human value="For community services, contained Location must include PTRES or OF when virtualService is not present." />
        <expression value="serviceCategory.coding.where(&#xA;  code = '3' or&#xA;  code = '4' or&#xA;  code = '5' or&#xA;  code = '6' or&#xA;  code = '7' or&#xA;  code = '8' or&#xA;  code = '9' or&#xA;  code = '10' or&#xA;  code = '16' or&#xA;  code = '17' or&#xA;  code = '18' or&#xA;  code = '19'&#xA;).empty()&#xA;or extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').exists()&#xA;or extension('http://hl7.no/fhir/StructureDefinition/no-basis-virtual-service').exists()&#xA;or contained.ofType(Location).where(&#xA;     type.coding.where(&#xA;       system = 'http://terminology.hl7.org/CodeSystem/v3-RoleCode'&#xA;       and (code = 'PTRES' or code = 'OF')&#xA;     ).exists()&#xA;   ).exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="community-services-location-not-both-ptres-and-of" />
        <severity value="error" />
        <human value="When serviceCategory is 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18 or 19, the appointment is not partOf another appointment, and virtualService is not present, contained Location must not include both PTRES and OF." />
        <expression value="serviceCategory.coding.where(code in ('3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '16' | '17' | '18' | '19')).empty() or extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').exists() or &#xA;    extension('http://hl7.no/fhir/StructureDefinition/no-basis-virtual-service').exists()&#xA;    or (contained.ofType(Location).where(type.coding.where(system = 'http://terminology.hl7.org/CodeSystem/v3-RoleCode' and code = 'PTRES').exists()).exists() and contained.ofType(Location).where(type.coding.where(system = 'http://terminology.hl7.org/CodeSystem/v3-RoleCode' and code = 'OF').exists()).exists()).not()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="community-services-no-dialog-flags" />
        <severity value="error" />
        <human value="For community health services (3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, and 19), contained Flag resources must not use the codes canAcknowledge, canChangeAppointmentDialog, canHaveAppointmentDetails, or canInitiateDialog." />
        <expression value="serviceCategory.coding.where(code in ('3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '16' | '17' | '18' | '19')).empty() or contained.ofType(Flag).all(code.coding.where(code in ('canAcknowledge' | 'canChangeAppointmentDialog' | 'canHaveAppointmentDetails' | 'canInitiateDialog')).empty())" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="contained-flag-allowed-codes" />
        <severity value="error" />
        <human value="When contained Flag resources are used, only canAcknowledge, canChangeAppointmentDialog, canHaveAppointmentDetails, canInitiateDialog, cancel, cancelWithComment, canCancelServiceRequest, and canChangeAppointment are allowed, and each code may only occur once." />
        <expression value="contained.ofType(Flag).code.coding.all(code in ('canAcknowledge' | 'canChangeAppointmentDialog' | 'canHaveAppointmentDetails' | 'canInitiateDialog' | 'cancel' | 'cancelWithComment' | 'canCancelServiceRequest' | 'canChangeAppointment')) and contained.ofType(Flag).code.coding.where(code = 'canAcknowledge').count() &lt;= 1 and contained.ofType(Flag).code.coding.where(code = 'canChangeAppointmentDialog').count() &lt;= 1 and contained.ofType(Flag).code.coding.where(code = 'canHaveAppointmentDetails').count() &lt;= 1 and contained.ofType(Flag).code.coding.where(code = 'canInitiateDialog').count() &lt;= 1 and contained.ofType(Flag).code.coding.where(code = 'cancel').count() &lt;= 1 and contained.ofType(Flag).code.coding.where(code = 'cancelWithComment').count() &lt;= 1 and contained.ofType(Flag).code.coding.where(code = 'canCancelServiceRequest').count() &lt;= 1 and contained.ofType(Flag).code.coding.where(code = 'canChangeAppointment').count() &lt;= 1" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="serviceCategory-7-ptres-no-varsling-or-paminnelse" />
        <severity value="error" />
        <human value="When serviceCategory is 7 and a contained Location has type PTRES, meta.tag varsling and paminnelse must not be used." />
        <expression value="serviceCategory.coding.where(code = '7').empty() or contained.ofType(Location).where(type.coding.where(system = 'http://terminology.hl7.org/CodeSystem/v3-RoleCode' and code = 'PTRES').exists()).empty() or meta.tag.where(system = 'http://helsenorge.no/fhir/varsling' or system = 'http://helsenorge.no/fhir/paminnelse').empty()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="kommunikasjonspart-parent-organization" />
        <severity value="error" />
        <human value="When serviceCategory is not 27 or 30, the kommunikasjonspart Organization referenced from supportingInformation shall have a partOf reference to a parent no-basis-Organization containing both an organization number and a HER-id." />
        <expression value="serviceCategory.coding.code.where($this = '27' or $this = '30').exists()&#xA;or&#xA;supportingInformation.resolve().ofType(Organization)&#xA;.where(meta.profile.exists($this = 'http://helsenorge.no/fhir/StructureDefinition/kommunikasjonspart-Organization'))&#xA;.all(&#xA;  partOf.exists()&#xA;  and partOf.resolve().ofType(Organization).all(&#xA;    meta.profile.exists($this = 'http://hl7.no/fhir/StructureDefinition/no-basis-Organization')&#xA;    and identifier.where(system = 'urn:oid:2.16.578.1.12.4.1.4.101').exists()&#xA;    and identifier.where(system = 'urn:oid:2.16.578.1.12.4.1.2').exists()&#xA;  )&#xA;)" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="virtualservice-or-location-required" />
        <severity value="error" />
        <human value="For appointments that are not part of another appointment, either virtual service or at least one Location must be present." />
        <expression value="extension.where(&#xA;  url='http://hl7.no/fhir/StructureDefinition/no-basis-partof'&#xA;).exists()&#xA;or&#xA;extension.where(&#xA;  url='http://hl7.no/fhir/StructureDefinition/no-basis-virtual-service'&#xA;).exists()&#xA;or&#xA;contained.ofType(Location).exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-proposed-only-servicecategory-7" />
        <severity value="error" />
        <human value="status proposed is only allowed when serviceCategory is 7." />
        <expression value="status != 'proposed' or serviceCategory.coding.where(code = '7').exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-entered-in-error-requires-start-and-end" />
        <severity value="error" />
        <human value="When status is entered-in-error, start and end SHALL be populated. If explicit start and end are not available, they SHALL be derived from requestedPeriod before submission." />
        <expression value="status != 'entered-in-error' or (start.exists() and end.exists())" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-specialist-cancelation-reason" />
        <severity value="error" />
        <human value="Service categories 27 and 30 shall use Norwegian cancellation reason codes" />
        <expression value="(serviceCategory.coding.where(code='27' or code='30').exists()&#xA;  and status = 'cancelled'&#xA;  and extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').empty())&#xA;   implies&#xA;   cancelationReason.coding.where(&#xA;     system='urn:oid:2.16.578.1.12.4.1.1.8445'&#xA;     or&#xA;     system='urn:oid:2.16.578.1.12.4.1.1.9179'&#xA;   ).exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="hn-app-community-cancelation-reason" />
        <severity value="error" />
        <human value="Cancelled appointments that are not service category 27 or 30 shall use a cancellation reason from code system 7621." />
        <expression value="(status = 'cancelled'&#xA; and extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').empty()&#xA; and serviceCategory.coding.where(code = '27' or code = '30').empty())&#xA;implies&#xA;cancelationReason.coding.where(&#xA;  system = 'urn:oid:2.16.578.1.12.4.1.1.7621'&#xA;).exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
      <constraint>
        <key value="root-appointment-requires-patient" />
        <severity value="error" />
        <human value="Root appointments must contain a patient participant" />
        <expression value="extension('http://hl7.no/fhir/StructureDefinition/no-basis-partof').exists() or&#xA;participant.where(&#xA;  actor.identifier.where(&#xA;    system = 'urn:oid:2.16.578.1.12.4.1.4.1' or&#xA;    system = 'urn:oid:2.16.578.1.12.4.1.4.2' or&#xA;    system = 'urn:oid:2.16.578.1.12.4.1.4.3'&#xA;  ).exists()&#xA;).exists()" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.meta">
      <path value="Appointment.meta" />
      <short value="Metadata used for Appointment in Helsenorge" />
      <definition value="Appointment-specific use of generic Helsenorge FHIR metadata. See generic description of metadata mechanisms: &lt;https://helsenorge.atlassian.net/wiki/spaces/HELSENORGE/pages/743014401/Meta+informasjon+som+kan+benyttes+for+alle+FHIR+ressurser&gt;. This profile constrains selected metadata elements relevant for Appointment, including conditional access restriction, notification handling, and reminder handling." />
    </element>
    <element id="Appointment.meta.lastUpdated">
      <path value="Appointment.meta.lastUpdated" />
      <short value="Last updated timestamp for the resource" />
      <definition value="If present, indicates when the resource was created or last changed." />
      <comment value="This value is typically populated by the server/resource manager." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Appointment.meta.security">
      <path value="Appointment.meta.security" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="Appointment.meta.security:tilgangsbegrensning">
      <path value="Appointment.meta.security" />
      <sliceName value="tilgangsbegrensning" />
      <short value="Betinget tilgangsbegrensning metadata" />
      <definition value="Metadata for conditional access restriction for Appointment in Helsenorge." />
      <min value="0" />
      <max value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-tilgangsbegrensning-vs" />
      </binding>
    </element>
    <element id="Appointment.meta.security:tilgangsbegrensning.system">
      <path value="Appointment.meta.security.system" />
      <min value="1" />
      <fixedUri value="urn:oid:2.16.578.1.12.4.1.1.9603" />
    </element>
    <element id="Appointment.meta.security:tilgangsbegrensning.code">
      <path value="Appointment.meta.security.code" />
      <min value="1" />
    </element>
    <element id="Appointment.meta.tag">
      <path value="Appointment.meta.tag" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="Appointment.meta.tag:varsling">
      <path value="Appointment.meta.tag" />
      <sliceName value="varsling" />
      <short value="Varsling metadata" />
      <definition value="Metadata used to control notification behaviour for the Appointment in Helsenorge, including optional sender organization name." />
      <min value="0" />
      <max value="*" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-varsling-vs" />
      </binding>
    </element>
    <element id="Appointment.meta.tag:varsling.extension:varselorganisasjon">
      <path value="Appointment.meta.tag.extension" />
      <sliceName value="varselorganisasjon" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://helsenorge.no/fhir/StructureDefinition/hn-extension-varselorganisasjon" />
      </type>
    </element>
    <element id="Appointment.meta.tag:varsling.system">
      <path value="Appointment.meta.tag.system" />
      <min value="1" />
      <fixedUri value="http://helsenorge.no/fhir/varsling" />
    </element>
    <element id="Appointment.meta.tag:varsling.code">
      <path value="Appointment.meta.tag.code" />
      <min value="1" />
    </element>
    <element id="Appointment.meta.tag:paminnelse">
      <path value="Appointment.meta.tag" />
      <sliceName value="paminnelse" />
      <short value="Påminnelse metadata" />
      <definition value="Metadata used to control reminder behaviour for the Appointment in Helsenorge." />
      <min value="0" />
      <max value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-paminnelse-vs" />
      </binding>
    </element>
    <element id="Appointment.meta.tag:paminnelse.system">
      <path value="Appointment.meta.tag.system" />
      <min value="1" />
      <fixedUri value="http://helsenorge.no/fhir/paminnelse" />
    </element>
    <element id="Appointment.meta.tag:paminnelse.code">
      <path value="Appointment.meta.tag.code" />
      <min value="1" />
    </element>
    <element id="Appointment.implicitRules">
      <path value="Appointment.implicitRules" />
      <max value="0" />
    </element>
    <element id="Appointment.language">
      <path value="Appointment.language" />
      <max value="0" />
    </element>
    <element id="Appointment.text">
      <path value="Appointment.text" />
      <max value="0" />
    </element>
    <element id="Appointment.extension:virtualService">
      <path value="Appointment.extension" />
      <sliceName value="virtualService" />
    </element>
    <element id="Appointment.extension:virtualService.extension:channelType">
      <path value="Appointment.extension.extension" />
      <sliceName value="channelType" />
    </element>
    <element id="Appointment.extension:virtualService.extension:channelType.value[x]">
      <path value="Appointment.extension.extension.value[x]" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-basis-virtual-service-type.valueset" />
      </binding>
    </element>
    <element id="Appointment.extension:recurring">
      <path value="Appointment.extension" />
      <sliceName value="recurring" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-Recurring" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Appointment.extension:postponementReason">
      <path value="Appointment.extension" />
      <sliceName value="postponementReason" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-postponementreason" />
      </type>
    </element>
    <element id="Appointment.extension:consultationType">
      <path value="Appointment.extension" />
      <sliceName value="consultationType" />
      <min value="0" />
      <max value="0" />
      <type>
        <code value="Extension" />
        <profile value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-consultationType" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Appointment.extension:availabilityStatus">
      <path value="Appointment.extension" />
      <sliceName value="availabilityStatus" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://helsenorge.no/fhir/StructureDefinition/hn-availability-status" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Appointment.identifier">
      <path value="Appointment.identifier" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Appointment.identifier.system">
      <path value="Appointment.identifier.system" />
      <min value="1" />
    </element>
    <element id="Appointment.identifier.value">
      <path value="Appointment.identifier.value" />
      <min value="1" />
    </element>
    <element id="Appointment.identifier.assigner">
      <path value="Appointment.identifier.assigner" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Organization" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Organization" />
      </type>
    </element>
    <element id="Appointment.status">
      <path value="Appointment.status" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-appointment-status-vs" />
      </binding>
    </element>
    <element id="Appointment.cancelationReason">
      <path value="Appointment.cancelationReason" />
      <short value="Reason for cancellation" />
      <definition value="Volven 8445 is a preferred code system but other code systems as Volven 9179 can also be used" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-cancelation-reason-vs" />
      </binding>
    </element>
    <element id="Appointment.cancelationReason.coding">
      <path value="Appointment.cancelationReason.coding" />
      <min value="1" />
      <max value="1" />
      <constraint>
        <key value="inv-4" />
        <severity value="error" />
        <human value="If code is used in a codable consept the system must be used" />
        <expression value="code &gt; '' implies (system &gt; '' )" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.cancelationReason.coding.code">
      <path value="Appointment.cancelationReason.coding.code" />
      <min value="1" />
    </element>
    <element id="Appointment.cancelationReason.text">
      <path value="Appointment.cancelationReason.text" />
      <constraint>
        <key value="must-be-max-250-chars" />
        <severity value="error" />
        <human value="Length MUST be &lt;= 250" />
        <expression value="$this.length() &lt;= 250" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.serviceCategory">
      <path value="Appointment.serviceCategory" />
      <min value="1" />
      <max value="1" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-appointment-ServiceCategory-code-vs" />
      </binding>
    </element>
    <element id="Appointment.serviceCategory.coding">
      <path value="Appointment.serviceCategory.coding" />
      <constraint>
        <key value="inv-4" />
        <severity value="error" />
        <human value="If code is used in a codable consept the system must be used" />
        <expression value="code &gt; '' implies (system &gt; '' )" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.serviceType">
      <path value="Appointment.serviceType" />
      <max value="0" />
    </element>
    <element id="Appointment.serviceType.coding">
      <path value="Appointment.serviceType.coding" />
      <constraint>
        <key value="inv-4" />
        <severity value="error" />
        <human value="If code is used in a codable consept the system must be used" />
        <expression value="code &gt; '' implies (system &gt; '' )" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.specialty">
      <path value="Appointment.specialty" />
      <max value="0" />
    </element>
    <element id="Appointment.specialty.coding">
      <path value="Appointment.specialty.coding" />
      <constraint>
        <key value="inv-4" />
        <severity value="error" />
        <human value="If code is used in a codable consept the system must be used" />
        <expression value="code &gt; '' implies (system &gt; '' )" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.appointmentType">
      <path value="Appointment.appointmentType" />
      <min value="1" />
    </element>
    <element id="Appointment.appointmentType.coding">
      <path value="Appointment.appointmentType.coding" />
      <constraint>
        <key value="inv-4" />
        <severity value="error" />
        <human value="If code is used in a codable consept the system must be used" />
        <expression value="code &gt; '' implies (system &gt; '' )" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.appointmentType.coding:omsorgsNiva">
      <path value="Appointment.appointmentType.coding" />
      <sliceName value="omsorgsNiva" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-appointment-type-omsorgsniva-vs" />
      </binding>
    </element>
    <element id="Appointment.appointmentType.coding:kontaktType">
      <path value="Appointment.appointmentType.coding" />
      <sliceName value="kontaktType" />
      <binding>
        <strength value="required" />
        <valueSet value="urn:oid:2.16.578.1.12.4.1.1.8432" />
      </binding>
    </element>
    <element id="Appointment.appointmentType.coding:innbygger">
      <path value="Appointment.appointmentType.coding" />
      <sliceName value="innbygger" />
      <binding>
        <strength value="required" />
        <valueSet value="http://helsenorge.no/fhir/ValueSet/hn-appointment-type-inbygger-vs" />
      </binding>
    </element>
    <element id="Appointment.reasonCode">
      <path value="Appointment.reasonCode" />
      <max value="0" />
    </element>
    <element id="Appointment.reasonReference">
      <path value="Appointment.reasonReference" />
      <max value="0" />
    </element>
    <element id="Appointment.priority">
      <path value="Appointment.priority" />
      <max value="0" />
    </element>
    <element id="Appointment.description">
      <path value="Appointment.description" />
      <constraint>
        <key value="must-be-max-1000-chars" />
        <severity value="error" />
        <human value="Length MUST be &lt;= 1000" />
        <expression value="$this.length() &lt;= 1000" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.supportingInformation">
      <path value="Appointment.supportingInformation" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="resolve()" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="1" />
    </element>
    <element id="Appointment.supportingInformation:kommunikasjonspart">
      <path value="Appointment.supportingInformation" />
      <sliceName value="kommunikasjonspart" />
      <short value="Kommunikasjonspart" />
      <definition value="Kommunikasjonspart organization used to transfer HER-id level 2 for the communication partner when serviceCategory is not 7." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://helsenorge.no/fhir/StructureDefinition/kommunikasjonspart-Organization" />
      </type>
    </element>
    <element id="Appointment.supportingInformation:documentReference">
      <path value="Appointment.supportingInformation" />
      <sliceName value="documentReference" />
      <short value="Document reference" />
      <definition value="DocumentReference resource with supporting documentation for the appointment." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-DocumentReference" />
      </type>
    </element>
    <element id="Appointment.supportingInformation:flag">
      <path value="Appointment.supportingInformation" />
      <sliceName value="flag" />
      <short value="Flag" />
      <definition value="Flag resource with supporting flag information for the appointment." />
      <min value="0" />
      <max value="*" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-Flag" />
      </type>
    </element>
    <element id="Appointment.slot">
      <path value="Appointment.slot" />
      <max value="0" />
    </element>
    <element id="Appointment.comment">
      <path value="Appointment.comment" />
      <max value="0" />
    </element>
    <element id="Appointment.patientInstruction">
      <path value="Appointment.patientInstruction" />
      <constraint>
        <key value="must-be-max-1000-chars" />
        <severity value="error" />
        <human value="Length MUST be &lt;= 1000" />
        <expression value="$this.length() &lt;= 1000" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.participant">
      <path value="Appointment.participant" />
      <slicing>
        <discriminator>
          <type value="profile" />
          <path value="actor.resolve()" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="Appointment.participant.type.coding">
      <path value="Appointment.participant.type.coding" />
      <constraint>
        <key value="inv-4" />
        <severity value="error" />
        <human value="If code is used in a codable consept the system must be used" />
        <expression value="code &gt; '' implies (system &gt; '' )" />
        <source value="http://helsenorge.no/fhir/StructureDefinition/hn-basis-appointment" />
      </constraint>
    </element>
    <element id="Appointment.participant.actor">
      <path value="Appointment.participant.actor" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Patient" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Practitioner" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Location" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-PractitionerRole" />
      </type>
    </element>
    <element id="Appointment.participant:patient">
      <path value="Appointment.participant" />
      <sliceName value="patient" />
      <min value="0" />
      <max value="1" />
    </element>
    <element id="Appointment.participant:patient.actor">
      <path value="Appointment.participant.actor" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.no/fhir/StructureDefinition/no-basis-Patient" />
      </type>
    </element>
    <element id="Appointment.participant:patient.actor.identifier">
      <path value="Appointment.participant.actor.identifier" />
      <min value="1" />
    </element>
  </differential>
</StructureDefinition>