<StructureDefinition xmlns="http://hl7.org/fhir" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <id value="specialty-rx-task-smart-launch" />
  <meta>
    <lastUpdated value="2020-10-02T00:00:00+00:00" />
  </meta>
  <url value="http://hl7.org/fhir/us/specialty-rx/StructureDefinition/specialty-rx-task-smart-launch" />
  <version value="0.1.00" />
  <name value="SpecialtyRxTaskSmartLaunch" />
  <title value="Specialty Rx Task - SMART Launch" />
  <status value="active" />
  <experimental value="false" />
  <date value="2020-10-02" />
  <publisher value="HL7 International - Pharmacy" />
  <description value="This profile defines Task content enabling a pharmacy or other external party to prompt clinic staff to launch a SMART app and answer prescription-related questions." />
  <jurisdiction>
    <coding>
      <system value="urn:iso:std:iso:3166" />
      <code value="US" />
      <display value="United States of America" />
    </coding>
  </jurisdiction>
  <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" />
    </element>
    <element id="Task.id">
      <path value="Task.id" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.identifier">
      <path value="Task.identifier" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <comment value="MAY contain multiple task identifiers, but one MUST be an application context ID to be passed in the appContext parameter while launching the SMART app specified in this Task." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.identifier:appContext">
      <path value="Task.identifier" />
      <sliceName value="appContext" />
      <short value="SMART App Context ID" />
      <min value="1" />
      <max value="1" />
      <patternIdentifier>
        <type>
          <coding>
            <system value="http://hl7.org/fhir/us/specialty-rx/CodeSystem/specialty-rx-task-identifier-type" />
            <code value="app-context" />
          </coding>
        </type>
      </patternIdentifier>
      <mustSupport value="true" />
    </element>
    <element id="Task.identifier.type">
      <path value="Task.identifier.type" />
      <comment value="At least one identifier must be a SMART application contenxt identifier" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.identifier.system">
      <path value="Task.identifier.system" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="uri" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.identifier.value">
      <path value="Task.identifier.value" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="string" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Task.intent">
      <path value="Task.intent" />
      <min value="1" />
      <fixedCode value="plan" />
      <mustSupport value="true" />
    </element>
    <element id="Task.code">
      <path value="Task.code" />
      <label value="SMART App Task Type" />
      <definition value="A particular SMART app task type, e.g., complete-app-questionnaire" />
      <comment value="A code specifying the requested user action to be performed using the referenced SMART app. E.g., complete-app-questionnaire" />
      <min value="1" />
      <max value="1" />
      <binding>
        <strength value="extensible" />
        <description value="Task types used in the Specialty Rx workflow" />
        <valueSet value="http://hl7.org/fhir/us/specialty-rx/ValueSet/specialty-rx-task-type" />
      </binding>
    </element>
    <element id="Task.description">
      <path value="Task.description" />
      <definition value="Human-readable description of the task to be performed by the user." />
      <comment value="SHOULD include the user-recognizable name of the SMART application to launch to perform the task. SHALL state the action to be performed in the app once it's been launched." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.focus">
      <path value="Task.focus" />
      <label value="Related Prescription" />
      <short value="Related Prescription" />
      <definition value="Related prescription order" />
      <comment value="The prescription to which the task pertains. Either a reference to a MedicationRequest resource or the prescription identifier set by the prescribing system MAY be present." />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/MedicationRequest" />
      </type>
      <constraint>
        <key value="srx-1" />
        <severity value="warning" />
        <human value="If Task.focus is present, either reference or identifier SHOULD be present. If focus.identifier is present, SHOULD be the placer order ID" />
        <expression value="reference.exists() or identifier.exists()" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Task.focus.reference">
      <path value="Task.focus.reference" />
      <label value="Prescription Reference" />
      <short value="Prescription Reference" />
      <definition value="Reference to the related MedicationRequest resource" />
      <min value="0" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.focus.identifier">
      <path value="Task.focus.identifier" />
      <label value="Placer Order Number" />
      <short value="Placer Order Number" />
      <definition value="The prescription order number established by the ordering system" />
      <comment value="Referred to as the Placer Order Number in HL7 v2 and Prescriber Order Number in NCPDP SCRIPT" />
      <min value="0" />
      <max value="1" />
      <patternIdentifier>
        <type>
          <coding>
            <system value="http://terminology.hl7.org/CodeSystem/v2-0203" />
            <code value="PLAC" />
          </coding>
        </type>
      </patternIdentifier>
      <mustSupport value="true" />
    </element>
    <element id="Task.focus.display">
      <path value="Task.focus.display" />
      <definition value="A human-readable description of the related prescription order" />
      <comment value="A human-readable prescription description SHOULD be present. SHOULD contain the medication name and MAY contain the date written. MAY contain strength, dose form, or other specifics." />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.for">
      <path value="Task.for" />
      <label value="Related Patient" />
      <short value="Related Patient" />
      <definition value="The patient for whom the related prescription was written" />
      <min value="1" />
      <max 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.for.reference">
      <path value="Task.for.reference" />
      <label value="Patient Reference" />
      <short value="Patient Reference" />
      <definition value="Reference to a Patient resource" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.authoredOn">
      <path value="Task.authoredOn" />
      <label value="Prescription Written Date" />
      <short value="Prescription Written Date" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.requester">
      <path value="Task.requester" />
      <comment value="The organization requesting that this task be performed" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Organization" />
      </type>
      <constraint>
        <key value="srx-2" />
        <severity value="error" />
        <human value="Either requester.reference or requester.identifier MUST be present" />
        <expression value="reference.exists() or identifier.exists()" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Task.requester.reference">
      <path value="Task.requester.reference" />
      <min value="0" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.requester.identifier">
      <path value="Task.requester.identifier" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="$this" />
        </discriminator>
        <rules value="open" />
      </slicing>
      <definition value="An identifier of the party reqesting that the task be performed." />
      <comment value="If the requester is a pharmacy, the identifier SHOULD be an NCPDP Provider Identifier, otherwise if the requester possesses an NPI, an NPI SHOULD be used." />
      <min value="0" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.requester.identifier:pharmacyNcpdpId">
      <path value="Task.requester.identifier" />
      <sliceName value="pharmacyNcpdpId" />
      <short value="The pharmacy's NCPDP Provider ID" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Identifier" />
      </type>
      <patternIdentifier>
        <system value="http://terminology.hl7.org/CodeSystem/NCPDP/ProviderIdentificationNumber" />
      </patternIdentifier>
      <mustSupport value="true" />
    </element>
    <element id="Task.requester.identifier:NPI">
      <path value="Task.requester.identifier" />
      <sliceName value="NPI" />
      <short value="National Provider Identifier (NPI)" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Identifier" />
      </type>
      <patternIdentifier>
        <system value="http://hl7.org/fhir/sid/us-npi" />
      </patternIdentifier>
      <mustSupport value="true" />
    </element>
    <element id="Task.owner">
      <path value="Task.owner" />
      <label value="Prescriber" />
      <short value="Prescriber" />
      <comment value="The practitioner that prescribed the related medication" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org/fhir/StructureDefinition/Practitioner" />
      </type>
      <constraint>
        <key value="srx-3" />
        <severity value="error" />
        <human value="Either owner.reference or owner.identifier MUST be present" />
        <expression value="reference.exists() or identifier.exists()" />
      </constraint>
      <mustSupport value="true" />
    </element>
    <element id="Task.owner.reference">
      <path value="Task.owner.reference" />
      <label value="Prescriber Reference" />
      <short value="Prescriber Reference" />
      <min value="0" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.owner.identifier">
      <path value="Task.owner.identifier" />
      <definition value="The prescriber's individual NPI" />
      <min value="0" />
      <max value="1" />
      <patternIdentifier>
        <system value="http://hl7.org/fhir/sid/us-npi" />
      </patternIdentifier>
      <mustSupport value="true" />
    </element>
    <element id="Task.input">
      <path value="Task.input" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="type" />
        </discriminator>
        <description value="The Task SHALL contain an input containing the URL for the SMART app to be launched to complete the task" />
        <rules value="open" />
      </slicing>
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <!-- test 
    <element id="Task.input.type">
      <path value="Task.input.type" />
      <binding>
        <strength value="extensible" />
        <description value="This value set contains task input types used in the Specialty Rx Task profile." />
        <valueSet value="http://hl7.org/fhir/us/specialty-rx/ValueSet/specialty-rx-task-input-type" />
      </binding>
      <min value="1" />
      <mustSupport value="true" />
    </element>
    end test -->
    <element id="Task.input:SmartUrl">
      <path value="Task.input" />
      <sliceName value="SmartLaunchUrl" />
      <label value="Smart App Launch URL" />
      <short value="Smart App URL" />
      <definition value="The launch URL of the SMART application to be used to complete this task" />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Task.input:SmartURL.type">
      <path value="Task.input.type" />
      <min value="1" />
      <patternCodeableConcept>
        <coding>
          <system value="http://hl7.org/fhir/us/specialty-rx/CodeSystem/specialty-rx-task-input-type" />
          <code value="smart-app-launch-url" />
          <display value="SMART Application Launch URL" />
        </coding>
      </patternCodeableConcept>
      <mustSupport value="true" />
    </element>
    <element id="Task.input:SmartUrl.valueUrl">
      <path value="Task.input.valueUrl" />
      <label value="SMART application launch URL" />
      <short value="SMART launch URL" />
      <min value="1" />
      <type>
        <code value="url" />
      </type>
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>