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 DateTimeType to search #419

Merged
merged 39 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d765f84
Add date to search
epicadk Apr 2, 2021
81628a2
Fix tests
epicadk Apr 3, 2021
aa2df65
Handle ParamPrefix
epicadk Apr 3, 2021
875fcda
Refractor: BigDecimal to Long
epicadk Apr 3, 2021
a66fa6d
Add test
epicadk Apr 12, 2021
dee5178
Merge remote-tracking branch 'upstream/master' into date_search
epicadk Apr 19, 2021
d32bff4
Merge branch 'master' into date_search
epicadk Apr 22, 2021
f7b5701
Empty commit
epicadk Apr 23, 2021
2455119
Merge branch 'master' into date_search
epicadk Apr 23, 2021
f2baaf9
Fix failing tests
epicadk May 6, 2021
348682d
Fix merge conflicts
epicadk May 10, 2021
2263927
Add tests and minor fixes
epicadk May 10, 2021
53026fa
Add tests
epicadk May 10, 2021
7c30e56
Merge branch 'master' into date_search
epicadk May 10, 2021
16e0a7a
Minor fix
epicadk May 10, 2021
9b76cd2
Merge branch 'date_search' of https://github.com/epicadk/android-fhir…
epicadk May 10, 2021
91cee66
Merge branch 'master' into date_search
epicadk May 13, 2021
f359dfd
Merge branch 'master' into date_search
epicadk Jun 1, 2021
e3f59a7
Apply spotless
epicadk Jun 1, 2021
daf5506
address review comments
epicadk Jun 3, 2021
e876536
Merge branch 'master' into date_search
epicadk Jun 3, 2021
ca58df5
Apply spotless
epicadk Jun 3, 2021
fe0174e
Apply spotless
epicadk Jun 4, 2021
851e930
Merge branch 'master' into date_search
epicadk Jun 7, 2021
93d80f5
address review comments
epicadk Jun 7, 2021
f6c5dfb
Merge branch 'master' into date_search
epicadk Jun 12, 2021
2610cce
Apply spotless
epicadk Jun 14, 2021
5675762
Merge branch 'master' into date_search
epicadk Jun 15, 2021
38e4942
Improve tests
epicadk Jun 15, 2021
c166f67
Update engine/src/main/java/com/google/android/fhir/search/MoreSearch.kt
epicadk Jun 16, 2021
f53a1d4
Update engine/src/main/java/com/google/android/fhir/search/MoreSearch.kt
epicadk Jun 16, 2021
c5bae83
Update engine/src/main/java/com/google/android/fhir/search/MoreSearch.kt
epicadk Jun 16, 2021
9dbc124
address review comments
epicadk Jun 16, 2021
cda990a
address review comments
epicadk Jun 17, 2021
63bc9e8
address review comments
epicadk Jun 21, 2021
0db7045
Merge branch 'master' into date_search
epicadk Jun 21, 2021
cf68cf0
address review comments
epicadk Jun 21, 2021
f2e5386
Merge branch 'date_search' of https://github.com/epicadk/android-fhir…
epicadk Jun 21, 2021
1c6e4a3
address review comments
epicadk Jun 21, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.google.common.truth.Truth.assertThat
import java.math.BigDecimal
import kotlinx.coroutines.runBlocking
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.DateTimeType
import org.hl7.fhir.r4.model.DecimalType
import org.hl7.fhir.r4.model.Enumerations
import org.hl7.fhir.r4.model.HumanName
Expand Down Expand Up @@ -964,6 +965,357 @@ class DatabaseImplTest {
assertThat(result).isEmpty()
}

@Test
fun search_date_starts_after() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-23T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.STARTS_AFTER
value = DateTimeType("2013-03-14")
Copy link
Contributor

Choose a reason for hiding this comment

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

The DateTimeType supplied above to patient has time zone but not here. Will running the query in different time zones produce consistent results?

Can we add tests for that case or create an issue to add them later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I have opened #567

}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}

@Test
fun search_date_starts_after_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-13T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.STARTS_AFTER
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

@Test
fun search_date_ends_before() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-13T01:00:00")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.ENDS_BEFORE
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}

@Test
fun search_date_ends_before_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2014-03-13T01:00:00")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.ENDS_BEFORE
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

@Test
fun search_date_not_equals() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-13T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.NOT_EQUAL
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}

@Test
fun search_date_not_equals_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-14T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.NOT_EQUAL
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

@Test
fun search_date_equals() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-14T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.EQUAL
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}

@Test
fun search_date_equals_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-13T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.EQUAL
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

@Test
fun search_date_greater() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-15")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.GREATERTHAN
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}

@Test
fun search_date_greater_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-14T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.GREATERTHAN
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

@Test
fun search_date_greater_or_equal() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-14T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.GREATERTHAN_OR_EQUALS
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}
@Test
fun search_date_greater_or_equal_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-13T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.GREATERTHAN_OR_EQUALS
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

@Test
fun search_date_less() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-13")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.LESSTHAN
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}

@Test
fun search_date_less_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-14T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.LESSTHAN
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

@Test
fun search_date_less_or_equal() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-14T10:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.LESSTHAN_OR_EQUALS
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result.single().id).isEqualTo("Patient/1")
}

@Test
fun search_date_less_or_equal_noMatch() = runBlocking {
val patient =
Patient().apply {
id = "1"
deceased = DateTimeType("2013-03-14T23:00:00-05:30")
}
database.insert(patient)
val result =
database.search<Patient>(
Search(ResourceType.Patient)
.apply {
filter(Patient.DEATH_DATE) {
prefix = ParamPrefixEnum.LESSTHAN_OR_EQUALS
value = DateTimeType("2013-03-14")
}
}
.getQuery()
)
assertThat(result).isEmpty()
}

private companion object {
const val TEST_PATIENT_1_ID = "test_patient_1"
val TEST_PATIENT_1 = Patient()
Expand Down
Loading