Skip to content

Commit

Permalink
Fix sort and filter issues (#3254)
Browse files Browse the repository at this point in the history
* Activate sorting for related resources

Signed-off-by: Elly Kitoto <[email protected]>

* Remove material3 dependencies

Signed-off-by: Elly Kitoto <[email protected]>

* Use all the provided register filter criteria

Previously only the filter criteria that were updated by content
from the Questionnaire fields were used.

Signed-off-by: Elly Kitoto <[email protected]>

* Set questionnaire submit button text via configuration

Signed-off-by: Elly Kitoto <[email protected]>

* Implement clear all action on register filter questionnaire

Signed-off-by: Elly Kitoto <[email protected]>

* Add more assertion on register filter data queries test

Signed-off-by: Elly Kitoto <[email protected]>

---------

Signed-off-by: Elly Kitoto <[email protected]>
Co-authored-by: Benjamin Mwalimu <[email protected]>
  • Loading branch information
ellykits and dubdabasoduba authored May 15, 2024
1 parent 2dc4f28 commit 09e1f05
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ constructor(
)
applyConfiguredSortAndFilters(
resourceConfig = resourceConfig,
sortData = false,
sortData = true,
configComputedRuleValues = configComputedRuleValues,
)
}
Expand Down
4 changes: 1 addition & 3 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ lifecycle= "2.7.0"
mapbox-sdk-turf = "4.8.0"
material = "1.11.0"
compose-material-icons = "1.6.3"
material3 = "1.2.1"
mockk = "1.13.8"
mockk-android = "1.13.8"
msg-simple = "1.2"
Expand Down Expand Up @@ -158,7 +157,6 @@ mapbox-sdk-turf = { group = "com.mapbox.mapboxsdk", name = "mapbox-sdk-turf", ve
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
compose-material-icons-core = { group = "androidx.compose.material", name = "material-icons-core", version.ref = "compose-material-icons" }
compose-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "compose-material-icons" }
material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
mockk-android = { group = "io.mockk", name = "mockk-android", version.ref = "mockk-android" }
msg-simple = { group = "com.github.java-json-tools", name = "msg-simple", version.ref = "msg-simple" }
Expand Down Expand Up @@ -221,7 +219,7 @@ lifecycle = ["lifecycle-viewmodel-ktx", "lifecycle-viewmodel-compose", "lifecycl
okhttp3 = ["okhttp-logging-interceptor", "okhttp"]
accompanist = ["accompanist-placeholder", "accompanist-flowlayout"]
klint = ["ktlint-cli-ruleset", "ktlint-rule-engine-core"]
compose = ["activity-compose","activity-ktx", "material", "ui", "ui-tooling-preview", "constraintlayout-compose", "foundation","runtime-livedata"]
compose = ["activity-compose","activity-ktx", "ui", "ui-tooling-preview", "constraintlayout-compose", "foundation","runtime-livedata"]
navigation = ["navigation-compose", "navigation-fragment-ktx", "navigation-ui-ktx"]
junit-test = ["junit-ktx", "junit"]
coroutines = ["kotlinx-coroutines-core", "kotlinx-coroutines-android"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {

private fun renderQuestionnaire() {
lifecycleScope.launch {
var questionnaireFragment: QuestionnaireFragment? = null
if (supportFragmentManager.findFragmentByTag(QUESTIONNAIRE_FRAGMENT_TAG) == null) {
viewModel.setProgressState(QuestionnaireProgressState.QuestionnaireLaunch(true))
with(viewBinding) {
Expand All @@ -234,19 +235,23 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {
questionnaireTitle.apply { text = questionnaireConfig.title }
clearAll.apply {
visibility = if (questionnaireConfig.showClearAll) View.VISIBLE else View.GONE
setOnClickListener {
// TODO Clear current QuestionnaireResponse items -> SDK
}
setOnClickListener { questionnaireFragment?.clearAllAnswers() }
}
}

questionnaire = viewModel.retrieveQuestionnaire(questionnaireConfig, actionParameters)

try {
val questionnaireFragmentBuilder = buildQuestionnaireFragment(questionnaire!!)
val questionnaireFragmentBuilder =
buildQuestionnaireFragment(
questionnaire = questionnaire!!,
questionnaireConfig = questionnaireConfig,
)

questionnaireFragment = questionnaireFragmentBuilder.build()
supportFragmentManager.commit {
setReorderingAllowed(true)
add(R.id.container, questionnaireFragmentBuilder.build(), QUESTIONNAIRE_FRAGMENT_TAG)
add(R.id.container, questionnaireFragment, QUESTIONNAIRE_FRAGMENT_TAG)
}

registerFragmentResultListener()
Expand All @@ -262,6 +267,7 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {

private suspend fun buildQuestionnaireFragment(
questionnaire: Questionnaire,
questionnaireConfig: QuestionnaireConfig,
): QuestionnaireFragment.Builder {
if (questionnaire.subjectType.isNullOrEmpty()) {
val subjectRequiredMessage = getString(R.string.missing_subject_type)
Expand All @@ -271,15 +277,18 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {
}

val (questionnaireResponse, launchContextResources) =
viewModel.populateQuestionnaire(questionnaire, questionnaireConfig, actionParameters)
viewModel.populateQuestionnaire(questionnaire, this.questionnaireConfig, actionParameters)

return QuestionnaireFragment.builder()
.setQuestionnaire(questionnaire.json())
.setCustomQuestionnaireItemViewHolderFactoryMatchersProvider(
OPENSRP_ITEM_VIEWHOLDER_FACTORY_MATCHERS_PROVIDER,
)
.showAsterisk(questionnaireConfig.showRequiredTextAsterisk)
.showRequiredText(questionnaireConfig.showRequiredText)
.setSubmitButtonText(
questionnaireConfig.saveButtonText ?: getString(R.string.submit_questionnaire),
)
.showAsterisk(this.questionnaireConfig.showRequiredTextAsterisk)
.showRequiredText(this.questionnaireConfig.showRequiredText)
.apply {
if (questionnaireResponse != null) {
questionnaireResponse
Expand Down Expand Up @@ -395,7 +404,6 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {
const val QUESTIONNAIRE_SUBMISSION_EXTRACTED_RESOURCE_IDS = "questionnaireExtractedResourceIds"
const val QUESTIONNAIRE_RESPONSE = "questionnaireResponse"
const val QUESTIONNAIRE_ACTION_PARAMETERS = "questionnaireActionParameters"
const val QUESTIONNAIRE_POPULATION_RESOURCES = "questionnairePopulationResources"

fun intentBundle(
questionnaireConfig: QuestionnaireConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,15 @@ constructor(
dataQueries?.map {
val newFilterCriteria = mutableListOf<FilterCriterionConfig>()
it.filterCriteria.forEach { filterCriterionConfig ->
val answerComponent = qrItemMap[filterCriterionConfig.dataFilterLinkId]
answerComponent?.answer?.forEach { itemAnswerComponent ->
val criterion = convertAnswerToFilterCriterion(itemAnswerComponent, filterCriterionConfig)
if (criterion != null) newFilterCriteria.add(criterion)
if (!filterCriterionConfig.dataFilterLinkId.isNullOrEmpty()) {
val answerComponent = qrItemMap[filterCriterionConfig.dataFilterLinkId]
answerComponent?.answer?.forEach { itemAnswerComponent ->
val criterion =
convertAnswerToFilterCriterion(itemAnswerComponent, filterCriterionConfig)
if (criterion != null) newFilterCriteria.add(criterion)
}
} else {
newFilterCriteria.add(filterCriterionConfig)
}
}
it.copy(
Expand Down
1 change: 1 addition & 0 deletions android/quest/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@
<string name="location_permissions_denied">Location Access Denied: To capture GPS coordinates, please enable location permissions in your device settings.</string>
<string name="location_services_disabled">Location services are disabled. Do you want to enable them?</string>
<string name="copy_text_success_message">Link %1$s copied successfully</string>
<string name="submit_questionnaire">Submit</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ class RegisterViewModelTest : RobolectricTest() {
},
)

Assert.assertNotNull(
newBaseResourceQueries.find { dataQuery ->
dataQuery.paramName == "relationship" &&
dataQuery.filterCriteria.any {
it.dataType == Enumerations.DataType.CODE && (it.value as Code).code == "N" ||
it.dataType == Enumerations.DataType.CODE && (it.value as Code).code == "M"
}
},
)

val taskRelatedResourceDataQueries =
updatedFhirResourceConfig.relatedResources
.find { it.id == ResourceType.Task.name }
Expand Down Expand Up @@ -329,6 +339,20 @@ class RegisterViewModelTest : RobolectricTest() {
),
),
),
DataQuery(
paramName = "relationship",
filterCriteria =
listOf(
FilterCriterionConfig.TokenFilterCriterionConfig(
dataType = Enumerations.DataType.CODE,
value = Code(code = "N", system = "http://hl7.org/fhir/v2/0131"),
),
FilterCriterionConfig.TokenFilterCriterionConfig(
dataType = Enumerations.DataType.CODE,
value = Code(code = "M", system = "http://hl7.org/fhir/v2/0132"),
),
),
),
),
),
RegisterFilterField(
Expand Down

0 comments on commit 09e1f05

Please sign in to comment.