# Class GlucoseMeasurement

java.lang.Object
com.codename1.health.sensors.GlucoseMeasurement

public final class GlucoseMeasurement extends Object

A decoded Glucose Measurement, characteristic `0x2A18`.

##### Wire format

A flags byte, a `uint16` sequence number, a 7-byte base time, then the optional fields the flags select:

Bit | Meaning
--- | ---
0 | time offset present (`sint16` minutes)
1 | concentration, type and location present
2 | concentration units: 0 = kg/L, 1 = mol/L
3 | sensor status annunciation present
4 | context information will follow on `0x2A34`

##### The units bit selects a different quantity, not a different scale

A meter reporting kg/L transmits a mass concentration; one reporting mol/L transmits a molar concentration. Converting between them divides by the molar mass of glucose, 18.0182 -- it is not a generic unit conversion, and applying it to any other analyte would be wrong. This parser normalizes to mmol/L, the SI clinical unit, and exposes `getMilligramsPerDeciliter()` for the convention used in the United States.

##### Sequence numbers and stored records

Meters store readings and upload them in a burst, so the sequence number rather than the arrival order is what identifies a measurement. Retrieving stored records means driving the Record Access Control Point -- see `GlucoseRecordFilter` and `SensorSession.requestStoredRecords(GlucoseRecordFilter)`.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `SAMPLE_LOCATION_ALTERNATE_SITE`
  Alternate site test, such as the forearm.
  `static final int`
  `SAMPLE_LOCATION_CONTROL_SOLUTION`
  Control solution rather than blood -- a calibration check, and
  `static final int`
  `SAMPLE_LOCATION_EARLOBE`
  Earlobe.
  `static final int`
  `SAMPLE_LOCATION_FINGER`
  Fingertip.
  `static final int`
  `SAMPLE_LOCATION_UNKNOWN`
  The sample came from somewhere this profile does not name.
  `static final int`
  `TYPE_CONTROL_SOLUTION`
  The fluid-type code the profile assigns to control solution.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `double`
  `getMilligramsPerDeciliter()`
  The concentration in mg/dL, the unit used clinically in the United States, or `Double.NaN` when absent.
  `double`
  `getMillimolesPerLiter()`
  The concentration in mmol/L, or `Double.NaN` when this record carried none.
  `int`
  `getSampleLocation()`
  Where the sample was taken, as a `SAMPLE_LOCATION_` constant.
  `int`
  `getSampleType()`
  The fluid type code the meter reported -- capillary whole blood, venous plasma, interstitial fluid and so on.
  `int`
  `getSequenceNumber()`
  The meter's sequence number for this reading.
  `long`
  `getTimestampMillis()`
  When the reading was taken, epoch millis, or `-1` when the meter's clock was unset.
  `boolean`
  `hasConcentration()`
  `true` when this record carried a concentration.
  `boolean`
  `isContextFollowing()`
  `true` when the meter will follow this record with a context notification on `0x2A34` carrying meal, exercise and medication annotations.
  `boolean`
  `isControlSolution()`
  `true` when this reading came from control solution rather than blood and must not be stored as a glucose measurement.
  `static GlucoseMeasurement`
  `parse(byte[] value)`
  Decodes a `0x2A18` value.
  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### SAMPLE_LOCATION_UNKNOWN

    public static final int SAMPLE_LOCATION_UNKNOWN
    The sample came from somewhere this profile does not name.
    See Also:
      - Constant Field Values

  - ### SAMPLE_LOCATION_FINGER

    public static final int SAMPLE_LOCATION_FINGER
    Fingertip.
    See Also:
      - Constant Field Values

  - ### SAMPLE_LOCATION_ALTERNATE_SITE

    public static final int SAMPLE_LOCATION_ALTERNATE_SITE
    Alternate site test, such as the forearm.
    See Also:
      - Constant Field Values

  - ### SAMPLE_LOCATION_EARLOBE

    public static final int SAMPLE_LOCATION_EARLOBE
    Earlobe.
    See Also:
      - Constant Field Values

  - ### SAMPLE_LOCATION_CONTROL_SOLUTION

    public static final int SAMPLE_LOCATION_CONTROL_SOLUTION
    Control solution rather than blood -- a calibration check, and not a reading to store as the user's glucose.
    See Also:
      - Constant Field Values

  - ### TYPE_CONTROL_SOLUTION

    public static final int TYPE_CONTROL_SOLUTION

    The fluid-type code the profile assigns to control solution.

    A meter can say "this is not blood" through either nibble of the type-and-location byte, and they are independent: some report the type and leave the location unknown.

    See Also:
      - Constant Field Values

- ## Method Details

  - ### parse

    public static GlucoseMeasurement parse(byte[] value)
    Decodes a `0x2A18` value. Returns `null` for a malformed or truncated payload; never throws.

  - ### getSequenceNumber

    public int getSequenceNumber()
    The meter's sequence number for this reading. Stable across re-transmission, and the right key for de-duplicating a burst of stored records.

  - ### getTimestampMillis

    public long getTimestampMillis()
    When the reading was taken, epoch millis, or `-1` when the meter's clock was unset. Prefer this over the time of receipt -- stored records arrive long after the fact.

  - ### getMillimolesPerLiter

    public double getMillimolesPerLiter()
    The concentration in mmol/L, or `Double.NaN` when this record carried none.

  - ### getMilligramsPerDeciliter

    public double getMilligramsPerDeciliter()
    The concentration in mg/dL, the unit used clinically in the United States, or `Double.NaN` when absent.

  - ### hasConcentration

    public boolean hasConcentration()
    `true` when this record carried a concentration. A record without one is a placeholder the meter kept for a failed test.

  - ### getSampleLocation

    public int getSampleLocation()

    Where the sample was taken, as a `SAMPLE_LOCATION_` constant.

    Check for `SAMPLE_LOCATION_CONTROL_SOLUTION` before storing a reading as the user's glucose: that value means the meter was being calibrated against a test fluid, and recording it as a blood measurement puts a fictitious reading into their medical history.

  - ### getSampleType

    public int getSampleType()
    The fluid type code the meter reported -- capillary whole blood, venous plasma, interstitial fluid and so on.

  - ### isContextFollowing

    public boolean isContextFollowing()
    `true` when the meter will follow this record with a context notification on `0x2A34` carrying meal, exercise and medication annotations.

  - ### isControlSolution

    public boolean isControlSolution()

    `true` when this reading came from control solution rather than blood and must not be stored as a glucose measurement.

    Either nibble settles it. The profile carries control solution as a fluid type and as a sample location, and they are independent -- a meter that reports type 10 while leaving the location unknown is stating plainly that this is calibration fluid, and reading only the location published it as the user's blood glucose.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
    Overrides:
      `toString` in class `Object`