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

Add ability to validate the min/max for Date on a FHIR Questionnaire #1050

Closed
wants to merge 26 commits into from

Conversation

RaaziaTarique
Copy link
Contributor

@RaaziaTarique RaaziaTarique commented Jan 18, 2022

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

  • I have read and acknowledged the Code of conduct
  • I have read How to Contribute
  • I have read the Developer's guide
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally
  • I have built and run the reference app(s) to verify my change fixes the issue and/or does not break the reference app(s)

… current date.

- Add test case in QuestionnaireItemDatePickerViewHolderFactoryInstrumentedTest for checking "today()" filter code
@codecov
Copy link

codecov bot commented Jan 18, 2022

Codecov Report

Merging #1050 (a0d471a) into master (a292e50) will increase coverage by 0.00%.
The diff coverage is 88.23%.

@@            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     
Impacted Files Coverage Δ
...d/fhir/datacapture/utilities/TypeConversionUtil.kt 84.61% <77.77%> (-15.39%) ⬇️
...acapture/validation/MaxValueConstraintValidator.kt 100.00% <100.00%> (ø)
...acapture/validation/MinValueConstraintValidator.kt 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

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

@RaaziaTarique RaaziaTarique self-assigned this Jan 24, 2022
…raintValidatorTest.kt and MinValueConstraintValidatorTest.kt
@jingtang10
Copy link
Collaborator

Hi @RaaziaTarique! Thanks for the PR. If this is ready for review can you mark it so?

@RaaziaTarique
Copy link
Contributor Author

RaaziaTarique commented Jan 25, 2022

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.

Copy link
Collaborator

@jingtang10 jingtang10 left a 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.

Comment on lines 37 to 42
if (extension.value is StringType && (extension.value as StringType).value.equals("today()")
) {
DateType(Date())
} else {
extension.value
}
Copy link
Collaborator

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.

Copy link
Contributor Author

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

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
@RaaziaTarique
Copy link
Contributor Author

today()

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.

@f-odhiambo
Copy link
Collaborator

today()

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 :)

@RaaziaTarique
Copy link
Contributor Author

today()

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.

Found the link for this particular filter. http://hl7.org/fhirpath/#datetime-arithmetic CC: @jingtang10 @f-odhiambo

@jingtang10
Copy link
Collaborator

@RaaziaTarique have you used FHIRPathEngine before? See our usage https://github.com/google/android-fhir/search?q=fhirpathengine.

Can you try to use that instead of manually handling expressions?

@RaaziaTarique
Copy link
Contributor Author

@RaaziaTarique have you used FHIRPathEngine before? See our usage https://github.com/google/android-fhir/search?q=fhirpathengine.

Can you try to use that instead of manually handling expressions?

@jingtang10, I have not used it previously, checking it now.

@RaaziaTarique
Copy link
Contributor Author

@RaaziaTarique have you used FHIRPathEngine before? See our usage https://github.com/google/android-fhir/search?q=fhirpathengine.
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 ResourceMapper is using FHIRPathEngine but currently it's only using (http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression)

In ResourceMapper I added the functionality to detect "today()" field if passed as an expression and in ResourceMapper we are not using http://hl7.org/fhir/StructureDefinition/maxValue and http://hl7.org/fhir/StructureDefinition/minValue expressions as these expressions are being validated separately.

Copy link
Collaborator

@jingtang10 jingtang10 left a 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()
Copy link
Collaborator

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!

Comment on lines +50 to +55
internal fun Type.detectTodayDate(): Type =
if (this is StringType && value.equals("today()")) {
DateType(Date())
} else {
this
}
Copy link
Collaborator

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.

@jingtang10
Copy link
Collaborator

@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 today. We need to make a change that handles expressions in general. I'm ok with not having a full implementation of that, but the structure needs to be there. At the moment the code logic seems strange.

@Tarun-Bhardwaj
Copy link

@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 today. We need to make a change that handles expressions in general. I'm ok with not having a full implementation of that, but the structure needs to be there. At the moment the code logic seems strange.

@maimoonak @shoaibmushtaq25 @f-odhiambo is someone working on the changes suggested by @jingtang10 above?

@f-odhiambo
Copy link
Collaborator

@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 today. We need to make a change that handles expressions in general. I'm ok with not having a full implementation of that, but the structure needs to be there. At the moment the code logic seems strange.

@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

@jingtang10
Copy link
Collaborator

ok closing this in that case. thanks @f-odhiambo and @aurangzaibumer.

@jingtang10 jingtang10 closed this Jun 15, 2022
@jingtang10 jingtang10 deleted the 1040_date_validation branch July 1, 2022 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add ability to validate the min/max for Date on a FHIR Questionnaire
4 participants