<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="hddt-continuous-glucose-measurement" />
  <url value="https://gematik.de/fhir/hddt/StructureDefinition/hddt-continuous-glucose-measurement" />
  <version value="1.0.1" />
  <name value="HddtContinuousGlucoseMeasurement" />
  <title value="Observation – Continuous Glucose Measurement" />
  <status value="active" />
  <date value="2026-04-29" />
  <publisher value="gematik GmbH" />
  <description value="Profile for capturing continuous glucose measurements from real-time monitoring devices (esp. rtCGM). &#xA;&#xA;This profile defines the exchange of raw measurement data for the Mandatory Interoperable Value (MIV) \&quot;Continuous Glucose Measurement\&quot; which is technically defined &#xA;by the ValueSet _hddt-miv-continuous-glucose-measurement_. This MIV is e.g. implemented by real-time Continuous Glocose Monitoring devices (rtCGM) and Automated Insulin Delivery systems (AID) that control &#xA;an insulin pump from rtCGM data. Future non-invasive measuring methods will expectedly be linked with this MIV and therefore use this profile for sharing data with DiGA, too.&#xA;&#xA;**Obligations and Conventions:**&#xA;&#xA;Devices for continuously measuring glucose values may produce data with a sample rate of more than 1000 values per day (e.g. current&#xA;rtCGM provide measures for glucose in interstitial fluid with up to one value per minute). For sharing such data efficently, this profile&#xA;makes use of the FHIR [sampledData](https://hl7.org/fhir/R4/datatypes.html#SampledData) data type. Sampled data is portioned into&#xA;chunks of a fixed size (for an exception see below), with the chunk size being set by the resource server (e.g. such that 24 h of measurements fit into a single chunk). If a DiGA&#xA;requests data for a period where the end time is earlier that the expected end time of the current chunk, the resource server only fills up the chunk &#xA;up to the requested end time and sets the `Observation.status` to _incomplete_ while `Observation.effectivePeriod` captures the &#xA;full period of the chunk (see section \&quot;Retrieving Data\&quot; in the HDDT specification for details on chunks and missing data). &#xA;&#xA;Each Continuous Glucose Measurement 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). A reference to _Sensor Type And Calibration Status_ MUST be provided &#xA;from the Observation resource if the sensor for continuous measuring needs to be calibrated (either automatically or by the user) &#xA;or if the sensor may change its calibration status over time. A change in `DeviceMetric.calibration.state` or a change of `Device.status` to _inactive_ finalizes the&#xA;current chunk and therefore is the only reason why a chunk may be smaller than the defined fixed size. &#xA;&#xA;**Constraints applied:**  &#xA;- `code` is constrained to the ValueSet that represents the MIV _Continuous Glucose Measurement_&#xA;- `effective[x]` is restricted to `effectivePeriod` and constrained as mandatory. Both a starting time and an end tme MUST be given.&#xA;- `value[x]` is restricted to _valueSampledData_. The elements `valueSampledData.origin.unit`, `valueSampledData.origin.system`, and `valueSampledData.origin.code` are mandatory. `valueSampledData.origin.system` is restricted to UCUM. `Observation.valueSampledData` 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">
      <path value="Observation" />
      <short value="Chunk of continuous glucose measurements" />
      <definition value="An Observation representing a continuous glucose measurement (CGM) series over a defined effective period, captured as SampledData from a personal health device." />
    </element>
    <element id="Observation.status">
      <path value="Observation.status" />
      <short value="Status of the continuous glucose measurements chunk" />
      <definition value="The status of the continuous glucose measurements chunk. The status 'final' means the measurement is complete and verified; 'preliminary' means the data MAY be still being collected and not complete. It SHOULD be called at a later time for collecting complete data." />
    </element>
    <element id="Observation.code">
      <path value="Observation.code" />
      <short value="Type of continuous glucose measurement" />
      <binding>
        <strength value="required" />
        <description value="Specifies the type of continuous glucose measurement using codes from the ValueSet for CGM measurements." />
        <valueSet value="https://gematik.de/fhir/hddt/ValueSet/hddt-miv-continuous-glucose-measurement" />
      </binding>
    </element>
    <element id="Observation.effective[x]">
      <path value="Observation.effective[x]" />
      <short value="Time interval covered by the CGM measurement chunk" />
      <definition value="The time span covered by this chunk of continuous glucose measurements. The length of every time span is a fixed value defined &#xA;internaly by the data recorder per personal health device." />
      <min value="1" />
      <type>
        <code value="Period" />
      </type>
    </element>
    <element id="Observation.effective[x].start">
      <path value="Observation.effective[x].start" />
      <min value="1" />
    </element>
    <element id="Observation.effective[x].end">
      <path value="Observation.effective[x].end" />
      <min value="1" />
    </element>
    <element id="Observation.value[x]">
      <path value="Observation.value[x]" />
      <short value="Series of glucose measurements" />
      <type>
        <code value="SampledData" />
      </type>
      <mustSupport value="true" />
    </element>
    <element id="Observation.value[x].origin.unit">
      <path value="Observation.value[x].origin.unit" />
      <short value="Unit of continuous glucose measurement" />
      <definition value="The unit of measurement used for all data in `valueSampledData.data`." />
    </element>
    <element id="Observation.value[x].origin.system">
      <path value="Observation.value[x].origin.system" />
      <min value="1" />
      <fixedUri value="http://unitsofmeasure.org" />
    </element>
    <element id="Observation.value[x].origin.code">
      <path value="Observation.value[x].origin.code" />
      <short value="UCUM code for unit of measurements" />
      <definition value="The UCUM code representing the unit of the continuous glucose measurement. 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 measurement unit for continuous glucose values using UCUM codes." />
        <valueSet value="http://hl7.org/fhir/ValueSet/ucum-units" />
      </binding>
    </element>
    <element id="Observation.value[x].data">
      <path value="Observation.value[x].data" />
      <min value="1" />
    </element>
    <element id="Observation.dataAbsentReason">
      <path value="Observation.dataAbsentReason" />
      <definition value="Indicates why the measurement data is missing. A value of 'temp-unknown' MUST only be used if no data is available at all&#xA;for the requested period but may be available later (e.g. because the Device Data Recorder could temporarely not &#xA;connect with the Personal Health Device)." />
      <comment value="If some data is available for the requested period with more data expected to come, an incomplete chunk MUST &#xA;be provided with with the avialable vaues and `Observation.status` MUST set to _incomplete_. See section &#xA;\&quot;Retrieving Data\&quot; in the HDDT specification for more details on how to deal with incomplete or missing data." />
    </element>
    <element id="Observation.device">
      <path value="Observation.device" />
      <short value="Reference to personal health device or its sensor type and calibration status" />
      <definition value="Reference to the DeviceMetric resource that describes the sensor type and calibration status of the personal health device or reference to the Device resource that describes the personal health device itself." />
      <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>