<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="hddt-lung-function-testing" />
  <url value="https://gematik.de/fhir/hddt/StructureDefinition/hddt-lung-function-testing" />
  <version value="1.0.1" />
  <name value="HddtLungFunctionTesting" />
  <title value="Observation – Lung Function Testing" />
  <status value="active" />
  <date value="2026-04-29" />
  <publisher value="gematik GmbH" />
  <contact>
    <telecom>
      <system value="url" />
      <value value="https://www.gematik.de" />
    </telecom>
  </contact>
  <description value="Profile for capturing lung function testings as FHIR Observation resources.&#xA;&#xA;This profile defines the exchange of a single measurement data 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 MUST 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;**Constraints applied:**  &#xA;- `code` is constrained to a subset of the _MIV Lung Function Testing_ ValueSet, defined by the _HddtLungFunctionTestingValues_ 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;- `device` is set to be mandatory in order to provide the DiGA with information about the sensor's calibration status and with information about the static and dynamic attributes of the Personal Health Device." />
  <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="Raw measurement type for lung function" />
      <binding>
        <strength value="required" />
        <description value="Specifies the type of measurement using codes from the ValueSet for lung function testings. Constrained via invariant to either PEF or FEV1." />
        <valueSet value="https://gematik.de/fhir/hddt/ValueSet/hddt-lung-function-testing-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="Measured lung function value" />
      <definition value="The quantitative lung function value, measured either in liters (L) for FEV1 or liters per minute (L/min) for PEF, represented as a UCUM Quantity." />
      <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>
  </differential>
</StructureDefinition>