<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="KT2DeletePendingTask" />
  <language value="nl-NL" />
  <url value="http://koppeltaal.nl/fhir/StructureDefinition/KT2DeletePendingTask" />
  <version value="0.1.0" />
  <name value="KT2_DeletePendingTask" />
  <status value="draft" />
  <date value="2026-07-09" />
  <publisher value="VZVZ" />
  <contact>
    <name value="VZVZ" />
    <telecom>
      <system value="email" />
      <value value="standaardisatie@vzvz.nl" />
      <use value="work" />
    </telecom>
  </contact>
  <description value="The KT2_DeletePendingTask profile represents the announcement that a patient's data within the Koppeltaal service is scheduled for definitive deletion. When the grace period starts, the Koppeltaal service creates one Task per (Patient × participating application); the Task is server-owned but readable by participating applications and carries the server-owned `kt2-delete-flow` security label (`meta.security`). The target application responds through the native Task lifecycle: `on-hold` as a temporary emergency brake and `accepted` as green light. The Task resides in the Patient compartment and is removed together with the Patient. See the page Opschoning Patient-data." />
  <jurisdiction>
    <coding>
      <system value="urn:iso:std:iso:3166" />
      <code value="NL" />
      <display value="Netherlands" />
    </coding>
  </jurisdiction>
  <copyright value="VZVZ" />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Task" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Task" />
  <derivation value="constraint" />
  <differential>
    <element id="Task">
      <path value="Task" />
      <constraint>
        <key value="kt2-dpt-status-reason" />
        <severity value="error" />
        <human value="statusReason is mandatory when status is on-hold and must be absent for every other status" />
        <expression value="(status = 'on-hold' implies statusReason.exists()) and (statusReason.exists() implies status = 'on-hold')" />
        <source value="http://koppeltaal.nl/fhir/StructureDefinition/KT2DeletePendingTask" />
      </constraint>
      <constraint>
        <key value="kt2-dpt-delete-flow-marker" />
        <severity value="error" />
        <human value="The Task must carry the server-owned kt2-delete-flow security label, because that marker is what grants applications access to the deletion flow" />
        <expression value="meta.security.where(system = 'http://vzvz.nl/fhir/CodeSystem/koppeltaal-security-label' and code = 'kt2-delete-flow').exists()" />
        <source value="http://koppeltaal.nl/fhir/StructureDefinition/KT2DeletePendingTask" />
      </constraint>
      <constraint>
        <key value="kt2-dpt-grace-deadline" />
        <severity value="error" />
        <human value="The grace deadline must lie after the announcement, since the grace period starts at authoredOn" />
        <expression value="restriction.period.end &gt; authoredOn" />
        <source value="http://koppeltaal.nl/fhir/StructureDefinition/KT2DeletePendingTask" />
      </constraint>
    </element>
    <element id="Task.extension">
      <path value="Task.extension" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="url" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
    </element>
    <element id="Task.extension:resource-origin">
      <path value="Task.extension" />
      <sliceName value="resource-origin" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Extension" />
        <profile value="http://koppeltaal.nl/fhir/StructureDefinition/resource-origin" />
      </type>
    </element>
    <element id="Task.instantiatesUri">
      <path value="Task.instantiatesUri" />
      <max value="0" />
    </element>
    <element id="Task.basedOn">
      <path value="Task.basedOn" />
      <max value="0" />
    </element>
    <element id="Task.groupIdentifier">
      <path value="Task.groupIdentifier" />
      <max value="0" />
    </element>
    <element id="Task.status">
      <path value="Task.status" />
      <comment value="Native Task lifecycle. The Koppeltaal service sets `requested` (announcement), `cancelled` (renewed patient engagement) and `completed` (deletion executed). The target application only sets `on-hold` (temporary emergency brake) or `accepted` (green light); the server validates every transition." />
      <binding>
        <strength value="required" />
        <valueSet value="http://vzvz.nl/fhir/ValueSet/koppeltaal-delete-pending-task-status" />
      </binding>
    </element>
    <element id="Task.statusReason">
      <path value="Task.statusReason" />
      <short value="Reason for the emergency brake when `status = on-hold`" />
      <comment value="Coded, from a closed list; `text` is closed off so the reason itself is not a free-text field. It must not be used to convey demographics. Set by the target application in the status write to `on-hold`; the server clears it when `on-hold` is left. The reason lives on the Task only (per application) and is not carried in the aggregated deletion lifecycle AuditEvents." />
      <binding>
        <strength value="required" />
        <valueSet value="http://vzvz.nl/fhir/ValueSet/koppeltaal-delete-hold-reason" />
      </binding>
    </element>
    <element id="Task.statusReason.coding">
      <path value="Task.statusReason.coding" />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Task.statusReason.coding.display">
      <path value="Task.statusReason.coding.display" />
      <short value="Human-readable description of the emergency-brake reason" />
    </element>
    <element id="Task.statusReason.text">
      <path value="Task.statusReason.text" />
      <max value="0" />
    </element>
    <element id="Task.businessStatus">
      <path value="Task.businessStatus" />
      <max value="0" />
    </element>
    <element id="Task.intent">
      <path value="Task.intent" />
      <fixedCode value="order" />
    </element>
    <element id="Task.code">
      <path value="Task.code" />
      <short value="Type of the announcement Task" />
      <min value="1" />
      <patternCodeableConcept>
        <coding>
          <system value="http://vzvz.nl/fhir/CodeSystem/koppeltaal-task-code" />
          <code value="delete-pending" />
        </coding>
      </patternCodeableConcept>
      <binding>
        <strength value="required" />
        <valueSet value="http://vzvz.nl/fhir/ValueSet/koppeltaal-task-code" />
      </binding>
    </element>
    <element id="Task.description">
      <path value="Task.description" />
      <max value="0" />
    </element>
    <element id="Task.focus">
      <path value="Task.focus" />
      <max value="0" />
    </element>
    <element id="Task.for">
      <path value="Task.for" />
      <short value="The Patient whose data is scheduled for deletion" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://koppeltaal.nl/fhir/StructureDefinition/KT2Patient" />
      </type>
    </element>
    <element id="Task.encounter">
      <path value="Task.encounter" />
      <max value="0" />
    </element>
    <element id="Task.authoredOn">
      <path value="Task.authoredOn" />
      <short value="Moment of the announcement; the grace period starts here" />
      <min value="1" />
    </element>
    <element id="Task.requester">
      <path value="Task.requester" />
      <short value="The Koppeltaal service announcing the deletion" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://koppeltaal.nl/fhir/StructureDefinition/KT2Device" />
      </type>
    </element>
    <element id="Task.performerType">
      <path value="Task.performerType" />
      <max value="0" />
    </element>
    <element id="Task.owner">
      <path value="Task.owner" />
      <short value="The target application this announcement is directed at" />
      <comment value="Always a Device. Never the Patient or a RelatedPerson, because a Task owned by the patient counts as patient engagement and would reset the retention clock." />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://koppeltaal.nl/fhir/StructureDefinition/KT2Device" />
      </type>
    </element>
    <element id="Task.location">
      <path value="Task.location" />
      <max value="0" />
    </element>
    <element id="Task.reasonCode">
      <path value="Task.reasonCode" />
      <max value="0" />
    </element>
    <element id="Task.reasonReference">
      <path value="Task.reasonReference" />
      <max value="0" />
    </element>
    <element id="Task.insurance">
      <path value="Task.insurance" />
      <max value="0" />
    </element>
    <element id="Task.note">
      <path value="Task.note" />
      <max value="0" />
    </element>
    <element id="Task.relevantHistory">
      <path value="Task.relevantHistory" />
      <max value="0" />
    </element>
    <element id="Task.restriction">
      <path value="Task.restriction" />
      <min value="1" />
    </element>
    <element id="Task.restriction.period">
      <path value="Task.restriction.period" />
      <min value="1" />
    </element>
    <element id="Task.restriction.period.end">
      <path value="Task.restriction.period.end" />
      <short value="Grace deadline: the planned moment of definitive deletion" />
      <comment value="Server-managed: on a grace reset the Koppeltaal service sets a new deadline; applications never modify this element." />
      <min value="1" />
    </element>
    <element id="Task.input">
      <path value="Task.input" />
      <max value="0" />
    </element>
    <element id="Task.output">
      <path value="Task.output" />
      <max value="0" />
    </element>
  </differential>
</StructureDefinition>