{
  "resourceType": "StructureDefinition",
  "id": "pcm-consent",
  "url": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent",
  "version": "0.4.1",
  "name": "PCMConsent",
  "title": "PCM Consent",
  "status": "active",
  "description": "PCM consent resource. Created by a Service Provider Organization with status 'proposed'. Patient decisions and assisted/delegated flows are handled outside the client FHIR API and may narrow the service-requested continuous mode to one-time and/or shorten the service maximum duration. The authoritative Consent carries the requested mode while proposed and the effective approved mode and period after approval. Service providers may set status to 'inactive' only for consents they created; deletion is not allowed. Client search/get is limited to consents created by 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",
        "path": "Consent",
        "constraint": [
          {
            "key": "pcm-consent-business-status-map",
            "severity": "error",
            "human": "The PCM Consent business status must agree with Consent.status.",
            "expression": "(status = 'proposed' implies extension.where(url = 'http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status').value.ofType(Coding).code = 'requested') and (status = 'active' implies extension.where(url = 'http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status').value.ofType(Coding).code = 'active') and (status = 'rejected' implies extension.where(url = 'http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status').value.ofType(Coding).code = 'rejected') and (status = 'inactive' implies (extension.where(url = 'http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status').value.ofType(Coding).code = 'temporarily-inactive' or extension.where(url = 'http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status').value.ofType(Coding).code = 'permanently-inactive' or extension.where(url = 'http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status').value.ofType(Coding).code = 'service-provider-cancelled')) and (status = 'entered-in-error' implies extension.where(url = 'http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status').value.ofType(Coding).code = 'permanently-inactive')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          },
          {
            "key": "pcm-consent-period-by-status",
            "severity": "error",
            "human": "Active Consent resources require an approval-anchored period; proposed and rejected Consent resources must not have one.",
            "expression": "(status = 'active' implies provision.period.exists()) and ((status = 'proposed' or status = 'rejected') implies provision.period.empty())",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          },
          {
            "key": "pcm-consent-period-order",
            "severity": "error",
            "human": "When a Consent period is present, it must have both endpoints and end must be later than start.",
            "expression": "provision.period.empty() or (provision.period.start.exists() and provision.period.end.exists() and provision.period.start < provision.period.end)",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          },
          {
            "key": "pcm-consent-sources-by-status",
            "severity": "error",
            "human": "Proposed and rejected Consent resources must not identify approved Data Sources.",
            "expression": "(status = 'proposed' or status = 'rejected') implies provision.actor.where(role.coding.where(system = 'http://terminology.hl7.org/CodeSystem/v3-ParticipationType' and code = 'CST').exists()).empty()",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          },
          {
            "key": "pcm-consent-test-security-label",
            "severity": "error",
            "human": "The two synthetic test patients require the HTEST security label, and HTEST is not used for another patient identifier.",
            "expression": "(patient.identifier.system = 'http://fhir.health.gov.il/identifier/il-hdp-test-id') = meta.security.where(system = 'http://terminology.hl7.org/CodeSystem/v3-ActReason' and code = 'HTEST').exists()",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
          }
        ]
      },
      {
        "id": "Consent.id",
        "path": "Consent.id",
        "min": 1
      },
      {
        "id": "Consent.meta",
        "path": "Consent.meta",
        "min": 1
      },
      {
        "id": "Consent.meta.lastUpdated",
        "path": "Consent.meta.lastUpdated",
        "comment": "Server-managed timestamp of the most recent authoritative resource change.",
        "min": 1
      },
      {
        "id": "Consent.meta.profile",
        "path": "Consent.meta.profile",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "$this"
            }
          ],
          "rules": "open"
        },
        "comment": "PCM includes the applicable server-return profile URL; additional compatible profile URLs are allowed.",
        "min": 1
      },
      {
        "id": "Consent.meta.profile:pcmProfile",
        "path": "Consent.meta.profile",
        "sliceName": "pcmProfile",
        "min": 1,
        "max": "1",
        "fixedCanonical": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent"
      },
      {
        "id": "Consent.extension",
        "path": "Consent.extension",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "url"
            }
          ],
          "ordered": false,
          "rules": "open"
        },
        "min": 2
      },
      {
        "id": "Consent.extension:businessStatus",
        "path": "Consent.extension",
        "sliceName": "businessStatus",
        "comment": "PCM-managed business status. A Service Provider cannot create, select, or modify it directly.",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status"
            ]
          }
        ]
      },
      {
        "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": "PCM-managed stable business identifier for the Consent. It is distinct from the FHIR logical id.",
        "min": 1,
        "max": "1"
      },
      {
        "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 approval/rejection/revocation is handled outside the client FHIR API. PCM may set status after patient decision, expiration, or policy events. Service providers may set status 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": "closed"
        },
        "min": 2,
        "max": "2",
        "binding": {
          "strength": "extensible",
          "valueSet": "http://pcm.fhir.health.gov.il/ValueSet/pcm-consent-category"
        }
      },
      {
        "id": "Consent.category:actCode",
        "path": "Consent.category",
        "sliceName": "actCode",
        "short": "Fixed information-access category.",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Consent.category:actCode.coding",
        "path": "Consent.category.coding",
        "min": 1,
        "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",
        "min": 1,
        "fixedCode": "INFA"
      },
      {
        "id": "Consent.category:accessMode",
        "path": "Consent.category",
        "sliceName": "accessMode",
        "short": "Server-managed requested/effective access mode.",
        "comment": "PCM initializes the proposed Consent from the selected HealthcareService access mode. An authorized patient decision, including an assisted or delegated flow, may retain that mode or narrow continuous access to one-time. The authoritative Consent carries the requested mode while proposed and the effective approved mode after a decision; it never widens a one-time service to continuous.",
        "min": 1,
        "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://pcm.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 an identifier-only logical reference. The identifier uses an Israeli or Palestinian national-ID system, an allowed passport system, or the exact synthetic test system http://fhir.health.gov.il/identifier/il-hdp-test-id with value 1 or 2.",
        "min": 1
      },
      {
        "id": "Consent.patient.reference",
        "path": "Consent.patient.reference",
        "max": "0"
      },
      {
        "id": "Consent.patient.identifier",
        "path": "Consent.patient.identifier",
        "comment": "Logical patient identifier. The synthetic test system accepts only values 1 and 2 and requires the HTEST meta.security label on the returned Consent.",
        "min": 1,
        "constraint": [
          {
            "key": "pcm-consent-patient-id-system",
            "severity": "error",
            "human": "Consent.patient.identifier must use an Israeli or Palestinian national-ID system, an allowed passport system, or one of the two exact synthetic test identifiers.",
            "expression": "system = 'http://fhir.health.gov.il/identifier/il-national-id' or system = 'http://fhir.health.gov.il/identifier/pna-national-id' or system.memberOf('http://fhir.health.gov.il/ValueSet/passport-uri') or (system = 'http://fhir.health.gov.il/identifier/il-hdp-test-id' and (value = '1' or value = '2'))",
            "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": "value.exists() and value.matches('^\\\\S(.*\\\\S)?$')",
            "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": "system = 'http://fhir.health.gov.il/identifier/il-national-id' implies (value.matches('^[0-9]{9}$') and value.substring(8,1).toInteger()= (10-((value.substring(0,1).toInteger() + value.substring(1,1).toInteger()*2 mod 10 + value.substring(1,1).toInteger()*2 div 10 + value.substring(2,1).toInteger() + value.substring(3,1).toInteger()*2 mod 10 + value.substring(3,1).toInteger()*2 div 10 + value.substring(4,1).toInteger() + value.substring(5,1).toInteger()*2 mod 10 + value.substring(5,1).toInteger()*2 div 10 + value.substring(6,1).toInteger() + value.substring(7,1).toInteger()*2 mod 10 + 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.",
        "min": 1
      },
      {
        "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",
        "comment": "PCM-managed reference to the versioned legal Consent policy.",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Consent.policy.authority",
        "path": "Consent.policy.authority",
        "min": 1,
        "fixedUri": "https://www.gov.il/"
      },
      {
        "id": "Consent.policy.uri",
        "path": "Consent.policy.uri",
        "min": 1,
        "fixedUri": "https://pcm.fhir.health.gov.il/consent-policy/medical-information-mobility-law-2024"
      },
      {
        "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.",
        "min": 1
      },
      {
        "id": "Consent.provision.type",
        "path": "Consent.provision.type",
        "min": 1,
        "fixedCode": "permit"
      },
      {
        "id": "Consent.provision.period",
        "path": "Consent.provision.period",
        "comment": "PCM sets this period when the patient approves the Consent. The start is the approval timestamp. The end reflects the effective patient-approved duration and cannot exceed the selected service's accessDuration ceiling. An authorized later patient decision, including an assisted or delegated flow, may shorten the effective period. Proposed and rejected Consent resources have no period."
      },
      {
        "id": "Consent.provision.period.start",
        "path": "Consent.provision.period.start",
        "min": 1
      },
      {
        "id": "Consent.provision.period.end",
        "path": "Consent.provision.period.end",
        "min": 1
      },
      {
        "id": "Consent.provision.actor",
        "path": "Consent.provision.actor",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "role.coding.code"
            }
          ],
          "rules": "open"
        },
        "min": 1
      },
      {
        "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": 1,
        "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:requestor.reference.reference",
        "path": "Consent.provision.actor.reference.reference",
        "min": 1
      },
      {
        "id": "Consent.provision.actor:requestor.reference.identifier",
        "path": "Consent.provision.actor.reference.identifier",
        "max": "0"
      },
      {
        "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.actor:data-source.reference.reference",
        "path": "Consent.provision.actor.reference.reference",
        "min": 1
      },
      {
        "id": "Consent.provision.actor:data-source.reference.identifier",
        "path": "Consent.provision.actor.reference.identifier",
        "max": "0"
      },
      {
        "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"
      }
    ]
  }
}