<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="hddt-lung-function-testing-complete" />
  <url value="https://gematik.de/fhir/hddt/StructureDefinition/hddt-lung-function-testing-complete" />
  <version value="1.0.1" />
  <name value="HddtLungFunctionTestingComplete" />
  <title value="Observation – Complete Lung Function Testing" />
  <status value="active" />
  <date value="2026-04-29" />
  <publisher value="gematik GmbH" />
  <description value="Profile for capturing the relative lung function testings (i.e. an individual measurement divided by the corresponding reference value) &#xA;as FHIR Observation resources.&#xA;&#xA;This profile defines the exchange of a single relative value for the Mandatory Interoperable Value (MIV) \&quot;Lung Function Testing\&quot; which is technically defined &#xA;by the ValueSet _hddt-miv-lung-function-testing_. This MIV is e.g. implemented by peak flow meter that can connect to &#xA;a Personal Health Gateway (e.g. a mobile app for tracking lung function values) through wireless or wired communication.&#xA;&#xA;**Obligations and Conventions:**&#xA;&#xA;Each Lung Function Testing MAY either hold a reference to a _Sensor Type And Calibration Status_ [DeviceMetric](https://hl7.org/fhir/R4/devicemetric.html) resource or to a &#xA;_Personal Health Device_ [Device](https://hl7.org/fhir/R4/device.html) resource (eXclusive OR). Typically the reference will be &#xA;to a [Device](https://hl7.org/fhir/R4/device.html) resource, but the option to reference a [DeviceMetric](https://hl7.org/fhir/R4/devicemetric.html) &#xA;resource is provided for compatibility with the overarching HDDT specification.&#xA;&#xA;Each instance of this Observation MUST reference the Observations holding the corresponding raw measurement and reference value via the `derivedFrom` element.&#xA;&#xA;**Constraints applied:**  &#xA;- `code` is constrained to a subset of the _MIV Lung Function Relative Values_ ValueSet, defined by the _HddtLungFunctionRelativeValues_ ValueSet.&#xA;- `effective[x]` is restricted to `effectiveDateTime` and constrained as mandatory.&#xA;- `value[x]` is restricted to `valueQuantity`. The elements `valueQuantity.value`, `valueQuantity.system`, and `valueQuantity.code` are constrained in a way that a value MUST be provided and that UCUM MUST be used for encoding the unit of measurement. `Observation.valueQuantity` MAY only be omitted in case of an error that accured with the measurement. In this case, `Observation.dataAbsentReason` MUST be provided.&#xA;- `derivedFrom` is constrained to require exactly two references: one to the raw lung function testing Observation and one to the lung function reference value Observation." />
  <copyright value="Copyright (c) 2026 gematik GmbH" />
  <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.code">
      <path value="Observation.code" />
      <short value="Percentage measurement type for lung function" />
      <binding>
        <strength value="required" />
        <description value="Specifies the type of measurement using codes from the ValueSet for lung function testing as percentage of the reference value. Constrained via invariant to either PEF or FEV1." />
        <valueSet value="https://gematik.de/fhir/hddt/ValueSet/hddt-lung-function-relative-values" />
      </binding>
    </element>
    <element id="Observation.effective[x]">
      <path value="Observation.effective[x]" />
      <short value="Time of measurement" />
      <definition value="The time when the lung function testing was taken." />
      <min value="1" />
      <type>
        <code value="dateTime" />
      </type>
    </element>
    <element id="Observation.value[x]">
      <path value="Observation.value[x]" />
      <short value="Calculated lung function value as percentage of reference value" />
      <definition value="The lung function value represented as percentage of the reference value" />
      <type>
        <code value="Quantity" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Observation.value[x].value">
      <path value="Observation.value[x].value" />
      <min value="1" />
    </element>
    <element id="Observation.value[x].system">
      <path value="Observation.value[x].system" />
      <min value="1" />
      <fixedUri value="http://unitsofmeasure.org" />
    </element>
    <element id="Observation.value[x].code">
      <path value="Observation.value[x].code" />
      <definition value="The UCUM code representing the unit of the lung function testing. The UCUM code MUST be compliant with the example unit that is linked with the LOINC code given as `Observation.code`." />
      <min value="1" />
      <binding>
        <strength value="required" />
        <description value="Defines the unit of measurement using codes from the UCUM units ValueSet. The UCUM code MUST be compliant with the unit that is linked with the LOINC code given as `Observation.code`." />
        <valueSet value="http://hl7.org/fhir/ValueSet/ucum-units" />
      </binding>
    </element>
    <element id="Observation.device">
      <path value="Observation.device" />
      <short value="Reference to personal health device" />
      <definition value="References a Device resource that describes the personal health device." />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/hddt/StructureDefinition/hddt-personal-health-device" />
        <targetProfile value="https://gematik.de/fhir/hddt/StructureDefinition/hddt-sensor-type-and-calibration-status" />
      </type>
    </element>
    <element id="Observation.derivedFrom">
      <path value="Observation.derivedFrom" />
      <slicing>
        <discriminator>
          <type value="profile" />
          <path value="resolve()" />
        </discriminator>
        <description value="Slice to require one reference to a measurement and one to a reference value" />
        <rules value="closed" />
      </slicing>
      <min value="2" />
      <max value="2" />
    </element>
    <element id="Observation.derivedFrom:measurement">
      <path value="Observation.derivedFrom" />
      <sliceName value="measurement" />
      <short value="Reference to raw lung function testing" />
      <definition value="Reference to the lung function testing Observation that holds the actual measured value." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/hddt/StructureDefinition/hddt-lung-function-testing" />
      </type>
    </element>
    <element id="Observation.derivedFrom:referenceValue">
      <path value="Observation.derivedFrom" />
      <sliceName value="referenceValue" />
      <short value="Reference to lung function reference value" />
      <definition value="Reference to the Observation holding the reference range and information about the reference range determination method." />
      <min value="1" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="https://gematik.de/fhir/hddt/StructureDefinition/hddt-lung-reference-value" />
      </type>
    </element>
  </differential>
</StructureDefinition>