Skip to content

Commit

Permalink
Refactor loading bitmap images (#3546)
Browse files Browse the repository at this point in the history
* Add date service to rules engine facts map (#3519)

* Add summary mode (#3500)

Co-authored-by: Elly Kitoto <junkmailstoelly@gmail.com>

* Refactor PDF config properties in QuestionnaireConfig (#3498)

* Refactor to use PdfConfig

Initially using QuestionnaireConfig for simplicity.

* Process multi QRs in HtmlPopulator

* Add new tag to check if Questionnaire has been submitted

* Remove subjectType since subjectReference is used

* Fix test and spotless

* Address review

* spotless

* Cleanup

* spotless

* Fix test

---------

Co-authored-by: Elly Kitoto <junkmailstoelly@gmail.com>

* Fix error validation highlighting not working when submit button is clicked bug (#3525)

* Change progress bar color to blue (#3428)

* update in-progress color on the map view. (#3529)

      Signed-off-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>

* Add medication sort custom search param (#3534)

* Add medication sort custom search param

* Run spotlessApply

* Fix failing time based test

* Pld docs adjustment (#3540)

* sync typo

* correct heading title

* update header definition for p2p

* upgrade packages

* Update Geowidget to only show the Set Location dialog if no Locations to sync by have been selected (#3526)

* Don't show no results dialogue on map when locations selected on multiselect.

Signed-off-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>

* Fix failing tests.

Signed-off-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>

---------

Signed-off-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>

* Add Exit Dialog (#3487)

* Add exit dialog

* Fix a typo

* Show Dialog only when Map or Register is visible

* PR feedback changes

* Fix failing check

* Remove incorrect test

* Refactor dialog condition logic

---------

Co-authored-by: Benjamin Mwalimu <dubdabasoduba@gmail.com>

* Refactor working with bitmap images

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>

* Add the EUSM Burundi flavour and Rename the existing EUSM flavour (#3548)

* - Add the EUSM Burundi flavour
- Rename the exisiting EUSM flavour

* - Update the app naming

* - update the flavour naming

* Configure submit anyway button (#3535)

* Update the Burundi EUSM flavor (#3553)

* - Add the EUSM Burundi flavour
- Rename the exisiting EUSM flavour

* - Update the app naming

* - update the flavour naming

* - Update the flavor naming
- Update the documentation

* - Update the flavors section of the documentation to clarify on the naming convention

* Bum p up data capture version (#3547)

* Map search bug fixes (#3516)

* - Updating the infinite scroll paging
- Updating the behaviour after clearing search bar on the maps

* - spotless apply

* - Fix breaking tests on geo widget module

* - Fix tests

* - Run spotless

* - Import `LazyPagingItems`

* - Adding tests

* - Update the APK naming

* Ignore test to be refactored later

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>

* - Run spotless

* Update kujaku version.

Signed-off-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>

---------

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
Signed-off-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>
Co-authored-by: Lentumunai Mark <90028422+Lentumunai-Mark@users.noreply.github.com>
Co-authored-by: Elly Kitoto <junkmailstoelly@gmail.com>
Co-authored-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>

* Fix loading related resources

Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>

---------

Signed-off-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>
Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
Co-authored-by: Rkareko <47570855+Rkareko@users.noreply.github.com>
Co-authored-by: FikriMilano <fikrimilano1@gmail.com>
Co-authored-by: Lentumunai Mark <90028422+Lentumunai-Mark@users.noreply.github.com>
Co-authored-by: Peter Lubell-Doughtie <peter@ona.io>
Co-authored-by: Hamza Ahmed Khan <70560433+hamza-vd@users.noreply.github.com>
Co-authored-by: Benjamin Mwalimu <dubdabasoduba@gmail.com>
Co-authored-by: Lentumunai-Mark <lentumunai.mark@students.jkuat.ac.ke>
  • Loading branch information
8 people authored Oct 14, 2024
1 parent 2e8ef96 commit 58ec04d
Show file tree
Hide file tree
Showing 60 changed files with 508 additions and 307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package org.smartregister.fhircore.engine.configuration

import android.content.Context
import android.database.SQLException
import android.graphics.Bitmap
import androidx.compose.runtime.mutableStateMapOf
import ca.uhn.fhir.context.ConfigurationException
import ca.uhn.fhir.context.FhirContext
import ca.uhn.fhir.parser.DataFormatException
Expand Down Expand Up @@ -98,7 +96,6 @@ constructor(

val configsJsonMap = mutableMapOf<String, String>()
val configCacheMap = mutableMapOf<String, Configuration>()
val decodedImageMap = mutableStateMapOf<String, Bitmap>()
val localizationHelper: LocalizationHelper by lazy { LocalizationHelper(this) }
private val supportedFileExtensions = listOf("json", "properties")
private var _isNonProxy = BuildConfig.IS_NON_PROXY_APK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ data class QuestionnaireConfig(
val managingEntityRelationshipCode: String? = null,
val uniqueIdAssignment: UniqueIdAssignmentConfig? = null,
val linkIds: List<LinkIdConfig>? = null,
val showSubmitAnywayButton: String = "false",
) : java.io.Serializable, Parcelable {

fun interpolate(computedValuesMap: Map<String, Any>) =
Expand Down Expand Up @@ -100,6 +101,7 @@ data class QuestionnaireConfig(
uniqueIdAssignment?.copy(linkId = uniqueIdAssignment.linkId.interpolate(computedValuesMap)),
linkIds = linkIds?.onEach { it.linkId.interpolate(computedValuesMap) },
saveButtonText = saveButtonText?.interpolate(computedValuesMap),
showSubmitAnywayButton = showSubmitAnywayButton.interpolate(computedValuesMap),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ data class ListResourceConfig(
val sortConfig: SortConfig? = null,
val fhirPathExpression: String? = null,
val relatedResources: List<ListResourceConfig> = emptyList(),
val isRevInclude: Boolean = true,
) : Parcelable, java.io.Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data class StackViewProperties(
override val clickable: String = "false",
override val visible: String = "true",
val opacity: Float = 0f,
val size: Int? = 0,
val size: Int = 0,
val children: List<ViewProperties> = emptyList(),
) : ViewProperties(), Parcelable {
override fun interpolate(computedValuesMap: Map<String, Any>): StackViewProperties {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,14 +1070,20 @@ constructor(
if (currentPage != null && pageSize != null) {
val fromIndex = currentPage * pageSize
val toIndex = (currentPage + 1) * pageSize
with(searchResults.subList(fromIndex, min(toIndex, searchResults.size))) {
mapResourceToRepositoryResourceData(
relatedResourcesConfig = relatedResourcesConfig,
configComputedRuleValues = configComputedRuleValues,
secondaryResourceConfigs = secondaryResourceConfigs,
filterActiveResources = filterActiveResources,
baseResourceConfig = baseResourceConfig,
)
val maxSublistIndex = min(toIndex, searchResults.size)

if (fromIndex < maxSublistIndex) {
with(searchResults.subList(fromIndex, maxSublistIndex)) {
mapResourceToRepositoryResourceData(
relatedResourcesConfig = relatedResourcesConfig,
configComputedRuleValues = configComputedRuleValues,
secondaryResourceConfigs = secondaryResourceConfigs,
filterActiveResources = filterActiveResources,
baseResourceConfig = baseResourceConfig,
)
}
} else {
emptyList()
}
} else {
searchResults.mapResourceToRepositoryResourceData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.runtime.snapshots.SnapshotStateMap
import com.google.android.fhir.datacapture.extensions.logicalId
import javax.inject.Inject
import org.hl7.fhir.r4.model.Resource
import org.jeasy.rules.api.Facts
import org.smartregister.fhircore.engine.configuration.view.ListProperties
Expand All @@ -29,7 +30,6 @@ import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.domain.model.RuleConfig
import org.smartregister.fhircore.engine.domain.model.ViewType
import org.smartregister.fhircore.engine.util.extension.extractLogicalIdUuid
import javax.inject.Inject

/**
* This class is used to fire rules used to extract and manipulate data from FHIR resources.
Expand Down Expand Up @@ -115,7 +115,7 @@ class ResourceDataRulesExecutor @Inject constructor(val rulesFactory: RulesFacto
this.forEach { baseListResource ->
val relatedResourcesQueue =
ArrayDeque<Pair<Resource, List<ListResourceConfig>>>().apply {
addFirst(Pair(baseListResource, listOf(listResourceConfig)))
addFirst(Pair(baseListResource, listResourceConfig.relatedResources))
}

val listItemRelatedResources = mutableMapOf<String, List<Resource>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ constructor(
relatedResourceKey: String,
referenceFhirPathExpression: String?,
relatedResourcesMap: Map<String, List<Resource>>? = null,
isRevInclude: Boolean = true,
): List<Resource> {
val value: List<Resource> =
relatedResourcesMap?.get(relatedResourceKey)
Expand All @@ -192,14 +193,23 @@ constructor(
emptyList()
}

return if (referenceFhirPathExpression.isNullOrEmpty()) {
value
if (referenceFhirPathExpression.isNullOrEmpty()) {
return value
}

// Reverse search; look for related resource that references the provided resource
return if (isRevInclude) {
value.filter { res ->
fhirPathDataExtractor.extractData(res, referenceFhirPathExpression).all {
resource.logicalId == it.primitiveValue().extractLogicalIdUuid()
}
}
} else {
value.filter {
resource.logicalId ==
fhirPathDataExtractor
.extractValue(it, referenceFhirPathExpression)
.extractLogicalIdUuid()
// Forward search; extract value provided resource, then search resources with matching id
value.filter { res ->
fhirPathDataExtractor.extractData(resource, referenceFhirPathExpression).all {
res.logicalId == it.primitiveValue().extractLogicalIdUuid()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,50 @@ class RegisterRepositoryTest : RobolectricTest() {
}
}

@Ignore("Refactor this test")
@Test
fun countRegisterDataWithParamsAndRelatedEntityLocationFilter() {
runTest {
val paramsList =
arrayListOf(
ActionParameter(
key = "paramsName",
paramType = ActionParameterType.PARAMDATA,
value = "testing1",
dataType = DataType.STRING,
linkId = null,
),
ActionParameter(
key = "paramName2",
paramType = ActionParameterType.PARAMDATA,
value = "testing2",
dataType = DataType.STRING,
linkId = null,
),
)
paramsList
.asSequence()
.filter { it.paramType == ActionParameterType.PARAMDATA && it.value.isNotEmpty() }
.associate { it.key to it.value }
val paramsMap = emptyMap<String, String>()
val searchSlot = slot<Search>()
every {
registerRepository.retrieveRegisterConfiguration(PATIENT_REGISTER, emptyMap())
} returns
RegisterConfiguration(
appId = "app",
id = PATIENT_REGISTER,
fhirResource = fhirResourceConfig(),
filterDataByRelatedEntityLocation = true,
)
coEvery { fhirEngine.count(capture(searchSlot)) } returns 20
val recordsCount =
registerRepository.countRegisterData(registerId = PATIENT_REGISTER, paramsMap = paramsMap)
Assert.assertEquals(ResourceType.Group, searchSlot.captured.type)
Assert.assertEquals(20, recordsCount)
}
}

@Test
fun testLoadRegisterDataWithForwardAndReverseIncludedResources() =
runTest(timeout = 90.seconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import org.smartregister.fhircore.engine.rule.CoroutineTestRule
import org.smartregister.fhircore.engine.rulesengine.services.LocationService
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.extension.SDF_YYYY_MM_DD
import org.smartregister.fhircore.engine.util.extension.asReference
import org.smartregister.fhircore.engine.util.extension.plusYears
import org.smartregister.fhircore.engine.util.fhirpath.FhirPathDataExtractor

Expand Down Expand Up @@ -298,6 +299,29 @@ class RulesFactoryTest : RobolectricTest() {
Assert.assertEquals("careplan-1", result[0].logicalId)
}

@Test
fun retrieveRelatedResourcesReturnsCorrectResourceWithForwardInclude() {
val patient = Faker.buildPatient()
val group =
Group().apply {
id = "grp1"
addMember(
Group.GroupMemberComponent().apply { entity = patient.asReference() },
)
}
populateFactsWithResources(group)
val result =
rulesEngineService.retrieveRelatedResources(
resource = group,
relatedResourceKey = ResourceType.Patient.name,
referenceFhirPathExpression = "Group.member.entity.reference",
isRevInclude = false,
)
Assert.assertEquals(1, result.size)
Assert.assertEquals("Patient", result[0].resourceType.name)
Assert.assertEquals(patient.logicalId, result[0].logicalId)
}

@Test
fun retrieveRelatedResourcesWithoutReferenceReturnsResources() {
populateFactsWithResources()
Expand Down Expand Up @@ -887,13 +911,16 @@ class RulesFactoryTest : RobolectricTest() {
Assert.assertTrue(result.isEmpty())
}

private fun populateFactsWithResources() {
private fun populateFactsWithResources(vararg resource: Resource = emptyArray()) {
val carePlanRelatedResource = mutableListOf(Faker.buildCarePlan())
val patientRelatedResource = mutableListOf(Faker.buildPatient())
val patient = Faker.buildPatient()
val patientRelatedResource = mutableListOf(patient)

val facts = ReflectionHelpers.getField<Facts>(rulesFactory, "facts")
facts.apply {
put(carePlanRelatedResource[0].resourceType.name, carePlanRelatedResource)
put(patientRelatedResource[0].resourceType.name, patientRelatedResource)
resource.forEach { put(it.resourceType.name, it) }
}
ReflectionHelpers.setField(rulesFactory, "facts", facts)
}
Expand Down
4 changes: 2 additions & 2 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ easyRulesCore = "4.1.1-SNAPSHOT"
espresso-core = "3.6.1"
fhir-sdk-contrib-barcode = "0.1.0-beta3-preview7-rc1-SNAPSHOT"
fhir-sdk-contrib-locationwidget = "0.1.0-alpha01-preview2-rc1-SNAPSHOT"
fhir-sdk-data-capture = "1.1.0-preview14-rc3-SNAPSHOT"
fhir-sdk-data-capture = "1.2.0-preview-1-SNAPSHOT"
fhir-sdk-engine = "1.0.0-preview14-rc3-SNAPSHOT"
fhir-sdk-knowledge = "0.1.0-alpha03-preview5-rc1-SNAPSHOT"
fhir-sdk-workflow = "0.1.0-alpha04-preview10-rc1-SNAPSHOT"
Expand All @@ -49,7 +49,7 @@ kotlinx-coroutines = "1.9.0"
kotlinx-serialization-json = "1.6.0"
kt3k-coveralls-ver="2.12.0"
ktlint = "0.50.0"
kujaku-library = "0.10.6-2-SNAPSHOT"
kujaku-library = "0.10.7-SNAPSHOT"
kujaku-mapbox-sdk-turf = "7.2.0"
leakcanary-android = "2.10"
lifecycle= "2.8.5"
Expand Down
15 changes: 11 additions & 4 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,18 @@ android {
manifestPlaceholders["appLabel"] = "PSI WFA"
}

create("eusm") {
create("eusmMg") {
dimension = "apps"
applicationIdSuffix = ".eusm"
versionNameSuffix = "-eusm"
manifestPlaceholders["appLabel"] = "EUSM"
applicationIdSuffix = ".eusmMg"
versionNameSuffix = "-eusmMg"
manifestPlaceholders["appLabel"] = "EUSM Madagascar"
}

create("eusmBi") {
dimension = "apps"
applicationIdSuffix = ".eusmBi"
versionNameSuffix = "-eusmBi"
manifestPlaceholders["appLabel"] = "EUSM Burundi"
}

create("demoEir") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class AppDrawerTest {
appVersionPair = Pair(1, "0.0.1"),
onCountUnSyncedResources = {},
unSyncedResourceCount = remember { mutableIntStateOf(0) },
decodeImage = null,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TopScreenSectionTest {
navController = TestNavHostController(LocalContext.current),
isSearchBarVisible = true,
onClick = {},
decodeImage = null,
)
}

Expand Down Expand Up @@ -83,6 +84,7 @@ class TopScreenSectionTest {
navController = TestNavHostController(LocalContext.current),
isSearchBarVisible = true,
onClick = {},
decodeImage = null,
)
}

Expand Down Expand Up @@ -116,6 +118,7 @@ class TopScreenSectionTest {
navController = TestNavHostController(LocalContext.current),
isSearchBarVisible = true,
onClick = {},
decodeImage = null,
)
}

Expand All @@ -135,6 +138,7 @@ class TopScreenSectionTest {
navController = TestNavHostController(LocalContext.current),
isSearchBarVisible = true,
onClick = {},
decodeImage = null,
)
}
composeTestRule.onNodeWithTag(TRAILING_QR_SCAN_ICON_BUTTON_TEST_TAG).assertDoesNotExist()
Expand All @@ -150,6 +154,7 @@ class TopScreenSectionTest {
navController = TestNavHostController(LocalContext.current),
isSearchBarVisible = true,
onClick = {},
decodeImage = null,
)
}
composeTestRule.onNodeWithTag(TRAILING_QR_SCAN_ICON_BUTTON_TEST_TAG).assertIsDisplayed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class ProfileScreenTest {
ProfileScreen(
navController = rememberNavController(),
profileUiState = profileUiState,
onEvent = {},
snackStateFlow = snackBarStateFlow,
onEvent = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MemberProfileBottomSheetViewTest {
buttonProperties = buttonProperties,
onViewProfile = { /*Do nothing*/},
resourceData = ResourceData("id", ResourceType.Patient, emptyMap()),
decodeImage = null,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class RegisterCardListTest {
registerUiState = RegisterUiState(),
currentPage = mutableStateOf(1),
onSearchByQrSingleResultAction = {},
decodeImage = decodeImage,
)
}

Expand All @@ -85,6 +86,7 @@ class RegisterCardListTest {
registerUiState = RegisterUiState(),
currentPage = mutableStateOf(1),
onSearchByQrSingleResultAction = {},
decodeImage = decodeImage,
)
}

Expand Down Expand Up @@ -117,6 +119,7 @@ class RegisterCardListTest {
currentPage = mutableStateOf(1),
showPagination = true,
onSearchByQrSingleResultAction = {},
decodeImage = decodeImage,
)
}

Expand All @@ -143,6 +146,7 @@ class RegisterCardListTest {
registerUiState = RegisterUiState(),
currentPage = mutableStateOf(1),
onSearchByQrSingleResultAction = {},
decodeImage = decodeImage,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class ActionableButtonTest {
),
resourceData = ResourceData("id", ResourceType.Patient, computedValuesMap),
navController = TestNavHostController(LocalContext.current),
decodeImage = null,
)
}
}
Expand Down
Loading

0 comments on commit 58ec04d

Please sign in to comment.