openmhealth_schemas 0.2.1+1 copy "openmhealth_schemas: ^0.2.1+1" to clipboard
openmhealth_schemas: ^0.2.1+1 copied to clipboard

A Flutter implementation of the Open mHealth (omh) schemas. Used for formatting health data collected from mobile phones (mHealth).

example/openmhealth_schemas_example.dart

import 'package:openmhealth_schemas/openmhealth_schemas.dart';
import 'dart:convert';

void main() {
  // Creating a [BloodPressure] similar to the one shown at
  // http://www.openmhealth.org/documentation/#/schema-docs/schema-library/schemas/omh_blood-pressure

  BloodPressure bp = BloodPressure(
      systolicBloodPressure: SystolicBloodPressure(
          unit: BloodPressureUnit.MM_OF_MERCURY, value: 160.0),
      diastolicBloodPressure: DiastolicBloodPressure(
          unit: BloodPressureUnit.MM_OF_MERCURY, value: 80.0),
      positionDuringMeasurement: PositionDuringMeasurement.SITTING);

  DateTime start = new DateTime(2016, 2, 5);
  DateTime end = new DateTime(2016, 6, 5);
  TimeInterval time = new TimeInterval(startDateTime: start, endDateTime: end);
  bp.effectiveTimeFrame = new TimeFrame(timeInterval: time);
  bp.descriptiveStatistic = DescriptiveStatistic.MAXIMUM;

  // Now convert this to JSON
  final bp_json = _encode(bp);
  print("\nBloodPressure:\n" + bp_json);

  // Similarly - create a [Geoposition] object, convert it to JSON and print it.
  Geoposition position = Geoposition(
      longitude: PlaneAngleUnitValue(
          unit: PlaneAngleUnit.DEGREE_OF_ARC, value: 40.059692382),
      latitude: PlaneAngleUnitValue(
          unit: PlaneAngleUnit.DEGREE_OF_ARC, value: -105.21440124511719),
      elevation: LengthUnitValue((LengthUnit.METER), 1548.5));

  position.positioningSystem = PositioningSystem.GPS;
  position.effectiveTimeFrame = new TimeFrame(dateTime: DateTime.now());
  print("\nGeoposition:\n" + _encode(position));

  //Creating OMH data point ready to be uploaded to an OMH sever

  //First, the data point for the blood pressure measure.
  DataPoint dp_1 = new DataPoint(body: bp);
  print("\nDataPoint_BloodPressure:\n" + _encode(dp_1));

  // Then the data point for the geo position measure.
  DataPoint dp_2 = new DataPoint(
    body: position,
    userId: "bardram",
    provenance: new DataPointAcquisitionProvenance(
        sourceName: "Android Nexus Phone", modality: DataPointModality.SENSED),
  );

  print("\nDataPoint_Geoposition:\n" + _encode(dp_2));

  //Finally, read a JSON string and convert it into a Flutter object.
  final act_1 =
      PhysicalActivity.fromJson(json.decode(omh_pa) as Map<String, dynamic>);

  print("\nA person has been " +
      act_1.activityName +
      " " +
      act_1.distance.value.toString() +
      " " +
      act_1.distance.unit);
}

String _encode(Object object) =>
    const JsonEncoder.withIndent(' ').convert(object);

// The following data is various OMH JSON examples from the OMH website.
// Testing if we can load these.
final String omh_pa =
    '{    "activity_name": "walking", "distance": { "value": 3.1, "unit": "mi" }, "effective_time_frame": { "time_interval": { "start_date_time": "2015-02-06T06:25:00Z", "end_date_time": "2015-02-06T07:25:00Z" } },"kcal_burned": {"value": 160,"unit": "kcal"},"met_value": 3.5}';
1
likes
120
pub points
28%
popularity

Publisher

verified publishercachet.dk

A Flutter implementation of the Open mHealth (omh) schemas. Used for formatting health data collected from mobile phones (mHealth).

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

json_annotation, uuid

More

Packages that depend on openmhealth_schemas