<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="pcm-consent-submit" />
  <url value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent-submit" />
  <version value="0.3.2" />
  <name value="PCMConsentSubmit" />
  <title value="PCM Consent Submit" />
  <status value="active" />
  <description value="Closed interaction-specific submit profile for a Service Provider consent request. Clients may assert this profile in meta.profile, but PCM validates the interaction shape independently and does not require the declaration. The business-minimal submit data is status=proposed, patient.identifier, and pcmService. scope=patient-privacy, category=INFA, and the fixed legal policy are mandatory request-envelope values." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Consent" />
  <baseDefinition value="http://fhir.health.gov.il/StructureDefinition/il-core-consent" />
  <derivation value="constraint" />
  <differential>
    <element id="Consent.id">
      <path value="Consent.id" />
      <comment value="FHIR create metadata. If supplied, PCM ignores it and assigns the logical id." />
    </element>
    <element id="Consent.meta.versionId">
      <path value="Consent.meta.versionId" />
      <comment value="Server-managed FHIR metadata. Prohibited in client requests." />
      <max value="0" />
    </element>
    <element id="Consent.meta.lastUpdated">
      <path value="Consent.meta.lastUpdated" />
      <comment value="Server-managed FHIR metadata. Prohibited in client requests." />
      <max value="0" />
    </element>
    <element id="Consent.meta.source">
      <path value="Consent.meta.source" />
      <max value="0" />
    </element>
    <element id="Consent.meta.profile">
      <path value="Consent.meta.profile" />
      <comment value="Clients may assert the interaction-specific request profile, but PCM validates the request shape independently and does not require this declaration." />
    </element>
    <element id="Consent.meta.security">
      <path value="Consent.meta.security" />
      <comment value="Prohibited on submit. PCM derives the HTEST security label only from the exact synthetic test-patient identifier." />
      <max value="0" />
    </element>
    <element id="Consent.meta.tag">
      <path value="Consent.meta.tag" />
      <max value="0" />
    </element>
    <element id="Consent.implicitRules">
      <path value="Consent.implicitRules" />
      <max value="0" />
    </element>
    <element id="Consent.language">
      <path value="Consent.language" />
      <max value="0" />
    </element>
    <element id="Consent.text">
      <path value="Consent.text" />
      <max value="0" />
    </element>
    <element id="Consent.contained">
      <path value="Consent.contained" />
      <max value="0" />
    </element>
    <element id="Consent.extension">
      <path value="Consent.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <min value="1" />
    </element>
    <element id="Consent.extension:businessStatus">
      <path value="Consent.extension" />
      <sliceName value="businessStatus" />
      <comment value="Prohibited on submit. PCM derives the authoritative business status." />
      <min value="0" />
      <max value="0" />
      <type>
        <code value="Extension" />
        <profile value="http://pcm.fhir.health.gov.il/StructureDefinition/ext-consent-business-status" />
      </type>
    </element>
    <element id="Consent.extension:pcmService">
      <path value="Consent.extension" />
      <sliceName value="pcmService" />
      <comment value="Required on submit. Reference to the active/usable HealthcareService instance being requested. PCM rejects canonical, inactive, pending, rejected, frozen, suspended, cancelled, or otherwise blocked instances, and also rejects requests when the referenced catalog service is not active/usable." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://pcm.fhir.health.gov.il/StructureDefinition/ext-pcm-service" />
      </type>
    </element>
    <element id="Consent.modifierExtension">
      <path value="Consent.modifierExtension" />
      <max value="0" />
    </element>
    <element id="Consent.identifier">
      <path value="Consent.identifier" />
      <comment value="Omitted on submit. PCM assigns the returned Consent business identifier." />
      <max value="0" />
    </element>
    <element id="Consent.status">
      <path value="Consent.status" />
      <comment value="Required on submit. Consent creation always starts as proposed." />
      <fixedCode value="proposed" />
    </element>
    <element id="Consent.scope">
      <path value="Consent.scope" />
      <comment value="Required fixed value on submit. PCM stores scope=patient-privacy." />
    </element>
    <element id="Consent.scope.coding">
      <path value="Consent.scope.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Consent.scope.coding.system">
      <path value="Consent.scope.coding.system" />
      <min value="1" />
      <fixedUri value="http://terminology.hl7.org/CodeSystem/consentscope" />
    </element>
    <element id="Consent.scope.coding.code">
      <path value="Consent.scope.coding.code" />
      <min value="1" />
      <fixedCode value="patient-privacy" />
    </element>
    <element id="Consent.category">
      <path value="Consent.category" />
      <comment value="Required fixed value on submit. PCM stores category=INFA." />
      <max value="1" />
    </element>
    <element id="Consent.category.coding">
      <path value="Consent.category.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Consent.category.coding.system">
      <path value="Consent.category.coding.system" />
      <min value="1" />
      <fixedUri value="http://terminology.hl7.org/CodeSystem/v3-ActCode" />
    </element>
    <element id="Consent.category.coding.code">
      <path value="Consent.category.coding.code" />
      <min value="1" />
      <fixedCode value="INFA" />
    </element>
    <element id="Consent.patient">
      <path value="Consent.patient" />
      <comment value="Required on submit. Always a logical patient identifier." />
      <min value="1" />
    </element>
    <element id="Consent.patient.reference">
      <path value="Consent.patient.reference" />
      <max value="0" />
    </element>
    <element id="Consent.patient.identifier">
      <path value="Consent.patient.identifier" />
      <min value="1" />
      <constraint>
        <key value="pcm-consent-patient-id-system" />
        <severity value="error" />
        <human value="Consent.patient.identifier must use IL national-id, an allowed passport system, or one of the two exact synthetic test identifiers." />
        <expression value="system = 'http://fhir.health.gov.il/identifier/il-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 value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent-submit" />
      </constraint>
      <constraint>
        <key value="pcm-consent-patient-id-value-trimmed" />
        <severity value="error" />
        <human value="Consent.patient.identifier.value must be non-empty and must not have leading/trailing whitespace." />
        <expression value="value.exists() and value.matches('^\\S(.*\\S)?$')" />
        <source value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent-submit" />
      </constraint>
      <constraint>
        <key value="pcm-consent-patient-il-id-chk" />
        <severity value="error" />
        <human value="If Consent.patient.identifier.system is IL national-id, the value must be 9 digits and pass the Israeli ID check-digit algorithm." />
        <expression value="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 value="http://pcm.fhir.health.gov.il/StructureDefinition/pcm-consent-submit" />
      </constraint>
    </element>
    <element id="Consent.patient.identifier.system">
      <path value="Consent.patient.identifier.system" />
      <min value="1" />
    </element>
    <element id="Consent.patient.identifier.value">
      <path value="Consent.patient.identifier.value" />
      <min value="1" />
    </element>
    <element id="Consent.dateTime">
      <path value="Consent.dateTime" />
      <comment value="Omitted on submit. PCM assigns the creation timestamp." />
      <max value="0" />
    </element>
    <element id="Consent.performer">
      <path value="Consent.performer" />
      <max value="0" />
    </element>
    <element id="Consent.organization">
      <path value="Consent.organization" />
      <max value="0" />
    </element>
    <element id="Consent.source[x]">
      <path value="Consent.source[x]" />
      <max value="0" />
    </element>
    <element id="Consent.source[x]:sourceReference">
      <path value="Consent.source[x]" />
      <sliceName value="sourceReference" />
      <max value="0" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://fhir.health.gov.il/StructureDefinition/il-core-consent" />
        <targetProfile value="http://fhir.health.gov.il/StructureDefinition/il-core-document-reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Contract" />
        <targetProfile value="http://fhir.health.gov.il/StructureDefinition/il-core-questionnaire-response" />
      </type>
    </element>
    <element id="Consent.source[x]:sourceAttachment">
      <path value="Consent.source[x]" />
      <sliceName value="sourceAttachment" />
      <min value="0" />
      <max value="0" />
      <type>
        <code value="Attachment" />
      </type>
    </element>
    <element id="Consent.policy">
      <path value="Consent.policy" />
      <comment value="Required fixed legal policy covered by the Consent request." />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Consent.policy.authority">
      <path value="Consent.policy.authority" />
      <min value="1" />
      <fixedUri value="https://www.gov.il/" />
    </element>
    <element id="Consent.policy.uri">
      <path value="Consent.policy.uri" />
      <min value="1" />
      <fixedUri value="https://pcm.fhir.health.gov.il/consent-policy/medical-information-mobility-law-2024" />
    </element>
    <element id="Consent.policyRule">
      <path value="Consent.policyRule" />
      <max value="0" />
    </element>
    <element id="Consent.verification">
      <path value="Consent.verification" />
      <max value="0" />
    </element>
    <element id="Consent.provision">
      <path value="Consent.provision" />
      <comment value="Omitted on submit. Returned resources carry the server-derived provision." />
      <max value="0" />
    </element>
  </differential>
</StructureDefinition>