<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="ObservationVitalsMERT" />
  <url value="https://intrahealth.com/fhir/mert/StructureDefinition/ObservationVitalsMERT" />
  <name value="ObservationVitalsMERT" />
  <title value="Observation (Vitals) (MERT)" />
  <status value="draft" />
  <description value="MERT vital signs Observation. Restricted to a small set of LOINC codes, with special handling for blood pressure panel." />
  <fhirVersion value="4.0.1" />
  <kind value="resource" />
  <abstract value="false" />
  <type value="Observation" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Observation" />
  <derivation value="constraint" />
  <differential>
    <element id="Observation">
      <path value="Observation" />
      <constraint>
        <key value="mert-vitals-bp-panel-structure" />
        <severity value="error" />
        <human value="If code is blood pressure panel (LOINC 85354-9), Observation.value SHALL be absent and at least one component (systolic and/or diastolic) SHALL be present." />
        <expression value="code.coding.where(system='http://loinc.org' and code='85354-9').empty() or (value.empty() and component.where(code.coding.where(system='http://loinc.org' and (code='8480-6' or code='8462-4')).exists()).exists())" />
        <source value="https://intrahealth.com/fhir/mert/StructureDefinition/ObservationVitalsMERT" />
      </constraint>
      <constraint>
        <key value="mert-vitals-nonbp-requires-quantity" />
        <severity value="error" />
        <human value="If code is not blood pressure panel (LOINC 85354-9), Observation.valueQuantity SHALL be present." />
        <expression value="code.coding.where(system='http://loinc.org' and code='85354-9').exists() or value.ofType(Quantity).exists()" />
        <source value="https://intrahealth.com/fhir/mert/StructureDefinition/ObservationVitalsMERT" />
      </constraint>
    </element>
    <element id="Observation.status">
      <path value="Observation.status" />
      <comment value="MERT transmits vitals as final observations." />
      <patternCode value="final" />
      <mustSupport value="true" />
    </element>
    <element id="Observation.category">
      <path value="Observation.category" />
      <comment value="MERT uses the vital-signs category." />
      <min value="1" />
      <max value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Observation.category.coding">
      <path value="Observation.category.coding" />
      <min value="1" />
      <mustSupport value="true" />
    </element>
    <element id="Observation.category.coding.system">
      <path value="Observation.category.coding.system" />
      <min value="1" />
      <patternUri value="http://terminology.hl7.org/CodeSystem/observation-category" />
    </element>
    <element id="Observation.category.coding.code">
      <path value="Observation.category.coding.code" />
      <min value="1" />
      <patternCode value="vital-signs" />
    </element>
    <element id="Observation.code">
      <path value="Observation.code" />
      <comment value="Only the MERT-supported vital sign LOINC codes are permitted." />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://intrahealth.com/fhir/mert/ValueSet/mert-vitals-code-vs" />
      </binding>
    </element>
    <element id="Observation.subject">
      <path value="Observation.subject" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://intrahealth.com/fhir/mert/StructureDefinition/PatientMERT" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Observation.encounter">
      <path value="Observation.encounter" />
      <mustSupport value="true" />
    </element>
    <element id="Observation.effective[x]">
      <path value="Observation.effective[x]" />
      <mustSupport value="true" />
    </element>
    <element id="Observation.value[x]">
      <path value="Observation.value[x]" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="$this" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <comment value="For non-blood-pressure vitals, valueQuantity is required. For BP panel (85354-9), value is absent and components carry the values." />
      <mustSupport value="true" />
    </element>
    <element id="Observation.value[x]:valueQuantity">
      <path value="Observation.value[x]" />
      <sliceName value="valueQuantity" />
      <comment value="For BMI (LOINC 39156-5), represent the result as valueQuantity in kg/m2." />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Quantity" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Observation.note">
      <path value="Observation.note" />
      <mustSupport value="true" />
    </element>
    <element id="Observation.hasMember">
      <path value="Observation.hasMember" />
      <mustSupport value="true" />
    </element>
    <element id="Observation.component">
      <path value="Observation.component" />
      <comment value="Used for blood pressure panel (LOINC 85354-9) to carry systolic/diastolic components. Other vitals generally have no components." />
      <mustSupport value="true" />
    </element>
    <element id="Observation.component.code">
      <path value="Observation.component.code" />
      <mustSupport value="true" />
      <binding>
        <strength value="required" />
        <valueSet value="https://intrahealth.com/fhir/mert/ValueSet/mert-bp-component-code-vs" />
      </binding>
    </element>
    <element id="Observation.component.value[x]">
      <path value="Observation.component.value[x]" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="$this" />
        </discriminator>
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <mustSupport value="true" />
    </element>
    <element id="Observation.component.value[x]:valueQuantity">
      <path value="Observation.component.value[x]" />
      <sliceName value="valueQuantity" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Quantity" />
      </type>
      <mustSupport value="true" />
    </element>
  </differential>
</StructureDefinition>