<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="hrex-task-data-request" />
  <url value="http://hl7.org/fhir/us/davinci-hrex/StructureDefinition/hrex-task-data-request" />
  <version value="0.2.0" />
  <name value="HRexTaskDataRequest" />
  <title value="HRex Task Data Request Profile" />
  <status value="active" />
  <experimental value="false" />
  <date value="2020-09-11T05:25:14+00:00" />
  <publisher value="HL7 International - Clinical Interoperability Council" />
  <contact>
    <telecom>
      <system value="url" />
      <value value="http://www.hl7.org/Special/committees/cic" />
    </telecom>
  </contact>
  <description value="This Task profile is used to solicit information from a system when direct query is not possible and human intervention might be required" />
  <jurisdiction>
    <coding>
      <system value="urn:iso:std:iso:3166" />
      <code value="US" />
    </coding>
  </jurisdiction>
  <fhirVersion value="4.0.1" />
  <mapping>
    <identity value="workflow" />
    <uri value="http://hl7.org/fhir/workflow" />
    <name value="Workflow Pattern" />
  </mapping>
  <mapping>
    <identity value="rim" />
    <uri value="http://hl7.org/v3" />
    <name value="RIM Mapping" />
  </mapping>
  <mapping>
    <identity value="w5" />
    <uri value="http://hl7.org/fhir/fivews" />
    <name value="FiveWs Pattern Mapping" />
  </mapping>
  <mapping>
    <identity value="v2" />
    <uri value="http://hl7.org/v2" />
    <name value="HL7 v2 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" />
      <definition value="This Task profile is used to solicit information from a system when direct query is not possible and human intervention might be required" />
      <constraint>
        <key value="tdr-1" />
        <severity value="error" />
        <human value="Must have exactly one input that is data-query or data-code" />
        <expression value="input.type.where(coding.where(system='http://hl7.org/fhir/us/davinci-hrex/CodeSystem/hrex-temp' and (code='data-code' or code='data-query')).exists()).count()=1" />
      </constraint>
      <constraint>
        <key value="tdr-2" />
        <severity value="error" />
        <human value="Task statusReason SHALL be populated if status is 'rejected' or 'failed'" />
        <expression value="(status = 'rejected' or status = 'failed') implies statusReason.exists()" />
      </constraint>
      <constraint>
        <key value="tdr-3" />
        <severity value="error" />
        <human value="Task output SHALL be populated if status is 'completed'" />
        <expression value="(status = 'completed') implies output.exists()" />
      </constraint>
    </element>
    <element id="Task.basedOn">
      <path value="Task.basedOn" />
      <short value="Also known as Member identifier" />
      <requirements value="Indicates the order (ServiceRequest, CommunicationRequest, etc.) that authorizes the data request" />
      <mustSupport value="true" />
    </element>
    <element id="Task.status">
      <path value="Task.status" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="http://hl7.org/fhir/us/davinci-hrex/ValueSet/hrex-task-status" />
      </binding>
    </element>
    <element id="Task.statusReason">
      <path value="Task.statusReason" />
      <requirements value="Indicates why task failed or was rejected." />
      <mustSupport value="true" />
    </element>
    <element id="Task.statusReason.text">
      <path value="Task.statusReason.text" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.businessStatus">
      <path value="Task.businessStatus" />
      <short value="E.g. 'waiting on internal review'" />
      <comment value="Conveys the internal business progress of the request and provides more nuance than the overall status.  There is no expectation this will be coded, but negotiation of agreed codes can be used between partners" />
      <requirements value="Indicates progress in retrieving the data" />
      <mustSupport value="true" />
    </element>
    <element id="Task.businessStatus.text">
      <path value="Task.businessStatus.text" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.intent">
      <path value="Task.intent" />
      <fixedCode value="order" />
      <mustSupport value="true" />
    </element>
    <element id="Task.code">
      <path value="Task.code" />
      <min value="1" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/us/davinci-hrex/CodeSystem/hrex-temp" />
          <code value="data-request" />
        </coding>
      </patternCodeableConcept>
      <mustSupport value="true" />
    </element>
    <element id="Task.for">
      <path value="Task.for" />
      <short value="Member being queried" />
      <comment value="Queries must always be in the scope of a single member" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.authoredOn">
      <path value="Task.authoredOn" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.requester">
      <path value="Task.requester" />
      <short value="Who is asking for data" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/us/core/StructureDefinition/us-core-organization" />
        <targetProfile value="http://hl7.org/fhir/us/core/StructureDefinition/us-core-practitioner" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.owner">
      <path value="Task.owner" />
      <short value="Who is being asked for data" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/us/core/StructureDefinition/us-core-organization" />
        <targetProfile value="http://hl7.org/fhir/us/core/StructureDefinition/us-core-practitioner" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.reasonCode">
      <path value="Task.reasonCode" />
      <comment value="Only text is expected, though codes can be used for partners with agreed value sets" />
      <requirements value="Indicates why the information request is occurring" />
      <mustSupport value="true" />
    </element>
    <element id="Task.reasonCode.text">
      <path value="Task.reasonCode.text" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.reasonReference">
      <path value="Task.reasonReference" />
      <comment value="Likely targets would be HRex Coverage, PCDE Claim (for prior authorization) or a bare Claim resource for referencing an actual Claim." />
      <requirements value="Indicates why the information request is occurring" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Claim" />
        <targetProfile value="http://hl7.org/fhir/us/davinci-hrex/StructureDefinition/hrex-coverage" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.input">
      <path value="Task.input" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="type" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.input:query">
      <path value="Task.input" />
      <sliceName value="query" />
      <short value="Requested query" />
      <definition value="Indicates the specific FHIR RESTful query to be executed" />
      <comment value="This will contain the text that should go after the '?' when executing the query." />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.input:query.type">
      <path value="Task.input.type" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/us/davinci-hrex/CodeSystem/hrex-temp" />
          <code value="data-query" />
        </coding>
      </patternCodeableConcept>
      <mustSupport value="true" />
    </element>
    <element id="Task.input:query.value[x]">
      <path value="Task.input.value[x]" />
      <short value="query value" />
      <type>
        <code value="string" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.input:code">
      <path value="Task.input" />
      <sliceName value="code" />
      <short value="Requested data code" />
      <definition value="A code indicating the type of data/document to be returned" />
      <comment value="This might be a document code or other code describing the requested information.  If no appropriate standard code exists, local codes may be used between partners, or a human-readable textual description of the desired data can be provided.  Downstream profiles may tighten expectations for this element." />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.input:code.type">
      <path value="Task.input.type" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/us/davinci-hrex/CodeSystem/hrex-temp" />
          <code value="data-code" />
        </coding>
      </patternCodeableConcept>
      <mustSupport value="true" />
    </element>
    <element id="Task.input:code.value[x]">
      <path value="Task.input.value[x]" />
      <short value="query value" />
      <type>
        <code value="CodeableConcept" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.output">
      <path value="Task.output" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="type" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <mustSupport value="true" />
    </element>
    <element id="Task.output:data">
      <path value="Task.output" />
      <sliceName value="data" />
      <short value="Requested data" />
      <definition value="The data content requested.  Multiple repetitions are permitted in the event that a single request returns multiple instances and packaging in a Bundle is not necessary/approrpriate.  Also, in most cases Provenance instances should accompany returned data so that the requester can best integrate and allocate trust/confidence to the provided data." />
      <mustSupport value="true" />
    </element>
    <element id="Task.output:data.type">
      <path value="Task.output.type" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/us/davinci-hrex/CodeSystem/hrex-temp" />
          <code value="data-value" />
        </coding>
      </patternCodeableConcept>
      <mustSupport value="true" />
    </element>
    <element id="Task.output:data.value[x]">
      <path value="Task.output.value[x]" />
      <short value="data reference" />
      <comment value="The referenced data might be contained within the Task (if it doesn't have/shouldn't have independent persistence), but can also refer to data stored elsewhere - either on the owner's system or some other system.  Note that all returned data SHOULD comply with appropriate US-Core and/or Da Vinci profiles." />
      <type>
        <code value="Reference" />
      </type>
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>