diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt index 916d625887..337a818cf5 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt @@ -341,24 +341,14 @@ constructor( sectionComponent.focus.hasReferenceElement() && sectionComponent.focus.hasIdentifier() ) { - val referenceResourceType = - sectionComponent.focus.reference.substringBefore(TYPE_REFERENCE_DELIMITER) - val configIdentifier = sectionComponent.focus.identifier.value addBinaryToConfigsJsonMap( - referenceResourceType, - configIdentifier, sectionComponent.focus, configsLoadedCallback, ) } if (sectionComponent.hasEntry() && sectionComponent.entry.isNotEmpty()) { sectionComponent.entry.forEach { entryReference -> - val referenceResourceType = - entryReference.reference.substringBefore(TYPE_REFERENCE_DELIMITER) - val configIdentifier = entryReference.identifier.value addBinaryToConfigsJsonMap( - referenceResourceType, - configIdentifier, entryReference, configsLoadedCallback, ) @@ -370,13 +360,13 @@ constructor( } private suspend fun addBinaryToConfigsJsonMap( - referenceResourceType: String, - configIdentifier: String, entryReference: Reference, configsLoadedCallback: (Boolean) -> Unit, ) { + val configIdentifier = entryReference.identifier.value + val referenceResourceType = entryReference.reference.substringBefore(TYPE_REFERENCE_DELIMITER) if (isAppConfig(referenceResourceType) && !isIconConfig(configIdentifier)) { - val extractedId = entryReference.identifier + val extractedId = entryReference.extractId() try { val configBinary = fhirEngine.get(extractedId.toString()) configsJsonMap[configIdentifier] = configBinary.content.decodeToString() diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt index 4e6f1b6a0e..4a6b7e9b78 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistryTest.kt @@ -1138,6 +1138,10 @@ class ConfigurationRegistryTest : RobolectricTest() { SectionComponent().apply { entry = listOf( + Reference().apply { + reference = "Binary/1" + identifier = Identifier().apply { value = "resource1" } + }, Reference().apply { reference = "Binary/2" identifier = Identifier().apply { value = "resource2" } @@ -1149,7 +1153,8 @@ class ConfigurationRegistryTest : RobolectricTest() { coEvery { fhirEngine.get(any()) } returns Binary().apply { content = ByteArray(0) } configRegistry.populateConfigurationsMap(context, composition, false, "app-id") {} - assertEquals(1, configRegistry.configsJsonMap.size) + assertEquals(2, configRegistry.configsJsonMap.size) + assertTrue(configRegistry.configsJsonMap.containsKey("resource1")) assertTrue(configRegistry.configsJsonMap.containsKey("resource2")) } @@ -1182,57 +1187,4 @@ class ConfigurationRegistryTest : RobolectricTest() { assertTrue(configRegistry.configsJsonMap.containsKey("resource1")) assertTrue(configRegistry.configsJsonMap.containsKey("resource2")) } - - @Test - fun testFetchNonWorkflowConfigResourcesWithAllFocus() = runTest { - val appId = "app-id" - val composition = - Composition().apply { - identifier = Identifier().apply { value = appId } - section = - listOf( - SectionComponent().apply { - focus = - Reference().apply { - identifier = Identifier().apply { value = "focus-1" } - reference = "ResourceType/1" - } - }, - ) - } - - coEvery { fhirResourceDataSource.getResource(any()) } returns - Bundle().apply { addEntry().resource = composition } - - configRegistry.fetchNonWorkflowConfigResources() - } - - @Test - fun testFetchNonWorkflowConfigResourcesWithAllEntry() = runTest { - val appId = "app-id" - val composition = - Composition().apply { - identifier = Identifier().apply { value = appId } - section = - listOf( - SectionComponent().apply { - entry = - listOf( - Reference().apply { - identifier = Identifier().apply { value = "focus-1" } - reference = "ResourceType/1" - }, - ) - }, - ) - } - - coEvery { fhirResourceDataSource.getResource(any()) } returns - Bundle().apply { addEntry().resource = composition } - - // configRegistry.fetchNonWorkflowConfigResources() - configRegistry.populateConfigurationsMap(context, composition, true, "app-id") {} - - assertEquals(1, configRegistry.configsJsonMap.size) - } }