HealthKitToFhir

1.0.3

The HealthKitToFhir Swift Library provides a simple way to create FHIR Resources from HKObjects.
microsoft/healthkit-to-fhir

What's New

1.0.3

2021-03-04T01:14:34Z

Fixed issue with improper OS Version string.

HealthKitToFhir Swift Library

Build Status

The HealthKitToFhir Swift Library provides a simple way to create FHIR® Resources from HKObjects.

Installation

HealthKitToFhir uses Swift Package Manager to manage dependencies. It is recommended that you use Xcode 11 or newer to add HealthKitToFhir to your project.

  1. Using Xcode 11 go to File > Swift Packages > Add Package Dependency
  2. Paste the project URL: https://github.com/microsoft/healthkit-to-fhir
  3. Click on next and select the project target

Basic Usage

Create the factory

Resources are created using "Factory" classes that can be initialized with an optional JSON configuration to provide additional conversion data used to decorate the Resource. In the example below, an observation factory is initialized with no configuration.

do {
    let  factory = try ObservationFactory()
} catch {
    // Handle errors
}

Use the factory for creating resources

do {
    let observation = try factory.observation(from: healthKitObject)
} catch {
    // Handle errors
}

Supported conversions

Observations

Additional observation conversions can be added by providing a custom configuration to the ObservationFactory when it is initialized at runtime.

  • HKQuantityTypeIdentifierHeartRate
  • HKCorrelationTypeIdentifierBloodPressure
  • HKQuantityTypeIdentifierBloodPressureDiastolic
  • HKQuantityTypeIdentifierBloodPressureSystolic
  • HKQuantityTypeIdentifierStepCount
  • HKQuantityTypeIdentifierBloodGlucose
  • HKQuantityTypeIdentifierOxygenSaturation
  • HKQuantityTypeIdentifierBodyMass
  • HKQuantityTypeIdentifierBodyTemperature
  • HKQuantityTypeIdentifierRespiratoryRate
  • HKQuantityTypeIdentifierHeight
  • HKQuantityTypeIdentifierRestingHeartRate
  • HKQuantityTypeIdentifierHeartRateVariabilitySDNN
  • HKQuantityTypeIdentifierWalkingHeartRateAverage
  • HKQuantityTypeIdentifierAppleExerciseTime
  • HKQuantityTypeIdentifierAppleStandTime
  • HKQuantityTypeIdentifierActiveEnergyBurned
  • HKQuantityTypeIdentifierEnvironmentalAudioExposure
  • HKQuantityTypeIdentifierDietaryEnergyConsumed

Devices

The DeviceFactory will extract data provided in HKObject device and sourceRevision properties to create a Device Resource. No configuration is required for this conversion.

Adding support for new conversions

HealthKitToFhir uses JSON configuration files to provide additional data required to perform conversions from HealthKit HKObjects to FHIR Resources. The DefaultObservationFactoryConfig.json contains conversion data for the ObservationFactory class to support the types listed above.

The example below shows data used for converting an HKQuantitySample containing a Blood Glucose reading to a FHIR Resource. The HKObject type identifier is used to look up data required to populate the Observation, this includes the code and valueQuantity properties of the Blood Glucose Observation. This "static" data will be "copied" to the Observation during the conversion process, while values like the measurement, date, and identifier will be converted from properties of the HKObject.

"HKQuantityTypeIdentifierBloodGlucose": {
        "code": {
            "coding": [
                {
                    "system": "http://loinc.org",
                    "code": "41653-7",
                    "display": "Glucose Glucometer (BldC) [Mass/Vol]"
                }
            ]
        },
        "valueQuantity": {
            "unit" : "mg/dL",
            "system" : "http://unitsofmeasure.org",
            "code" : "mg/dL"
        }
    }

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

There are many other ways to contribute to the HealthKitToFhir Project.

See Contributing to HealthKitToFhir for more information.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

FHIR® is the registered trademark of HL7 and is used with the permission of HL7.

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

Last updated: Thu Apr 11 2024 08:33:40 GMT-0900 (Hawaii-Aleutian Daylight Time)