Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set time zone from HK metadata in FHIR resources #50

Merged
merged 10 commits into from
Dec 29, 2024
Merged

Conversation

vishnuravi
Copy link
Member

@vishnuravi vishnuravi commented Dec 9, 2024

Set time zone from HK metadata in FHIR resources

♻️ Current situation & Problem

The HealthKitOnFHIR library currently assumes that HealthKit samples were created in the current time zone of the device at the time of mapping and applies the corresponding UTC offset. While this is true for most situations, it is possible that older HealthKit data may be mapped using the library that was created while the user was in a different time zone.

For example, if a sample was originally created by HealthKit in San Francisco on December 1st, 2024 at 9:00am (-08:00), but then mapped by HealthKitOnFHIR later on in New York, the timestamp would read 2024-12-01T12:00:00-05:00. While technically these are the same point in time, they are offset differently.

The information regarding the original timezone of the sample may be stored by HealthKit in the object's metadata via HKMetadataKeyTimeZone, if this was written by the original application or device that created the data, and we should use it to apply the appropriate offset.

⚙️ Release Notes

  • If a time zone has been defined in HKMetadataKeyTimeZone, it is set when serializing HealthKit samples.

✅ Testing

Unit tests have been updated to test that the appropriate offset is applied for multiple time zones specified via metadata and test that the offset of the current time zone is applied if none is specified.

Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.92%. Comparing base (a1a7125) to head (e20e9ae).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #50      +/-   ##
==========================================
+ Coverage   92.71%   92.92%   +0.21%     
==========================================
  Files          23       24       +1     
  Lines        1097     1115      +18     
==========================================
+ Hits         1017     1036      +19     
+ Misses         80       79       -1     
Files with missing lines Coverage Δ
.../HealthKit Extensions/HKSample+ResourceProxy.swift 97.44% <100.00%> (+0.30%) ⬆️
...nFHIR/HealthKit Extensions/HKSample+TimeZone.swift 100.00% <100.00%> (ø)
...HIR/Observation Extensions/Observation+Dates.swift 100.00% <100.00%> (+6.67%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1a7125...e20e9ae. Read the comment docs.

@vishnuravi vishnuravi marked this pull request as ready for review December 9, 2024 14:01
Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great; thank you for the quick feature addition! 👍

@PSchmiedmayer PSchmiedmayer added the enhancement New feature or request label Dec 9, 2024
@vishnuravi vishnuravi merged commit c898c0b into main Dec 29, 2024
10 checks passed
@vishnuravi vishnuravi deleted the time-zone branch December 29, 2024 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants