<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="restriction-re" />
  <url value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
  <version value="0.1.0" />
  <name value="RestrictionRe" />
  <title value="Restriction (RE)" />
  <status value="active" />
  <description value="Profile for restricting access to patient data" />
  <fhirVersion value="5.0.0" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Consent" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Consent" />
  <derivation value="constraint" />
  <differential>
    <element id="Consent">
      <path value="Consent" />
      <constraint>
        <key value="ndi-consent-date-2" />
        <severity value="error" />
        <human value="If present, date SHALL have a lower or equal value than period.start" />
        <expression value="date.hasValue().not() or date &lt;= period.start" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-consent-actors-1" />
        <severity value="error" />
        <human value="If any of category codes is &quot;restriction&quot;, the person whose access is being restricted (grantee) cannot be the same person as the one whose data the restriction concerns (subject)." />
        <expression value="(subject.identifier != grantee.identifier) or category.coding.all(code != 'restriction')" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-consent-actors-2" />
        <severity value="error" />
        <human value="If any of category codes is &quot;restriction&quot;, the person whose access is being restricted (grantee) cannot be the same person as the one is creating the restriction (grantor)." />
        <expression value="(grantor.identifier != grantee.identifier) or category.coding.all(code != 'restriction')" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
    </element>
    <element id="Consent.status">
      <path value="Consent.status" />
      <short value="active | inactive" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://electronichealth.se/fhir/NDI/ValueSet/re-restriction-statuses" />
      </binding>
    </element>
    <element id="Consent.category">
      <path value="Consent.category" />
      <min value="1" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://electronichealth.se/fhir/NDI/ValueSet/re-restriction-categories" />
      </binding>
    </element>
    <element id="Consent.category.coding">
      <path value="Consent.category.coding" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.category.coding.system">
      <path value="Consent.category.coding.system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.category.coding.code">
      <path value="Consent.category.coding.code" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.subject">
      <path value="Consent.subject" />
      <short value="The patient whom the Restriction concerns" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://electronichealth.se/fhir/NDI/StructureDefinition/patient-data-access" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Consent.subject.reference">
      <path value="Consent.subject.reference" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.subject.identifier">
      <path value="Consent.subject.identifier" />
      <constraint>
        <key value="ndi-personal-identity-number-value-1" />
        <severity value="error" />
        <human value="A Swedish personal identity number (sv: personnummer) should follow format 198001032385" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\\d{4}$') or system != 'http://electronichealth.se/identifier/personnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-coordination-number-value-1" />
        <severity value="error" />
        <human value="A Swedish coordination number (sv: samordningsnummer) should follow format 201903682399" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])([6-9][1-9])\\d{4}$') or system != 'http://electronichealth.se/identifier/samordningsnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Consent.subject.identifier.system">
      <path value="Consent.subject.identifier.system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.subject.identifier.value">
      <path value="Consent.subject.identifier.value" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.date">
      <path value="Consent.date" />
      <short value="Date the restriction was created" />
      <definition value="The date when the grantor created the restriction. Can be before it was submitted to a server, e.g. by filling in a physical form" />
      <constraint>
        <key value="ndi-consent-date-1" />
        <severity value="error" />
        <human value="Date SHALL have a lower or equal value than today's date" />
        <expression value="$this &lt;= today()" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Consent.period">
      <path value="Consent.period" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.period.start">
      <path value="Consent.period.start" />
      <min value="1" />
      <constraint>
        <key value="ndi-consent-period-start-1" />
        <severity value="error" />
        <human value="Period.start SHALL have a higher or equal value than today's date" />
        <expression value="$this &gt;= today()" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-dateTime-1" />
        <severity value="error" />
        <human value="DateTime must be without timestamp" />
        <expression value="$this.toString().contains('T') = false" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Consent.period.end">
      <path value="Consent.period.end" />
      <constraint>
        <key value="ndi-consent-period-end-1" />
        <severity value="error" />
        <human value="Period.end SHALL have a higher or equal value than today's date" />
        <expression value="$this &gt;= today()" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-dateTime-1" />
        <severity value="error" />
        <human value="DateTime must be without timestamp" />
        <expression value="$this.toString().contains('T') = false" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantor">
      <path value="Consent.grantor" />
      <short value="The individual that created the Restriction" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://electronichealth.se/fhir/NDI/StructureDefinition/patient-data-access" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/PractitionerRole" />
        <targetProfile value="http://electronichealth.se/fhir/NDI/StructureDefinition/related-person-data-access" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantor.reference">
      <path value="Consent.grantor.reference" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantor.type">
      <path value="Consent.grantor.type" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantor.identifier">
      <path value="Consent.grantor.identifier" />
      <constraint>
        <key value="ndi-personal-identity-number-value-1" />
        <severity value="error" />
        <human value="A Swedish personal identity number (sv: personnummer) should follow format 198001032385" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\\d{4}$') or system != 'http://electronichealth.se/identifier/personnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-coordination-number-value-1" />
        <severity value="error" />
        <human value="A Swedish coordination number (sv: samordningsnummer) should follow format 201903682399" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])([6-9][1-9])\\d{4}$') or system != 'http://electronichealth.se/identifier/samordningsnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-hsa-identifier-value-1" />
        <severity value="error" />
        <human value="If identifier.system = urn:oid:1.2.752.29.4.19, value should follow format for HSA ID: SE1234567890-ABC1. Characters å, ä, ö, @ not valid." />
        <expression value="value.matches('^SE[0-9]{10}-[A-za-z0-9]+$') or system != 'urn:oid:1.2.752.29.4.19'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantor.identifier.system">
      <path value="Consent.grantor.identifier.system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantor.identifier.value">
      <path value="Consent.grantor.identifier.value" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantee">
      <path value="Consent.grantee" />
      <short value="The organization or individual whose access is being restricted" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://electronichealth.se/fhir/NDI/StructureDefinition/organization-data-access" />
        <targetProfile value="http://electronichealth.se/fhir/NDI/StructureDefinition/patient-data-access" />
        <targetProfile value="http://electronichealth.se/fhir/NDI/StructureDefinition/related-person-data-access" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Practitioner" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantee.reference">
      <path value="Consent.grantee.reference" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantee.type">
      <path value="Consent.grantee.type" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantee.identifier">
      <path value="Consent.grantee.identifier" />
      <constraint>
        <key value="ndi-personal-identity-number-value-1" />
        <severity value="error" />
        <human value="A Swedish personal identity number (sv: personnummer) should follow format 198001032385" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\\d{4}$') or system != 'http://electronichealth.se/identifier/personnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-coordination-number-value-1" />
        <severity value="error" />
        <human value="A Swedish coordination number (sv: samordningsnummer) should follow format 201903682399" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])([6-9][1-9])\\d{4}$') or system != 'http://electronichealth.se/identifier/samordningsnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-organization-identifier-value-1" />
        <severity value="error" />
        <human value="A Swedish organization identifier (sv: organisationsnummer) should follow format 7999000057" />
        <expression value="value.matches('^\\d{6}\\d{4}$') or system != 'urn:oid:2.5.4.97'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-country-identifier-value-1" />
        <severity value="error" />
        <human value="A country identifier should follow ISO-3166 format, e.g. SE" />
        <expression value="value.matches('^[A-Z]{2}$') or system != 'urn:iso:std:iso:3166'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantee.identifier.system">
      <path value="Consent.grantee.identifier.system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.grantee.identifier.value">
      <path value="Consent.grantee.identifier.value" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.regulatoryBasis">
      <path value="Consent.regulatoryBasis" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://electronichealth.se/fhir/NDI/ValueSet/re-regulatory-bases-of-restriction" />
      </binding>
    </element>
    <element id="Consent.regulatoryBasis.coding">
      <path value="Consent.regulatoryBasis.coding" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.regulatoryBasis.coding.system">
      <path value="Consent.regulatoryBasis.coding.system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.regulatoryBasis.coding.code">
      <path value="Consent.regulatoryBasis.coding.code" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.policyBasis">
      <path value="Consent.policyBasis" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.policyBasis.url">
      <path value="Consent.policyBasis.url" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.decision">
      <path value="Consent.decision" />
      <short value="Fixed to deny to use Consent as a Restriction" />
      <min value="1" />
      <fixedCode value="deny" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision">
      <path value="Consent.provision" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.purpose">
      <path value="Consent.provision.purpose" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.purpose.system">
      <path value="Consent.provision.purpose.system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.purpose.code">
      <path value="Consent.provision.purpose.code" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.documentType">
      <path value="Consent.provision.documentType" />
      <short value="The category of data the provision concerns" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://electronichealth.se/fhir/NDI/ValueSet/ndi-ehds-categories" />
      </binding>
    </element>
    <element id="Consent.provision.data">
      <path value="Consent.provision.data" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="meaning" />
        </discriminator>
        <description value="Slice data based on meaning" />
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data.meaning">
      <path value="Consent.provision.data.meaning" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data.reference">
      <path value="Consent.provision.data.reference" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data:fromCaregiverOrUnit">
      <path value="Consent.provision.data" />
      <sliceName value="fromCaregiverOrUnit" />
      <min value="0" />
      <max value="*" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data:fromCaregiverOrUnit.meaning">
      <path value="Consent.provision.data.meaning" />
      <fixedCode value="authoredby" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data:fromCaregiverOrUnit.reference">
      <path value="Consent.provision.data.reference" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://electronichealth.se/fhir/NDI/StructureDefinition/organization-data-access" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data:fromCaregiverOrUnit.reference.reference">
      <path value="Consent.provision.data.reference.reference" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data:fromCaregiverOrUnit.reference.identifier">
      <path value="Consent.provision.data.reference.identifier" />
      <constraint>
        <key value="ndi-organization-identifier-value-1" />
        <severity value="error" />
        <human value="A Swedish organization identifier (sv: organisationsnummer) should follow format 7999000057" />
        <expression value="value.matches('^\\d{6}\\d{4}$') or system != 'urn:oid:2.5.4.97'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-personal-identity-number-value-1" />
        <severity value="error" />
        <human value="A Swedish personal identity number (sv: personnummer) should follow format 198001032385" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\\d{4}$') or system != 'http://electronichealth.se/identifier/personnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <constraint>
        <key value="ndi-coordination-number-value-1" />
        <severity value="error" />
        <human value="A Swedish coordination number (sv: samordningsnummer) should follow format 201903682399" />
        <expression value="value.matches('^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(0[1-9]|1[0-2])([6-9][1-9])\\d{4}$') or system != 'http://electronichealth.se/identifier/samordningsnummer'" />
        <source value="http://electronichealth.se/fhir/NDI/StructureDefinition/restriction-re" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data:fromCaregiverOrUnit.reference.identifier.system">
      <path value="Consent.provision.data.reference.identifier.system" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.data:fromCaregiverOrUnit.reference.identifier.value">
      <path value="Consent.provision.data.reference.identifier.value" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Consent.provision.provision">
      <path value="Consent.provision.provision" />
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>