-
Notifications
You must be signed in to change notification settings - Fork 302
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
Add ability to validate the min/max for Date on a FHIR Questionnaire #1050
Conversation
… current date. - Add test case in QuestionnaireItemDatePickerViewHolderFactoryInstrumentedTest for checking "today()" filter code
Codecov Report
@@ Coverage Diff @@
## master #1050 +/- ##
=========================================
Coverage 84.15% 84.15%
Complexity 666 666
=========================================
Files 146 146
Lines 10609 10622 +13
Branches 807 809 +2
=========================================
+ Hits 8928 8939 +11
Misses 1278 1278
- Partials 403 405 +2
Continue to review full report at Codecov.
|
- Add test case in MinValueConstraintValidatorTest and QuestionnaireItemDatePickerViewHolderFactoryInstrumentedTest for checking "today()" filter code
…seItemValidatorTest
…raintValidatorTest.kt and MinValueConstraintValidatorTest.kt
Hi @RaaziaTarique! Thanks for the PR. If this is ready for review can you mark it so? |
Hi @jingtang10, this PR is ready but currently code coverage check for patch and project is failing. That's why it's still marked as draft. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RaaziaTarique thanks for this PR!
Can you please point me to any documentation (on hl7.org or other sites) on the expression today()
? I've seen this expression in questionnaires but couldn't find any actual documentation in the specifications.
if (extension.value is StringType && (extension.value as StringType).value.equals("today()") | ||
) { | ||
DateType(Date()) | ||
} else { | ||
extension.value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what you have done here, is to add the capability to parse an expression and convert it into a value of a different type. This shouldn't be done inside this class. There should be another class that handles the parsing and interpreting of expressions.
likewise for the min value constraint validator. you should not have the code duplication in these 2 classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create another class and will do the parsing there and use it on both max and min validator classes.
QuestionnaireResponse.QuestionnaireResponseItemComponent().apply { | ||
addAnswer( | ||
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply { | ||
value = DateType(2026, 0, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this test will start failing in year 2026?
is there a way for you to mock/fake the system date to make this test more stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using hardcoded date I can pass 5 years future date from current date. This will stable this test case as well.
# Conflicts: # datacapture/src/androidTest/java/com/google/android/fhir/datacapture/views/QuestionnaireItemDatePickerViewHolderFactoryInstrumentedTest.kt
I just found this sample "Library" where they using something similar to it http://hl7.org/fhir/uv/cpg/Library-CKDRiskLogic.html. Maybe @f-odhiambo can comment better on it. |
Looking into this :) |
Found the link for this particular filter. http://hl7.org/fhirpath/#datetime-arithmetic CC: @jingtang10 @f-odhiambo |
@RaaziaTarique have you used Can you try to use that instead of manually handling expressions? |
@jingtang10, I have not used it previously, checking it now. |
@jingtang10 , I checked that In |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maimoonak @RaaziaTarique @ekigamba please take a look i think this PR's logic is still incorrect.
@@ -29,10 +31,13 @@ internal object MaxValueConstraintValidator : | |||
predicate = { | |||
extension: Extension, | |||
answer: QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent -> | |||
answer.value > extension.value | |||
answer.value > extension.value.detectTodayDate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is assuming if there's a max value constraint for a date it will be today's date? this is incorrect logic!
internal fun Type.detectTodayDate(): Type = | ||
if (this is StringType && value.equals("today()")) { | ||
DateType(Date()) | ||
} else { | ||
this | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function signature is not great - it's very confusing. please refactor!
you shouldn't have vastly different behaviors due to date time.
@maimoonak @shoaibmushtaq25 @f-odhiambo can someone take over this PR please? My main issue with this PR is that the logic is very specific - we can't have this type of hard-coded logic just for |
@maimoonak @shoaibmushtaq25 @f-odhiambo is someone working on the changes suggested by @jingtang10 above? |
@aurangzaibumer is working on this and should be raising a PR. You can reassign to him @Tarun-Bhardwaj |
ok closing this in that case. thanks @f-odhiambo and @aurangzaibumer. |
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Fixes #1040
Description
Clear and concise code change description.
Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?
Type
Choose one: Feature
Screenshots (if applicable)
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project./gradlew check
and./gradlew connectedCheck
to test my changes locally