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

Fix issue with empty context with initial expression #1228

Merged
merged 36 commits into from
Apr 23, 2022

Conversation

RaaziaTarique
Copy link
Contributor

@RaaziaTarique RaaziaTarique commented Mar 10, 2022

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #1033

Description
Added functionality to use FhirPath functions such as today(), now() and etc.
Previously these functions were not supported in SDK because it was only using the extracted resource from the FhirPath expression and in case of FhirPath functions, the FhirPath Expressions doesn't have any resource name in it.

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 the Contributing page.
  • 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 demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

@codecov
Copy link

codecov bot commented Mar 10, 2022

Codecov Report

Merging #1228 (59ce913) into master (ae4c26a) will increase coverage by 0.02%.
The diff coverage is 86.66%.

@@             Coverage Diff              @@
##             master    #1228      +/-   ##
============================================
+ Coverage     84.50%   84.53%   +0.02%     
- Complexity      686      687       +1     
============================================
  Files           148      148              
  Lines         10697    10701       +4     
  Branches        832      832              
============================================
+ Hits           9040     9046       +6     
+ Misses         1244     1240       -4     
- Partials        413      415       +2     
Impacted Files Coverage Δ
...iews/QuestionnaireItemDropDownViewHolderFactory.kt 54.28% <0.00%> (+2.85%) ⬆️
...android/fhir/datacapture/mapping/ResourceMapper.kt 83.50% <92.85%> (+0.84%) ⬆️

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 3db36db...59ce913. Read the comment docs.

@f-odhiambo f-odhiambo marked this pull request as ready for review March 22, 2022 08:08
@ekigamba ekigamba self-requested a review March 22, 2022 13:20
@@ -957,6 +990,231 @@ class ResourceMapperTest {
.isEqualTo(true)
}

@Test
fun `populate() should fill QuestionnaireResponse with values when given a single Resource should use definition based extraction`() =
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Just a question. What does this test assert that the other population tests do not
  2. I think that the should use definition based extraction should not be part of this tests function and name

Copy link
Contributor Author

@RaaziaTarique RaaziaTarique Mar 24, 2022

Choose a reason for hiding this comment

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

As per the discussion, I have removed the definition based initial expression evaluation code and test cases in favour of itemPopulationContext http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemPopulationContext which will be handled in another PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool

@@ -490,6 +491,38 @@ class ResourceMapperTest {
assertThat(patient.telecom[0].value).isEqualTo("+254711001122")
}

@Test
fun `populate() should correctly populate current date in QuestionnaireResponse`() = runBlocking {
val ITEM_EXTRACTION_CONTEXT_EXTENSION_URL =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use this directly instead

@RaaziaTarique RaaziaTarique requested a review from ekigamba March 24, 2022 08:23
@@ -490,6 +491,38 @@ class ResourceMapperTest {
assertThat(patient.telecom[0].value).isEqualTo("+254711001122")
}

@Test
fun `populate() should correctly populate current date in QuestionnaireResponse`() = runBlocking {
val ITEM_EXTRACTION_CONTEXT_EXTENSION_URL =
Copy link
Collaborator

Choose a reason for hiding this comment

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

the name of this is wrong, this is not item extraction context. this is initial expression

@@ -198,17 +197,21 @@ object ResourceMapper {
) {
if (questionnaireItem.type != Questionnaire.QuestionnaireItemType.GROUP) {
questionnaireItem.fetchExpression?.let { exp ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you rename the fetchExpression property to intialExpression?

@RaaziaTarique RaaziaTarique requested a review from jingtang10 April 5, 2022 09:17
Comment on lines 215 to 216
extractedAnswers =
fhirPathEngine.evaluate(resources[0], expression.expression.removePrefix("%"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

these lines and line 221-222 are doing the same except for the context resource. So what you should do is to have

val contextResource = if( ... ) { ... } else { ... }

and then have

extractedAnswers =
          fhirPathEngine.evaluate(contextResource, expression.expression.removePrefix("%"))

Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this logic not in the function getContextResource?

@jingtang10 jingtang10 changed the title Initial expression support extension Fix issue with empty context with initial expression Apr 20, 2022
Copy link
Contributor

@aditya-07 aditya-07 left a comment

Choose a reason for hiding this comment

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

LGTM

@jingtang10
Copy link
Collaborator

Struggling to make the tests pass on GitHub even though they're passing locally...

@jingtang10
Copy link
Collaborator

tests should hopefully pass after #1324

@jingtang10 jingtang10 enabled auto-merge (squash) April 22, 2022 18:43
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.

initialExpression extension for advanced form behaviour
7 participants