<StructureDefinition xmlns="http://hl7.org/fhir">
  <url value="http://example.org/fhir/StructureDefinition/ConstrainedQuantity" />
  <name value="ConstrainedQuantity" />
  <status value="draft" />
  <fhirVersion value="4.0.0" />
  <kind value="complex-type" />
  <abstract value="false" />
  <type value="Quantity" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Quantity" />
  <derivation value="constraint" />
  <differential>
    <element id="Quantity">
      <path value="Quantity" />
      <short value="A measured or measurable amount" />
      <definition value="A measured amount (or an amount that can potentially be measured). Note that measured amounts include amounts that are not precisely quantified, including amounts involving arbitrary units and floating currencies." />
      <comment value="The context of use may frequently define what kind of quantity this is and therefore what kind of units can be used. The context of use may also restrict the values for the comparator." />
      <constraint>
        <key value="qty-3" />
        <severity value="error" />
        <human value="If a code for the unit is present, the system SHALL also be present" />
        <expression value="code.empty() or system.exists()" />
        <xpath value="not(exists(f:code)) or exists(f:system)" />
      </constraint>
      <mapping>
        <identity value="v2" />
        <map value="SN (see also Range) or CQ" />
      </mapping>
      <mapping>
        <identity value="rim" />
        <map value="PQ, IVL&lt;PQ&gt;, MO, CO, depending on the values" />
      </mapping>
    </element>
    <element id="Quantity.comparator">
      <path value="Quantity.comparator" />
      <max value="0" />
    </element>
    <element id="Quantity.code">
      <path value="Quantity.code" />
      <min value="1" />
    </element>
  </differential>
</StructureDefinition>