Skip to content

Commit

Permalink
refactor and fix id fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
pld committed Dec 21, 2024
1 parent d9a0bd5 commit 2c96061
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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<Binary>(extractedId.toString())
configsJsonMap[configIdentifier] = configBinary.content.decodeToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -1149,7 +1153,8 @@ class ConfigurationRegistryTest : RobolectricTest() {

coEvery { fhirEngine.get<Binary>(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"))
}

Expand Down Expand Up @@ -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)
}
}

0 comments on commit 2c96061

Please sign in to comment.