HealthKitToFhir Swift Library

Overview

HealthKitToFhir Swift Library

Relevant for my master thesis is the following: the ObservationFactory class was extended by all data types required for the master thesis. ECG, audiograms, workouts, categories and characteristic data from the HealthStore can now be converted to FHIR Observations.

The modified 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/Boogy2/healthkit-to-fhir-MSC
  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"
        }
    }

Supported Conversion

  • HKQuantityTypeIdentifierHeartRate
  • HKCorrelationTypeIdentifierBloodPressure
  • HKQuantityTypeIdentifierBloodPressureDiastolic
  • HKQuantityTypeIdentifierBloodPressureSystolic
  • HKQuantityTypeIdentifierStepCount
  • HKQuantityTypeIdentifierBloodGlucose
  • HKQuantityTypeIdentifierOxygenSaturation
  • HKQuantityTypeIdentifierBodyMass
  • HKQuantityTypeIdentifierBodyTemperature
  • HKQuantityTypeIdentifierRespiratoryRate
  • HKQuantityTypeIdentifierHeight
  • HKQuantityTypeIdentifierRestingHeartRate
  • HKQuantityTypeIdentifierHeartRateVariabilitySDNN
  • HKQuantityTypeIdentifierWalkingHeartRateAverage
  • HKQuantityTypeIdentifierAppleExerciseTime
  • HKQuantityTypeIdentifierAppleStandTime
  • HKQuantityTypeIdentifierActiveEnergyBurned
  • HKQuantityTypeIdentifierEnvironmentalAudioExposure
  • HKQuantityTypeIdentifierDietaryEnergyConsumed
  • HKAudiogramSample
  • HKElectrocardiogram
  • HKWorkout
  • HKCharacteristicsTypeIdentifier(HKHealthStore)
  • HKCategoryTypeIdentifierSleepAnalysis

Contributing

This project is a extended clone of:

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

You might also like...
Linenoise-Swift  A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement.
Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement.

Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement. Supports Mac OS and Linux Line edit

The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable
The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable

Q: How will my calendar dateCells look with this library? A: However you want them to look. More Images Features Range selection - select dates in a r

Swift Validator is a rule-based validation library for Swift.
Swift Validator is a rule-based validation library for Swift.

Swift Validator is a rule-based validation library for Swift. Core Concepts UITextField + [Rule] + (and optional error UILabel) go into

🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5
🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5

🧡 Easy to use SQLite ORM library written with Swift

Swift library to manage in app notification in swift language, like WhatsApp, Telegram, Frind, ecc.
Swift library to manage in app notification in swift language, like WhatsApp, Telegram, Frind, ecc.

InAppNotify - Manage in App notifications During develop of my app Frind, I needed to manage in app notifications like whatsapp or telegram, but i did

A Swift library for creating and exporting CoreML Models in Swift

SwiftCoreMLTools A Swift Library for creating CoreML models in Swift. Work in progress This library expose a (function builder based) DSL as well as a

swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

Kukai Crypto Swift is a native Swift library for creating regular or HD wallets for the Tezos blockchain

Kukai Crypto Swift Kukai Crypto Swift is a native Swift library for creating regular and HD key pairs for the Tezos blockchain. Supporting both TZ1 (E

AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.
AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

A library to simplify iOS animations in Swift.

Updated for Swift 4.2 Requires Xcode 10 and Swift 4.2. Installation Drop in the Spring folder to your Xcode project (make sure to enable "Copy items i

Swift library for choreographing animations on the screen.
Swift library for choreographing animations on the screen.

Spruce iOS Animation Library (and Android) What is it? Spruce is a lightweight animation library that helps choreograph the animations on the screen.

A fantastic Physical animation library for swift
A fantastic Physical animation library for swift

A fantastic Physical animation library for swift(Not Just Spring !!!), it is base on UIDynamic and extension to it, friendly APIs make you use it or c

Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app.
Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app.

Apphud SDK Apphud SDK is a lightweight open-source Swift library to manage auto-renewable subscriptions and other in-app purchases in your iOS app. No

Beethoven is an audio processing Swift library
Beethoven is an audio processing Swift library

Beethoven is an audio processing Swift library that provides an easy-to-use interface to solve an age-old problem of pitch detection of musical signals.

SwiftySound is a simple library that lets you deal with Swift sounds easily

SwiftySound Overview SwiftySound is a simple library that lets you deal with Swift sounds easily. Static methods Sound.play(file: "dog.wav") Sound.pla

CachyKit - A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.
CachyKit - A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.

Nice threadsafe expirable cache management that can cache any object. Supports fetching from server, single object expire date, UIImageView loading etc.

PrettyColors is a Swift library for styling and coloring text in the Terminal.

PrettyColors is a Swift library for styling and coloring text in the Terminal. The library outputs ANSI escape codes and conforms to ECMA Standard 48.

CommandLineKit - A pure Swift library for creating command-line interfaces

CommandLineKit A pure Swift library for creating command-line interfaces. Note: This project is no longer maintained. It's preserved here for historic

Owner
null
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

ANIMATED TAB BAR Swift UI module library for adding animation to iOS tabbar items and icons.

Ramotion 11k Jan 8, 2023
Numpy-like library in swift. (Multi-dimensional Array, ndarray, matrix and vector library)

Matft Matft is Numpy-like library in Swift. Function name and usage is similar to Numpy. Matft Feature & Usage Declaration MfArray MfType Subscription

null 80 Dec 21, 2022
FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices.

FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices. Demo The demo a

Zed 3 May 2, 2022
MRFoundation - A library to complement the Swift Standard Library

MRFoundation MRFoundation is a library to complement the Swift Standard Library.

Roman Mogutnov 2 Feb 12, 2022
SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Tim Wise 4 Oct 25, 2021
Simple library to detect motion type (walking, running, automotive) and count users steps. This library will make motion detection much more easily.

SOMotionDetector Simple library to detect motion for iOS by arturdev . Based on location updates and acceleration. ###Requierments iOS > 6.0 Compatibl

Artur  Mkrtchyan 1.1k Nov 25, 2022
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
This library for animating text. Developed with SwiftUI. This library supports iOS/macOS.

AnimateText This library for animating text. Developed with SwiftUI. This library supports iOS/macOS. Screenshot AnimateText.mp4 Example https://fabul

jasu 123 Jan 2, 2023