Skip to content

Commit

Permalink
Upload HealthKit Device to Firebase (#25)
Browse files Browse the repository at this point in the history
# *Upload HealthKit Device to Firebase*

## ♻️ Current situation & Problem
The default SpeziHealthKit implementation does not upload information
about which device generated a given HKSample (e.g., iPhone, Apple
Watch, Oura, etc.). This has significant implications for downstream
featurization, since a user wearing multiple devices might have
duplicated data.


## ⚙️ Release Notes 
* Access device name as a string using
`HKSample.sourceRevision.source.name`
* Manually encode the FHIR ResourceProxy and manually add a "device"
field containing the device name


## 📚 Documentation
*Please ensure that you properly document any additions in conformance
to [Spezi Documentation
Guide](https://github.com/StanfordSpezi/.github/blob/main/DOCUMENTATIONGUIDE.md).*
*You can use this section to describe your solution, but we encourage
contributors to document your reasoning and changes using in-line
documentation.*


## ✅ Testing
*Please ensure that the PR meets the testing requirements set by CodeCov
and that new functionality is appropriately tested.*
*This section describes important information about the tests and why
some elements might not be testable.*


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md):
- [X] I agree to follow the [Code of
Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
mjoerke committed Feb 15, 2024
1 parent 2c4f82f commit 161d3f6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Prisma/Standard/PrismaStandard+HealthKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ extension PrismaStandard {

// try push to Firestore.
do {
try await Firestore.firestore().document(path).setData(from: sample.resource)
let deviceName = sample.sourceRevision.source.name
let resource = try sample.resource
let encoder = FirebaseFirestore.Firestore.Encoder()
var firestoreResource = try encoder.encode(resource)
firestoreResource["device"] = deviceName
try await Firestore.firestore().document(path).setData(firestoreResource)
} catch {
print("Failed to set data in Firestore: \(error.localizedDescription)")
}
Expand Down

0 comments on commit 161d3f6

Please sign in to comment.