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

[Quest/Malawi Core] Android App : Sync Resources by Organisation #34

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -443,8 +443,8 @@ suspend fun DefaultRepository.isPatientPregnant(patient: Patient) =
suspend fun DefaultRepository.isPatientBreastfeeding(patient: Patient) =
patientConditions(patient.logicalId).activelyBreastfeeding()

fun SharedPreferencesHelper.locationCode() =
read(ResourceType.Location.name, null)?.filter { it.isDigit() } ?: ""
fun SharedPreferencesHelper.organisationCode() =
read(ResourceType.Organization.name, null)?.filter { it.isDigit() } ?: ""

infix fun Patient.belongsTo(code: String) =
meta.tag.any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import org.smartregister.fhircore.engine.configuration.FhirConfiguration
import org.smartregister.fhircore.engine.configuration.app.AppConfigClassification
import org.smartregister.fhircore.engine.configuration.app.ApplicationConfiguration
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.data.local.register.dao.locationCode
import org.smartregister.fhircore.engine.data.local.register.dao.organisationCode
import org.smartregister.fhircore.engine.data.remote.model.response.UserInfo
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.USER_INFO_SHARED_PREFERENCE_KEY
Expand Down Expand Up @@ -223,16 +223,16 @@ private fun SharedPreferencesHelper.filterByResourceLocation(
val results = mutableListOf<Pair<ResourceType, Map<String, String>>>()
resourcesTemp.addAll(pairs)

val locationSystem = context.getString(R.string.sync_strategy_location_system)
val locationTag = "$locationSystem|${locationCode()}"
val organisationSystem = context.getString(R.string.sync_strategy_organization_system)
val organisationTag = "$organisationSystem|${organisationCode()}"

resourcesTemp.forEach {
val resourceType = it.first
if (resourceType != ResourceType.Practitioner &&
resourceType != ResourceType.Questionnaire &&
resourceType != ResourceType.StructureMap
) {
val tags = mutableMapOf("_tag" to locationTag)
val tags = mutableMapOf("_tag" to organisationTag)
it.second.entries.forEach { entry -> tags[entry.key] = entry.value }
results.add(Pair(resourceType, tags))
} else results.add(it)
Expand Down
Loading