Skip to content

Commit

Permalink
added candidateExpression support (#1789)
Browse files Browse the repository at this point in the history
* added candidateExpression support

* spotless fixes

* spotless fixes

* feedback addressed

* remove unused map

* 🔨 fixed conflicts and revert change in QuestionnaireViewModel

* 🔨 revert change in QuestionnaireViewItem and also rename the variable in candidate-expression test

---------

Co-authored-by: Francis Odhiambo Otieno <[email protected]>
  • Loading branch information
owais-vd and f-odhiambo committed May 3, 2023
1 parent 390b3de commit 97a63ad
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ internal const val EXTENSION_ENABLE_WHEN_EXPRESSION_URL: String =
internal const val EXTENSION_ANSWER_EXPRESSION_URL: String =
"http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression"

internal const val EXTENSION_CANDIDATE_EXPRESSION_URL: String =
"http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression"

internal const val EXTENSION_CHOICE_COLUMN_URL: String =
"http:https://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn"

Expand Down Expand Up @@ -534,6 +537,12 @@ internal val Questionnaire.QuestionnaireItemComponent.answerExpression: Expressi
it.castToExpression(it)
}

internal val Questionnaire.QuestionnaireItemComponent.candidateExpression: Expression?
get() =
ToolingExtensions.getExtension(this, EXTENSION_CANDIDATE_EXPRESSION_URL)?.value?.let {
it.castToExpression(it)
}

// TODO implement full functionality of choice column
// https://github.com/google/android-fhir/issues/1495
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,55 @@ class MoreQuestionnaireItemComponentsTest {
assertThat(questionItem.itemFirstRep.answerExpression).isNull()
}

@Test
fun `candidateExpression should return expression`() {
val questionnaire =
Questionnaire()
.addItem(
Questionnaire.QuestionnaireItemComponent().apply {
linkId = "first-name"
type = Questionnaire.QuestionnaireItemType.CHOICE
extension =
listOf(
Extension(
EXTENSION_CANDIDATE_EXPRESSION_URL,
Expression().apply {
language = "text/fhirpath"
expression = "%resource.item.where(linkId='diseases').value"
}
)
)
}
)

assertThat(questionnaire.itemFirstRep.candidateExpression!!.expression)
.isEqualTo("%resource.item.where(linkId='diseases').value")
}

@Test
fun `candidateExpression should return null for missing extension`() {
val questionnaire =
Questionnaire()
.addItem(
Questionnaire.QuestionnaireItemComponent().apply {
linkId = "first-name"
type = Questionnaire.QuestionnaireItemType.CHOICE
extension =
listOf(
Extension(
ITEM_INITIAL_EXPRESSION_URL,
Expression().apply {
language = "text/fhirpath"
expression = "today()"
}
)
)
}
)

assertThat(questionnaire.itemFirstRep.candidateExpression).isNull()
}

@Test
fun `choiceColumn should return choice columns list`() {
val questionItem =
Expand Down

0 comments on commit 97a63ad

Please sign in to comment.