{
  "resourceType": "StructureDefinition",
  "id": "pcm-data-access-authorization-contract",
  "url": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract",
  "version": "0.4.2",
  "name": "PCMDataAccessAuthorizationContract",
  "title": "PCM Data Access Authorization Contract",
  "status": "active",
  "description": "Abstract returned-resource shape for a specific data-access grant: one recipient, one workflow permission package, an effective period and an explicit source list. Recipient and permission meaning are fixed at creation; PCM may maintain source membership and cancel the grant. Concrete profiles define supported workflows, participating organizations and restrictions on additional R4 Contract content.",
  "fhirVersion": "4.0.1",
  "kind": "resource",
  "abstract": true,
  "type": "Contract",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Contract",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Contract",
        "path": "Contract",
        "constraint": [
          {
            "key": "pcm-authorization-period",
            "severity": "error",
            "human": "If an authorization grant has an expiry, it SHALL end after it starts.",
            "expression": "applies.end.empty() or applies.start < applies.end",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          },
          {
            "key": "pcm-authorization-terminated-period",
            "severity": "error",
            "human": "A terminated grant SHALL carry its expiry; historical records are not compared to the current time.",
            "expression": "status = 'terminated' implies applies.end.exists()",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          },
          {
            "key": "pcm-authorization-distinct-sources",
            "severity": "error",
            "human": "Each permitted Data Source SHALL occur only once in a Contract.",
            "expression": "term.asset.context.reference.reference.isDistinct()",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          }
        ]
      },
      {
        "id": "Contract.id",
        "path": "Contract.id",
        "min": 1
      },
      {
        "id": "Contract.meta",
        "path": "Contract.meta",
        "min": 1
      },
      {
        "id": "Contract.meta.lastUpdated",
        "path": "Contract.meta.lastUpdated",
        "min": 1
      },
      {
        "id": "Contract.extension",
        "path": "Contract.extension",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "url"
            }
          ],
          "ordered": false,
          "rules": "open"
        }
      },
      {
        "id": "Contract.extension:exampleQuery",
        "path": "Contract.extension",
        "sliceName": "exampleQuery",
        "comment": "Informational query examples only. Authorization follows the normative workflow selected by subType.",
        "min": 0,
        "max": "*",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://pcm.fhir.health.gov.il/StructureDefinition/ext-example-query"
            ]
          }
        ]
      },
      {
        "id": "Contract.identifier",
        "path": "Contract.identifier",
        "comment": "PCM-assigned immutable grant identity. Source-list changes and cancellation retain the identity; replacement uses a new identifier. Token requests select it by exact system/value, never by caller-supplied grant content.",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.identifier.use",
        "path": "Contract.identifier.use",
        "min": 1,
        "fixedCode": "official"
      },
      {
        "id": "Contract.identifier.system",
        "path": "Contract.identifier.system",
        "min": 1,
        "fixedUri": "http://pcm.fhir.health.gov.il/identifier/pcm-data-access-authorization-id"
      },
      {
        "id": "Contract.identifier.value",
        "path": "Contract.identifier.value",
        "min": 1
      },
      {
        "id": "Contract.status",
        "path": "Contract.status",
        "comment": "Executed means the grant has been formally established. Only executed grants can authorize, subject to the period and current dependencies. Terminated means expired; revoked means intentionally withdrawn; entered-in-error means created erroneously. These three states are terminal. Dependency suspension does not change the Contract status.",
        "min": 1,
        "binding": {
          "strength": "required",
          "valueSet": "http://pcm.fhir.health.gov.il/ValueSet/pcm-authorization-status"
        }
      },
      {
        "id": "Contract.instantiatesUri",
        "path": "Contract.instantiatesUri",
        "comment": "Optional URI of the governing external policy or agreement definition. Multiple grants may adhere to the same definition; it is not the grant identity or a source-membership selector."
      },
      {
        "id": "Contract.issued",
        "path": "Contract.issued",
        "min": 1,
        "constraint": [
          {
            "key": "pcm-authorization-timestamp",
            "severity": "error",
            "human": "Authorization grant issuance and any validity dates SHALL include a full date, hours, minutes, seconds and timezone.",
            "expression": "toString().matches('^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          }
        ]
      },
      {
        "id": "Contract.applies",
        "path": "Contract.applies",
        "comment": "Start and any end are full timestamps with seconds and timezone; both Period boundaries are inclusive. An absent end means ongoing. PCM checks applicability even before a stored status changes to terminated and bounds token expiry by end when present. Start is fixed at creation; PCM may shorten end, but extending validity requires a new grant.",
        "min": 1
      },
      {
        "id": "Contract.applies.start",
        "path": "Contract.applies.start",
        "min": 1,
        "constraint": [
          {
            "key": "pcm-authorization-timestamp",
            "severity": "error",
            "human": "Authorization grant issuance and any validity dates SHALL include a full date, hours, minutes, seconds and timezone.",
            "expression": "toString().matches('^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          }
        ]
      },
      {
        "id": "Contract.applies.end",
        "path": "Contract.applies.end",
        "constraint": [
          {
            "key": "pcm-authorization-timestamp",
            "severity": "error",
            "human": "Authorization grant issuance and any validity dates SHALL include a full date, hours, minutes, seconds and timezone.",
            "expression": "toString().matches('^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          }
        ]
      },
      {
        "id": "Contract.author",
        "path": "Contract.author",
        "comment": "Organization issuing the grant. This is distinct from its recipient and any governing law or commercial agreement.",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Organization"
            ]
          }
        ],
        "constraint": [
          {
            "key": "pcm-authorization-organization-reference",
            "severity": "error",
            "human": "Grant organizations SHALL use a relative Organization reference at the PCM FHIR base.",
            "expression": "reference.matches('^Organization/[A-Za-z0-9.-]{1,64}$')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          }
        ]
      },
      {
        "id": "Contract.author.reference",
        "path": "Contract.author.reference",
        "min": 1
      },
      {
        "id": "Contract.author.identifier",
        "path": "Contract.author.identifier",
        "max": "0"
      },
      {
        "id": "Contract.type",
        "path": "Contract.type",
        "min": 1,
        "patternCodeableConcept": {
          "coding": [
            {
              "code": "data-access-authorization",
              "system": "http://pcm.fhir.health.gov.il/cs/pcm-authorization-vocabulary"
            }
          ]
        },
        "binding": {
          "strength": "required",
          "valueSet": "http://pcm.fhir.health.gov.il/ValueSet/pcm-authorization-type"
        }
      },
      {
        "id": "Contract.type.coding",
        "path": "Contract.type.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.subType",
        "path": "Contract.subType",
        "comment": "Immutable workflow classification selecting one complete permission package. Concrete profiles define its supported codes and normative scope/disclosure rules. Narrative and example queries do not grant permissions. A material change to permission meaning requires a new grant.",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.subType.coding",
        "path": "Contract.subType.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.subType.coding.system",
        "path": "Contract.subType.coding.system",
        "min": 1
      },
      {
        "id": "Contract.subType.coding.code",
        "path": "Contract.subType.coding.code",
        "min": 1
      },
      {
        "id": "Contract.term",
        "path": "Contract.term",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.term.offer.party",
        "path": "Contract.term.offer.party",
        "comment": "One recipient organization, fixed at creation. PCM SHALL separately entitle each client application to the grant workflow; organization membership alone is insufficient. A different recipient requires a new grant.",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.term.offer.party.reference",
        "path": "Contract.term.offer.party.reference",
        "max": "1",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://hl7.org/fhir/StructureDefinition/Organization"
            ]
          }
        ],
        "constraint": [
          {
            "key": "pcm-authorization-organization-reference",
            "severity": "error",
            "human": "Grant organizations SHALL use a relative Organization reference at the PCM FHIR base.",
            "expression": "reference.matches('^Organization/[A-Za-z0-9.-]{1,64}$')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          }
        ]
      },
      {
        "id": "Contract.term.offer.party.reference.reference",
        "path": "Contract.term.offer.party.reference.reference",
        "min": 1
      },
      {
        "id": "Contract.term.offer.party.reference.identifier",
        "path": "Contract.term.offer.party.reference.identifier",
        "max": "0"
      },
      {
        "id": "Contract.term.offer.party.role",
        "path": "Contract.term.offer.party.role",
        "patternCodeableConcept": {
          "coding": [
            {
              "code": "grantee",
              "system": "http://pcm.fhir.health.gov.il/cs/pcm-authorization-vocabulary"
            }
          ]
        }
      },
      {
        "id": "Contract.term.offer.party.role.coding",
        "path": "Contract.term.offer.party.role.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.term.asset",
        "path": "Contract.term.asset",
        "short": "Workflow-defined data held by one permitted source",
        "comment": "One entry per permitted Data Source, with no duplicates. PCM may add/remove entries under the governing arrangement while retaining this Contract identity. No entries means no source access, never all sources. Membership is independent of current source availability. Each token still has one exact Endpoint.address audience."
      },
      {
        "id": "Contract.term.asset.context",
        "path": "Contract.term.asset.context",
        "min": 1,
        "max": "1"
      },
      {
        "id": "Contract.term.asset.context.reference",
        "path": "Contract.term.asset.context.reference",
        "comment": "The Data Source organization holding the workflow-defined data. Issuance and introspection require current membership and eligible source, parent Organization, Endpoint state. Workflow prerequisites may further narrow access.",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-organization-source"
            ]
          }
        ],
        "constraint": [
          {
            "key": "pcm-authorization-organization-reference",
            "severity": "error",
            "human": "Grant organizations SHALL use a relative Organization reference at the PCM FHIR base.",
            "expression": "reference.matches('^Organization/[A-Za-z0-9.-]{1,64}$')",
            "source": "http://pcm.fhir.health.gov.il/StructureDefinition/pcm-data-access-authorization-contract"
          }
        ]
      },
      {
        "id": "Contract.term.asset.context.reference.reference",
        "path": "Contract.term.asset.context.reference.reference",
        "min": 1
      },
      {
        "id": "Contract.term.asset.context.reference.identifier",
        "path": "Contract.term.asset.context.reference.identifier",
        "max": "0"
      }
    ]
  }
}