diff --git a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchOrdering.kt b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchOrdering.kt index d0bfb5f364..c03b1cb1be 100644 --- a/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchOrdering.kt +++ b/engine/src/main/java/com/google/android/fhir/sync/upload/patch/PatchOrdering.kt @@ -131,11 +131,11 @@ internal object PatchOrdering { Patch.Type.INSERT, Patch.Type.UPDATE, -> { localChanges.forEach { localChange -> - localChange.token.ids.forEach { id -> - localChangeIdToReferenceMap[id]?.let { - references.addAll(it.map { it.resourceReferenceValue }) + references.addAll( + localChange.token.ids.flatMap { id -> + localChangeIdToReferenceMap[id]?.map { it.resourceReferenceValue } ?: emptyList() } - } + ) } } Patch.Type.DELETE -> {