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

Support initial expression extension in questionnaire population #1295

Closed

Conversation

RaaziaTarique
Copy link
Contributor

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

RaaziaTarique and others added 30 commits March 10, 2022 09:04
- Add test cases in ResourceMapperTest.kt
@codecov
Copy link

codecov bot commented Apr 14, 2022

Codecov Report

Merging #1295 (6c33f0d) into master (d33bbf4) will increase coverage by 0.01%.
The diff coverage is 91.30%.

@@             Coverage Diff              @@
##             master    #1295      +/-   ##
============================================
+ Coverage     84.53%   84.54%   +0.01%     
- Complexity      684      688       +4     
============================================
  Files           148      148              
  Lines         10687    10699      +12     
  Branches        826      827       +1     
============================================
+ Hits           9034     9046      +12     
  Misses         1244     1244              
  Partials        409      409              
Impacted Files Coverage Δ
...android/fhir/datacapture/mapping/ResourceMapper.kt 83.65% <91.30%> (+1.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 fccb883...6c33f0d. Read the comment docs.

@jingtang10 jingtang10 changed the title Initial expression support extension Support initial expression extension in questionnaire population Apr 14, 2022
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.

can you please create an issue in the codebase, so that in the validator API, we will throw an exception if inital value and intial value expression are both present.

reference this url: http:https://build.fhir.org/ig/HL7/sdc/expressions.html

and this sentence: Since both initial.value and initialExpression generate values before the user has access to the form, it is not allowed to have both present on a Questionnaire.item.

.addItem(
Questionnaire.QuestionnaireItemComponent().apply {
linkId = "patient-dob"
type = Questionnaire.QuestionnaireItemType.TEXT
Copy link
Collaborator

Choose a reason for hiding this comment

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

why isn't this DATE type?

val patient = Patient().apply { id = "Patient/$patientId/_history/2" }
val questionnaireResponse = ResourceMapper.populate(questionnaire, patient)

assertThat((questionnaireResponse.item[0].answer[0].value as DateType).localDate)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assertThat((questionnaireResponse.item[0].answer[0].value as DateType).localDate)
assertThat((questionnaireResponse.item.single().answer.single().value as DateType).localDate)

val patient = Patient().apply { id = "Patient/$patientId/_history/2" }
val questionnaireResponse = ResourceMapper.populate(questionnaire, patient)

assertThat((questionnaireResponse.item[0].answer[0].value as DateType).localDate)
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 compare the two DateTypes directly instead of converting them to local date?

look at the equalsDeep function in HAPI lib.

then your assert becomes something like this:

assert(this.equalsDeep(that)).isTrue()

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 tried to use equalsDeep but it was returning false because of the minor time difference in currentDate and date returned from FHIRPath Function.
I added another assertions to make sure that FHIRPath Function returns currentDate
assertThat(fhirFunctionDateType.isToday).isTrue()

@@ -514,7 +548,7 @@ private fun wrapAnswerInFieldType(answer: Base, fieldType: Field): Base {
return answer
}

private const val ITEM_INITIAL_EXPRESSION_URL: String =
const val ITEM_INITIAL_EXPRESSION_URL: String =
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this be internal?

@@ -21,6 +21,7 @@ import android.os.Build
import androidx.test.core.app.ApplicationProvider
import ca.uhn.fhir.context.FhirContext
import ca.uhn.fhir.parser.IParser
import com.google.android.fhir.datacapture.views.localDate
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can be removed - see later comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reason mentioned here #1295 (comment)

Comment on lines 241 to 242
// extension function for evaluating provided initial expression and using the result as an
// initial value of the QuestionnaireItemComponent
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// extension function for evaluating provided initial expression and using the result as an
// initial value of the QuestionnaireItemComponent
// Extension function for evaluating provided initial expression and using the result as an
// initial value of the QuestionnaireItemComponent.

)
}
}
questionnaireItem.setInitialValueFromInitialExpression(resources = resources.asList())
Copy link
Collaborator

Choose a reason for hiding this comment

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

please rename populateInitialValue to populateIntialValueWithInitialExpression.

@RaaziaTarique
Copy link
Contributor Author

@jingtang10, I have incorporated all the requested changes. Kindly re-review this PR.

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.

What's the relationship between this PR and #1228?

I worked on #1228 and added some refactoring.

@RaaziaTarique
Copy link
Contributor Author

RaaziaTarique commented Apr 21, 2022

What's the relationship between this PR and #1228?

I worked on #1228 and added some refactoring.

I created this PR as I don't have write access of https://github.com/google/android-fhir repo. I have resolved the changes that you requested earlier on this PR due to the same reason.

@jingtang10
Copy link
Collaborator

Thanks @RaaziaTarique

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.

None yet

3 participants