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