StanfordBDHG / ResearchKitOnFHIR

HL7 FHIR Structured Data Capture with ResearchKit on iOS
https://swiftpackageindex.com/StanfordBDHG/ResearchKitOnFHIR/documentation
MIT License
13 stars 2 forks source link

Add support for FHIRPath expression-based, relative min and max date extensions #80

Closed Supereg closed 6 months ago

Supereg commented 6 months ago

Add support for FHIRPath expression-based, relative min and max date extensions

:recycle: Current situation & Problem

Currently, with date questionnaire items, FHIR only supports exact min and max date values (e.g., exact date like 2024-04-14). However, as it is typical with, e.g., a date of birth picker, you want to restrict the max date relative to the current date (e.g., no value larger than today). Equally, specifying a min value that is relative to the current time might be desirable.

The Phoenix builder currently supports specifying such relative date ranges using FHIRPath expressions. This looks something like today() + 3 months or just today(). See FHIRPath and Current date and time functions.

This PR adds functionality for these expressions, implementing a parsers for the FHIRPath Grammar using Antlr4. It uses the generated syntax tree parser and implements a just in time evaluation for date expressions. All these operations are implemented in the internal FHIRPathParser target.

Consequentially, we integrate that with the ResearchKitOnFHIR conversion logic to consider the extensions from phoenix and parse the respective expressions.

:gear: Release Notes

:books: Documentation

Documentation was added for all new infrastructure.

:white_check_mark: Testing

Unit tests were added to verify the implementation for the date expression evaluation.

Code of Conduct & Contributing Guidelines

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

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 71.30435% with 132 lines in your changes are missing coverage. Please review.

Project coverage is 81.95%. Comparing base (7cd02fe) to head (ddeadcc).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80/graphs/tree.svg?width=650&height=150&src=pr&token=A9IUX2PFCL&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG)](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG) ```diff @@ Coverage Diff @@ ## main #80 +/- ## =========================================== + Coverage 69.62% 81.95% +12.33% =========================================== Files 9 27 +18 Lines 971 2908 +1937 =========================================== + Hits 676 2383 +1707 - Misses 295 525 +230 ``` | [Files](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG) | Coverage Δ | | |---|---|---| | [Sources/FHIRPathParser/DateExpressionError.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Sources%2FFHIRPathParser%2FDateExpressionError.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-U291cmNlcy9GSElSUGF0aFBhcnNlci9EYXRlRXhwcmVzc2lvbkVycm9yLnN3aWZ0) | `100.00% <100.00%> (ø)` | | | [Sources/FHIRPathParser/FHIRPathExpression.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Sources%2FFHIRPathParser%2FFHIRPathExpression.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-U291cmNlcy9GSElSUGF0aFBhcnNlci9GSElSUGF0aEV4cHJlc3Npb24uc3dpZnQ=) | `100.00% <100.00%> (ø)` | | | [...ests/FHIRPathParserTests/FHIRPathParserTests.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Tests%2FFHIRPathParserTests%2FFHIRPathParserTests.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-VGVzdHMvRkhJUlBhdGhQYXJzZXJUZXN0cy9GSElSUGF0aFBhcnNlclRlc3RzLnN3aWZ0) | `95.96% <95.96%> (ø)` | | | [Sources/FHIRPathParser/Date+FHIRPathValue.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Sources%2FFHIRPathParser%2FDate%2BFHIRPathValue.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-U291cmNlcy9GSElSUGF0aFBhcnNlci9EYXRlK0ZISVJQYXRoVmFsdWUuc3dpZnQ=) | `69.57% <69.57%> (ø)` | | | [...RToResearchKit/QuestionnaireItem+ResearchKit.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Sources%2FResearchKitOnFHIR%2FFHIRToResearchKit%2FQuestionnaireItem%2BResearchKit.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-U291cmNlcy9SZXNlYXJjaEtpdE9uRkhJUi9GSElSVG9SZXNlYXJjaEtpdC9RdWVzdGlvbm5haXJlSXRlbStSZXNlYXJjaEtpdC5zd2lmdA==) | `73.24% <0.00%> (-1.67%)` | :arrow_down: | | [...earchKitOnFHIR/FHIRExtensions/FHIRExtensions.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Sources%2FResearchKitOnFHIR%2FFHIRExtensions%2FFHIRExtensions.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-U291cmNlcy9SZXNlYXJjaEtpdE9uRkhJUi9GSElSRXh0ZW5zaW9ucy9GSElSRXh0ZW5zaW9ucy5zd2lmdA==) | `38.00% <61.54%> (-0.49%)` | :arrow_down: | | [...ces/FHIRPathParser/DateComponents+Operations.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Sources%2FFHIRPathParser%2FDateComponents%2BOperations.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-U291cmNlcy9GSElSUGF0aFBhcnNlci9EYXRlQ29tcG9uZW50cytPcGVyYXRpb25zLnN3aWZ0) | `53.58% <53.58%> (ø)` | | | [...rces/FHIRPathParser/DateExpressionEvaluation.swift](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?src=pr&el=tree&filepath=Sources%2FFHIRPathParser%2FDateExpressionEvaluation.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG#diff-U291cmNlcy9GSElSUGF0aFBhcnNlci9EYXRlRXhwcmVzc2lvbkV2YWx1YXRpb24uc3dpZnQ=) | `65.54% <65.54%> (ø)` | | ... and [12 files with indirect coverage changes](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG) ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG). Last update [7cd02fe...ddeadcc](https://app.codecov.io/gh/StanfordBDHG/ResearchKitOnFHIR/pull/80?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordBDHG).
Supereg commented 6 months ago

The generated parser dramatically reduces our code coverage. Not sure if it makes sense to exclude it somehow from the codecov report?

vishnuravi commented 6 months ago

The generated parser dramatically reduces our code coverage. Not sure if it makes sense to exclude it somehow from the codecov report?

This is incredible work @Supereg! :rocket:

Perhaps it makes sense to make the FHIRPathParser into a separate Swift package or part of SpeziFHIR? This would not only address the code coverage issue, but also make it easier to use for other use cases beyond ResearchKit surveys, and could be expanded beyond date expressions in the near future.

Supereg commented 6 months ago

Perhaps it makes sense to make the FHIRPathParser into a separate Swift package or part of SpeziFHIR? This would not only address the code coverage issue, but also make it easier to use for other use cases beyond ResearchKit surveys, and could be expanded beyond date expressions in the near future.

As discussed, I think that would be a great step forward to eventually branch it out into a SpeziFHIR package. However, this would probably require a bit more work building a proper abstract syntax tree (AST) around the current syntax tree generated by Antlr. So for now, let's leave it as an internal target that just drives some of our features 🚀

vishnuravi commented 6 months ago

Perhaps it makes sense to make the FHIRPathParser into a separate Swift package or part of SpeziFHIR? This would not only address the code coverage issue, but also make it easier to use for other use cases beyond ResearchKit surveys, and could be expanded beyond date expressions in the near future.

As discussed, I think that would be a great step forward to eventually branch it out into a SpeziFHIR package. However, this would probably require a bit more work building a proper abstract syntax tree (AST) around the current syntax tree generated by Antlr. So for now, let's leave it as an internal target that just drives some of our features 🚀

Sounds good to me!