{
  "resourceType": "StructureDefinition",
  "id": "hddt-lung-function-testing-complete",
  "url": "https://gematik.de/fhir/hddt/StructureDefinition/hddt-lung-function-testing-complete",
  "version": "1.0.1",
  "name": "HddtLungFunctionTestingComplete",
  "title": "Observation – Complete Lung Function Testing",
  "status": "active",
  "date": "2026-04-29",
  "publisher": "gematik GmbH",
  "description": "Profile for capturing the relative lung function testings (i.e. an individual measurement divided by the corresponding reference value) \nas FHIR Observation resources.\n\nThis profile defines the exchange of a single relative value for the Mandatory Interoperable Value (MIV) \\\"Lung Function Testing\\\" which is technically defined \nby the ValueSet _hddt-miv-lung-function-testing_. This MIV is e.g. implemented by peak flow meter that can connect to \na Personal Health Gateway (e.g. a mobile app for tracking lung function values) through wireless or wired communication.\n\n**Obligations and Conventions:**\n\nEach 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 \n_Personal Health Device_ [Device](https://hl7.org/fhir/R4/device.html) resource (eXclusive OR). Typically the reference will be \nto a [Device](https://hl7.org/fhir/R4/device.html) resource, but the option to reference a [DeviceMetric](https://hl7.org/fhir/R4/devicemetric.html) \nresource is provided for compatibility with the overarching HDDT specification.\n\nEach instance of this Observation MUST reference the Observations holding the corresponding raw measurement and reference value via the `derivedFrom` element.\n\n**Constraints applied:**  \n- `code` is constrained to a subset of the _MIV Lung Function Relative Values_ ValueSet, defined by the _HddtLungFunctionRelativeValues_ ValueSet.\n- `effective[x]` is restricted to `effectiveDateTime` and constrained as mandatory.\n- `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.\n- `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": "Copyright (c) 2026 gematik GmbH",
  "fhirVersion": "4.0.1",
  "kind": "resource",
  "abstract": false,
  "type": "Observation",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Observation",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Observation.code",
        "path": "Observation.code",
        "short": "Percentage measurement type for lung function",
        "binding": {
          "strength": "required",
          "valueSet": "https://gematik.de/fhir/hddt/ValueSet/hddt-lung-function-relative-values",
          "description": "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."
        }
      },
      {
        "id": "Observation.effective[x]",
        "path": "Observation.effective[x]",
        "short": "Time of measurement",
        "definition": "The time when the lung function testing was taken.",
        "min": 1,
        "type": [
          {
            "code": "dateTime"
          }
        ]
      },
      {
        "id": "Observation.value[x]",
        "path": "Observation.value[x]",
        "short": "Calculated lung function value as percentage of reference value",
        "definition": "The lung function value represented as percentage of the reference value",
        "type": [
          {
            "code": "Quantity"
          }
        ],
        "mustSupport": true
      },
      {
        "id": "Observation.value[x].value",
        "path": "Observation.value[x].value",
        "min": 1
      },
      {
        "id": "Observation.value[x].system",
        "path": "Observation.value[x].system",
        "min": 1,
        "fixedUri": "http://unitsofmeasure.org"
      },
      {
        "id": "Observation.value[x].code",
        "path": "Observation.value[x].code",
        "definition": "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": 1,
        "binding": {
          "strength": "required",
          "valueSet": "http://hl7.org/fhir/ValueSet/ucum-units",
          "description": "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`."
        }
      },
      {
        "id": "Observation.device",
        "path": "Observation.device",
        "short": "Reference to personal health device",
        "definition": "References a Device resource that describes the personal health device.",
        "min": 1,
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://gematik.de/fhir/hddt/StructureDefinition/hddt-personal-health-device",
              "https://gematik.de/fhir/hddt/StructureDefinition/hddt-sensor-type-and-calibration-status"
            ]
          }
        ]
      },
      {
        "id": "Observation.derivedFrom",
        "path": "Observation.derivedFrom",
        "slicing": {
          "discriminator": [
            {
              "type": "profile",
              "path": "resolve()"
            }
          ],
          "rules": "closed",
          "description": "Slice to require one reference to a measurement and one to a reference value"
        },
        "min": 2,
        "max": "2"
      },
      {
        "id": "Observation.derivedFrom:measurement",
        "path": "Observation.derivedFrom",
        "sliceName": "measurement",
        "short": "Reference to raw lung function testing",
        "definition": "Reference to the lung function testing Observation that holds the actual measured value.",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://gematik.de/fhir/hddt/StructureDefinition/hddt-lung-function-testing"
            ]
          }
        ]
      },
      {
        "id": "Observation.derivedFrom:referenceValue",
        "path": "Observation.derivedFrom",
        "sliceName": "referenceValue",
        "short": "Reference to lung function reference value",
        "definition": "Reference to the Observation holding the reference range and information about the reference range determination method.",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "https://gematik.de/fhir/hddt/StructureDefinition/hddt-lung-reference-value"
            ]
          }
        ]
      }
    ]
  }
}