{
  "resourceType": "StructureDefinition",
  "id": "pcm-consent",
  "url": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent",
  "version": "0.1.6",
  "name": "PCMConsent",
  "title": "PCM Consent",
  "status": "active",
  "description": "PCM consent resource. Created by a Service Provider Organization with status 'proposed'. Status is later controlled by the patient (active/rejected) and by PCM on expiration (inactive). Service providers may set status to 'inactive' only for consents they created; deletion is not allowed. Search/get is limited to PCM administrators and the requesting provider.",
  "fhirVersion": "4.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "Consent",
  "baseDefinition": "http://fhir.health.gov.il/StructureDefinition/il-core-consent",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Consent.extension",
        "path": "Consent.extension",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "url"
            }
          ],
          "ordered": false,
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "Consent.extension:pcmService",
        "path": "Consent.extension",
        "sliceName": "pcmService",
        "comment": "Set on creation. Reference to the HealthcareService instance that the provider is requesting consent for.",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://pcm.fhir.health.gov.il/StructureDefinition/ext-pcm-service"
            ]
          }
        ]
      },
      {
        "id": "Consent.identifier",
        "path": "Consent.identifier",
        "comment": "Stable business identifier for the consent (do not rely on resource.id for business workflows)."
      },
      {
        "id": "Consent.identifier.use",
        "path": "Consent.identifier.use",
        "min": 1,
        "fixedCode": "official"
      },
      {
        "id": "Consent.identifier.system",
        "path": "Consent.identifier.system",
        "min": 1,
        "fixedUri": "http://pcm.fhir.health.gov.il/identifier/pcm-consent-id"
      },
      {
        "id": "Consent.identifier.value",
        "path": "Consent.identifier.value",
        "min": 1
      },
      {
        "id": "Consent.status",
        "path": "Consent.status",
        "comment": "Created by provider as 'proposed'. Patient can change to 'active' or 'rejected'. PCM sets to 'inactive' after expiration. Service providers may set to 'inactive' only for consents they created; deletion is not allowed.",
        "binding": {
          "strength": "required",
          "valueSet": "http://pcm.fhir.health.gov.il/ValueSet/pcm-consent-status"
        }
      },
      {
        "id": "Consent.scope",
        "path": "Consent.scope",
        "comment": "PCM consent is a privacy consent for information access."
      },
      {
        "id": "Consent.scope.coding",
        "path": "Consent.scope.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Consent.scope.coding.system",
        "path": "Consent.scope.coding.system",
        "min": 1,
        "fixedUri": "http://terminology.hl7.org/CodeSystem/consentscope"
      },
      {
        "id": "Consent.scope.coding.code",
        "path": "Consent.scope.coding.code",
        "min": 1,
        "fixedCode": "patient-privacy"
      },
      {
        "id": "Consent.category",
        "path": "Consent.category",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "coding.system"
            }
          ],
          "rules": "open"
        },
        "binding": {
          "strength": "extensible",
          "valueSet": "http://pcm.fhir.health.gov.il/ValueSet/pcm-consent-category"
        }
      },
      {
        "id": "Consent.category:actCode",
        "path": "Consent.category",
        "sliceName": "actCode",
        "short": "ActCode category (optional informational category).",
        "min": 0,
        "max": "1"
      },
      {
        "id": "Consent.category:actCode.coding.system",
        "path": "Consent.category.coding.system",
        "min": 1,
        "fixedUri": "http://terminology.hl7.org/CodeSystem/v3-ActCode"
      },
      {
        "id": "Consent.category:actCode.coding.code",
        "path": "Consent.category.coding.code",
        "fixedCode": "INFA"
      },
      {
        "id": "Consent.category:accessMode",
        "path": "Consent.category",
        "sliceName": "accessMode",
        "short": "Access mode copied from the HealthcareService catalog.",
        "comment": "PCM copies the access mode (#one-time or #continuous) from the selected HealthcareService into this category coding.",
        "min": 0,
        "max": "1",
        "binding": {
          "strength": "required",
          "valueSet": "http://pcm.fhir.health.gov.il/ValueSet/pcm-access-mode"
        }
      },
      {
        "id": "Consent.category:accessMode.coding",
        "path": "Consent.category.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Consent.category:accessMode.coding.system",
        "path": "Consent.category.coding.system",
        "min": 1,
        "fixedUri": "http://fhir.health.gov.il/cs/pcm-consent-access-mode"
      },
      {
        "id": "Consent.category:accessMode.coding.code",
        "path": "Consent.category.coding.code",
        "min": 1,
        "binding": {
          "strength": "required",
          "valueSet": "http://pcm.fhir.health.gov.il/ValueSet/pcm-access-mode"
        }
      },
      {
        "id": "Consent.patient",
        "path": "Consent.patient",
        "comment": "Always a logical reference (identifier only). The identifier.system can be IL national-id or a passport system URI (passport-uri VS).",
        "min": 1
      },
      {
        "id": "Consent.patient.reference",
        "path": "Consent.patient.reference",
        "max": "0"
      },
      {
        "id": "Consent.patient.identifier",
        "path": "Consent.patient.identifier",
        "comment": "Logical patient identifier used for PCM portal identification flows (ID or Passport).",
        "min": 1,
        "constraint": [
          {
            "key": "pcm-consent-patient-id-system",
            "severity": "error",
            "human": "Consent.patient.identifier.system must be either IL national-id or one of the passport system URIs.",
            "expression": "patient.identifier.system = 'http://fhir.health.gov.il/identifier/il-national-id' or patient.identifier.system.memberOf('http://fhir.health.gov.il/ValueSet/passport-uri')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          },
          {
            "key": "pcm-consent-patient-id-value-trimmed",
            "severity": "error",
            "human": "Consent.patient.identifier.value must be non-empty and must not have leading/trailing whitespace.",
            "expression": "patient.identifier.value.exists() and patient.identifier.value = patient.identifier.value.trim() and patient.identifier.value.trim() != ''",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          },
          {
            "key": "pcm-consent-patient-il-id-chk",
            "severity": "error",
            "human": "If Consent.patient.identifier.system is IL national-id, the value must be 9 digits and pass the Israeli ID check-digit algorithm.",
            "expression": "patient.identifier.system = 'http://fhir.health.gov.il/identifier/il-national-id' implies (patient.identifier.value.matches('^[0-9]{9}$') and patient.identifier.value.substring(8,1).toInteger()= (10-((patient.identifier.value.substring(0,1).toInteger() + patient.identifier.value.substring(1,1).toInteger()*2 mod 10 + patient.identifier.value.substring(1,1).toInteger()*2 div 10 + patient.identifier.value.substring(2,1).toInteger() + patient.identifier.value.substring(3,1).toInteger()*2 mod 10 + patient.identifier.value.substring(3,1).toInteger()*2 div 10 + patient.identifier.value.substring(4,1).toInteger() + patient.identifier.value.substring(5,1).toInteger()*2 mod 10 + patient.identifier.value.substring(5,1).toInteger()*2 div 10 + patient.identifier.value.substring(6,1).toInteger() + patient.identifier.value.substring(7,1).toInteger()*2 mod 10 + patient.identifier.value.substring(7,1).toInteger()*2 div 10) mod 10)) mod 10))",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          }
        ]
      },
      {
        "id": "Consent.patient.identifier.system",
        "path": "Consent.patient.identifier.system",
        "min": 1
      },
      {
        "id": "Consent.patient.identifier.value",
        "path": "Consent.patient.identifier.value",
        "min": 1
      },
      {
        "id": "Consent.dateTime",
        "path": "Consent.dateTime",
        "comment": "Timestamp when the Consent was created. Set by the PCM."
      },
      {
        "id": "Consent.performer",
        "path": "Consent.performer",
        "max": "0"
      },
      {
        "id": "Consent.organization",
        "path": "Consent.organization",
        "max": "0"
      },
      {
        "id": "Consent.source[x]",
        "path": "Consent.source[x]",
        "max": "0"
      },
      {
        "id": "Consent.source[x]:sourceReference",
        "path": "Consent.source[x]",
        "sliceName": "sourceReference",
        "max": "0",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://fhir.health.gov.il/StructureDefinition/il-core-consent",
              "http://fhir.health.gov.il/StructureDefinition/il-core-document-reference",
              "http://hl7.org/fhir/StructureDefinition/Contract",
              "http://fhir.health.gov.il/StructureDefinition/il-core-questionnaire-response"
            ]
          }
        ]
      },
      {
        "id": "Consent.source[x]:sourceAttachment",
        "path": "Consent.source[x]",
        "sliceName": "sourceAttachment",
        "min": 0,
        "max": "0",
        "type": [
          {
            "code": "Attachment"
          }
        ]
      },
      {
        "id": "Consent.policy",
        "path": "Consent.policy",
        "max": "0"
      },
      {
        "id": "Consent.policyRule",
        "path": "Consent.policyRule",
        "max": "0"
      },
      {
        "id": "Consent.verification",
        "path": "Consent.verification",
        "max": "0"
      },
      {
        "id": "Consent.provision",
        "path": "Consent.provision",
        "comment": "PCM uses a single provision of type 'permit' to express the access grant."
      },
      {
        "id": "Consent.provision.type",
        "path": "Consent.provision.type",
        "min": 1,
        "fixedCode": "permit"
      },
      {
        "id": "Consent.provision.period",
        "path": "Consent.provision.period",
        "comment": "Derived from the HealthcareService catalog (access duration), resulting in an explicit validity period."
      },
      {
        "id": "Consent.provision.actor",
        "path": "Consent.provision.actor",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "role.coding.code"
            }
          ],
          "rules": "open"
        }
      },
      {
        "id": "Consent.provision.actor:requestor",
        "path": "Consent.provision.actor",
        "sliceName": "requestor",
        "short": "The requesting Service Provider organization.",
        "comment": "Always populated by the server from the access token/certificate. Role fixed to IRCP.",
        "min": 0,
        "max": "1"
      },
      {
        "id": "Consent.provision.actor:requestor.role.coding",
        "path": "Consent.provision.actor.role.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Consent.provision.actor:requestor.role.coding.system",
        "path": "Consent.provision.actor.role.coding.system",
        "min": 1,
        "fixedUri": "http://terminology.hl7.org/CodeSystem/v3-ParticipationType"
      },
      {
        "id": "Consent.provision.actor:requestor.role.coding.code",
        "path": "Consent.provision.actor.role.coding.code",
        "min": 1,
        "fixedCode": "IRCP"
      },
      {
        "id": "Consent.provision.actor:requestor.reference",
        "path": "Consent.provision.actor.reference",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-service-provider"
            ]
          }
        ]
      },
      {
        "id": "Consent.provision.actor:data-source",
        "path": "Consent.provision.actor",
        "sliceName": "data-source",
        "short": "Allowed data sources (filled by PCM after patient approval).",
        "comment": "After consent approval, PCM derives relevant Data Source organizations and adds them here (role CST).",
        "min": 0,
        "max": "*"
      },
      {
        "id": "Consent.provision.actor:data-source.role.coding",
        "path": "Consent.provision.actor.role.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Consent.provision.actor:data-source.role.coding.system",
        "path": "Consent.provision.actor.role.coding.system",
        "min": 1,
        "fixedUri": "http://terminology.hl7.org/CodeSystem/v3-ParticipationType"
      },
      {
        "id": "Consent.provision.actor:data-source.role.coding.code",
        "path": "Consent.provision.actor.role.coding.code",
        "min": 1,
        "fixedCode": "CST"
      },
      {
        "id": "Consent.provision.actor:data-source.reference",
        "path": "Consent.provision.actor.reference",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-source"
            ]
          }
        ]
      },
      {
        "id": "Consent.provision.action",
        "path": "Consent.provision.action",
        "max": "0"
      },
      {
        "id": "Consent.provision.securityLabel",
        "path": "Consent.provision.securityLabel",
        "max": "0"
      },
      {
        "id": "Consent.provision.purpose",
        "path": "Consent.provision.purpose",
        "comment": "Purpose of use for PCM information sharing (currently treatment).",
        "min": 1
      },
      {
        "id": "Consent.provision.purpose.system",
        "path": "Consent.provision.purpose.system",
        "min": 1,
        "fixedUri": "http://terminology.hl7.org/CodeSystem/v3-ActReason"
      },
      {
        "id": "Consent.provision.purpose.code",
        "path": "Consent.provision.purpose.code",
        "min": 1,
        "fixedCode": "TREAT"
      },
      {
        "id": "Consent.provision.class",
        "path": "Consent.provision.class",
        "max": "0"
      },
      {
        "id": "Consent.provision.code",
        "path": "Consent.provision.code",
        "max": "0"
      },
      {
        "id": "Consent.provision.dataPeriod",
        "path": "Consent.provision.dataPeriod",
        "max": "0"
      },
      {
        "id": "Consent.provision.data",
        "path": "Consent.provision.data",
        "max": "0"
      }
    ]
  }
}