{
  "resourceType": "StructureDefinition",
  "id": "tasktriggeredcommunicationtemplate-profile",
  "url": "http://fhir.xt.dev/StructureDefinition/TaskTriggeredCommunicationTemplate",
  "version": "1.0.0",
  "name": "TaskTriggeredCommunicationTemplate",
  "status": "active",
  "date": "2026-05-20T11:56:26.2350821+00:00",
  "publisher": "x-tention Informationstechnologie GmbH",
  "contact": [
    {
      "telecom": [
        {
          "system": "email",
          "value": "fhir.profiling@x-tention.com",
          "use": "work"
        }
      ]
    }
  ],
  "description": "The template for a planned communication, automatically triggered by changes in data. The communication is usually a structured interaction modeled as a Task, but might also be a more conventional message. This type of communication template is triggered by a completed Task.",
  "copyright": "x-tention Informationstechnologie GmbH",
  "fhirVersion": "4.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "CommunicationRequest",
  "baseDefinition": "http://fhir.xt.dev/StructureDefinition/BaseCommunicationTemplate",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "CommunicationRequest.basedOn",
        "path": "CommunicationRequest.basedOn",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "type"
            },
            {
              "type": "value",
              "path": "identifier.type.coding.system"
            },
            {
              "type": "value",
              "path": "identifier.type.coding.code"
            }
          ],
          "rules": "closed"
        },
        "min": 1
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri",
        "path": "CommunicationRequest.basedOn",
        "sliceName": "workflowUri",
        "min": 1
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.extension:questionnaireResponseItemFilter",
        "path": "CommunicationRequest.basedOn.extension",
        "sliceName": "questionnaireResponseItemFilter",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://fhir.xt.dev/StructureDefinition/QuestionnaireResponseItemFilter"
            ]
          }
        ],
        "isModifier": false
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.type",
        "path": "CommunicationRequest.basedOn.type",
        "min": 1,
        "fixedUri": "CommunicationRequest"
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier",
        "path": "CommunicationRequest.basedOn.identifier",
        "min": 1
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.type",
        "path": "CommunicationRequest.basedOn.identifier.type",
        "min": 1
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.type.coding",
        "path": "CommunicationRequest.basedOn.identifier.type.coding",
        "min": 1,
        "max": "1"
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.type.coding.system",
        "path": "CommunicationRequest.basedOn.identifier.type.coding.system",
        "min": 1,
        "fixedUri": "http://fhir.xt.dev/CodeSystem/IdentifierType"
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.type.coding.version",
        "path": "CommunicationRequest.basedOn.identifier.type.coding.version",
        "max": "0"
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.type.coding.code",
        "path": "CommunicationRequest.basedOn.identifier.type.coding.code",
        "min": 1,
        "fixedCode": "WRKU"
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.type.coding.userSelected",
        "path": "CommunicationRequest.basedOn.identifier.type.coding.userSelected",
        "max": "0"
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.system",
        "path": "CommunicationRequest.basedOn.identifier.system",
        "min": 1,
        "fixedUri": "urn:ietf:rfc:3986"
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.value",
        "path": "CommunicationRequest.basedOn.identifier.value",
        "min": 1
      },
      {
        "id": "CommunicationRequest.basedOn:workflowUri.identifier.period",
        "path": "CommunicationRequest.basedOn.identifier.period",
        "max": "0"
      },
      {
        "id": "CommunicationRequest.category.coding.system",
        "path": "CommunicationRequest.category.coding.system",
        "fixedUri": "http://fhir.xt.dev/CodeSystem/CommunicationTemplateCategory"
      },
      {
        "id": "CommunicationRequest.category.coding.code",
        "path": "CommunicationRequest.category.coding.code",
        "fixedCode": "TaskCompletion"
      },
      {
        "id": "CommunicationRequest.occurrence[x].extension:startTiming",
        "path": "CommunicationRequest.occurrence[x].extension",
        "sliceName": "startTiming"
      },
      {
        "id": "CommunicationRequest.occurrence[x].extension:startTiming.extension:eventCode",
        "path": "CommunicationRequest.occurrence[x].extension.extension",
        "sliceName": "eventCode"
      },
      {
        "id": "CommunicationRequest.occurrence[x].extension:startTiming.extension:eventCode.value[x].code",
        "path": "CommunicationRequest.occurrence[x].extension.extension.value[x].code",
        "constraint": [
          {
            "key": "tt-commtemplate-1",
            "severity": "error",
            "human": "The eventCode must be task-based",
            "expression": "$this.exists() and ($this = 'afterTaskCompleted' or $this = 'afterTaskDue' or $this = 'beforeTaskDue')"
          }
        ]
      },
      {
        "id": "CommunicationRequest.occurrence[x].extension:dueDateTiming",
        "path": "CommunicationRequest.occurrence[x].extension",
        "sliceName": "dueDateTiming"
      },
      {
        "id": "CommunicationRequest.occurrence[x].extension:dueDateTiming.extension:eventCode",
        "path": "CommunicationRequest.occurrence[x].extension.extension",
        "sliceName": "eventCode"
      },
      {
        "id": "CommunicationRequest.occurrence[x].extension:dueDateTiming.extension:eventCode.value[x].code",
        "path": "CommunicationRequest.occurrence[x].extension.extension.value[x].code",
        "constraint": [
          {
            "key": "tt-commtemplate-2",
            "severity": "error",
            "human": "The eventCode must be task-based",
            "expression": "$this.exists() and ($this = 'afterTaskCompleted' or $this = 'afterTaskDue' or $this = 'beforeTaskDue')"
          }
        ]
      }
    ]
  }
}