Skip to content

Commit

Permalink
refactor element guards
Browse files Browse the repository at this point in the history
  • Loading branch information
pld committed Dec 21, 2024
1 parent c15c012 commit 29d8973
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,18 @@ constructor(
}
} else {
composition.retrieveCompositionSections().forEach { sectionComponent ->
if (
sectionComponent.hasFocus() &&
sectionComponent.focus.hasReferenceElement() &&
sectionComponent.focus.hasIdentifier()
) {
if (sectionComponent.hasFocus()) {
addBinaryToConfigsJsonMap(
sectionComponent.focus,
configsLoadedCallback,
)
}
if (sectionComponent.hasEntry() && sectionComponent.entry.isNotEmpty()) {
sectionComponent.entry.forEach { entryReference ->
if (entryReference.hasReferenceElement() && entryReference.hasIdentifier()) {
addBinaryToConfigsJsonMap(
entryReference,
configsLoadedCallback,
)
}
addBinaryToConfigsJsonMap(
entryReference,
configsLoadedCallback,
)
}
}
}
Expand All @@ -365,16 +359,18 @@ constructor(
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.extractId()
try {
val configBinary = fhirEngine.get<Binary>(extractedId.toString())
configsJsonMap[configIdentifier] = configBinary.content.decodeToString()
} catch (resourceNotFoundException: ResourceNotFoundException) {
Timber.e("Missing Binary file with ID :$extractedId")
withContext(dispatcherProvider.main()) { configsLoadedCallback(false) }
if (entryReference.hasReferenceElement() && entryReference.hasIdentifier()) {
val configIdentifier = entryReference.identifier.value
val referenceResourceType = entryReference.reference.substringBefore(TYPE_REFERENCE_DELIMITER)
if (isAppConfig(referenceResourceType) && !isIconConfig(configIdentifier)) {
val extractedId = entryReference.extractId()
try {
val configBinary = fhirEngine.get<Binary>(extractedId.toString())
configsJsonMap[configIdentifier] = configBinary.content.decodeToString()
} catch (resourceNotFoundException: ResourceNotFoundException) {
Timber.e("Missing Binary file with ID :$extractedId")

Check warning on line 371 in android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt

View check run for this annotation

Codecov / codecov/patch

android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt#L370-L371

Added lines #L370 - L371 were not covered by tests
withContext(dispatcherProvider.main()) { configsLoadedCallback(false) }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,7 @@ class ConfigurationRegistryTest : RobolectricTest() {
SectionComponent().apply {
entry =
listOf(
Reference().apply {
reference = "Binary/1"
},
Reference().apply { reference = "Binary/1" },
Reference().apply {
reference = "Binary/2"
identifier = Identifier().apply { value = "resource2" }
Expand Down

0 comments on commit 29d8973

Please sign in to comment.