<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="DataStandardsWales-PSOM-Task" />
  <url value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-PSOM-Task" />
  <name value="DataStandardsWalesPSOMTask" />
  <title value="Data Standards Wales PSOM Task" />
  <status value="active" />
  <publisher value="NHS Wales" />
  <contact>
    <name value="Data Standards" />
    <telecom>
      <system value="email" />
      <value value="data.standards@wales.nhs.uk" />
      <use value="work" />
    </telecom>
  </contact>
  <description value="Defines how a Task is used to ask for a Questionnaire to be completed. Each Task represents one PROMs Tool within a Collection Event.&#xD;&#xA;&#xD;&#xA;This profile is heavily influenced by the [SDCTaskQuestionnaire](http://hl7.org/fhir/uv/sdc/STU3/StructureDefinition-sdc-task.profile.json.html)." />
  <copyright value="© 2023 NHS Wales." />
  <fhirVersion value="4.0.1" />
  <mapping>
    <identity value="PROMs-Metadata-2024004" />
    <name value="NHS Wales DSCN Metadata Mapping" />
  </mapping>
  <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="PSOM-Task-01" />
        <severity value="error" />
        <human value="If the Task contains a questionnaire response, the completion date SHALL be provided." />
        <expression value="output.where(type.coding.system = 'http://hl7.org/fhir/uv/sdc/CodeSystem/temp' and type.coding.code = 'questionnaire-response').exists() implies executionPeriod.end.exists()" />
      </constraint>
    </element>
    <element id="Task.status">
      <path value="Task.status" />
      <comment value="In interactions between the Health Board and the PROMs provider, the Task uses the following statuses:&#xA;&#xA;* Requesting PROMs collection = _requested_&#xD;&#xA;* Providing PROMs collection = _accepted_ | _in-progress_ | _completed_&#xA;* Cancelling PROMs collection = _ cancelled_" />
    </element>
    <element id="Task.intent">
      <path value="Task.intent" />
      <comment value="In interactions between the Health Board and the PROMs provider, the Task intent is fixed as:&#xD;&#xA;&#xD;&#xA;* Requesting PROMs collection = _order_ &#xD;&#xA;* Providing PROMs collection = _order_&#xA;* Cancelling PROMs collection = _ order_" />
    </element>
    <element id="Task.code">
      <path value="Task.code" />
      <min value="1" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/uv/sdc/CodeSystem/temp" />
          <code value="complete-questionnaire" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="Task.focus">
      <path value="Task.focus" />
      <comment value="For referencing the CarePlan, the `.basedOn` or `.focus` element could be used. The SDC IG adopts the latter approach.  However, in our use case it is discouraged to use this element to refer to the CarePlan because `CarePlan.activity` already contains a reference to the Task. This would lead to a circular reference which could potentially lead to issues when updating or deleting resources." />
    </element>
    <element id="Task.executionPeriod">
      <path value="Task.executionPeriod" />
      <min value="1" />
    </element>
    <element id="Task.executionPeriod.start">
      <path value="Task.executionPeriod.start" />
      <short value="PROMs Issued Date" />
      <definition value="The date and time the PROMs form was issued to the patient. This is populated by the PROMs platform." />
      <min value="1" />
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX002X" />
        <comment value="PROMs Issued Date" />
      </mapping>
    </element>
    <element id="Task.executionPeriod.end">
      <path value="Task.executionPeriod.end" />
      <short value="PROMs Completion Date &amp; Time" />
      <definition value="The date and time the PROMs form was completed (or when the last item was recorded for incomplete records). If only the date component is captured, this can be provided without a time component. This is populated by the PROMs platform." />
      <condition value="PSOM-Task-01" />
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX003X" />
        <comment value="PROMs Completion Date &amp; Time" />
      </mapping>
    </element>
    <element id="Task.location">
      <path value="Task.location" />
      <short value="Event Location Code" />
      <definition value="The code of the site where the PROMs form was initiated. This is populated by the Health Board system." />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-Location" />
      </type>
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX001X" />
        <comment value="Event Location Code (implicit, main mapping is on Location.identifier)" />
      </mapping>
    </element>
    <element id="Task.reasonCode">
      <path value="Task.reasonCode" />
      <short value="PROMs Trigger Event Type" />
      <definition value="The national code representing the type of healthcare or administrative event that triggers a requirement for a questionnaire (or onboarding process) to be completed." />
      <min value="1" />
      <binding>
        <strength value="extensible" />
        <valueSet value="https://fhir.nhs.wales/ValueSet/DataStandardsWales-PSOM-TriggerEventType" />
      </binding>
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX007X" />
        <comment value="PROMs Trigger Event Type" />
      </mapping>
    </element>
    <element id="Task.input">
      <path value="Task.input" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="type" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <definition value="Additional information that may be needed in the execution of the Task populated by the Health Board." />
      <min value="2" />
    </element>
    <element id="Task.input:promsTriggerEventDate">
      <path value="Task.input" />
      <sliceName value="promsTriggerEventDate" />
      <definition value="Indicates the date of the event that triggers a requirement for a questionnaire (or onboarding process) to be completed, irrespective of the date that the PROMs form was triggered/issued." />
      <comment value="Mandatory for healthcare pathway activity-based event types, e.g. referrals, outpatient appointments, interventions, etc. (i.e. not mandatory for event types not directly resulting from these, such as clinician or patient initiated event types)." />
      <max value="1" />
    </element>
    <element id="Task.input:promsTriggerEventDate.type">
      <path value="Task.input.type" />
      <patternCodeableConcept>
        <coding>
          <system value="https://fhir.nhs.wales/CodeSystem/DataStandardsWales-PSOM-TaskInputType" />
          <code value="MPRPX013X" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="Task.input:promsTriggerEventDate.value[x]">
      <path value="Task.input.value[x]" />
      <short value="PROMs Trigger Event Date" />
      <definition value="The date of the event that triggers a requirement for a questionnaire (or onboarding process) to be completed, irrespective of the date that the PROMs form was triggered/issued." />
      <type>
        <code value="dateTime" />
      </type>
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX013X" />
        <comment value="PROMs Trigger Event Date" />
      </mapping>
    </element>
    <element id="Task.input:promsLaterality">
      <path value="Task.input" />
      <sliceName value="promsLaterality" />
      <definition value="Indicates the anatomical side associated with the questionnaire being completed." />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Task.input:promsLaterality.type">
      <path value="Task.input.type" />
      <patternCodeableConcept>
        <coding>
          <system value="https://fhir.nhs.wales/CodeSystem/DataStandardsWales-PSOM-TaskInputType" />
          <code value="MDEPX004X" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="Task.input:promsLaterality.value[x]">
      <path value="Task.input.value[x]" />
      <short value="PROMs Laterality" />
      <definition value="The anatomical side associated with the questionnaire being completed." />
      <comment value="Note that if a patient completes a questionnaire for both left and right sides, two records should be generated and labelled as per the specified value set. Note also that this item is intended to capture the laterality specified as part of the patient’s PROMs pathway record as opposed to any patient reported laterality information which would be captured within the form itself." />
      <type>
        <code value="CodeableConcept" />
      </type>
      <binding>
        <strength value="required" />
        <description value="Identifies the laterality" />
        <valueSet value="https://fhir.nhs.wales/ValueSet/DataStandardsWales-PSOM-PROMsLaterality" />
      </binding>
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MDEPX004X" />
        <comment value="PROMs Laterality" />
      </mapping>
    </element>
    <element id="Task.input:questionnaire">
      <path value="Task.input" />
      <sliceName value="questionnaire" />
      <definition value="Indicates the questionnaire to be completed." />
      <min value="1" />
      <max value="1" />
    </element>
    <element id="Task.input:questionnaire.type">
      <path value="Task.input.type" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/uv/sdc/CodeSystem/temp" />
          <code value="questionnaire" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="Task.input:questionnaire.value[x]">
      <path value="Task.input.value[x]" />
      <short value="(Local) PROMs Tool" />
      <definition value="The Questionnaire that is requested to be filled in. A reference to the canonical identifier including the `.version` (MPRPX012X) of the PROMs Tool SHALL be implemented, to specify the correct version." />
      <type>
        <code value="canonical" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-Questionnaire" />
        <!-- DataStandardsWales-Questionnaire profile does not contain any constraints.-->
      </type>
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX006X" />
        <comment value="PROMs Tool (implicit, main mapping is on Questionnaire.url)" />
      </mapping>
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX010X" />
        <comment value="Local PROMs Tool (implicit, main mapping is on Questionnaire.url)" />
      </mapping>
      <mapping>
        <identity value="PROMs-Metadata-2024004" />
        <map value="MPRPX012X" />
        <comment value="PROMs Data Standard Version (implicit, main mapping is on Questionnaire.version)" />
      </mapping>
    </element>
    <element id="Task.input:responseEndpoint">
      <path value="Task.input" />
      <sliceName value="responseEndpoint" />
      <definition value="Indicates an endpoint the form should be posted to on completion." />
    </element>
    <element id="Task.input:responseEndpoint.type">
      <path value="Task.input.type" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/uv/sdc/CodeSystem/temp" />
          <code value="response-endpoint" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="Task.input:responseEndpoint.value[x]">
      <path value="Task.input.value[x]" />
      <type>
        <code value="url" />
      </type>
    </element>
    <element id="Task.output">
      <path value="Task.output" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="type" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <definition value="Outputs produced by the Task populated by the PROMs platform." />
    </element>
    <element id="Task.output:response">
      <path value="Task.output" />
      <sliceName value="response" />
      <max value="1" />
      <condition value="PSOM-Task-01" />
    </element>
    <element id="Task.output:response.type">
      <path value="Task.output.type" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/uv/sdc/CodeSystem/temp" />
          <code value="questionnaire-response" />
        </coding>
      </patternCodeableConcept>
    </element>
    <element id="Task.output:response.value[x]">
      <path value="Task.output.value[x]" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://fhir.nhs.wales/StructureDefinition/DataStandardsWales-PSOM-QuestionnaireResponse" />
      </type>
    </element>
  </differential>
</StructureDefinition>