Skip to content

Commit

Permalink
Merge branch 'master' into ak/workflow-api-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-07 authored Dec 30, 2024
2 parents 373a477 + 69b8ebf commit 9138067
Show file tree
Hide file tree
Showing 18 changed files with 567 additions and 494 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ internal data class QuestionnairePage(
)

internal val QuestionnairePagination.hasPreviousPage: Boolean
get() = pages.any { it.index < currentPageIndex && it.enabled }
get() = pages.any { it.index < currentPageIndex && it.enabled && !it.hidden }

internal val QuestionnairePagination.hasNextPage: Boolean
get() = pages.any { it.index > currentPageIndex && it.enabled }
get() = pages.any { it.index > currentPageIndex && it.enabled && !it.hidden }
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,102 @@ class QuestionnaireViewModelTest {
// Pagination //
// //
// ==================================================================== //
@Test
fun `should include all top level items as pages when any item has page extension`() = runTest {
val questionnaire =
Questionnaire().apply {
id = "a-questionnaire"
addItem(
QuestionnaireItemComponent().apply {
linkId = "page1-noExtension"
type = Questionnaire.QuestionnaireItemType.GROUP
addItem(
QuestionnaireItemComponent().apply {
linkId = "page1-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 1"
},
)
},
)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page2"
type = Questionnaire.QuestionnaireItemType.GROUP
addExtension(paginationExtension)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page2-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 2"
},
)
},
)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page3-noExtension"
type = Questionnaire.QuestionnaireItemType.GROUP
addItem(
QuestionnaireItemComponent().apply {
linkId = "page3-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 3"
},
)
},
)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page4-noExtension-hidden"
addExtension(hiddenExtension)
type = Questionnaire.QuestionnaireItemType.GROUP
addItem(
QuestionnaireItemComponent().apply {
linkId = "page4-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 4"
},
)
},
)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page5"
type = Questionnaire.QuestionnaireItemType.GROUP
addExtension(paginationExtension)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page5-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 5"
},
)
},
)
}

val viewModel = createQuestionnaireViewModel(questionnaire)
viewModel.runViewModelBlocking {
assertThat(
(viewModel.questionnaireStateFlow.value.displayMode as DisplayMode.EditMode).pagination,
)
.isEqualTo(
QuestionnairePagination(
isPaginated = true,
pages =
listOf(
QuestionnairePage(0, enabled = true, hidden = false),
QuestionnairePage(1, enabled = true, hidden = false),
QuestionnairePage(2, enabled = true, hidden = false),
QuestionnairePage(3, enabled = true, hidden = true),
QuestionnairePage(4, enabled = true, hidden = false),
),
currentPageIndex = 0,
),
)
}
}

@Test
fun `should show current page`() = runTest {
Expand Down Expand Up @@ -1830,8 +1926,11 @@ class QuestionnaireViewModelTest {
}
val viewModel = createQuestionnaireViewModel(questionnaire)
viewModel.runViewModelBlocking {
val questionnaireStatePagination =
(viewModel.questionnaireStateFlow.value.displayMode as DisplayMode.EditMode).pagination

assertThat(
(viewModel.questionnaireStateFlow.value.displayMode as DisplayMode.EditMode).pagination,
questionnaireStatePagination,
)
.isEqualTo(
QuestionnairePagination(
Expand All @@ -1845,6 +1944,83 @@ class QuestionnaireViewModelTest {
currentPageIndex = 1,
),
)

assertThat(questionnaireStatePagination.hasPreviousPage).isFalse()
}
}

@Test
fun `should skip last page if it is hidden`() = runTest {
val questionnaire =
Questionnaire().apply {
id = "a-questionnaire"
addItem(
QuestionnaireItemComponent().apply {
linkId = "page1"
type = Questionnaire.QuestionnaireItemType.GROUP
addExtension(paginationExtension)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page1-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 1"
},
)
},
)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page2"
type = Questionnaire.QuestionnaireItemType.GROUP
addExtension(paginationExtension)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page2-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 2"
},
)
},
)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page3"
type = Questionnaire.QuestionnaireItemType.GROUP
addExtension(paginationExtension)
addExtension(hiddenExtension)
addItem(
QuestionnaireItemComponent().apply {
linkId = "page3-1"
type = Questionnaire.QuestionnaireItemType.BOOLEAN
text = "Question on page 3"
},
)
},
)
}
val viewModel = createQuestionnaireViewModel(questionnaire)
viewModel.runViewModelBlocking {
viewModel.goToNextPage()
val questionnaireStatePagination =
(viewModel.questionnaireStateFlow.value.displayMode as DisplayMode.EditMode).pagination

assertThat(
questionnaireStatePagination,
)
.isEqualTo(
QuestionnairePagination(
isPaginated = true,
pages =
listOf(
QuestionnairePage(0, enabled = true, hidden = false),
QuestionnairePage(1, enabled = true, hidden = false),
QuestionnairePage(2, enabled = true, hidden = true),
),
currentPageIndex = 1,
),
)

assertThat(questionnaireStatePagination.hasNextPage).isFalse()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@ import com.google.android.fhir.search.StringFilterModifier
import com.google.android.fhir.search.count
import com.google.android.fhir.search.search
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.ZoneId
import kotlinx.coroutines.launch
import org.hl7.fhir.r4.model.Patient
import org.hl7.fhir.r4.model.RiskAssessment
Expand Down Expand Up @@ -183,7 +183,7 @@ internal fun Patient.toPatientItem(position: Int): PatientListViewModel.PatientI
val gender = if (hasGenderElement()) genderElement.valueAsString else ""
val dob =
if (hasBirthDateElement()) {
LocalDate.parse(birthDateElement.valueAsString, DateTimeFormatter.ISO_DATE)
birthDateElement.value.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
} else {
null
}
Expand Down
Loading

0 comments on commit 9138067

Please sign in to comment.