healthkitonfhir
Converts HealthKit data to HL7 FHIR resources
Science Score: 64.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: zenodo.org -
✓Committers with academic emails
1 of 7 committers (14.3%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.9%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Converts HealthKit data to HL7 FHIR resources
Basic Info
- Host: GitHub
- Owner: StanfordBDHG
- License: mit
- Language: Swift
- Default Branch: main
- Homepage: https://swiftpackageindex.com/StanfordBDHG/HealthKitOnFHIR/documentation
- Size: 246 KB
Statistics
- Stars: 24
- Watchers: 14
- Forks: 9
- Open Issues: 2
- Releases: 24
Topics
Metadata Files
README.md
HealthKitOnFHIR
The HealthKitOnFHIR library provides extensions that convert supported HealthKit samples to corresponding FHIR resources using FHIRModels encapsulated in a ResourceProxy.
For more information, please refer to the API documentation.
HealthKitOnFHIR supports: - Extensions to convert data from Apple HealthKit to HL7® FHIR® R4. - Customizable mappings between HealthKit data types and standardized codes (e.g., LOINC)
Please refer to the HKObject Support Table for a complete list of supported types.
[!NOTE] HealthKitOnFHIR will use the time zone specified in HKMetadataKeyTimeZone when creating FHIR Observations from HealthKit samples. If no time zone is specified, HealthKitOnFHIR will use the device's current time zone.
Installation
HealthKitOnFHIR can be installed into your Xcode project using Swift Package Manager.
- In Xcode 14 and newer (requires Swift 5.7), go to “File” » “Add Packages...”
- Enter the URL to this GitHub repository, then select the
HealthKitOnFHIRpackage to install.
Usage
The HealthKitOnFHIR library provides extensions that convert supported HealthKit samples to corresponding FHIR resources using FHIRModels encapsulated in a ResourceProxy.
swift
let sample: HKSample = // ...
let resource = try sample.resource()
Observations
HKQuantitySample, HKCategorySample, HKCorrelationSample, HKElectrocardiogram, and HKWorkout will be converted into FHIR Observation resources encapsulated in a ResourceProxy.
swift
let sample: HKQuantitySample = // ...
let observation = try sample.resource().get(if: Observation.self)
Codes and units can be customized by passing in a custom HKSampleMapping instance to the resource(withMapping:) method.
swift
let sample: HKQuantitySample = // ...
let sampleMapping: HKSampleMapping = // ...
let observation = try sample.resource(withMapping: sampleMapping).get(if: Observation.self)
Clinical Records
HKClinicalRecord will be converted to FHIR resources based on the type of its underlying data. Only records encoded in FHIR R4 are supported at this time.
swift
let allergyRecord: HKClinicalRecord = // ...
let allergyIntolerance = try allergyRecord.resource().get(if: AllergyIntolerance.self)
Example
In the following example, we will query the HealthKit store for heart rate data, convert the resulting samples to FHIR observations, and encode them into JSON.
```swift import HealthKitOnFHIR
// Initialize an HKHealthStore instance and request permissions with it // ...
let date = ISO8601DateFormatter().date(from: "1885-11-11T00:00:00-08:00") ?? .now let sample = HKQuantitySample( type: HKQuantityType(.heartRate), quantity: HKQuantity(unit: HKUnit.count().unitDivided(by: .minute()), doubleValue: 42.0), start: date, end: date )
// Convert the results to FHIR observations let observation: Observation? do { try observation = sample.resource().get(if: Observation.self) } catch { // Handle any mapping errors here. // ... }
// Encode FHIR observations as JSON let encoder = JSONEncoder() encoder.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes, .sortedKeys]
guard let observation, let data = try? encoder.encode(observation) else { // Handle any encoding errors here. // ... }
// Print the resulting JSON let json = String(decoding: data, as: UTF8.self) print(json) ```
The following example generates the following FHIR observation:
json
{
"code" : {
"coding" : [
{
"code" : "8867-4",
"display" : "Heart rate",
"system" : "http://loinc.org"
}
]
},
"effectiveDateTime" : "1885-11-11T00:00:00-08:00",
"identifier" : [
{
"id" : "8BA093D9-B99B-4A3C-8C9E-98C86F49F5D8"
}
],
"issued" : "2023-01-01T00:00:00-08:00",
"resourceType" : "Observation",
"status" : "final",
"valueQuantity" : {
"code": "/min",
"unit": "beats/minute",
"system": "http://unitsofmeasure.org",
"value" : 42
}
}
License
This project is licensed under the MIT License. See Licenses for more information.
Contributors
This project is developed as part of the Stanford Biodesign for Digital Health projects at Stanford. See CONTRIBUTORS.md for a full list of all HealthKitOnFHIR contributors.
Notices
HealthKit is a registered trademark of Apple, Inc. FHIR is a registered trademark of Health Level Seven International.

Owner
- Name: Stanford Biodesign Digital Health
- Login: StanfordBDHG
- Kind: organization
- Location: United States of America
- Twitter: StanfordBDHG
- Repositories: 18
- Profile: https://github.com/StanfordBDHG
Citation (CITATION.cff)
# # This source file is part of the HealthKitOnFHIR open source project # # SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) # # SPDX-License-Identifier: MIT # cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Ravi" given-names: "Vishnu" orcid: "https://orcid.org/0000-0003-0359-1275" - family-names: "Schmiedmayer" given-names: "Paul" orcid: "https://orcid.org/0000-0002-8607-9148" - family-names: "Aalami" given-names: "Oliver" orcid: "https://orcid.org/0000-0002-7799-2429" title: "HealthKitOnFHIR" doi: 10.5281/zenodo.7538171 url: "https://github.com/StanfordBDHG/HealthKitOnFHIR"
GitHub Events
Total
- Create event: 17
- Release event: 7
- Issues event: 6
- Watch event: 3
- Delete event: 9
- Member event: 2
- Issue comment event: 20
- Push event: 52
- Pull request review comment event: 21
- Pull request review event: 22
- Pull request event: 16
Last Year
- Create event: 17
- Release event: 7
- Issues event: 6
- Watch event: 3
- Delete event: 9
- Member event: 2
- Issue comment event: 20
- Push event: 52
- Pull request review comment event: 21
- Pull request review event: 22
- Pull request event: 16
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Vishnu Ravi | v****i@g****m | 26 |
| Paul Schmiedmayer | P****r | 16 |
| Lukas Kollmer | h****y@l****e | 8 |
| Vasiliki (Vicky) Bikia | v****a@g****m | 1 |
| Matthew Turk | m****5@g****m | 1 |
| Andreas Bauer | a****r@s****u | 1 |
| Matthew Jörke | m****e@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 4
- Total pull requests: 48
- Average time to close issues: 28 days
- Average time to close pull requests: 2 days
- Total issue authors: 3
- Total pull request authors: 7
- Average comments per issue: 0.5
- Average comments per pull request: 1.1
- Merged pull requests: 47
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 7
- Average time to close issues: 28 days
- Average time to close pull requests: 5 days
- Issue authors: 2
- Pull request authors: 4
- Average comments per issue: 0.67
- Average comments per pull request: 1.29
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- vishnuravi (2)
- PSchmiedmayer (1)
- Dlemex (1)
- philippzagar (1)
Pull Request Authors
- vishnuravi (29)
- PSchmiedmayer (19)
- lukaskollmer (9)
- MatthewTurk247 (2)
- Vicbi (2)
- Supereg (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 6
- Total dependent repositories: 6
- Total versions: 24
swiftpackageindex.com: github.com/StanfordBDHG/HealthKitOnFHIR
Converts HealthKit data to HL7 FHIR resources
- Homepage: https://swiftpackageindex.com/StanfordBDHG/HealthKitOnFHIR/documentation
- Documentation: https://swiftpackageindex.com/StanfordBDHG/HealthKitOnFHIR/documentation
- License: mit
-
Latest release: 1.1.2
published 8 months ago
Rankings
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- ad-m/github-push-action v0.6.0 composite