<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="MedicationRequestMERT" />
  <url value="https://intrahealth.com/fhir/mert/StructureDefinition/MedicationRequestMERT" />
  <name value="MedicationRequestMERT" />
  <title value="MedicationRequest (MERT)" />
  <status value="draft" />
  <description value="This profile describes the MedicationRequest constraints for MERT." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="MedicationRequest" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/MedicationRequest" />
  <derivation value="constraint" />
  <differential>
    <element id="MedicationRequest">
      <path value="MedicationRequest" />
      <constraint>
        <key value="mert-medreq-din-should" />
        <severity value="warning" />
        <human value="When medication as a CodeableConcept has codings, a DIN coding should be included (Canada-first)." />
        <expression value="medication.ofType(CodeableConcept).coding.empty() or medication.ofType(CodeableConcept).coding.where(system = 'http://hl7.org/fhir/sid/ca-din').exists()" />
        <source value="https://intrahealth.com/fhir/mert/StructureDefinition/MedicationRequestMERT" />
      </constraint>
    </element>
    <element id="MedicationRequest.status">
      <path value="MedicationRequest.status" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.intent">
      <path value="MedicationRequest.intent" />
      <short value="'order' only" />
      <definition value="For MERT, MedicationRequest.intent only processes those that are 'order'. Other intent values will not be processed." />
      <patternCode value="order" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.medication[x]">
      <path value="MedicationRequest.medication[x]" />
      <comment value="Medication SHALL be represented as a CodeableConcept for MERT exchange. When codings are present, DIN coding is preferred." />
      <type>
        <code value="CodeableConcept" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.medication[x].coding">
      <path value="MedicationRequest.medication[x].coding" />
      <slicing>
        <discriminator>
          <type value="value" />
          <path value="system" />
        </discriminator>
        <rules value="open" />
      </slicing>
    </element>
    <element id="MedicationRequest.medication[x].coding:din">
      <path value="MedicationRequest.medication[x].coding" />
      <sliceName value="din" />
      <min value="0" />
      <max value="*" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.medication[x].coding:din.system">
      <path value="MedicationRequest.medication[x].coding.system" />
      <min value="1" />
      <patternUri value="http://hl7.org/fhir/sid/ca-din" />
    </element>
    <element id="MedicationRequest.medication[x].coding:din.code">
      <path value="MedicationRequest.medication[x].coding.code" />
      <min value="1" />
    </element>
    <element id="MedicationRequest.medication[x].text">
      <path value="MedicationRequest.medication[x].text" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.subject">
      <path value="MedicationRequest.subject" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://intrahealth.com/fhir/mert/StructureDefinition/PatientMERT" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.encounter">
      <path value="MedicationRequest.encounter" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.authoredOn">
      <path value="MedicationRequest.authoredOn" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.requester">
      <path value="MedicationRequest.requester" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://intrahealth.com/fhir/mert/StructureDefinition/PractitionerMERT" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.note">
      <path value="MedicationRequest.note" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.dosageInstruction">
      <path value="MedicationRequest.dosageInstruction" />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Dosage" />
        <profile value="https://intrahealth.com/fhir/mert/StructureDefinition/DosageMERT" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.dispenseRequest">
      <path value="MedicationRequest.dispenseRequest" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.dispenseRequest.numberOfRepeatsAllowed">
      <path value="MedicationRequest.dispenseRequest.numberOfRepeatsAllowed" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.dispenseRequest.quantity">
      <path value="MedicationRequest.dispenseRequest.quantity" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.dispenseRequest.expectedSupplyDuration">
      <path value="MedicationRequest.dispenseRequest.expectedSupplyDuration" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.substitution">
      <path value="MedicationRequest.substitution" />
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.substitution.allowed[x]">
      <path value="MedicationRequest.substitution.allowed[x]" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="$this" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <type>
        <code value="boolean" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="MedicationRequest.substitution.allowed[x]:allowedBoolean">
      <path value="MedicationRequest.substitution.allowed[x]" />
      <sliceName value="allowedBoolean" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="boolean" />
      </type>
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>