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 searchable multiselect widget #3123

Merged
merged 35 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6025f75
Implement multiselectview
ellykits Mar 1, 2024
5e94cc8
Change preview data
ellykits Mar 1, 2024
e8967f5
Use TristateCheckbox on MultiSelect view
ellykits Mar 4, 2024
26ca4da
Implement functionality for generating map required in multiselectview
ellykits Mar 5, 2024
d717c73
Merge branch 'main' into implement-searchable-multiselect-widget
dubdabasoduba Mar 8, 2024
445f050
Implement bottomsheet for multi select widget
ellykits Mar 13, 2024
0b1e7c1
Merge branch 'implement-searchable-multiselect-widget' of github.com:…
ellykits Mar 13, 2024
adbe701
Merge branch 'main' into implement-searchable-multiselect-widget
ellykits Mar 13, 2024
65387d5
Merge branch 'main' into implement-searchable-multiselect-widget
ellykits Mar 13, 2024
c19d72f
Fix multi-select checkbox select color
ellykits Mar 13, 2024
4944abf
Implement functionality for node selection
ellykits Mar 13, 2024
3f0fdde
Merge branch 'main' into implement-searchable-multiselect-widget
ellykits Mar 19, 2024
0889ca0
Merge branch 'main' into implement-searchable-multiselect-widget
ellykits Mar 22, 2024
f49d0d2
Refactor multi select implementation
ellykits Mar 27, 2024
13c6d6a
Merge branch 'main' into implement-searchable-multiselect-widget
ellykits Mar 27, 2024
9da1e8d
Improve UX on multi selector widget search
ellykits Mar 28, 2024
3993aa1
Refactor MultiSelect UI to use Compose Scaffold
ellykits Apr 2, 2024
30483bc
Use ProtoDataStore to store SyncLocations
ellykits Apr 15, 2024
c395d7c
Use selected locations from multi-select widget to sync resources
ellykits Apr 15, 2024
c1cf091
Refactor ApplicationConfiguration.syncStrategies to syncStrategy
ellykits Apr 16, 2024
ba73743
Merge branch 'main' into implement-searchable-multiselect-widget
hamza-vd Apr 16, 2024
c48f876
Fix child node checked state issue
hamza-vd Apr 17, 2024
5e382fa
Show progress dialog
hamza-vd Apr 17, 2024
2d4610e
Add no results view
hamza-vd Apr 17, 2024
e07d48b
Merge branch 'main' into implement-searchable-multiselect-widget
hamza-vd Apr 18, 2024
dd69ade
Refactor initial sync logic + disable sync progresss dialog
hamza-vd Apr 22, 2024
bd7795c
Merge branch 'main' into implement-searchable-multiselect-widget
hamza-vd Apr 22, 2024
51c6f19
Merge branch 'main' into implement-searchable-multiselect-widget
dubdabasoduba Apr 30, 2024
866d972
Merge branch 'main' into implement-searchable-multiselect-widget
hamza-vd May 6, 2024
ef0fc07
Disable progress dialog on initial sync
hamza-vd May 6, 2024
ad62bb6
Fix spotless formatting errors
hamza-vd May 7, 2024
8511d77
Merge branch 'main' into implement-searchable-multiselect-widget
hamza-vd May 7, 2024
10186f9
Add Practitioner to SyncStrategy
hamza-vd May 7, 2024
3667e78
Fix failing tests
ellykits May 7, 2024
4cd04ed
Merge branch 'main' into implement-searchable-multiselect-widget
ellykits May 13, 2024
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
1 change: 0 additions & 1 deletion android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ dependencies {
api(libs.jjwt)
api(libs.fhir.common.utils) { exclude(group = "org.slf4j", module = "jcl-over-slf4j") }
api(libs.runtime.livedata)
// api(libs.material3)
api(libs.foundation)
api(libs.fhir.common.utils)
api(libs.kotlinx.serialization.json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ sealed class ConfigType(
val parseAsResource: Boolean = false,
val multiConfig: Boolean = false,
) {
object Application : ConfigType("application")
data object Application : ConfigType("application")

object Sync : ConfigType(name = "sync", parseAsResource = true)
data object Sync : ConfigType(name = "sync", parseAsResource = true)

object Navigation : ConfigType("navigation")
data object Navigation : ConfigType("navigation")

object Register : ConfigType(name = "register", multiConfig = true)
data object Register : ConfigType(name = "register", multiConfig = true)

object MeasureReport : ConfigType(name = "measureReport", multiConfig = true)
data object MeasureReport : ConfigType(name = "measureReport", multiConfig = true)

object Profile : ConfigType(name = "profile", multiConfig = true)
data object Profile : ConfigType(name = "profile", multiConfig = true)

object GeoWidget : ConfigType(name = "geoWidget", multiConfig = true)
data object GeoWidget : ConfigType(name = "geoWidget", multiConfig = true)

object DataMigration : ConfigType(name = "dataMigration", multiConfig = true)
data object DataMigration : ConfigType(name = "dataMigration", multiConfig = true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data class ApplicationConfiguration(
val languages: List<String> = listOf("en"),
val useDarkTheme: Boolean = false,
val syncInterval: Long = 15,
val syncStrategies: List<String> = listOf(),
val syncStrategy: List<SyncStrategy> = listOf(),
val loginConfig: LoginConfig = LoginConfig(),
val deviceToDeviceSync: DeviceToDeviceSyncConfig? = null,
val snackBarTheme: SnackBarThemeConfig = SnackBarThemeConfig(),
Expand All @@ -42,8 +42,19 @@ data class ApplicationConfiguration(
val taskBackgroundWorkerBatchSize: Int = 500,
val eventWorkflows: List<EventWorkflow> = emptyList(),
val logGpsLocation: List<LocationLogOptions> = emptyList(),
val usePractitionerAssignedLocationOnSync: Boolean =
true, // TODO This defaults to scheduling periodic sync, otherwise use sync location ids from
// location selector
) : Configuration()

enum class SyncStrategy {
Location,
CareTeam,
RelatedEntityLocation,
Organization,
Practitioner,
}

enum class LocationLogOptions {
QUESTIONNAIRE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ enum class ApplicationWorkflow {

/** A workflow that copies text to keyboard */
COPY_TEXT,

/** A workflow that launches location selector widget * */
LAUNCH_LOCATION_SELECTOR,
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class PreferenceDataStore @Inject constructor(@ApplicationContext val context: C
companion object Keys {
val APP_ID by lazy { stringPreferencesKey("appId") }
val LANG by lazy { stringPreferencesKey("lang") }
val SYNC_LOCATION_IDS by lazy { stringPreferencesKey("syncLocationIds") }
val MIGRATION_VERSION by lazy { intPreferencesKey("migrationVersion") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import kotlinx.coroutines.flow.catch
import org.smartregister.fhircore.engine.datastore.mockdata.PractitionerDetails
import org.smartregister.fhircore.engine.datastore.mockdata.UserInfo
import org.smartregister.fhircore.engine.datastore.serializers.PractitionerDetailsDataStoreSerializer
import org.smartregister.fhircore.engine.datastore.serializers.SyncLocationIdDataStoreSerializer
import org.smartregister.fhircore.engine.datastore.serializers.UserInfoDataStoreSerializer
import org.smartregister.fhircore.engine.domain.model.SyncLocationToggleableState
import timber.log.Timber

private const val PRACTITIONER_DETAILS_DATASTORE_JSON = "practitioner_details.json"
private const val USER_INFO_DATASTORE_JSON = "user_info.json"
private const val SYNC_LOCATION_IDS = "sync_location_ids.json"
private const val TAG = "Proto DataStore"

val Context.practitionerProtoStore: DataStore<PractitionerDetails> by
Expand All @@ -46,6 +49,12 @@ val Context.userInfoProtoStore: DataStore<UserInfo> by
serializer = UserInfoDataStoreSerializer,
)

val Context.syncLocationIdsProtoStore: DataStore<List<SyncLocationToggleableState>> by
dataStore(
fileName = SYNC_LOCATION_IDS,
serializer = SyncLocationIdDataStoreSerializer,
)

@Singleton
class ProtoDataStore @Inject constructor(@ApplicationContext val context: Context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ object PractitionerDetailsDataStoreSerializer : Serializer<PractitionerDetails>
deserializer = PractitionerDetails.serializer(),
string = input.readBytes().decodeToString(),
)
} catch (e: SerializationException) {
Timber.tag(SerializerConstants.PROTOSTORE_SERIALIZER_TAG).d(e)
} catch (serializationException: SerializationException) {
Timber.e(serializationException)
defaultValue
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.datastore.serializers

import androidx.datastore.core.Serializer
import java.io.InputStream
import java.io.OutputStream
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.apache.commons.lang3.SerializationException
import org.smartregister.fhircore.engine.domain.model.SyncLocationToggleableState
import org.smartregister.fhircore.engine.util.extension.encodeJson
import org.smartregister.fhircore.engine.util.extension.json
import timber.log.Timber

object SyncLocationIdDataStoreSerializer : Serializer<List<SyncLocationToggleableState>> {

override val defaultValue: List<SyncLocationToggleableState>
get() = emptyList()

override suspend fun readFrom(input: InputStream): List<SyncLocationToggleableState> {
return try {
json.decodeFromString<List<SyncLocationToggleableState>>(input.readBytes().decodeToString())
} catch (serializationException: SerializationException) {
Timber.e(serializationException)
defaultValue
}
}

override suspend fun writeTo(t: List<SyncLocationToggleableState>, output: OutputStream) {
withContext(Dispatchers.IO) { output.write(t.encodeJson().encodeToByteArray()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ object UserInfoDataStoreSerializer : Serializer<UserInfo> {
deserializer = UserInfo.serializer(),
string = input.readBytes().decodeToString(),
)
} catch (e: SerializationException) {
Timber.tag(SerializerConstants.PROTOSTORE_SERIALIZER_TAG).d(e)
} catch (serializationException: SerializationException) {
Timber.e(serializationException)
defaultValue
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ data class ActionConfig(
val resourceConfig: FhirResourceConfig? = null,
val toolBarHomeNavigation: ToolBarHomeNavigation = ToolBarHomeNavigation.OPEN_DRAWER,
val popNavigationBackStack: Boolean? = null,
val multiSelectViewConfig: MultiSelectViewConfig? = null,
) : Parcelable, java.io.Serializable {
fun paramsBundle(computedValuesMap: Map<String, Any> = emptyMap()): Bundle =
Bundle().apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.domain.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

/**
* @property resourceConfig The configuration for FHIR resource to be loaded
* @property parentIdFhirPathExpression FhirPath expression for extracting the ID for the parent
* resource
* @property contentFhirPathExpression FhirPath expression for extracting the content displayed on
* the multi select widget e.g. the name of the Location in a Location hierarchy
* @property rootNodeFhirPathExpression A key value pair containing a FHIRPath expression for
* extracting the value used to identify if the current resource is Root. The key is the FHIRPath
* expression while value is the content to compare against.
*/
@Serializable
@Parcelize
data class MultiSelectViewConfig(
val resourceConfig: FhirResourceConfig,
val parentIdFhirPathExpression: String,
val contentFhirPathExpression: String,
val rootNodeFhirPathExpression: KeyValueConfig,
) : java.io.Serializable, Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
* limitations under the License.
*/

package org.smartregister.fhircore.engine.datastore.serializers
package org.smartregister.fhircore.engine.domain.model

object SerializerConstants {
const val PROTOSTORE_SERIALIZER_TAG = "Proto DataStore"
}
import androidx.compose.ui.state.ToggleableState
import kotlinx.serialization.Serializable

@Serializable
data class SyncLocationToggleableState(
val locationId: String,
val toggleableState: ToggleableState,
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,27 @@

package org.smartregister.fhircore.engine.sync

import android.content.Context
import androidx.compose.ui.state.ToggleableState
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.google.android.fhir.sync.SyncJobStatus
import dagger.hilt.android.qualifiers.ApplicationContext
import java.lang.ref.WeakReference
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.runBlocking
import org.hl7.fhir.r4.model.Parameters
import org.hl7.fhir.r4.model.ResourceType
import org.hl7.fhir.r4.model.SearchParameter
import org.smartregister.fhircore.engine.configuration.ConfigType
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.app.ApplicationConfiguration
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.datastore.syncLocationIdsProtoStore
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import timber.log.Timber
Expand All @@ -45,8 +52,14 @@ constructor(
val configService: ConfigService,
val configurationRegistry: ConfigurationRegistry,
val sharedPreferencesHelper: SharedPreferencesHelper,
@ApplicationContext val context: Context,
val dispatcherProvider: DefaultDispatcherProvider,
) {

private val appConfig by lazy {
configurationRegistry.retrieveConfiguration<ApplicationConfiguration>(
ConfigType.Application,
)
}
private val syncConfig by lazy {
configurationRegistry.retrieveResourceConfiguration<Parameters>(ConfigType.Sync)
}
Expand Down Expand Up @@ -87,10 +100,7 @@ constructor(

/** Retrieve registry sync params */
fun loadSyncParams(): Map<ResourceType, Map<String, String>> {
val pairs = mutableListOf<Pair<ResourceType, Map<String, String>>>()

val appConfig =
configurationRegistry.retrieveConfiguration<ApplicationConfiguration>(ConfigType.Application)
val pairs = mutableListOf<Pair<ResourceType, MutableMap<String, String>>>()

val organizationResourceTag =
configService.defineResourceTags().find { it.type == ResourceType.Organization.name }
Expand Down Expand Up @@ -143,24 +153,41 @@ constructor(
pairs.add(
Pair(
resourceType,
expressionValue?.let { mapOf(sp.code to expressionValue) } ?: mapOf(),
expressionValue?.let { mutableMapOf(sp.code to expressionValue) }
?: mutableMapOf(),
),
)
} else {
expressionValue?.let {
// add another parameter if there is a matching resource type
// e.g. [(Patient, {organization=105})] to [(Patient, {organization=105,
// _count=100})]
val updatedPair = pair.second.toMutableMap().apply { put(sp.code, expressionValue) }
val updatedPair = pair.second.apply { put(sp.code, expressionValue) }
val index = pairs.indexOfFirst { it.first == resourceType }
pairs.set(index, Pair(resourceType, updatedPair))
}
}
}
}

// Set sync locations Location query params
runBlocking {
context.syncLocationIdsProtoStore.data
.firstOrNull()
?.filter { it.toggleableState == ToggleableState.On }
?.map { it.locationId }
.takeIf { !it.isNullOrEmpty() }
?.let { locationIds ->
pairs.forEach { it.second[SYNC_LOCATION_IDS] = locationIds.joinToString(",") }
}
}

Timber.i("SYNC CONFIG $pairs")

return mapOf(*pairs.toTypedArray())
}

companion object {
private const val SYNC_LOCATION_IDS = "_syncLocations"
}
}
Loading
Loading