Skip to content

Commit

Permalink
Add fix to issue 2036 and Update KDocs (#2122)
Browse files Browse the repository at this point in the history
* Add fix to issue 2036

* spotless

* spotless

* cleanup and revert

* * Fix issues on practitioner_config and register_config
* Add documentation for datapass between registers abd profiles

* Update profile-config.mdx

* Update IterableUtil.kt

* Update and fix failing tests in ProfileViewModelTest and ConfigRegistryTest

* Fix failing tests on IterableUtilTest.kt

* Move convertActionParameterArrayToMap to ConfigExtension

* Move convertArrayToMap to extensions

* Fix type errors

* exclude some asset directories

---------

Co-authored-by: pld <[email protected]>
  • Loading branch information
SebaMutuku and pld authored Mar 9, 2023
1 parent c0114ac commit 8a83f82
Show file tree
Hide file tree
Showing 21 changed files with 244 additions and 115 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ captures/
# Fleet
.fleet/
.docusaurus/
android/quest/src/main/assets/configs/*
!android/quest/src/main/assets/configs/app

Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ constructor(
}

/**
* Receives @paramsMap , @configKey and @ConfigJsonMap as inputs and interpolates the value if
* found and if paramsMap are not empty return the result return the value if key is found and
* paramsMap is empty
* Receives [paramsMap], [configKey] and [ConfigJsonMap] as inputs and interpolates the value if
* found and if [paramsMap] are not empty return the result return the value if key is found and
* [paramsMap] is empty
*/
inline fun <reified T : Configuration> getConfigValueWithParam(
paramsMap: Map<String, String>?,
configKey: String,
configsJsonMap: Map<String, String>
) =
configsJsonMap.getValue(configKey).let { jsonValue ->
if (paramsMap?.isNullOrEmpty() == false) jsonValue.interpolate(paramsMap) else jsonValue
if (paramsMap != null) jsonValue.interpolate(paramsMap) else jsonValue
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.configuration.profile.ProfileConfiguration
import org.smartregister.fhircore.engine.configuration.register.RegisterConfiguration
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
import org.smartregister.fhircore.engine.domain.model.DataQuery
import org.smartregister.fhircore.engine.domain.model.DataType
import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig
Expand Down Expand Up @@ -276,13 +274,8 @@ constructor(
profileId: String,
resourceId: String,
fhirResourceConfig: FhirResourceConfig?,
paramsList: Array<ActionParameter>?
paramsMap: Map<String, String>?
): RepositoryResourceData {
val paramsMap: Map<String, String> =
paramsList
?.filter { it.paramType == ActionParameterType.PARAMDATA && !it.value.isNullOrEmpty() }
?.associate { it.key to it.value }
?: emptyMap()
val profileConfiguration =
configurationRegistry.retrieveConfiguration<ProfileConfiguration>(
ConfigType.Profile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.smartregister.fhircore.engine.domain.repository

import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig
import org.smartregister.fhircore.engine.domain.model.RepositoryResourceData
import org.smartregister.fhircore.engine.domain.model.ResourceData
Expand Down Expand Up @@ -54,6 +53,6 @@ interface Repository {
profileId: String,
resourceId: String,
fhirResourceConfig: FhirResourceConfig? = null,
paramsList: Array<ActionParameter>? = emptyArray()
paramsMap: Map<String, String>? = emptyMap()
): RepositoryResourceData?
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ class RegisterRepositoryTest : RobolectricTest() {
val profileData =
registerRepository.loadProfileData(
profileId = "patientProfileSecondary",
resourceId = "12345"
resourceId = "12345",
paramsMap = emptyMap()
)
Assert.assertNotNull(profileData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,6 @@
{
"key": "familyLogicalId",
"value": "@{familyLogicalId}"
},
{
"paramType": "PARAMDATA",
"dataType": "STRING",
"key": "practitionerId",
"value": "@{practitionerId}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
"actions": [
"data.put('assignedLocation', fhirPath.extractValue(size(Location) > 0 ? Location.get(0) : null, 'Location.name'))"
]
},
{
"name": "practitionerId",
"condition": "true",
"actions": [
"data.put('practitionerId', fhirPath.extractValue(Practitioner, \"Practitioner.id.replace(\"Practitioner/","\").split(\"/\").get(0)\")"
]
}
],
"views": [
Expand Down Expand Up @@ -136,7 +143,14 @@
"trigger": "ON_CLICK",
"workflow": "LAUNCH_REGISTER",
"id": "householdRegister",
"display": "@{practitionerName} - Household Register"
"display": "@{practitionerName} - Household Register",
"params": [
{
"paramType": "PARAMDATA",
"key": "practitionerId",
"value": "@{practitionerId}"
}
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@
{
"resource": "Task",
"searchParameter": "subject"
},
{
"id": "filterPractitioners",
"resource": "Practitioner",
"searchParameter": "subject"
}
]
}
Expand All @@ -66,8 +61,7 @@
"display": "{{ search.name.or.id }}",
"computedRules": [
"familyName",
"familyId",
"practitionerId"
"familyId"
]
},
"registerCard": {
Expand All @@ -86,13 +80,6 @@
"data.put('familyId', fhirPath.extractValue(Group, 'Group.identifier[0].value'))"
]
},
{
"name": "practitionerId",
"condition": "true",
"actions": [
"data.put('practitionerId', fhirPath.extractValue(Practitioner, \"Practitioner.id.split(\"/\")[1]\"))"
]
},
{
"name": "familyVillage",
"condition": "true",
Expand Down Expand Up @@ -158,11 +145,6 @@
{
"key": "familyId",
"value": "@{familyId}"
},
{
"paramType": "PARAMDATA",
"key": "practitionerId",
"value": "@{practitionerId}"
}
]
}
Expand All @@ -177,11 +159,6 @@
{
"key": "familyId",
"value": "@{familyId}"
},
{
"paramType": "PARAMDATA",
"key": "practitionerId",
"value": "@{practitionerId}"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ constructor(
private val simpleDateFormat = SimpleDateFormat(SYNC_TIMESTAMP_OUTPUT_FORMAT, Locale.getDefault())

val applicationConfiguration: ApplicationConfiguration by lazy {
configurationRegistry.retrieveConfiguration(ConfigType.Application)
configurationRegistry.retrieveConfiguration(ConfigType.Application, paramsMap = emptyMap())
}

val navigationConfiguration: NavigationConfiguration by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import org.smartregister.fhircore.quest.ui.profile.bottomSheet.ProfileBottomShee
import org.smartregister.fhircore.quest.ui.profile.model.EligibleManagingEntity
import org.smartregister.fhircore.quest.ui.questionnaire.QuestionnaireActivity
import org.smartregister.fhircore.quest.ui.shared.QuestionnaireHandler
import org.smartregister.fhircore.quest.util.convertActionParameterArrayToMap
import org.smartregister.fhircore.quest.util.extensions.toParamDataMap
import timber.log.Timber

@HiltViewModel
Expand Down Expand Up @@ -88,12 +88,12 @@ constructor(
profileId: String,
resourceId: String,
fhirResourceConfig: FhirResourceConfig? = null,
paramsList: Array<ActionParameter>?
paramsList: Array<ActionParameter>? = emptyArray()
) {
if (resourceId.isNotEmpty()) {
val paramsMap: Map<String, String> = paramsList.toParamDataMap<String, String>()
val repoResourceData =
registerRepository.loadProfileData(profileId, resourceId, fhirResourceConfig, paramsList)
val paramsMap: Map<String, String> = convertActionParameterArrayToMap(paramsList)
registerRepository.loadProfileData(profileId, resourceId, fhirResourceConfig, paramsMap)
val profileConfigs = retrieveProfileConfiguration(profileId, paramsMap)
val resourceData =
rulesExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.quest.data.register.RegisterPagingSource
import org.smartregister.fhircore.quest.data.register.model.RegisterPagingSourceState
import org.smartregister.fhircore.quest.util.convertActionParameterArrayToMap
import org.smartregister.fhircore.quest.util.extensions.toParamDataMap

@HiltViewModel
class RegisterViewModel
Expand Down Expand Up @@ -179,10 +179,10 @@ constructor(
fun retrieveRegisterUiState(
registerId: String,
screenTitle: String,
paramsList: Array<ActionParameter>?
params: Array<ActionParameter>? = emptyArray()
) {
if (registerId.isNotEmpty()) {
val paramsMap: Map<String, String> = convertActionParameterArrayToMap(paramsList)
val paramsMap: Map<String, String> = params.toParamDataMap<String, String>()
viewModelScope.launch(dispatcherProvider.io()) {
val currentRegisterConfiguration = retrieveRegisterConfiguration(registerId, paramsMap)
// Count register data then paginate the data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.smartregister.fhircore.quest.util

import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType

/**
* Helper to return a defaultValue when getting maybe null keys from a map.
*
Expand All @@ -31,24 +28,3 @@ import org.smartregister.fhircore.engine.domain.model.ActionParameterType
fun <A, B> nonNullGetOrDefault(map: Map<A, B>, key: A?, defaultValue: B): B {
return if (key != null) map.getOrDefault(key, defaultValue) else defaultValue
}

/**
* Function to convert the elements of an array that have paramType PARAM_DATA to a map of their
* keys to values.
*
* @property array The array of ActionParameter elements to convert
*
* @return Map of the values or emptyMap if [array] is null
*/
fun convertActionParameterArrayToMap(array: Array<ActionParameter>?): Map<String, String> {
val paramsMap: MutableMap<String, String> = mutableMapOf()
if (array != null) {
for (param in array) {
if (param.paramType == ActionParameterType.PARAMDATA && !param.value.isNullOrEmpty()) {
paramsMap[param.key] = param.value
}
}
return paramsMap.toMap()
}
return emptyMap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.smartregister.fhircore.engine.configuration.workflow.ActionTrigger
import org.smartregister.fhircore.engine.configuration.workflow.ApplicationWorkflow
import org.smartregister.fhircore.engine.domain.model.ActionConfig
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.util.extension.interpolate
import org.smartregister.fhircore.quest.navigation.MainNavigationScreen
Expand Down Expand Up @@ -76,6 +77,7 @@ fun List<ActionConfig>.handleClickEvent(
resourceData?.let { actionConfig.display(it.computedValuesMap) } ?: navMenu?.display
),
Pair(NavigationArg.TOOL_BAR_HOME_NAVIGATION, actionConfig.toolBarHomeNavigation),
Pair(NavigationArg.PARAMS, interpolateActionParamsValue(actionConfig, resourceData))
)

// Register is the entry point destination, clear back stack with every register switch
Expand All @@ -102,7 +104,7 @@ fun List<ActionConfig>.handleClickEvent(
}
}

private fun interpolateActionParamsValue(actionConfig: ActionConfig, resourceData: ResourceData?) =
fun interpolateActionParamsValue(actionConfig: ActionConfig, resourceData: ResourceData?) =
actionConfig
.params
.map {
Expand All @@ -127,3 +129,16 @@ fun ViewProperties.clickable(ResourceData: ResourceData) =

fun ViewProperties.isVisible(computedValuesMap: Map<String, Any>) =
this.visible.interpolate(computedValuesMap).toBoolean()

/**
* Function to convert the elements of an array that have paramType [ActionParameterType.PARAMDATA]
* to a map of their keys to values. It also returns [emptyMap] if [actionParameters] is null.
*
* @property array The array of ActionParameter elements to convert
* @return Map of the values or emptyMap if [array] is null
*/
fun <K, V> Array<ActionParameter>?.toParamDataMap() =
this?.asSequence()?.filter { it.paramType == ActionParameterType.PARAMDATA }?.associate {
it.key to it.value
}
?: emptyMap()
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
app:nullable="false" />
<argument
android:name="params"
android:defaultValue="@null"
app:argType="org.smartregister.fhircore.engine.domain.model.ActionParameter[]"
app:nullable="true" />
<argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
{
"resource": "Task",
"searchParameter": "subject"
},
{
"id": "filterPractitioners",
"resource": "Practitioner",
"searchParameter": "subject"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import org.junit.Test
import org.robolectric.Robolectric
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.data.local.register.RegisterRepository
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig
import org.smartregister.fhircore.engine.domain.model.RepositoryResourceData
import org.smartregister.fhircore.quest.R
Expand Down Expand Up @@ -75,7 +77,15 @@ class ProfileFragmentTest : RobolectricTest() {
bundleOf(
NavigationArg.PROFILE_ID to "defaultProfile",
NavigationArg.RESOURCE_ID to patient.id,
NavigationArg.RESOURCE_CONFIG to resourceConfig
NavigationArg.RESOURCE_CONFIG to resourceConfig,
NavigationArg.PARAMS to
arrayOf(
ActionParameter(
key = "anyId",
paramType = ActionParameterType.PARAMDATA,
value = "anyValue"
)
)
)
}
activityController.create().resume()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class RegisterViewModelTest : RobolectricTest() {
registerViewModel.retrieveRegisterUiState(
registerId = registerId,
screenTitle = screenTitle,
paramsList = null
params = null
)
val registerUiState = registerViewModel.registerUiState.value
Assert.assertNotNull(registerUiState)
Expand Down
Loading

0 comments on commit 8a83f82

Please sign in to comment.