Skip to content
Open
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 @@ -242,6 +242,7 @@ constructor(
*
* [configsLoadedCallback] is a callback function called once configs have been loaded.
*/

suspend fun loadConfigurations(
appId: String,
context: Context,
Expand All @@ -250,10 +251,9 @@ constructor(
// Reset configurations before loading new ones
configCacheMap.clear()

// For appId that ends with suffix /debug e.g. app/debug, we load configurations from assets
// extract appId by removing the suffix e.g. app from above example
val loadFromAssets = appId.endsWith(DEBUG_SUFFIX, ignoreCase = true)
val parsedAppId = appId.substringBefore(TYPE_REFERENCE_DELIMITER).trim()

if (loadFromAssets) {
try {
val localCompositionResource =
Expand Down Expand Up @@ -287,13 +287,29 @@ constructor(
context = context,
)
}

// Additional check: if configs are still empty, treat as missing
if (configCacheMap.isEmpty() && configsJsonMap.isEmpty()) {
Timber.e("No configurations loaded for app ID: $parsedAppId")
withContext(dispatcherProvider.main()) { configsLoadedCallback(false) }
return
}

} catch (fileNotFoundException: FileNotFoundException) {
Timber.e("Missing app configs for app ID: $parsedAppId", fileNotFoundException)
withContext(dispatcherProvider.main()) { configsLoadedCallback(false) }
return // Stop further execution
}

} else {
fhirEngine.searchCompositionByIdentifier(parsedAppId)?.run {
populateConfigurationsMap(context, this, false, parsedAppId, configsLoadedCallback)
val composition = fhirEngine.searchCompositionByIdentifier(parsedAppId)
if (composition != null) {
populateConfigurationsMap(context, composition, false, parsedAppId, configsLoadedCallback)
} else {
// Handle missing remote configuration
Timber.e("No configuration Composition found for app ID: $parsedAppId")
withContext(dispatcherProvider.main()) { configsLoadedCallback(false) }
return
}
}
}
Expand Down