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

Implement inequality operators (<, >, <=, >=) in the enable when statement #848

Merged
merged 20 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review comment changes.
  • Loading branch information
santosh-pingle committed Nov 23, 2021
commit 196978fed83db535e6dfbbcd3d9de145410bb827
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
api(Dependencies.HapiFhir.structuresR4)

implementation(Dependencies.fhirUcum)
implementation(Dependencies.Kotlin.kotlinTestJunit)

testImplementation(Dependencies.AndroidxTest.core)
testImplementation(Dependencies.junit)
Expand Down
34 changes: 34 additions & 0 deletions common/src/test/java/com/google/android/fhir/MoreTypesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.google.android.fhir
import android.os.Build
import com.google.common.truth.Truth.assertThat
import java.util.Calendar
import kotlin.test.assertFailsWith
import org.hl7.fhir.r4.model.Attachment
import org.hl7.fhir.r4.model.BooleanType
import org.hl7.fhir.r4.model.Coding
Expand Down Expand Up @@ -204,4 +205,37 @@ class MoreTypesTest {
assertThat(exception.message)
.isEqualTo("Cannot compare different data types: decimal and integer")
}

@Test
fun compareTo_quantityType_shouldReturnPositiveValue() {
val value = Quantity().setCode("h").setValue(10)
val otherValue = Quantity().setCode("h").setValue(5)

assertThat(value.compareTo(otherValue)).isEqualTo(1)
}

@Test
fun compareTo_quantityType_shouldReturnZero() {
val value = Quantity().setCode("h").setValue(10)
val otherValue = Quantity().setCode("h").setValue(10)

assertThat(value.compareTo(otherValue)).isEqualTo(0)
}

@Test
fun compareTo_quantityType_shouldReturnNegativeValue() {
val value = Quantity().setCode("h").setValue(10)
val otherValue = Quantity().setCode("h").setValue(20)

assertThat(value.compareTo(otherValue)).isEqualTo(-1)
}

@Test
fun compareTo_quantityWithDifferentCodes_shouldFail() {
assertFailsWith<IllegalArgumentException> {
val value = Quantity().setCode("h").setValue(10)
val otherValue = Quantity().setCode("kg").setValue(5)
value.compareTo(otherValue)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ package com.google.android.fhir.datacapture.enablement
import android.os.Build
import com.google.common.truth.BooleanSubject
import com.google.common.truth.Truth.assertThat
import kotlin.test.assertFailsWith
import org.hl7.fhir.r4.model.BooleanType
import org.hl7.fhir.r4.model.Coding
import org.hl7.fhir.r4.model.IntegerType
import org.hl7.fhir.r4.model.Quantity
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.hl7.fhir.r4.model.Type
Expand Down Expand Up @@ -489,33 +487,6 @@ class EnablementEvaluatorTest {
.isFalse()
}

@Test
fun evaluate_quantityType_lessOrEqual_answerLessOrEqualEnableWhenAnswer_shouldReturnTrue() {
evaluateEnableWhen(
behavior = null,
EnableWhen(
operator = Questionnaire.QuestionnaireItemOperator.LESS_OR_EQUAL,
expected = Quantity().setCode("h").setValue(10),
actual = listOf(Quantity().setCode("h").setValue(5))
)
)
.isTrue()
}

@Test
fun evaluate_quantityWithDifferentCodes_shouldFail() {
assertFailsWith<IllegalArgumentException> {
evaluateEnableWhen(
behavior = null,
EnableWhen(
operator = Questionnaire.QuestionnaireItemOperator.LESS_OR_EQUAL,
expected = Quantity().setCode("h").setValue(10),
actual = listOf(Quantity().setCode("kg").setValue(5))
)
)
}
}

/**
* Evaluates multiple `enableWhen` constraints according to the `behavior` (any or all).
*
Expand Down